Skip to content

Commit

Permalink
Merge branch '43-save_to_file-will-overwrite-data-from-same-scneario'…
Browse files Browse the repository at this point in the history
… into 'develop'

Include ego vehicle ID in saved file name

Closes #43

See merge request cps/commonroad/commonroad-criticality-measures!44
  • Loading branch information
YuanfeiLin committed May 15, 2024
2 parents 87b1f22 + 4e1fbb1 commit 281cb18
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions commonroad_crime/data_structure/crime_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def visualize(self, time_step: int = None):
if m_evaluator.time_step == time_step:
m_evaluator.visualize()

def safe_to_file(self, output_dir: str):
def save_to_file(self, output_dir: str):
"""
Saves the criticality measures of a scenario to an XML file.
Expand All @@ -141,8 +141,10 @@ def safe_to_file(self, output_dir: str):
Parameters:
output_dir (str): The directory where the XML file will be saved.
The XML file is named using the scenario ID and prefixed with 'CriMe-'. The
file will include pretty-printed XML for better readability.
The XML file is named using the scenario ID with the prefix 'CriMe-'
and the suffix '_veh_123' where 123 is the ID of the vehicle with respect
to which the criticality was computed (ego vehicle).
The file will include pretty-printed XML for better readability.
"""
# Ensure the output directory exists
if not os.path.exists(output_dir):
Expand Down Expand Up @@ -189,7 +191,7 @@ def safe_to_file(self, output_dir: str):
# Save to file
tree = etree.ElementTree(root)
tree.write(
f"{output_dir}/CriMe-{scenario.scenario_id}.xml",
f"{output_dir}/CriMe-{scenario.scenario_id}_veh_{self.config.vehicle.ego_id}.xml",
pretty_print=True,
xml_declaration=True,
encoding="utf-8",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,4 @@ def test_nan_evaluation(self):
"The result should be NaN.",
)

crime_interface.safe_to_file(config.general.path_output)
crime_interface.save_to_file(config.general.path_output)
2 changes: 1 addition & 1 deletion tutorials/evaluate_scenario_I.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def main():
# utils_vis.plot_criticality_curve(crime_interface)

# ==== save data to file
crime_interface.safe_to_file(config.general.path_output)
crime_interface.save_to_file(config.general.path_output)


if __name__ == "__main__":
Expand Down

0 comments on commit 281cb18

Please sign in to comment.