-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A new dynamic_geo_messaging() context was added to provide verbose geo console messaging, for instance when doing a geo.fetch_all(). The sim_messaging() context now has an option to enable verbose geo console messaging (if applicable). Also fixes a minor bug fetching county-level commuter data from ACS Commuter Flows. --------- Co-authored-by: Tyler Coles <tylercoles@gmail.com>
- Loading branch information
1 parent
8afbe52
commit bb83758
Showing
12 changed files
with
414 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,213 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from epymorph.geo.spec import DynamicGeoSpec, AttribDef, CentroidDType, Year\n", | ||
"from epymorph.geo.adrio.census.adrio_census import CensusGeography, Granularity\n", | ||
"from epymorph.data_shape import Shapes\n", | ||
"from pathlib import Path\n", | ||
"import numpy as np\n", | ||
"\n", | ||
"maricopa = DynamicGeoSpec(\n", | ||
" attributes=[\n", | ||
" AttribDef('label', np.str_, Shapes.N),\n", | ||
" AttribDef('geoid', np.str_, Shapes.N),\n", | ||
" AttribDef('centroid', CentroidDType, Shapes.N),\n", | ||
" AttribDef('median_income', np.int64, Shapes.N),\n", | ||
" AttribDef('tract_median_income', np.int64, Shapes.N),\n", | ||
" AttribDef('population', np.int64, Shapes.N),\n", | ||
" AttribDef('population_by_age', np.int64, Shapes.NxA(3)),\n", | ||
" AttribDef('population_by_age_x6', np.int64, Shapes.NxA(6)),\n", | ||
" AttribDef('pop_density_km2', np.float64, Shapes.N),\n", | ||
" AttribDef('median_age', np.int64, Shapes.N),\n", | ||
" AttribDef('average_household_size', np.int64, Shapes.N),\n", | ||
" AttribDef('gini_index', np.float64, Shapes.N)\n", | ||
" ],\n", | ||
" geography=CensusGeography(granularity=Granularity.CBG, filter={\n", | ||
" 'state': ['04'],\n", | ||
" 'county': ['013'],\n", | ||
" 'tract': ['*'],\n", | ||
" 'block group': ['*']\n", | ||
" }),\n", | ||
" time_period=Year(2019),\n", | ||
" source={\n", | ||
" 'label': 'Census:name',\n", | ||
" 'population': 'Census',\n", | ||
" 'geoid': 'Census',\n", | ||
" 'centroid': 'Census',\n", | ||
" 'median_income': 'Census',\n", | ||
" 'tract_median_income': 'Census',\n", | ||
" 'population_by_age': 'Census', \n", | ||
" 'population_by_age_x6': 'Census',\n", | ||
" 'pop_density_km2': 'Census',\n", | ||
" 'median_age': 'Census', \n", | ||
" 'average_household_size': 'Census',\n", | ||
" 'gini_index': 'Census'\n", | ||
" }\n", | ||
" )\n", | ||
"\n", | ||
"json = maricopa.serialize()\n", | ||
"with open(Path('./scratch/geo/maricopa_cbg_2019.geo'), mode='w', encoding='utf-8') as f:\n", | ||
" f.write(json)\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from epymorph.geo.dynamic import DynamicGeoFileOps\n", | ||
"from epymorph.geo.adrio import adrio_maker_library\n", | ||
"\n", | ||
"geo = DynamicGeoFileOps.load_from_spec(Path('./scratch/geo/maricopa_cbg_2019.geo'), adrio_maker_library)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 7, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Fetching dynamic geo data\n", | ||
"• 12 attributes\n", | ||
"Fetching name...[1/12]\n", | ||
"Fetching geoid...[2/12]\n", | ||
"Fetching centroid...[3/12]\n", | ||
"Fetching median_income...[4/12]\n", | ||
"Fetching tract_median_income...[5/12]\n", | ||
"Fetching population...[6/12]\n", | ||
"Fetching population_by_age...[7/12]\n", | ||
"Fetching population_by_age_x6...[8/12]\n", | ||
"Fetching pop_density_km2...[9/12]\n", | ||
"Fetching median_age...[10/12]\n", | ||
"Fetching average_household_size...[11/12]\n", | ||
"Fetching gini_index...[12/12]\n", | ||
"Gini Index cannot be retrieved for block group level, fetching tract level data instead.\n", | ||
"Complete.\n", | ||
"Total fetch time: 27.819s\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"from epymorph.logging.messaging import dynamic_geo_messaging\n", | ||
"\n", | ||
"with dynamic_geo_messaging(geo):\n", | ||
" geo.fetch_all()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 10, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Loading requirements:\n", | ||
"[✓] IPM (sirs)\n", | ||
"[✓] MM (centroids)\n", | ||
"[✓] GEO (us_sw_counties_2015)\n", | ||
"Running simulation (StandardSimulation):\n", | ||
"• 2010-01-01 to 2010-05-31 (150 days)\n", | ||
"• 158 geo nodes\n", | ||
"|####################| 100% \n", | ||
"Runtime: 12.335s\n", | ||
"Done\n" | ||
] | ||
}, | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"0" | ||
] | ||
}, | ||
"execution_count": 10, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"from epymorph.cli.run import run\n", | ||
"\n", | ||
"run(input_path='./scratch/adrio_test.toml',\n", | ||
" out_path=None,\n", | ||
" chart=None,\n", | ||
" profiling=False,\n", | ||
" ignore_cache=False,\n", | ||
" geo_messaging=True\n", | ||
")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 9, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Fetching dynamic geo data\n", | ||
"• 8 attributes\n", | ||
"Fetching name...[1/8]\n", | ||
"Fetching population...[2/8]\n", | ||
"Fetching population_by_age...[3/8]\n", | ||
"Fetching centroid...[4/8]\n", | ||
"Fetching geoid...[5/8]\n", | ||
"Fetching dissimilarity_index...[6/8]\n", | ||
"Fetching median_income...[7/8]\n", | ||
"Fetching pop_density_km2...[8/8]\n", | ||
"Complete.\n", | ||
"Total fetch time: 22.568s\n", | ||
"geo sucessfully cached.\n" | ||
] | ||
}, | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"0" | ||
] | ||
}, | ||
"execution_count": 9, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"from epymorph.cli.cache import fetch\n", | ||
"\n", | ||
"fetch('us_sw_counties_2015', True)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": ".venv", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.11.7" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.