Skip to content

Commit

Permalink
Fix/use display names (#184)
Browse files Browse the repository at this point in the history
* use display name when creating type mapping in AgentData

* fix physicell tests

* add test for using correct display name
  • Loading branch information
blairlyons authored Apr 11, 2024
1 parent fd90e98 commit 1494d22
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
8 changes: 4 additions & 4 deletions simulariumio/data_objects/agent_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,14 @@ def get_type_ids_and_mapping(self) -> Tuple[np.ndarray, Dict[str, Any]]:
tid = last_tid
last_tid += 1
type_id_mapping[type_name] = tid
type_name_mapping[str(tid)] = {"name": type_name}
if type_name not in self.display_data:
raise DataError(
f"Please provide DisplayData for agent type {type_name}"
)
type_name_mapping[str(tid)]["geometry"] = dict(
self.display_data[type_name]
)
type_name_mapping[str(tid)] = {
"name": self.display_data[type_name].name,
"geometry" : dict(self.display_data[type_name])
}
type_ids[time_index][agent_index] = type_id_mapping[type_name]
return type_ids, type_name_mapping

Expand Down
3 changes: 2 additions & 1 deletion simulariumio/physicell/physicell_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def _get_trajectory_data(
last_id=last_id,
type_mapping=type_mapping,
)
if type_mapping[tid] not in input_data.display_data:
if type_mapping[tid] not in result.display_data:
result.display_data[type_mapping[tid]] = DisplayData(
name=type_mapping[tid],
display_type=DISPLAY_TYPE.SPHERE,
Expand Down Expand Up @@ -376,6 +376,7 @@ def _read(
phase_id
)
agent_data.display_data[type_name] = display_data
agent_data.display_data[type_name].name = type_name
input_data.meta_data.scale_factor = scale_factor
input_data.meta_data._set_box_size()
return TrajectoryData(
Expand Down
13 changes: 13 additions & 0 deletions simulariumio/tests/converters/test_trajectory_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,15 @@ def test_camera_defaults(camera, expected_camera):


# test type mapping
test_display_name = "Test display name"
default_agents_converter._data.agent_data.display_data["C"].name = test_display_name
default_agents_data_display_name = JsonWriter.format_trajectory_data(
default_agents_converter._data
)
display_name_type_mapping = minimal_custom_type_mappings()
display_name_type_mapping["0"]["name"] = test_display_name


@pytest.mark.parametrize(
"typeMapping, expected_typeMapping",
[
Expand Down Expand Up @@ -306,6 +315,10 @@ def test_camera_defaults(camera, expected_camera):
},
},
),
(
default_agents_data_display_name["trajectoryInfo"]["typeMapping"],
display_name_type_mapping,
),
],
)
def test_type_mapping(typeMapping, expected_typeMapping):
Expand Down

0 comments on commit 1494d22

Please sign in to comment.