From 07cb55c1cc4ce799455ea46889a0329a0808cd84 Mon Sep 17 00:00:00 2001 From: "Zhenghao (Mark) Peng" Date: Sun, 21 Jan 2024 19:52:57 -0800 Subject: [PATCH] Use the utils from MetaDrive to update object summaries; update ScenarioDescription doc (#52) * Update * update * update * update --- README.md | 5 +++++ documentation/description.rst | 4 +++- scenarionet/converter/utils.py | 14 +++++--------- .../read_established_scenarionet_dataset.ipynb | 16 ++++++++-------- 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 8653965..f98b618 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,11 @@ All operations and API reference is available at our [documentation](https://scenarionet.readthedocs.io/en/latest/operations.html). If you already have ScenarioNet installed, you can check all operations by `python -m scenarionet.list`. +## ScenarioNet dataset and Scenario Description + +Please refer to the [Scenario Description section](https://metadrive-simulator.readthedocs.io/en/latest/scenario_description.html +) in MetaDrive documentation for a walk-through. + ## Citation If you used this project in your research, please cite: diff --git a/documentation/description.rst b/documentation/description.rst index b87533e..5af0838 100644 --- a/documentation/description.rst +++ b/documentation/description.rst @@ -4,4 +4,6 @@ Scenario Description ######################## -Coming soon! @Zhenghao please help this. \ No newline at end of file +Please visit the +`Scenario Description section `_ +in MetaDrive documentation. \ No newline at end of file diff --git a/scenarionet/converter/utils.py b/scenarionet/converter/utils.py index 9a24685..d83c138 100644 --- a/scenarionet/converter/utils.py +++ b/scenarionet/converter/utils.py @@ -224,16 +224,12 @@ def write_to_directory_single_worker( scenario_id = sd_scenario[SD.ID] export_file_name = SD.get_export_file_name(dataset_name, dataset_version, scenario_id) - # add agents summary - summary_dict = {} - for track_id, track in sd_scenario[SD.TRACKS].items(): - summary_dict[track_id] = SD.get_object_summary(state_dict=track, id=track_id) - sd_scenario[SD.METADATA][SD.SUMMARY.OBJECT_SUMMARY] = summary_dict + if hasattr(SD, "update_summaries"): + SD.update_summaries(sd_scenario) + else: + raise ValueError("Please update MetaDrive to latest version.") - # count some objects occurrence - sd_scenario[SD.METADATA][SD.SUMMARY.NUMBER_SUMMARY] = SD.get_number_summary(sd_scenario) - - # update summary/mapping dicy + # update summary/mapping dict if export_file_name in summary: logger.warning("Scenario {} already exists and will be overwritten!".format(export_file_name)) summary[export_file_name] = copy.deepcopy(sd_scenario[SD.METADATA]) diff --git a/tutorial/read_established_scenarionet_dataset.ipynb b/tutorial/read_established_scenarionet_dataset.ipynb index 588a541..0dc2217 100644 --- a/tutorial/read_established_scenarionet_dataset.ipynb +++ b/tutorial/read_established_scenarionet_dataset.ipynb @@ -232,8 +232,8 @@ { "data": { "text/plain": [ - "\u001b[0;31mSignature:\u001b[0m \u001b[0mread_dataset_summary\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdataset_path\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;31mDocstring:\u001b[0m\n", + "\u001B[0;31mSignature:\u001B[0m \u001B[0mread_dataset_summary\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mdataset_path\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n", + "\u001B[0;31mDocstring:\u001B[0m\n", "Read the dataset and return the metadata of each scenario in this dataset.\n", "\n", "Args:\n", @@ -244,8 +244,8 @@ " 1) the summary dict mapping from scenario ID to its metadata,\n", " 2) the list of all scenarios IDs, and\n", " 3) a dict mapping from scenario IDs to the folder that hosts their files.\n", - "\u001b[0;31mFile:\u001b[0m ~/scenarionet/scenarionet/common_utils.py\n", - "\u001b[0;31mType:\u001b[0m function" + "\u001B[0;31mFile:\u001B[0m ~/scenarionet/scenarionet/common_utils.py\n", + "\u001B[0;31mType:\u001B[0m function" ] }, "metadata": {}, @@ -3593,8 +3593,8 @@ { "data": { "text/plain": [ - "\u001b[0;31mSignature:\u001b[0m \u001b[0mread_scenario\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdataset_path\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmapping\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mscenario_file_name\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;31mDocstring:\u001b[0m\n", + "\u001B[0;31mSignature:\u001B[0m \u001B[0mread_scenario\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mdataset_path\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mmapping\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mscenario_file_name\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n", + "\u001B[0;31mDocstring:\u001B[0m\n", "Read a scenario pkl file and return the Scenario Description instance.\n", "\n", "Args:\n", @@ -3604,8 +3604,8 @@ "\n", "Returns:\n", " The Scenario Description instance of that scenario.\n", - "\u001b[0;31mFile:\u001b[0m ~/scenarionet/scenarionet/common_utils.py\n", - "\u001b[0;31mType:\u001b[0m function" + "\u001B[0;31mFile:\u001B[0m ~/scenarionet/scenarionet/common_utils.py\n", + "\u001B[0;31mType:\u001B[0m function" ] }, "metadata": {},