epymorph 1.0.0b0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- epymorph/__init__.py +7 -0
- epymorph/__main__.py +16 -0
- epymorph/adrio/__init__.py +0 -0
- epymorph/adrio/acs5.py +602 -0
- epymorph/adrio/adrio.py +215 -0
- epymorph/adrio/cdc.py +781 -0
- epymorph/adrio/commuting_flows.py +237 -0
- epymorph/adrio/csv.py +387 -0
- epymorph/adrio/humidity.py +84 -0
- epymorph/adrio/lodes.py +624 -0
- epymorph/adrio/numpy.py +119 -0
- epymorph/adrio/prism.py +543 -0
- epymorph/adrio/respiratory_cdc.py +489 -0
- epymorph/adrio/us_tiger.py +217 -0
- epymorph/attribute.py +301 -0
- epymorph/cache.py +494 -0
- epymorph/cli/__init__.py +0 -0
- epymorph/cli/cache.py +77 -0
- epymorph/cli/main.py +29 -0
- epymorph/compartment_model.py +1335 -0
- epymorph/data/__init__.py +1 -0
- epymorph/data/ipm/__init__.py +22 -0
- epymorph/data/ipm/no.py +14 -0
- epymorph/data/ipm/pei.py +40 -0
- epymorph/data/ipm/seirs.py +50 -0
- epymorph/data/ipm/sirh.py +55 -0
- epymorph/data/ipm/sirs.py +48 -0
- epymorph/data/ipm/sparsemod.py +96 -0
- epymorph/data/mm/__init__.py +22 -0
- epymorph/data/mm/centroids.py +76 -0
- epymorph/data/mm/flat.py +61 -0
- epymorph/data/mm/icecube.py +50 -0
- epymorph/data/mm/no.py +29 -0
- epymorph/data/mm/pei.py +105 -0
- epymorph/data/mm/sparsemod.py +73 -0
- epymorph/data/pei.py +424 -0
- epymorph/data_shape.py +475 -0
- epymorph/data_type.py +129 -0
- epymorph/data_usage.py +171 -0
- epymorph/database.py +1010 -0
- epymorph/error.py +183 -0
- epymorph/event.py +188 -0
- epymorph/geography/__init__.py +0 -0
- epymorph/geography/custom.py +61 -0
- epymorph/geography/scope.py +214 -0
- epymorph/geography/us_census.py +622 -0
- epymorph/geography/us_geography.py +278 -0
- epymorph/geography/us_tiger.py +755 -0
- epymorph/initializer.py +596 -0
- epymorph/kit.py +90 -0
- epymorph/log/__init__.py +0 -0
- epymorph/log/file.py +108 -0
- epymorph/log/messaging.py +129 -0
- epymorph/log/movement.py +151 -0
- epymorph/movement_model.py +274 -0
- epymorph/parameter_fitting/__init__.py +0 -0
- epymorph/parameter_fitting/distribution.py +68 -0
- epymorph/parameter_fitting/dynamics.py +19 -0
- epymorph/parameter_fitting/filter/__init__.py +0 -0
- epymorph/parameter_fitting/filter/base_filter.py +50 -0
- epymorph/parameter_fitting/filter/particle.py +32 -0
- epymorph/parameter_fitting/filter/particle_filter.py +296 -0
- epymorph/parameter_fitting/likelihood.py +54 -0
- epymorph/parameter_fitting/output.py +73 -0
- epymorph/parameter_fitting/particlefilter_simulation.py +175 -0
- epymorph/parameter_fitting/perturbation.py +19 -0
- epymorph/parameter_fitting/utils/__init__.py +0 -0
- epymorph/parameter_fitting/utils/data_loader.py +111 -0
- epymorph/parameter_fitting/utils/epymorph_simulation.py +119 -0
- epymorph/parameter_fitting/utils/observations.py +63 -0
- epymorph/parameter_fitting/utils/parameter_estimation.py +49 -0
- epymorph/parameter_fitting/utils/params_perturb.py +43 -0
- epymorph/parameter_fitting/utils/particle_initializer.py +95 -0
- epymorph/parameter_fitting/utils/resampler.py +249 -0
- epymorph/parameter_fitting/utils/utils.py +101 -0
- epymorph/params.py +248 -0
- epymorph/py.typed +0 -0
- epymorph/rume.py +700 -0
- epymorph/simulation.py +706 -0
- epymorph/simulator/__init__.py +0 -0
- epymorph/simulator/basic/__init__.py +0 -0
- epymorph/simulator/basic/basic_simulator.py +145 -0
- epymorph/simulator/basic/ipm_exec.py +406 -0
- epymorph/simulator/basic/mm_exec.py +197 -0
- epymorph/simulator/basic/output.py +181 -0
- epymorph/simulator/world.py +83 -0
- epymorph/simulator/world_list.py +196 -0
- epymorph/strata.py +12 -0
- epymorph/sympy_shim.py +55 -0
- epymorph/time.py +649 -0
- epymorph/tools/__init__.py +0 -0
- epymorph/tools/data.py +218 -0
- epymorph/tools/ipm_diagram.py +165 -0
- epymorph/tools/out_map.py +426 -0
- epymorph/tools/out_plot.py +412 -0
- epymorph/tools/out_table.py +575 -0
- epymorph/util.py +825 -0
- epymorph-1.0.0b0.dist-info/METADATA +57 -0
- epymorph-1.0.0b0.dist-info/RECORD +102 -0
- epymorph-1.0.0b0.dist-info/WHEEL +5 -0
- epymorph-1.0.0b0.dist-info/entry_points.txt +2 -0
- epymorph-1.0.0b0.dist-info/top_level.txt +1 -0
epymorph/adrio/lodes.py
ADDED
|
@@ -0,0 +1,624 @@
|
|
|
1
|
+
"""ADRIOs that access the US Census LODES files for commuting data."""
|
|
2
|
+
|
|
3
|
+
from abc import ABC
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Literal
|
|
6
|
+
|
|
7
|
+
import numpy as np
|
|
8
|
+
import pandas as pd
|
|
9
|
+
from numpy.typing import NDArray
|
|
10
|
+
from typing_extensions import override
|
|
11
|
+
|
|
12
|
+
from epymorph.adrio.adrio import ADRIO, ProgressCallback, adrio_cache
|
|
13
|
+
from epymorph.cache import check_file_in_cache, load_or_fetch_url, module_cache_path
|
|
14
|
+
from epymorph.data_usage import AvailableDataEstimate, DataEstimate
|
|
15
|
+
from epymorph.error import DataResourceError
|
|
16
|
+
from epymorph.geography.scope import GeoScope
|
|
17
|
+
from epymorph.geography.us_census import CensusScope
|
|
18
|
+
from epymorph.geography.us_geography import STATE
|
|
19
|
+
from epymorph.geography.us_tiger import CacheEstimate, get_states
|
|
20
|
+
|
|
21
|
+
_LODES_CACHE_PATH = module_cache_path(__name__)
|
|
22
|
+
|
|
23
|
+
_LODES_VERSION = "LODES8"
|
|
24
|
+
"""The current version of LODES"""
|
|
25
|
+
|
|
26
|
+
JobType = Literal[
|
|
27
|
+
"All Jobs",
|
|
28
|
+
"Primary Jobs",
|
|
29
|
+
"All Private Jobs",
|
|
30
|
+
"Private Primary Jobs",
|
|
31
|
+
"All Federal Jobs",
|
|
32
|
+
"Federal Primary Jobs",
|
|
33
|
+
]
|
|
34
|
+
"""Job type variables for use among all commuters classes"""
|
|
35
|
+
|
|
36
|
+
_JOB_VARIABLES: dict[JobType, str] = {
|
|
37
|
+
"All Jobs": "JT00",
|
|
38
|
+
"Primary Jobs": "JT01",
|
|
39
|
+
"All Private Jobs": "JT02",
|
|
40
|
+
"Private Primary Jobs": "JT03",
|
|
41
|
+
"All Federal Jobs": "JT04",
|
|
42
|
+
"Federal Primary Jobs": "JT05",
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
_STATE_FILE_ESTIMATES = {
|
|
46
|
+
"ak": 970_000,
|
|
47
|
+
"al": 8_300_000,
|
|
48
|
+
"ar": 4_400_000,
|
|
49
|
+
"az": 11_500_000,
|
|
50
|
+
"ca": 72_300_000,
|
|
51
|
+
"co": 10_600_000,
|
|
52
|
+
"ct": 6_500_000,
|
|
53
|
+
"dc": 719_000,
|
|
54
|
+
"de": 1_400_000,
|
|
55
|
+
"fl": 36_700_000,
|
|
56
|
+
"ga": 17_900_000,
|
|
57
|
+
"hi": 1_900_000,
|
|
58
|
+
"ia": 6_200_000,
|
|
59
|
+
"id": 2_700_000,
|
|
60
|
+
"il": 26_000_000,
|
|
61
|
+
"in": 12_800_000,
|
|
62
|
+
"ks": 5_200_000,
|
|
63
|
+
"ky": 7_200_000,
|
|
64
|
+
"la": 8_100_000,
|
|
65
|
+
"ma": 8_200_000,
|
|
66
|
+
"md": 9_900_000,
|
|
67
|
+
"me": 2_400_000,
|
|
68
|
+
"mi": 18_820_000,
|
|
69
|
+
"mn": 11_300_000,
|
|
70
|
+
"mo": 11_300_000,
|
|
71
|
+
"ms": 4_400_000,
|
|
72
|
+
"mt": 1_800_000,
|
|
73
|
+
"nc": 18_200_000,
|
|
74
|
+
"nd": 1_400_000,
|
|
75
|
+
"ne": 3_800_000,
|
|
76
|
+
"nh": 2_300_000,
|
|
77
|
+
"nj": 16_400_000,
|
|
78
|
+
"nm": 3_100_000,
|
|
79
|
+
"nv": 4_700_000,
|
|
80
|
+
"ny": 35_200_000,
|
|
81
|
+
"oh": 23_500_000,
|
|
82
|
+
"ok": 6_700_000,
|
|
83
|
+
"or": 7_300_000,
|
|
84
|
+
"pa": 25_100_000,
|
|
85
|
+
"ri": 1_900_000,
|
|
86
|
+
"sc": 8_100_000,
|
|
87
|
+
"sd": 1_500_000,
|
|
88
|
+
"tn": 11_400_000,
|
|
89
|
+
"tx": 50_300_000,
|
|
90
|
+
"ut": 5_400_000,
|
|
91
|
+
"va": 14_600_000,
|
|
92
|
+
"vt": 1_080_000,
|
|
93
|
+
"wa": 12_500_000,
|
|
94
|
+
"wi": 11_700_000,
|
|
95
|
+
"wv": 2_600_000,
|
|
96
|
+
"wy": 972_000,
|
|
97
|
+
}
|
|
98
|
+
"""File estimates for JT00-JT03 main files"""
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
# function for creating the urls
|
|
102
|
+
def _generate_lodes_file_name(
|
|
103
|
+
state: str, job_type: str, year: int, file_type: str
|
|
104
|
+
) -> tuple[str, str]:
|
|
105
|
+
url_aux = ""
|
|
106
|
+
url_main = f"https://lehd.ces.census.gov/data/lodes/{_LODES_VERSION}/{state}/od/{state}_od_main_{job_type}_{year}.csv.gz"
|
|
107
|
+
|
|
108
|
+
# if there are more than one state in the input,
|
|
109
|
+
# get the aux files (out of state residence)
|
|
110
|
+
if file_type == "aux":
|
|
111
|
+
url_aux = f"https://lehd.ces.census.gov/data/lodes/{_LODES_VERSION}/{state}/od/{state}_od_{file_type}_{job_type}_{year}.csv.gz"
|
|
112
|
+
|
|
113
|
+
return url_aux, url_main
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def _fetch_lodes(
|
|
117
|
+
scope: CensusScope,
|
|
118
|
+
worker_type: str,
|
|
119
|
+
job_type: str,
|
|
120
|
+
year: int,
|
|
121
|
+
progress: ProgressCallback,
|
|
122
|
+
) -> NDArray[np.int64]:
|
|
123
|
+
"""Fetches data from LODES commuting flow data for a given year"""
|
|
124
|
+
|
|
125
|
+
# check for valid year input
|
|
126
|
+
if year not in range(2002, 2022):
|
|
127
|
+
msg = "Invalid year. LODES data is only available for 2002-2021"
|
|
128
|
+
raise DataResourceError(msg)
|
|
129
|
+
|
|
130
|
+
# file type is main (residence in state only) by default
|
|
131
|
+
file_type = "main"
|
|
132
|
+
|
|
133
|
+
# initialize variables
|
|
134
|
+
aggregated_data = None
|
|
135
|
+
geoid = scope.node_ids
|
|
136
|
+
n_geocode = len(geoid)
|
|
137
|
+
geocode_to_index = {geocode: i for i, geocode in enumerate(geoid)}
|
|
138
|
+
geocode_len = len(geoid[0])
|
|
139
|
+
data_frames = []
|
|
140
|
+
|
|
141
|
+
if scope.granularity != "state":
|
|
142
|
+
states = list(STATE.truncate_unique(geoid))
|
|
143
|
+
else:
|
|
144
|
+
states = geoid
|
|
145
|
+
|
|
146
|
+
# check for multiple states
|
|
147
|
+
if len(states) > 1:
|
|
148
|
+
file_type = "aux"
|
|
149
|
+
|
|
150
|
+
# no federal jobs in given years
|
|
151
|
+
if year in range(2002, 2010) and (job_type == "JT04" or job_type == "JT05"):
|
|
152
|
+
msg = (
|
|
153
|
+
"Invalid year for job type, no federal jobs can be found "
|
|
154
|
+
"between 2002 to 2009"
|
|
155
|
+
)
|
|
156
|
+
raise DataResourceError(msg)
|
|
157
|
+
|
|
158
|
+
# LODES year and state exceptions
|
|
159
|
+
# exceptions can be found in this document for LODES8.1: https://lehd.ces.census.gov/data/lodes/LODES8/LODESTechDoc8.1.pdf
|
|
160
|
+
invalid_conditions = [
|
|
161
|
+
(
|
|
162
|
+
year in range(2002, 2010) and (job_type == "JT04" or job_type == "JT05"),
|
|
163
|
+
"Invalid year for job type, no federal jobs can be found "
|
|
164
|
+
"between 2002 to 2009",
|
|
165
|
+
),
|
|
166
|
+
(
|
|
167
|
+
("05" in states) and (year == 2002 or year in range(2019, 2022)),
|
|
168
|
+
"Invalid year for state, no commuters can be found "
|
|
169
|
+
"for Arkansas in 2002 or between 2019-2021",
|
|
170
|
+
),
|
|
171
|
+
(
|
|
172
|
+
("04" in states) and (year == 2002 or year == 2003),
|
|
173
|
+
"Invalid year for state, no commuters can be found "
|
|
174
|
+
"for Arizona in 2002 or 2003",
|
|
175
|
+
),
|
|
176
|
+
(
|
|
177
|
+
("11" in states) and (year in range(2002, 2010)),
|
|
178
|
+
"Invalid year for state, no commuters can be found "
|
|
179
|
+
"for DC in 2002 or between 2002-2009",
|
|
180
|
+
),
|
|
181
|
+
(
|
|
182
|
+
("25" in states) and (year in range(2002, 2011)),
|
|
183
|
+
"Invalid year for state, no commuters can be found "
|
|
184
|
+
"for Massachusetts between 2002-2010",
|
|
185
|
+
),
|
|
186
|
+
(
|
|
187
|
+
("28" in states)
|
|
188
|
+
and (year in range(2002, 2004) or year in range(2019, 2022)),
|
|
189
|
+
"Invalid year for state, no commuters can be found "
|
|
190
|
+
"for Mississippi in 2002, 2003, or between 2019-2021",
|
|
191
|
+
),
|
|
192
|
+
(
|
|
193
|
+
("33" in states) and year == 2002,
|
|
194
|
+
"Invalid year for state, no commuters can be found "
|
|
195
|
+
"for New Hampshire in 2002",
|
|
196
|
+
),
|
|
197
|
+
(
|
|
198
|
+
("02" in states) and year in range(2017, 2022),
|
|
199
|
+
"Invalid year for state, no commuters can be found "
|
|
200
|
+
"for Alaska in between 2017-2021",
|
|
201
|
+
),
|
|
202
|
+
]
|
|
203
|
+
for condition, message in invalid_conditions:
|
|
204
|
+
if condition:
|
|
205
|
+
raise DataResourceError(message)
|
|
206
|
+
|
|
207
|
+
# translate state FIPS code to state to use in URL
|
|
208
|
+
state_codes = get_states(scope.year).state_fips_to_code
|
|
209
|
+
state_abbreviations = [state_codes.get(fips, "").lower() for fips in states]
|
|
210
|
+
|
|
211
|
+
# start progress tracking
|
|
212
|
+
processing_steps = len(state_abbreviations) + 1
|
|
213
|
+
|
|
214
|
+
for i, state in enumerate(state_abbreviations):
|
|
215
|
+
# construct list of urls to fetch LODES data
|
|
216
|
+
url_list = []
|
|
217
|
+
url_aux, url_main = _generate_lodes_file_name(state, job_type, year, file_type)
|
|
218
|
+
|
|
219
|
+
if url_aux:
|
|
220
|
+
url_list.append(url_aux)
|
|
221
|
+
url_list.append(url_main)
|
|
222
|
+
|
|
223
|
+
try:
|
|
224
|
+
files = [
|
|
225
|
+
load_or_fetch_url(u, _LODES_CACHE_PATH / Path(u).name) for u in url_list
|
|
226
|
+
]
|
|
227
|
+
except Exception as e:
|
|
228
|
+
raise DataResourceError("Unable to fetch LODES data.") from e
|
|
229
|
+
|
|
230
|
+
# progress tracking here accounts for downloading aux and main files as one step
|
|
231
|
+
# since they are being downloaded one right after the other
|
|
232
|
+
if progress is not None:
|
|
233
|
+
progress((i + 1) / processing_steps, None)
|
|
234
|
+
|
|
235
|
+
unfiltered_df = [
|
|
236
|
+
pd.read_csv(
|
|
237
|
+
file,
|
|
238
|
+
compression="gzip",
|
|
239
|
+
converters={"w_geocode": str, "h_geocode": str},
|
|
240
|
+
)
|
|
241
|
+
for file in files
|
|
242
|
+
]
|
|
243
|
+
|
|
244
|
+
# go through dataframes, multiple if there are main and aux files
|
|
245
|
+
for df in unfiltered_df:
|
|
246
|
+
# filter the rows on if they start with the prefix
|
|
247
|
+
filtered_rows = [
|
|
248
|
+
df[
|
|
249
|
+
df["h_geocode"].str.startswith(tuple(geoid))
|
|
250
|
+
& df["w_geocode"].str.startswith(tuple(geoid))
|
|
251
|
+
]
|
|
252
|
+
]
|
|
253
|
+
|
|
254
|
+
# add the filtered dataframe to the list of dataframes
|
|
255
|
+
data_frames.append(pd.concat(filtered_rows))
|
|
256
|
+
|
|
257
|
+
for data_df in data_frames:
|
|
258
|
+
# convert w_geocode and h_geocode to strings
|
|
259
|
+
data_df["w_geocode"] = data_df["w_geocode"].astype(str)
|
|
260
|
+
data_df["h_geocode"] = data_df["h_geocode"].astype(str)
|
|
261
|
+
|
|
262
|
+
# group by w_geocode and h_geocode and sum the worker values
|
|
263
|
+
grouped_data = data_df.groupby(
|
|
264
|
+
[
|
|
265
|
+
data_df["w_geocode"].str[:geocode_len],
|
|
266
|
+
data_df["h_geocode"].str[:geocode_len],
|
|
267
|
+
]
|
|
268
|
+
)[worker_type].sum()
|
|
269
|
+
|
|
270
|
+
if aggregated_data is None:
|
|
271
|
+
aggregated_data = grouped_data
|
|
272
|
+
else:
|
|
273
|
+
aggregated_data = aggregated_data.add(grouped_data, fill_value=0)
|
|
274
|
+
|
|
275
|
+
# create an empty array to store worker type values
|
|
276
|
+
output = np.zeros((n_geocode, n_geocode), dtype=np.int64)
|
|
277
|
+
|
|
278
|
+
# loop through all of the grouped values and add to output
|
|
279
|
+
for (w_geocode, h_geocode), value in aggregated_data.items(): # type: ignore
|
|
280
|
+
w_index = geocode_to_index.get(w_geocode)
|
|
281
|
+
h_index = geocode_to_index.get(h_geocode)
|
|
282
|
+
output[h_index, w_index] += value
|
|
283
|
+
|
|
284
|
+
return output
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
def _validate_scope(scope: GeoScope) -> CensusScope:
|
|
288
|
+
if not isinstance(scope, CensusScope):
|
|
289
|
+
msg = "Census scope is required for LODES attributes."
|
|
290
|
+
raise DataResourceError(msg)
|
|
291
|
+
|
|
292
|
+
# check if the CensusScope year is the current LODES geography: 2020
|
|
293
|
+
if scope.year != 2020:
|
|
294
|
+
msg = "GeoScope year does not match the LODES geography year."
|
|
295
|
+
raise DataResourceError(msg)
|
|
296
|
+
|
|
297
|
+
return scope
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
def _estimate_lodes(self, scope: CensusScope, job_type: str, year: int) -> DataEstimate:
|
|
301
|
+
scope = _validate_scope(self.scope)
|
|
302
|
+
est_main_size = 0
|
|
303
|
+
est_aux_size = 0
|
|
304
|
+
urls_aux = []
|
|
305
|
+
urls_main = []
|
|
306
|
+
in_cache = 0
|
|
307
|
+
file_type = "main"
|
|
308
|
+
|
|
309
|
+
# get the states to estimate data sizes
|
|
310
|
+
if scope.granularity != "state":
|
|
311
|
+
states = list(STATE.truncate_unique(scope.node_ids))
|
|
312
|
+
else:
|
|
313
|
+
states = scope.node_ids
|
|
314
|
+
|
|
315
|
+
if len(states) > 1:
|
|
316
|
+
file_type = "aux"
|
|
317
|
+
|
|
318
|
+
# translate state FIPS code to state to use in URL
|
|
319
|
+
state_codes = get_states(scope.year).state_fips_to_code
|
|
320
|
+
state_abbreviations = [state_codes.get(fips, "").lower() for fips in states]
|
|
321
|
+
|
|
322
|
+
total_state_files = len(states)
|
|
323
|
+
|
|
324
|
+
# get the urls for each state to check the cache
|
|
325
|
+
for state in state_abbreviations:
|
|
326
|
+
url_aux, url_main = _generate_lodes_file_name(state, job_type, year, file_type)
|
|
327
|
+
|
|
328
|
+
if len(states) > 1:
|
|
329
|
+
urls_aux.append(url_aux)
|
|
330
|
+
|
|
331
|
+
# if the job type is not JT04-JT05, the file size is in the dictionary
|
|
332
|
+
if job_type not in ["JT04", "JT05"]:
|
|
333
|
+
est_main_size += _STATE_FILE_ESTIMATES[state]
|
|
334
|
+
if check_file_in_cache(_LODES_CACHE_PATH / Path(url_main).name):
|
|
335
|
+
in_cache += _STATE_FILE_ESTIMATES[state]
|
|
336
|
+
else:
|
|
337
|
+
urls_main.append(url_main)
|
|
338
|
+
|
|
339
|
+
# check the cache for main files if the job type is jt04-jt05
|
|
340
|
+
if job_type in ["JT04", "JT05"]:
|
|
341
|
+
missing_main_files = total_state_files - sum(
|
|
342
|
+
1
|
|
343
|
+
for u in urls_main
|
|
344
|
+
if check_file_in_cache(_LODES_CACHE_PATH / Path(u).name)
|
|
345
|
+
)
|
|
346
|
+
# jt04-jt05 main files average to 86.2KB
|
|
347
|
+
total_missing_main_size = missing_main_files * 86_200
|
|
348
|
+
else:
|
|
349
|
+
total_missing_main_size = (
|
|
350
|
+
est_main_size - in_cache
|
|
351
|
+
) # otherwise, adjust for cache
|
|
352
|
+
|
|
353
|
+
# check for missing aux files, if needed
|
|
354
|
+
if len(states) > 1:
|
|
355
|
+
# avg of 18.7KB for JT04-JT05 aux files, average of 723KB for aux otherwise
|
|
356
|
+
est_aux_size = 18_700 if job_type in ["JT04", "JT05"] else 723_000
|
|
357
|
+
missing_aux_files = total_state_files - sum(
|
|
358
|
+
1 for u in urls_aux if check_file_in_cache(_LODES_CACHE_PATH / Path(u).name)
|
|
359
|
+
)
|
|
360
|
+
|
|
361
|
+
else:
|
|
362
|
+
missing_aux_files = 0
|
|
363
|
+
|
|
364
|
+
total_missing_aux_size = missing_aux_files * est_aux_size
|
|
365
|
+
est_aux_size *= total_state_files
|
|
366
|
+
|
|
367
|
+
est = CacheEstimate(
|
|
368
|
+
total_cache_size=est_aux_size + est_main_size,
|
|
369
|
+
missing_cache_size=total_missing_main_size + total_missing_aux_size,
|
|
370
|
+
)
|
|
371
|
+
|
|
372
|
+
key = f"lodes:{year}:{job_type}"
|
|
373
|
+
return AvailableDataEstimate(
|
|
374
|
+
name=self.full_name,
|
|
375
|
+
cache_key=key,
|
|
376
|
+
new_network_bytes=est.missing_cache_size,
|
|
377
|
+
new_cache_bytes=est.missing_cache_size,
|
|
378
|
+
total_cache_bytes=est.total_cache_size,
|
|
379
|
+
max_bandwidth=None,
|
|
380
|
+
)
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
class _LodesADRIO(ADRIO[np.int64], ABC):
|
|
384
|
+
_override_year: int | None
|
|
385
|
+
"""The year for the commuting data.
|
|
386
|
+
If None, defaults to the year in which the simulation time frame starts."""
|
|
387
|
+
|
|
388
|
+
def __init__(self, year: int | None = None):
|
|
389
|
+
self._override_year = year
|
|
390
|
+
|
|
391
|
+
@property
|
|
392
|
+
def data_year(self) -> int:
|
|
393
|
+
if self._override_year is not None:
|
|
394
|
+
return self._override_year
|
|
395
|
+
return self.time_frame.start_date.year
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
@adrio_cache
|
|
399
|
+
class Commuters(_LodesADRIO):
|
|
400
|
+
"""
|
|
401
|
+
Creates an NxN matrix of integers representing the number of workers moving
|
|
402
|
+
from a home GEOID to a work GEOID.
|
|
403
|
+
"""
|
|
404
|
+
|
|
405
|
+
job_type: JobType
|
|
406
|
+
|
|
407
|
+
def __init__(self, year: int | None = None, job_type: JobType = "All Jobs"):
|
|
408
|
+
"""
|
|
409
|
+
Initializes the commuters matrix with the year and with the type of job, which
|
|
410
|
+
defaults to "All Jobs".
|
|
411
|
+
|
|
412
|
+
Parameters
|
|
413
|
+
----------
|
|
414
|
+
year : int, optional
|
|
415
|
+
The year for the commuting data.
|
|
416
|
+
Defaults to the year in which the simulation time frame starts.
|
|
417
|
+
|
|
418
|
+
job_type : JobType
|
|
419
|
+
The category of job all resulting commuters work under (options: "All Jobs",
|
|
420
|
+
"Primary Jobs", "All Private Jobs", "Private Primary Jobs",
|
|
421
|
+
"All Federal Jobs", "Federal Primary Jobs").
|
|
422
|
+
"""
|
|
423
|
+
super().__init__(year)
|
|
424
|
+
self.job_type = job_type
|
|
425
|
+
|
|
426
|
+
def estimate_data(self) -> DataEstimate:
|
|
427
|
+
scope = self.scope
|
|
428
|
+
scope = _validate_scope(scope)
|
|
429
|
+
job_var = _JOB_VARIABLES[self.job_type]
|
|
430
|
+
est = _estimate_lodes(self, scope, job_var, self.data_year)
|
|
431
|
+
return est
|
|
432
|
+
|
|
433
|
+
@override
|
|
434
|
+
def evaluate_adrio(self) -> NDArray[np.int64]:
|
|
435
|
+
scope = self.scope
|
|
436
|
+
scope = _validate_scope(scope)
|
|
437
|
+
job_var = _JOB_VARIABLES[self.job_type]
|
|
438
|
+
return _fetch_lodes(scope, "S000", job_var, self.data_year, self.progress)
|
|
439
|
+
|
|
440
|
+
|
|
441
|
+
@adrio_cache
|
|
442
|
+
class CommutersByAge(_LodesADRIO):
|
|
443
|
+
"""
|
|
444
|
+
Creates an NxN matrix of integers representing the number of workers moving from a
|
|
445
|
+
home GEOID to a work GEOID that fall under a certain age range.
|
|
446
|
+
"""
|
|
447
|
+
|
|
448
|
+
job_type: JobType
|
|
449
|
+
|
|
450
|
+
AgeRange = Literal["29 and Under", "30_54", "55 and Over"]
|
|
451
|
+
|
|
452
|
+
age_variables: dict[AgeRange, str] = {
|
|
453
|
+
"29 and Under": "SA01",
|
|
454
|
+
"30_54": "SA02",
|
|
455
|
+
"55 and Over": "SA03",
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
age_range: AgeRange
|
|
459
|
+
|
|
460
|
+
def __init__(
|
|
461
|
+
self,
|
|
462
|
+
age_range: AgeRange,
|
|
463
|
+
year: int | None = None,
|
|
464
|
+
job_type: JobType = "All Jobs",
|
|
465
|
+
):
|
|
466
|
+
"""
|
|
467
|
+
Initializes the commuters by age matrix with the year, the age range, and the
|
|
468
|
+
type of job, which defaults to "All Jobs".
|
|
469
|
+
|
|
470
|
+
Parameters
|
|
471
|
+
----------
|
|
472
|
+
age_range : AgeRange
|
|
473
|
+
The defined age range that all commuters fall under
|
|
474
|
+
(options: '29 and Under', '30_54', '55 and Over').
|
|
475
|
+
year : int, optional
|
|
476
|
+
The year for the commuting data.
|
|
477
|
+
Defaults to the year in which the simulation time frame starts.
|
|
478
|
+
job_type : JobType
|
|
479
|
+
The category of job all resulting commuters work under (options: "All Jobs",
|
|
480
|
+
"Primary Jobs", "All Private Jobs", "Private Primary Jobs",
|
|
481
|
+
"All Federal Jobs", "Federal Primary Jobs").
|
|
482
|
+
"""
|
|
483
|
+
super().__init__(year)
|
|
484
|
+
self.age_range = age_range
|
|
485
|
+
self.job_type = job_type
|
|
486
|
+
|
|
487
|
+
def estimate_data(self) -> DataEstimate:
|
|
488
|
+
scope = self.scope
|
|
489
|
+
scope = _validate_scope(scope)
|
|
490
|
+
job_var = _JOB_VARIABLES[self.job_type]
|
|
491
|
+
est = _estimate_lodes(self, scope, job_var, self.data_year)
|
|
492
|
+
return est
|
|
493
|
+
|
|
494
|
+
@override
|
|
495
|
+
def evaluate_adrio(self) -> NDArray[np.int64]:
|
|
496
|
+
scope = self.scope
|
|
497
|
+
scope = _validate_scope(scope)
|
|
498
|
+
age_var = self.age_variables[self.age_range]
|
|
499
|
+
job_var = _JOB_VARIABLES[self.job_type]
|
|
500
|
+
return _fetch_lodes(scope, age_var, job_var, self.data_year, self.progress)
|
|
501
|
+
|
|
502
|
+
|
|
503
|
+
@adrio_cache
|
|
504
|
+
class CommutersByEarnings(_LodesADRIO):
|
|
505
|
+
"""
|
|
506
|
+
Creates an NxN matrix of integers representing the number of workers moving from a
|
|
507
|
+
home GEOID to a work GEOID that earn a certain income range monthly.
|
|
508
|
+
"""
|
|
509
|
+
|
|
510
|
+
job_type: JobType
|
|
511
|
+
|
|
512
|
+
EarningRange = Literal["$1250 and Under", "$1251_$3333", "$3333 and Over"]
|
|
513
|
+
|
|
514
|
+
earnings_variables: dict[EarningRange, str] = {
|
|
515
|
+
"$1250 and Under": "SE01",
|
|
516
|
+
"$1251_$3333": "SE02",
|
|
517
|
+
"$3333 and Over": "SE03",
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
earning_range: EarningRange
|
|
521
|
+
|
|
522
|
+
def __init__(
|
|
523
|
+
self,
|
|
524
|
+
earning_range: EarningRange,
|
|
525
|
+
year: int | None = None,
|
|
526
|
+
job_type: JobType = "All Jobs",
|
|
527
|
+
):
|
|
528
|
+
"""
|
|
529
|
+
Initializes the commuters by monthly earnings matrix with the year, the earning
|
|
530
|
+
range, and the type of job, which defaults to "All Jobs".
|
|
531
|
+
|
|
532
|
+
Parameters
|
|
533
|
+
----------
|
|
534
|
+
earning_range : EarningRange
|
|
535
|
+
The defined monthly earnings range that all commuters fall under
|
|
536
|
+
(options: '$1250 and Under', '$1251_$3333', '$3333 and Over').
|
|
537
|
+
year : int, optional
|
|
538
|
+
The year for the commuting data.
|
|
539
|
+
Defaults to the year in which the simulation time frame starts.
|
|
540
|
+
job_type : JobType
|
|
541
|
+
The category of job all resulting commuters work under (options: "All Jobs",
|
|
542
|
+
"Primary Jobs", "All Private Jobs", "Private Primary Jobs",
|
|
543
|
+
"All Federal Jobs", "Federal Primary Jobs").
|
|
544
|
+
"""
|
|
545
|
+
super().__init__(year)
|
|
546
|
+
self.earning_range = earning_range
|
|
547
|
+
self.job_type = job_type
|
|
548
|
+
|
|
549
|
+
def estimate_data(self) -> DataEstimate:
|
|
550
|
+
scope = self.scope
|
|
551
|
+
scope = _validate_scope(scope)
|
|
552
|
+
job_var = _JOB_VARIABLES[self.job_type]
|
|
553
|
+
est = _estimate_lodes(self, scope, job_var, self.data_year)
|
|
554
|
+
return est
|
|
555
|
+
|
|
556
|
+
@override
|
|
557
|
+
def evaluate_adrio(self) -> NDArray[np.int64]:
|
|
558
|
+
scope = self.scope
|
|
559
|
+
scope = _validate_scope(scope)
|
|
560
|
+
earning_var = self.earnings_variables[self.earning_range]
|
|
561
|
+
job_var = _JOB_VARIABLES[self.job_type]
|
|
562
|
+
return _fetch_lodes(scope, earning_var, job_var, self.data_year, self.progress)
|
|
563
|
+
|
|
564
|
+
|
|
565
|
+
@adrio_cache
|
|
566
|
+
class CommutersByIndustry(_LodesADRIO):
|
|
567
|
+
"""
|
|
568
|
+
Creates an NxN matrix of integers representing the number of workers moving from a
|
|
569
|
+
home GEOID to a work GEOID that work under specified industry sector.
|
|
570
|
+
"""
|
|
571
|
+
|
|
572
|
+
job_type: JobType
|
|
573
|
+
|
|
574
|
+
Industries = Literal["Goods Producing", "Trade Transport Utility", "Other"]
|
|
575
|
+
|
|
576
|
+
industry_variables: dict[Industries, str] = {
|
|
577
|
+
"Goods Producing": "SI01",
|
|
578
|
+
"Trade Transport Utility": "SI02",
|
|
579
|
+
"Other": "SI03",
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
industry: Industries
|
|
583
|
+
|
|
584
|
+
def __init__(
|
|
585
|
+
self,
|
|
586
|
+
industry: Industries,
|
|
587
|
+
year: int | None = None,
|
|
588
|
+
job_type: JobType = "All Jobs",
|
|
589
|
+
):
|
|
590
|
+
"""
|
|
591
|
+
Initializes the commuters by industry matrix with the year, the industry type,
|
|
592
|
+
and the type of job, which defaults to "All Jobs".
|
|
593
|
+
|
|
594
|
+
Parameters
|
|
595
|
+
----------
|
|
596
|
+
industry : Industries
|
|
597
|
+
The defined industry that all commuters fall under
|
|
598
|
+
(options: 'Goods Producing', 'Trade Transport Utility', 'Other').
|
|
599
|
+
year : int, optional
|
|
600
|
+
The year for the commuting data.
|
|
601
|
+
Defaults to the year in which the simulation time frame starts.
|
|
602
|
+
job_type : JobType
|
|
603
|
+
The category of job all resulting commuters work under (options: "All Jobs",
|
|
604
|
+
"Primary Jobs", "All Private Jobs", "Private Primary Jobs",
|
|
605
|
+
"All Federal Jobs", "Federal Primary Jobs").
|
|
606
|
+
"""
|
|
607
|
+
super().__init__(year)
|
|
608
|
+
self.industry = industry
|
|
609
|
+
self.job_type = job_type
|
|
610
|
+
|
|
611
|
+
def estimate_data(self) -> DataEstimate:
|
|
612
|
+
scope = self.scope
|
|
613
|
+
scope = _validate_scope(scope)
|
|
614
|
+
job_var = _JOB_VARIABLES[self.job_type]
|
|
615
|
+
est = _estimate_lodes(self, scope, job_var, self.data_year)
|
|
616
|
+
return est
|
|
617
|
+
|
|
618
|
+
@override
|
|
619
|
+
def evaluate_adrio(self) -> NDArray[np.int64]:
|
|
620
|
+
scope = self.scope
|
|
621
|
+
scope = _validate_scope(scope)
|
|
622
|
+
industry_var = self.industry_variables[self.industry]
|
|
623
|
+
job_var = _JOB_VARIABLES[self.job_type]
|
|
624
|
+
return _fetch_lodes(scope, industry_var, job_var, self.data_year, self.progress)
|