Skip to content

Commit

Permalink
feat: Added metadata saving in PPSimulation_2DContinuous (#105)
Browse files Browse the repository at this point in the history
Fixes #81
  • Loading branch information
Abhinavcode13 authored Jun 17, 2024
1 parent 67afcbc commit 9ce2598
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/polyphy/core/continuous2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from .common import PPSimulation, PPPostSimulation
from utils.gui_helper import GuiHelper
from utils.logger import Logger
from utils.metadata import get_metadata, save_metadata

from PIL import Image

Expand Down Expand Up @@ -252,6 +253,9 @@ def __init__(self, ppInternalData, ppConfig, batch_mode=False, num_iterations=-1
window.show()
if self.do_export:
ppInternalData.store_fit()
# Generate metadata and save
metadata_dict = get_metadata(ppConfig, ppInternalData)
save_metadata(metadata_dict, ppConfig.ppData.ROOT + 'metadata.json')
self.do_export = False
if self.do_quit:
break
Expand Down
26 changes: 26 additions & 0 deletions src/polyphy/utils/metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import json
import os

def get_metadata(ppConfig, ppInternalData):
metadata = {
"_dataset": ppConfig.ppData.input_file,
"number_of_data_points": ppConfig.ppData.data.size,
"number_of_agents": ppConfig.ppData.N_AGENTS,
"simulation_grid_resolution": f"{ppConfig.TRACE_RESOLUTION[0]} x {ppConfig.TRACE_RESOLUTION[1]} [vox]",
"simulation_grid_size": f"{ppConfig.ppData.DOMAIN_SIZE[0]} x {ppConfig.ppData.DOMAIN_SIZE[1]} [mpc]",
"simulation_grid_center": f"({ppConfig.ppData.DOMAIN_SIZE[0] / 2}, {ppConfig.ppData.DOMAIN_SIZE[1] / 2}) [mpc]",
"move_distance": ppConfig.step_size,
"move_distance_grid": ppConfig.step_size / ppConfig.ppData.DOMAIN_SIZE[0] * ppConfig.TRACE_RESOLUTION[0],
"sense_distance": ppConfig.sense_distance,
"sense_distance_grid": ppConfig.sense_distance / ppConfig.ppData.DOMAIN_SIZE[0] * ppConfig.TRACE_RESOLUTION[0],
"move_spread": ppConfig.steering_rate,
"sense_spread": ppConfig.sense_angle,
"persistence_coefficient": ppConfig.sampling_exponent,
"agent_deposit": ppConfig.agent_deposit,
"sampling_sharpness": ppConfig.data_deposit
}
return metadata

def save_metadata(metadata, filename='metadata.json'):
with open(filename, 'w') as f:
json.dump(metadata, f, indent=4)

0 comments on commit 9ce2598

Please sign in to comment.