Skip to content

Commit

Permalink
Add additional metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
cthoyt committed Feb 26, 2024
1 parent 5353a43 commit 5b93cbe
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 76 deletions.
129 changes: 60 additions & 69 deletions notebooks/hackathon_2024.02/scenario5/Scenario 5 Notebook.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,43 @@
{
"cell_type": "code",
"execution_count": 1,
"id": "35aa5832-57f4-4a43-b3e0-3fd1db9c076d",
"id": "43e48670-9138-4ccf-8555-0086e0c8db19",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"from mira.modeling import Concept, TemplateModel, Annotations\n",
"from mira.sources.system_dynamics.vensim import template_model_from_mdl_url, template_model_from_mdl_file\n",
"from mira.modeling.amr.stockflow import template_model_to_stockflow_json\n",
"import os\n",
"import json\n",
"from pathlib import Path"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "dfeba82a-d808-4316-8909-c399a2697771",
"metadata": {},
"outputs": [],
"source": [
"HERE = Path(\".\").resolve()"
]
},
{
"cell_type": "markdown",
"id": "d7e0c90d-d4e2-4450-b1bd-809ebcf860a6",
"metadata": {},
"source": [
"## Grounding Map\n",
"\n",
"Load a custom grounding map, which lets us assign identifiers and contexts to most of the compartments."
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "3229560d-21d1-4fde-a16a-8b3a37f3111f",
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -216,53 +252,22 @@
"18 hospitalization=ncit:C25179/Hospitalization|pa... "
]
},
"execution_count": 1,
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import pandas as pd\n",
"from mira.modeling import Concept, TemplateModel\n",
"\n",
"grounding_map_df = pd.read_csv(\"grounding_map.csv\")\n",
"grounding_map_df"
]
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 4,
"id": "8e25ef6b-5b47-47bc-8262-c86edc1b0bce",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'susceptibles': Concept(name='susceptible population', display_name='susceptibles', description=None, identifiers={'ido': '0000514'}, context={}, units=None),\n",
" 'exposed': Concept(name='exposed population', display_name='exposed', description=None, identifiers={'apollosv': '00000154'}, context={}, units=None),\n",
" 'cumulative_cases_reported': Concept(name='Number of Cases', display_name='cumulative_cases_reported', description=None, identifiers={'ncit': 'C175885'}, context={}, units=None),\n",
" 'infectious_asymptomatic': Concept(name='infected population', display_name='infectious_asymptomatic', description=None, identifiers={'ido': '0000511'}, context={}, units=None),\n",
" 'dead': Concept(name='Dead', display_name='dead', description=None, identifiers={'ncit': 'C28554'}, context={}, units=None),\n",
" 'isolated_asymptomatic': Concept(name='infected population', display_name='isolated_asymptomatic', description=None, identifiers={'ido': '0000511'}, context={}, units=None),\n",
" 'quarantined_asymptomatic': Concept(name='infected population', display_name='quarantined_asymptomatic', description=None, identifiers={'ido': '0000511'}, context={}, units=None),\n",
" 'recovered_asympotmatic': Concept(name='immune population', display_name='recovered_asympotmatic', description=None, identifiers={'ido': '0000592'}, context={}, units=None),\n",
" 'isolated_symptomatic_mild': Concept(name='infected population', display_name='isolated_symptomatic_mild', description=None, identifiers={'ido': '0000511'}, context={}, units=None),\n",
" 'recovered_isolated_symptomatic_mild': Concept(name='immune population', display_name='recovered_isolated_symptomatic_mild', description=None, identifiers={'ido': '0000592'}, context={}, units=None),\n",
" 'infectious_symptomatic_mild': Concept(name='infected population', display_name='infectious_symptomatic_mild', description=None, identifiers={'ido': '0000511'}, context={}, units=None),\n",
" 'quarantined_symptomatic_mild': Concept(name='infected population', display_name='quarantined_symptomatic_mild', description=None, identifiers={'ido': '0000511'}, context={}, units=None),\n",
" 'recovered_mild': Concept(name='immune population', display_name='recovered_mild', description=None, identifiers={'ido': '0000592'}, context={}, units=None),\n",
" 'infected_symptomatic_hospital_overflow': Concept(name='infected population', display_name='infected_symptomatic_hospital_overflow', description=None, identifiers={'ido': '0000511'}, context={}, units=None),\n",
" 'infected_symptomatic_serious_hospital': Concept(name='infected population', display_name='infected_symptomatic_serious_hospital', description=None, identifiers={'ido': '0000511'}, context={}, units=None),\n",
" 'infected_symptomatic_icu_overflow': Concept(name='infected population', display_name='infected_symptomatic_icu_overflow', description=None, identifiers={'ido': '0000511'}, context={}, units=None),\n",
" 'intensive_sympotmatic_extreme_icu': Concept(name='infected population', display_name='intensive_sympotmatic_extreme_icu', description=None, identifiers={'ido': '0000511'}, context={}, units=None),\n",
" 'recovered_from_hospital': Concept(name='immune population', display_name='recovered_from_hospital', description=None, identifiers={'ido': '0000592'}, context={}, units=None)}"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"def curie_to_identifiers(curie):\n",
" prefix, identifier = curie.split(\":\")\n",
Expand All @@ -288,24 +293,7 @@
" display_name=display_name,\n",
" identifiers=curie_to_identifiers(curie),\n",
" context=context,\n",
" )\n",
"\n",
"grounding_map"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "576f0178-38e0-40e2-a306-e3248b790239",
"metadata": {},
"outputs": [],
"source": [
"from mira.sources.system_dynamics.vensim import template_model_from_mdl_url, template_model_from_mdl_file\n",
"from mira.modeling.amr.stockflow import template_model_to_stockflow_json\n",
"import os\n",
"import json\n",
"from pathlib import Path\n",
"HERE = Path(\".\").resolve()"
" )"
]
},
{
Expand All @@ -318,7 +306,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 5,
"id": "943251a0-4d0d-4398-9042-37faa48631af",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -356,7 +344,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 6,
"id": "8842160b-aa59-40e5-b24b-d3085e05c755",
"metadata": {},
"outputs": [
Expand All @@ -367,7 +355,7 @@
"<IPython.core.display.Image object>"
]
},
"execution_count": 5,
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -386,7 +374,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 7,
"id": "65a32653-dab6-4d3b-8986-1a5e15b3d1d7",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -493,7 +481,7 @@
"[134 rows x 2 columns]"
]
},
"execution_count": 6,
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -518,7 +506,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 8,
"id": "a52c41fe-d9c7-4664-91f6-732f2f201818",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -742,7 +730,7 @@
"30 31 0"
]
},
"execution_count": 7,
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -765,16 +753,16 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 9,
"id": "e4b46435-01b1-4c90-9eb4-9cb9e98a4a88",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'header': {'name': 'SIR Model',\n",
" 'schema': '',\n",
" 'description': 'SIR Model',\n",
"{'header': {'name': 'February 2024 Hackathon - Scenario 5',\n",
" 'schema': 'https://raw.githubusercontent.com/DARPA-ASKEM/Model-Representations/stockflow_v0.1/stockflow/stockflow_schema.json',\n",
" 'description': 'February 2024 Hackathon - Scenario 5',\n",
" 'schema_name': 'stockflow',\n",
" 'model_version': '0.1'},\n",
" 'properties': {},\n",
Expand Down Expand Up @@ -1074,16 +1062,16 @@
" 'expression': 'q_disease_progress_rate',\n",
" 'expression_mathml': '<ci>q_disease_progress_rate</ci>'}],\n",
" 'links': [{'id': 'link1',\n",
" 'source': 'disease_progression',\n",
" 'source': 'isolation_rate_asym',\n",
" 'target': 'flow1'},\n",
" {'id': 'link2', 'source': 'isolation_rate_sym', 'target': 'flow1'},\n",
" {'id': 'link3', 'source': 'q_disease_progress_rate', 'target': 'flow1'},\n",
" {'id': 'link4', 'source': 'isolation_rate_asym', 'target': 'flow1'},\n",
" {'id': 'link4', 'source': 'disease_progression', 'target': 'flow1'},\n",
" {'id': 'link5',\n",
" 'source': 'contacts_total_per_susceptible',\n",
" 'target': 'flow4'},\n",
" {'id': 'link6', 'source': 'susceptibles', 'target': 'flow4'},\n",
" {'id': 'link7', 'source': 'infectivity', 'target': 'flow4'}]},\n",
" {'id': 'link6', 'source': 'infectivity', 'target': 'flow4'},\n",
" {'id': 'link7', 'source': 'susceptibles', 'target': 'flow4'}]},\n",
" 'semantics': {'ode': {'parameters': [{'id': 'disease_progression',\n",
" 'value': 0.0,\n",
" 'units': {'expression': 'person/day',\n",
Expand Down Expand Up @@ -1300,14 +1288,17 @@
" 'metadata': {}}"
]
},
"execution_count": 8,
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# FIXME need to get header information in there correctly\n",
"\n",
"annotations = Annotations(name=\"February 2024 Hackathon - Scenario 5\")\n",
"tm.annotations = annotations\n",
"\n",
"amr = template_model_to_stockflow_json(tm)\n",
"HERE.joinpath(\"scenario_5_stockflow.json\").write_text(json.dumps(amr, indent=2))\n",
"amr"
Expand Down
14 changes: 7 additions & 7 deletions notebooks/hackathon_2024.02/scenario5/scenario_5_stockflow.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"header": {
"name": "SIR Model",
"schema": "",
"description": "SIR Model",
"name": "February 2024 Hackathon - Scenario 5",
"schema": "https://raw.githubusercontent.com/DARPA-ASKEM/Model-Representations/stockflow_v0.1/stockflow/stockflow_schema.json",
"description": "February 2024 Hackathon - Scenario 5",
"schema_name": "stockflow",
"model_version": "0.1"
},
Expand Down Expand Up @@ -527,7 +527,7 @@
"links": [
{
"id": "link1",
"source": "disease_progression",
"source": "isolation_rate_asym",
"target": "flow1"
},
{
Expand All @@ -542,7 +542,7 @@
},
{
"id": "link4",
"source": "isolation_rate_asym",
"source": "disease_progression",
"target": "flow1"
},
{
Expand All @@ -552,12 +552,12 @@
},
{
"id": "link6",
"source": "susceptibles",
"source": "infectivity",
"target": "flow4"
},
{
"id": "link7",
"source": "infectivity",
"source": "susceptibles",
"target": "flow4"
}
]
Expand Down

0 comments on commit 5b93cbe

Please sign in to comment.