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.
Files changed (102) hide show
  1. epymorph/__init__.py +7 -0
  2. epymorph/__main__.py +16 -0
  3. epymorph/adrio/__init__.py +0 -0
  4. epymorph/adrio/acs5.py +602 -0
  5. epymorph/adrio/adrio.py +215 -0
  6. epymorph/adrio/cdc.py +781 -0
  7. epymorph/adrio/commuting_flows.py +237 -0
  8. epymorph/adrio/csv.py +387 -0
  9. epymorph/adrio/humidity.py +84 -0
  10. epymorph/adrio/lodes.py +624 -0
  11. epymorph/adrio/numpy.py +119 -0
  12. epymorph/adrio/prism.py +543 -0
  13. epymorph/adrio/respiratory_cdc.py +489 -0
  14. epymorph/adrio/us_tiger.py +217 -0
  15. epymorph/attribute.py +301 -0
  16. epymorph/cache.py +494 -0
  17. epymorph/cli/__init__.py +0 -0
  18. epymorph/cli/cache.py +77 -0
  19. epymorph/cli/main.py +29 -0
  20. epymorph/compartment_model.py +1335 -0
  21. epymorph/data/__init__.py +1 -0
  22. epymorph/data/ipm/__init__.py +22 -0
  23. epymorph/data/ipm/no.py +14 -0
  24. epymorph/data/ipm/pei.py +40 -0
  25. epymorph/data/ipm/seirs.py +50 -0
  26. epymorph/data/ipm/sirh.py +55 -0
  27. epymorph/data/ipm/sirs.py +48 -0
  28. epymorph/data/ipm/sparsemod.py +96 -0
  29. epymorph/data/mm/__init__.py +22 -0
  30. epymorph/data/mm/centroids.py +76 -0
  31. epymorph/data/mm/flat.py +61 -0
  32. epymorph/data/mm/icecube.py +50 -0
  33. epymorph/data/mm/no.py +29 -0
  34. epymorph/data/mm/pei.py +105 -0
  35. epymorph/data/mm/sparsemod.py +73 -0
  36. epymorph/data/pei.py +424 -0
  37. epymorph/data_shape.py +475 -0
  38. epymorph/data_type.py +129 -0
  39. epymorph/data_usage.py +171 -0
  40. epymorph/database.py +1010 -0
  41. epymorph/error.py +183 -0
  42. epymorph/event.py +188 -0
  43. epymorph/geography/__init__.py +0 -0
  44. epymorph/geography/custom.py +61 -0
  45. epymorph/geography/scope.py +214 -0
  46. epymorph/geography/us_census.py +622 -0
  47. epymorph/geography/us_geography.py +278 -0
  48. epymorph/geography/us_tiger.py +755 -0
  49. epymorph/initializer.py +596 -0
  50. epymorph/kit.py +90 -0
  51. epymorph/log/__init__.py +0 -0
  52. epymorph/log/file.py +108 -0
  53. epymorph/log/messaging.py +129 -0
  54. epymorph/log/movement.py +151 -0
  55. epymorph/movement_model.py +274 -0
  56. epymorph/parameter_fitting/__init__.py +0 -0
  57. epymorph/parameter_fitting/distribution.py +68 -0
  58. epymorph/parameter_fitting/dynamics.py +19 -0
  59. epymorph/parameter_fitting/filter/__init__.py +0 -0
  60. epymorph/parameter_fitting/filter/base_filter.py +50 -0
  61. epymorph/parameter_fitting/filter/particle.py +32 -0
  62. epymorph/parameter_fitting/filter/particle_filter.py +296 -0
  63. epymorph/parameter_fitting/likelihood.py +54 -0
  64. epymorph/parameter_fitting/output.py +73 -0
  65. epymorph/parameter_fitting/particlefilter_simulation.py +175 -0
  66. epymorph/parameter_fitting/perturbation.py +19 -0
  67. epymorph/parameter_fitting/utils/__init__.py +0 -0
  68. epymorph/parameter_fitting/utils/data_loader.py +111 -0
  69. epymorph/parameter_fitting/utils/epymorph_simulation.py +119 -0
  70. epymorph/parameter_fitting/utils/observations.py +63 -0
  71. epymorph/parameter_fitting/utils/parameter_estimation.py +49 -0
  72. epymorph/parameter_fitting/utils/params_perturb.py +43 -0
  73. epymorph/parameter_fitting/utils/particle_initializer.py +95 -0
  74. epymorph/parameter_fitting/utils/resampler.py +249 -0
  75. epymorph/parameter_fitting/utils/utils.py +101 -0
  76. epymorph/params.py +248 -0
  77. epymorph/py.typed +0 -0
  78. epymorph/rume.py +700 -0
  79. epymorph/simulation.py +706 -0
  80. epymorph/simulator/__init__.py +0 -0
  81. epymorph/simulator/basic/__init__.py +0 -0
  82. epymorph/simulator/basic/basic_simulator.py +145 -0
  83. epymorph/simulator/basic/ipm_exec.py +406 -0
  84. epymorph/simulator/basic/mm_exec.py +197 -0
  85. epymorph/simulator/basic/output.py +181 -0
  86. epymorph/simulator/world.py +83 -0
  87. epymorph/simulator/world_list.py +196 -0
  88. epymorph/strata.py +12 -0
  89. epymorph/sympy_shim.py +55 -0
  90. epymorph/time.py +649 -0
  91. epymorph/tools/__init__.py +0 -0
  92. epymorph/tools/data.py +218 -0
  93. epymorph/tools/ipm_diagram.py +165 -0
  94. epymorph/tools/out_map.py +426 -0
  95. epymorph/tools/out_plot.py +412 -0
  96. epymorph/tools/out_table.py +575 -0
  97. epymorph/util.py +825 -0
  98. epymorph-1.0.0b0.dist-info/METADATA +57 -0
  99. epymorph-1.0.0b0.dist-info/RECORD +102 -0
  100. epymorph-1.0.0b0.dist-info/WHEEL +5 -0
  101. epymorph-1.0.0b0.dist-info/entry_points.txt +2 -0
  102. epymorph-1.0.0b0.dist-info/top_level.txt +1 -0
epymorph/adrio/cdc.py ADDED
@@ -0,0 +1,781 @@
1
+ """ADRIOs that access data.cdc.gov website for various health data."""
2
+
3
+ from dataclasses import dataclass
4
+ from datetime import date
5
+ from typing import Mapping
6
+ from urllib.parse import quote, urlencode
7
+ from warnings import warn
8
+
9
+ import numpy as np
10
+ from numpy.typing import NDArray
11
+ from pandas import DataFrame, concat, read_csv
12
+ from typing_extensions import override
13
+
14
+ from epymorph.adrio.adrio import ADRIO, ProgressCallback, adrio_cache
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, CensusGranularityName
19
+ from epymorph.geography.us_tiger import get_states
20
+ from epymorph.time import TimeFrame
21
+
22
+
23
+ @dataclass(frozen=True)
24
+ class DataSource:
25
+ url_base: str
26
+ date_col: str
27
+ fips_col: str
28
+ data_col: str
29
+ granularity: CensusGranularityName
30
+ """The geographic granularity of the source data."""
31
+ replace_sentinel: float | None
32
+ """If None, ignore sentinel values (-999999); otherwise, replace them with
33
+ the given value."""
34
+ map_geo_ids: Mapping[str, str] | None = None
35
+ """If None, use the scope node IDs as they are, otherwise use this mapping
36
+ to map them."""
37
+
38
+
39
+ _SENTINEL = -999999
40
+ """A common sentinel value which represents values which have been redacted
41
+ for privacy because there were less than 4 individuals in that data point."""
42
+
43
+
44
+ def _api_query(
45
+ source: DataSource,
46
+ scope: CensusScope,
47
+ time_frame: TimeFrame,
48
+ progress: ProgressCallback,
49
+ ) -> NDArray[np.float64]:
50
+ """
51
+ Composes URLs to query API and sends query requests. Limits each query to
52
+ 10000 rows, combining several query results if this number is exceeded.
53
+ Returns Dataframe containing requested data sorted by date and location fips.
54
+ """
55
+ node_ids = (
56
+ [source.map_geo_ids[x] for x in scope.node_ids]
57
+ if source.map_geo_ids is not None
58
+ else scope.node_ids
59
+ )
60
+ if scope.granularity == "state" and source.granularity != "state":
61
+ # query county level data with state fips codes
62
+ location_clauses = [f"starts_with({source.fips_col}, '{x}')" for x in node_ids]
63
+ else:
64
+ # query with full fips codes
65
+ formatted_fips = ",".join(f"'{node}'" for node in node_ids)
66
+ location_clauses = [f"{source.fips_col} in ({formatted_fips})"]
67
+
68
+ date_clause = (
69
+ f"{source.date_col} "
70
+ f"between '{time_frame.start_date}T00:00:00' "
71
+ f"and '{time_frame.end_date}T00:00:00'"
72
+ )
73
+
74
+ processing_steps = len(location_clauses) + 1
75
+
76
+ def query_step(index, loc_clause) -> DataFrame:
77
+ step_result = _query_location(source, loc_clause, date_clause)
78
+ progress((index + 1) / processing_steps, None)
79
+ return step_result
80
+
81
+ cdc_df = concat(
82
+ [query_step(i, loc_clause) for i, loc_clause in enumerate(location_clauses)]
83
+ )
84
+
85
+ if source.replace_sentinel is not None:
86
+ num_sentinel = (cdc_df[source.data_col] == _SENTINEL).sum()
87
+ if num_sentinel > 0:
88
+ cdc_df = cdc_df.replace(_SENTINEL, source.replace_sentinel)
89
+ warn(
90
+ f"{num_sentinel} values < 4 were replaced with "
91
+ f"{source.replace_sentinel} in returned data."
92
+ )
93
+
94
+ if scope.granularity == "state" and source.granularity != "state":
95
+ # aggregate county data to state level
96
+ cdc_df[source.fips_col] = cdc_df[source.fips_col].map(STATE.truncate)
97
+ cdc_df = cdc_df.groupby([source.fips_col, source.date_col]).sum().reset_index()
98
+
99
+ return _as_numpy(
100
+ cdc_df.sort_values(by=[source.date_col, source.fips_col]).pivot_table(
101
+ index=source.date_col,
102
+ columns=source.fips_col,
103
+ values=source.data_col,
104
+ )
105
+ )
106
+
107
+
108
+ def _as_numpy(data_df: DataFrame) -> NDArray[np.float64]:
109
+ """Convert a DataFrame to a time-series by node numpy array where each value is a
110
+ tuple of date and data value. Note: this time-series is not necessarily the same
111
+ length as simulation T, because not all ADRIOs produce a daily value."""
112
+ dates = data_df.index.to_numpy(dtype="datetime64[D]")
113
+ return np.array(
114
+ [list(zip(dates, data_df[col], strict=True)) for col in data_df.columns],
115
+ dtype=[("date", "datetime64[D]"), ("data", np.float64)],
116
+ ).T
117
+
118
+
119
+ def _fetch_cases(
120
+ attrib_name: str,
121
+ scope: CensusScope,
122
+ time_frame: TimeFrame,
123
+ progress: ProgressCallback,
124
+ ) -> NDArray[np.float64]:
125
+ """
126
+ Fetches data from HealthData dataset reporting COVID-19 cases per 100k population.
127
+ Available between 2/24/2022 and 5/4/2023 at state and county granularities.
128
+ https://healthdata.gov/dataset/United-States-COVID-19-Community-Levels-by-County/nn5b-j5u9/about_data
129
+ """
130
+ if time_frame.start_date < date(2022, 2, 24) or time_frame.end_date > date(
131
+ 2023, 5, 4
132
+ ):
133
+ msg = "COVID cases data is only available between 2/24/2022 and 5/4/2023."
134
+ raise DataResourceError(msg)
135
+
136
+ source = DataSource(
137
+ url_base="https://data.cdc.gov/resource/3nnm-4jni.csv?",
138
+ date_col="date_updated",
139
+ fips_col="county_fips",
140
+ data_col=attrib_name,
141
+ granularity="county",
142
+ replace_sentinel=None,
143
+ )
144
+
145
+ return _api_query(source, scope, time_frame, progress)
146
+
147
+
148
+ def _fetch_facility_hospitalization(
149
+ attrib_name: str,
150
+ scope: CensusScope,
151
+ time_frame: TimeFrame,
152
+ replace_sentinel: int,
153
+ progress: ProgressCallback,
154
+ ) -> NDArray[np.float64]:
155
+ """
156
+ Fetches data from HealthData dataset reporting number of people hospitalized for
157
+ COVID-19 and other respiratory illnesses at facility level during manditory
158
+ reporting period.
159
+ Available between 12/13/2020 and 5/10/2023 at state and county granularities.
160
+ https://healthdata.gov/Hospital/COVID-19-Reported-Patient-Impact-and-Hospital-Capa/anag-cw7u/about_data
161
+ """
162
+ if time_frame.start_date < date(2020, 12, 13) or time_frame.end_date > date(
163
+ 2023, 5, 10
164
+ ):
165
+ msg = (
166
+ "Facility level hospitalization data is only available between 12/13/2020 "
167
+ "and 5/10/2023."
168
+ )
169
+ raise DataResourceError(msg)
170
+
171
+ source = DataSource(
172
+ url_base="https://healthdata.gov/resource/anag-cw7u.csv?",
173
+ date_col="collection_week",
174
+ fips_col="fips_code",
175
+ data_col=attrib_name,
176
+ granularity="county",
177
+ replace_sentinel=replace_sentinel,
178
+ )
179
+
180
+ return _api_query(source, scope, time_frame, progress)
181
+
182
+
183
+ def _fetch_state_hospitalization(
184
+ attrib_name: str,
185
+ scope: CensusScope,
186
+ time_frame: TimeFrame,
187
+ progress: ProgressCallback,
188
+ ) -> NDArray[np.float64]:
189
+ """
190
+ Fetches data from CDC dataset reporting number of people hospitalized for COVID-19
191
+ and other respiratory illnesses at state level during manditory and voluntary
192
+ reporting periods.
193
+ Available from 1/4/2020 to present at state granularity.
194
+ Data reported voluntarily past 5/1/2024.
195
+ https://data.cdc.gov/Public-Health-Surveillance/Weekly-United-States-Hospitalization-Metrics-by-Ju/aemt-mg7g/about_data
196
+ """
197
+ if scope.granularity != "state":
198
+ msg = (
199
+ "State level hospitalization data can only be retrieved for state "
200
+ "granularity."
201
+ )
202
+ raise DataResourceError(msg)
203
+ if time_frame.start_date < date(2020, 1, 4):
204
+ msg = "State level hospitalization data is only available starting 1/4/2020."
205
+ raise DataResourceError(msg)
206
+ if time_frame.end_date > date(2024, 5, 1):
207
+ warn("State level hospitalization data is voluntary past 5/1/2024.")
208
+
209
+ source = DataSource(
210
+ url_base="https://data.cdc.gov/resource/aemt-mg7g.csv?",
211
+ date_col="week_end_date",
212
+ fips_col="jurisdiction",
213
+ data_col=attrib_name,
214
+ granularity="state",
215
+ replace_sentinel=None,
216
+ map_geo_ids=get_states(scope.year).state_fips_to_code,
217
+ )
218
+
219
+ return _api_query(source, scope, time_frame, progress)
220
+
221
+
222
+ def _fetch_vaccination(
223
+ attrib_name: str,
224
+ scope: CensusScope,
225
+ time_frame: TimeFrame,
226
+ progress: ProgressCallback,
227
+ ) -> NDArray[np.float64]:
228
+ """
229
+ Fetches data from CDC dataset reporting total COVID-19 vaccination numbers.
230
+ Available between 12/13/2020 and 5/10/2024 at state and county granularities.
231
+ https://data.cdc.gov/Vaccinations/COVID-19-Vaccinations-in-the-United-States-County/8xkx-amqh/about_data
232
+ """
233
+ if time_frame.start_date < date(2020, 12, 13) or time_frame.end_date > date(
234
+ 2024, 5, 10
235
+ ):
236
+ msg = "Vaccination data is only available between 12/13/2020 and 5/10/2024."
237
+ raise DataResourceError(msg)
238
+
239
+ source = DataSource(
240
+ url_base="https://data.cdc.gov/resource/8xkx-amqh.csv?",
241
+ date_col="date",
242
+ fips_col="fips",
243
+ data_col=attrib_name,
244
+ granularity="county",
245
+ replace_sentinel=None,
246
+ )
247
+
248
+ return _api_query(source, scope, time_frame, progress)
249
+
250
+
251
+ def _fetch_deaths_county(
252
+ attrib_name: str,
253
+ scope: CensusScope,
254
+ time_frame: TimeFrame,
255
+ progress: ProgressCallback,
256
+ ) -> NDArray[np.float64]:
257
+ """
258
+ Fetches data from CDC dataset reporting number of deaths from COVID-19.
259
+ Available between 1/4/2020 and 4/5/2024 at state and county granularities.
260
+ https://data.cdc.gov/NCHS/AH-COVID-19-Death-Counts-by-County-and-Week-2020-p/ite7-j2w7/about_data
261
+ """
262
+ if (
263
+ time_frame.start_date < date(2020, 1, 4) #
264
+ or time_frame.end_date > date(2024, 4, 5)
265
+ ):
266
+ msg = (
267
+ "County level deaths data is only available between 1/4/2020 and 4/5/2024."
268
+ )
269
+ raise DataResourceError(msg)
270
+
271
+ if scope.granularity == "state":
272
+ source = DataSource(
273
+ url_base="https://data.cdc.gov/resource/ite7-j2w7.csv?",
274
+ date_col="week_ending_date",
275
+ fips_col="stfips",
276
+ data_col=attrib_name,
277
+ granularity="state",
278
+ replace_sentinel=None,
279
+ )
280
+ else:
281
+ source = DataSource(
282
+ url_base="https://data.cdc.gov/resource/ite7-j2w7.csv?",
283
+ date_col="week_ending_date",
284
+ fips_col="fips_code",
285
+ data_col=attrib_name,
286
+ granularity="county",
287
+ replace_sentinel=None,
288
+ )
289
+
290
+ return _api_query(source, scope, time_frame, progress)
291
+
292
+
293
+ def _fetch_deaths_state(
294
+ attrib_name: str,
295
+ scope: CensusScope,
296
+ time_frame: TimeFrame,
297
+ progress: ProgressCallback,
298
+ ) -> NDArray[np.float64]:
299
+ """
300
+ Fetches data from CDC dataset reporting number of deaths from COVID-19 and other
301
+ respiratory illnesses.
302
+ Available from 1/4/2020 to present at state granularity.
303
+ https://data.cdc.gov/NCHS/Provisional-COVID-19-Death-Counts-by-Week-Ending-D/r8kw-7aab/about_data
304
+ """
305
+ if time_frame.start_date < date(2020, 1, 4):
306
+ msg = "State level deaths data is only available starting 1/4/2020."
307
+ raise DataResourceError(msg)
308
+
309
+ states = get_states(scope.year)
310
+ state_mapping = dict(zip(states.geoid, states.name, strict=True))
311
+
312
+ source = DataSource(
313
+ url_base="https://data.cdc.gov/resource/r8kw-7aab.csv?",
314
+ date_col="end_date",
315
+ fips_col="state",
316
+ data_col=attrib_name,
317
+ granularity="state",
318
+ replace_sentinel=None,
319
+ map_geo_ids=state_mapping,
320
+ )
321
+
322
+ return _api_query(source, scope, time_frame, progress)
323
+
324
+
325
+ def _query_location(info: DataSource, loc_clause: str, date_clause: str) -> DataFrame:
326
+ """
327
+ Helper function for _api_query() that builds and sends queries for
328
+ individual locations.
329
+ """
330
+ current_return = 10000
331
+ total_returned = 0
332
+ cdc_df = DataFrame()
333
+
334
+ group_col = ""
335
+ group_filter = ""
336
+ group_filter = (
337
+ "AND `group`='By Week'"
338
+ if info.url_base == "https://data.cdc.gov/resource/r8kw-7aab.csv?"
339
+ else ""
340
+ )
341
+
342
+ while current_return == 10000:
343
+ url = info.url_base + urlencode(
344
+ quote_via=quote,
345
+ safe=",()'$:",
346
+ query={
347
+ "$select": (
348
+ f"{info.date_col},{info.fips_col},{info.data_col}{group_col}"
349
+ ),
350
+ "$where": f"{loc_clause} AND {date_clause}{group_filter}",
351
+ "$limit": 10000,
352
+ "$offset": total_returned,
353
+ },
354
+ )
355
+
356
+ cdc_df = concat([cdc_df, read_csv(url, dtype={info.fips_col: str})])
357
+
358
+ current_return = len(cdc_df.index) - total_returned
359
+ total_returned += current_return
360
+
361
+ return cdc_df
362
+
363
+
364
+ def _validate_scope(scope: GeoScope) -> CensusScope:
365
+ if not isinstance(scope, CensusScope):
366
+ msg = "Census scope is required for CDC attributes."
367
+ raise DataResourceError(msg)
368
+ return scope
369
+
370
+
371
+ @adrio_cache
372
+ class CovidCasesPer100k(ADRIO[np.float64]):
373
+ """
374
+ Creates a TxN matrix of tuples, containing a date and a float representing the
375
+ number of COVID-19 cases per 100k population.
376
+ """
377
+
378
+ override_time_frame: TimeFrame | None
379
+ """The time period the data encompasses."""
380
+
381
+ def __init__(self, time_frame: TimeFrame | None = None):
382
+ self.override_time_frame = time_frame
383
+
384
+ @override
385
+ def evaluate_adrio(self) -> NDArray[np.float64]:
386
+ scope = _validate_scope(self.scope)
387
+ return _fetch_cases(
388
+ "covid_cases_per_100k",
389
+ scope,
390
+ self.override_time_frame or self.time_frame,
391
+ self.progress,
392
+ )
393
+
394
+
395
+ @adrio_cache
396
+ class CovidHospitalizationsPer100k(ADRIO[np.float64]):
397
+ """
398
+ Creates a TxN matrix of tuples, containing a date and a float representing the
399
+ number of COVID-19 hospitalizations per 100k population.
400
+ """
401
+
402
+ override_time_frame: TimeFrame | None
403
+ """The time period the data encompasses."""
404
+
405
+ def __init__(self, time_frame: TimeFrame | None = None):
406
+ self.override_time_frame = time_frame
407
+
408
+ @override
409
+ def evaluate_adrio(self) -> NDArray[np.float64]:
410
+ scope = _validate_scope(self.scope)
411
+ return _fetch_cases(
412
+ "covid_hospital_admissions_per_100k",
413
+ scope,
414
+ self.override_time_frame or self.time_frame,
415
+ self.progress,
416
+ )
417
+
418
+
419
+ @adrio_cache
420
+ class CovidHospitalizationAvgFacility(ADRIO[np.float64]):
421
+ """
422
+ Creates a TxN matrix of tuples, containing a date and a float representing the
423
+ weekly averages of COVID-19 hospitalizations from the facility level dataset.
424
+ """
425
+
426
+ override_time_frame: TimeFrame | None
427
+ """The time period the data encompasses."""
428
+ replace_sentinel: int
429
+ """The integer value in range 0-3 to replace sentinel values with."""
430
+
431
+ def __init__(self, replace_sentinel: int, time_frame: TimeFrame | None = None):
432
+ if replace_sentinel not in range(4):
433
+ msg = "Sentinel substitute value must be in range 0-3."
434
+ raise DataResourceError(msg)
435
+ self.replace_sentinel = replace_sentinel
436
+ self.override_time_frame = time_frame
437
+
438
+ @override
439
+ def evaluate_adrio(self) -> NDArray[np.float64]:
440
+ scope = _validate_scope(self.scope)
441
+ return _fetch_facility_hospitalization(
442
+ "total_adult_patients_hospitalized_confirmed_covid_7_day_avg",
443
+ scope,
444
+ self.override_time_frame or self.time_frame,
445
+ self.replace_sentinel,
446
+ self.progress,
447
+ )
448
+
449
+
450
+ @adrio_cache
451
+ class CovidHospitalizationSumFacility(ADRIO[np.float64]):
452
+ """
453
+ Creates a TxN matrix of tuples, containing a date and a float representing the
454
+ weekly sums of all COVID-19 hospitalizations from the facility level dataset.
455
+ """
456
+
457
+ override_time_frame: TimeFrame | None
458
+ """The time period the data encompasses."""
459
+ replace_sentinel: int
460
+ """The integer value in range 0-3 to replace sentinel values with."""
461
+
462
+ def __init__(self, replace_sentinel: int, time_frame: TimeFrame | None = None):
463
+ if replace_sentinel not in range(4):
464
+ msg = "Sentinel substitute value must be in range 0-3."
465
+ raise DataResourceError(msg)
466
+ self.replace_sentinel = replace_sentinel
467
+ self.override_time_frame = time_frame
468
+
469
+ @override
470
+ def evaluate_adrio(self) -> NDArray[np.float64]:
471
+ scope = _validate_scope(self.scope)
472
+ return _fetch_facility_hospitalization(
473
+ "total_adult_patients_hospitalized_confirmed_covid_7_day_sum",
474
+ scope,
475
+ self.override_time_frame or self.time_frame,
476
+ self.replace_sentinel,
477
+ self.progress,
478
+ )
479
+
480
+
481
+ @adrio_cache
482
+ class InfluenzaHosptializationAvgFacility(ADRIO[np.float64]):
483
+ """
484
+ Creates a TxN matrix of tuples, containing a date and a float representing the
485
+ weekly averages of influenza hospitalizations from the facility level dataset.
486
+ """
487
+
488
+ override_time_frame: TimeFrame | None
489
+ """The time period the data encompasses."""
490
+ replace_sentinel: int
491
+ """The integer value in range 0-3 to replace sentinel values with."""
492
+
493
+ def __init__(self, replace_sentinel: int, time_frame: TimeFrame | None = None):
494
+ if replace_sentinel not in range(4):
495
+ msg = "Sentinel substitute value must be in range 0-3."
496
+ raise DataResourceError(msg)
497
+ self.replace_sentinel = replace_sentinel
498
+ self.override_time_frame = time_frame
499
+
500
+ @override
501
+ def evaluate_adrio(self) -> NDArray[np.float64]:
502
+ scope = _validate_scope(self.scope)
503
+ return _fetch_facility_hospitalization(
504
+ "total_patients_hospitalized_confirmed_influenza_7_day_avg",
505
+ scope,
506
+ self.override_time_frame or self.time_frame,
507
+ self.replace_sentinel,
508
+ self.progress,
509
+ )
510
+
511
+
512
+ @adrio_cache
513
+ class InfluenzaHospitalizationSumFacility(ADRIO[np.float64]):
514
+ """
515
+ Creates a TxN matrix of tuples, containing a date and a float representing the
516
+ weekly sums of influenza hospitalizations from the facility level dataset.
517
+ """
518
+
519
+ override_time_frame: TimeFrame | None
520
+ """The time period the data encompasses."""
521
+ replace_sentinel: int
522
+ """The integer value in range 0-3 to replace sentinel values with."""
523
+
524
+ def __init__(self, replace_sentinel: int, time_frame: TimeFrame | None = None):
525
+ if replace_sentinel not in range(4):
526
+ msg = "Sentinel substitute value must be in range 0-3."
527
+ raise DataResourceError(msg)
528
+ self.replace_sentinel = replace_sentinel
529
+ self.override_time_frame = time_frame
530
+
531
+ @override
532
+ def evaluate_adrio(self) -> NDArray[np.float64]:
533
+ scope = _validate_scope(self.scope)
534
+ return _fetch_facility_hospitalization(
535
+ "total_patients_hospitalized_confirmed_influenza_7_day_sum",
536
+ scope,
537
+ self.override_time_frame or self.time_frame,
538
+ self.replace_sentinel,
539
+ self.progress,
540
+ )
541
+
542
+
543
+ @adrio_cache
544
+ class CovidHospitalizationAvgState(ADRIO[np.float64]):
545
+ """
546
+ Creates a TxN matrix of tuples, containing a date and a float representing the
547
+ weekly averages of COVID-19 hospitalizations from the state level dataset.
548
+ """
549
+
550
+ override_time_frame: TimeFrame | None
551
+ """The time period the data encompasses."""
552
+
553
+ def __init__(self, time_frame: TimeFrame | None = None):
554
+ self.override_time_frame = time_frame
555
+
556
+ @override
557
+ def evaluate_adrio(self) -> NDArray[np.float64]:
558
+ scope = _validate_scope(self.scope)
559
+ return _fetch_state_hospitalization(
560
+ "avg_admissions_all_covid_confirmed",
561
+ scope,
562
+ self.override_time_frame or self.time_frame,
563
+ self.progress,
564
+ )
565
+
566
+
567
+ @adrio_cache
568
+ class CovidHospitalizationSumState(ADRIO[np.float64]):
569
+ """
570
+ Creates a TxN matrix of tuples, containing a date and a float representing the
571
+ weekly sums of COVID-19 hospitalizations from the state level dataset.
572
+ """
573
+
574
+ override_time_frame: TimeFrame | None
575
+ """The time period the data encompasses."""
576
+
577
+ def __init__(self, time_frame: TimeFrame | None = None):
578
+ self.override_time_frame = time_frame
579
+
580
+ @override
581
+ def evaluate_adrio(self) -> NDArray[np.float64]:
582
+ scope = _validate_scope(self.scope)
583
+ return _fetch_state_hospitalization(
584
+ "total_admissions_all_covid_confirmed",
585
+ scope,
586
+ self.override_time_frame or self.time_frame,
587
+ self.progress,
588
+ )
589
+
590
+
591
+ @adrio_cache
592
+ class InfluenzaHospitalizationAvgState(ADRIO[np.float64]):
593
+ """
594
+ Creates a TxN matrix of tuples, containing a date and a float representing the
595
+ weekly averages of influenza hospitalizations from the state level dataset.
596
+ """
597
+
598
+ override_time_frame: TimeFrame | None
599
+ """The time period the data encompasses."""
600
+
601
+ def __init__(self, time_frame: TimeFrame | None = None):
602
+ self.override_time_frame = time_frame
603
+
604
+ @override
605
+ def evaluate_adrio(self) -> NDArray[np.float64]:
606
+ scope = _validate_scope(self.scope)
607
+ return _fetch_state_hospitalization(
608
+ "avg_admissions_all_influenza_confirmed",
609
+ scope,
610
+ self.override_time_frame or self.time_frame,
611
+ self.progress,
612
+ )
613
+
614
+
615
+ @adrio_cache
616
+ class InfluenzaHospitalizationSumState(ADRIO[np.float64]):
617
+ """
618
+ Creates a TxN matrix of tuples, containing a date and a float representing the
619
+ weekly sums of influenza hospitalizations from the state level dataset.
620
+ """
621
+
622
+ override_time_frame: TimeFrame | None
623
+ """The time period the data encompasses."""
624
+
625
+ def __init__(self, time_frame: TimeFrame | None = None):
626
+ self.override_time_frame = time_frame
627
+
628
+ @override
629
+ def evaluate_adrio(self) -> NDArray[np.float64]:
630
+ scope = _validate_scope(self.scope)
631
+ return _fetch_state_hospitalization(
632
+ "total_admissions_all_influenza_confirmed",
633
+ scope,
634
+ self.override_time_frame or self.time_frame,
635
+ self.progress,
636
+ )
637
+
638
+
639
+ @adrio_cache
640
+ class FullCovidVaccinations(ADRIO[np.float64]):
641
+ """
642
+ Creates a TxN matrix of tuples, containing a date and a float representing the
643
+ cumulative total number of individuals fully vaccinated for COVID-19.
644
+ """
645
+
646
+ override_time_frame: TimeFrame | None
647
+ """The time period the data encompasses."""
648
+
649
+ def __init__(self, time_frame: TimeFrame | None = None):
650
+ self.override_time_frame = time_frame
651
+
652
+ @override
653
+ def evaluate_adrio(self) -> NDArray[np.float64]:
654
+ scope = _validate_scope(self.scope)
655
+ return _fetch_vaccination(
656
+ "series_complete_yes",
657
+ scope,
658
+ self.override_time_frame or self.time_frame,
659
+ self.progress,
660
+ )
661
+
662
+
663
+ @adrio_cache
664
+ class OneDoseCovidVaccinations(ADRIO[np.float64]):
665
+ """
666
+ Creates a TxN matrix of tuples, containing a date and a float representing the
667
+ cumulative total number of individuals with at least one dose of COVID-19
668
+ vaccination.
669
+ """
670
+
671
+ override_time_frame: TimeFrame | None
672
+ """The time period the data encompasses."""
673
+
674
+ def __init__(self, time_frame: TimeFrame | None = None):
675
+ self.override_time_frame = time_frame
676
+
677
+ @override
678
+ def evaluate_adrio(self) -> NDArray[np.float64]:
679
+ scope = _validate_scope(self.scope)
680
+ return _fetch_vaccination(
681
+ "administered_dose1_recip",
682
+ scope,
683
+ self.override_time_frame or self.time_frame,
684
+ self.progress,
685
+ )
686
+
687
+
688
+ @adrio_cache
689
+ class CovidBoosterDoses(ADRIO[np.float64]):
690
+ """
691
+ Creates a TxN matrix of tuples, containing a date and a float representing the
692
+ cumulative total number of COVID-19 booster doses administered.
693
+ """
694
+
695
+ override_time_frame: TimeFrame | None
696
+ """The time period the data encompasses."""
697
+
698
+ def __init__(self, time_frame: TimeFrame | None = None):
699
+ self.override_time_frame = time_frame
700
+
701
+ @override
702
+ def evaluate_adrio(self) -> NDArray[np.float64]:
703
+ scope = _validate_scope(self.scope)
704
+ return _fetch_vaccination(
705
+ "booster_doses",
706
+ scope,
707
+ self.override_time_frame or self.time_frame,
708
+ self.progress,
709
+ )
710
+
711
+
712
+ @adrio_cache
713
+ class CovidDeathsCounty(ADRIO[np.float64]):
714
+ """
715
+ Creates a TxN matrix of tuples, containing a date and a float representing the
716
+ weekly total of COVID-19 deaths from the county level dataset.
717
+ """
718
+
719
+ override_time_frame: TimeFrame | None
720
+ """The time period the data encompasses."""
721
+
722
+ def __init__(self, time_frame: TimeFrame | None = None):
723
+ self.override_time_frame = time_frame
724
+
725
+ @override
726
+ def evaluate_adrio(self) -> NDArray[np.float64]:
727
+ scope = _validate_scope(self.scope)
728
+ return _fetch_deaths_county(
729
+ "covid_19_deaths",
730
+ scope,
731
+ self.override_time_frame or self.time_frame,
732
+ self.progress,
733
+ )
734
+
735
+
736
+ @adrio_cache
737
+ class CovidDeathsState(ADRIO[np.float64]):
738
+ """
739
+ Creates a TxN matrix of tuples, containing a date and a float representing the
740
+ weekly total of COVID-19 deaths from the state level dataset.
741
+ """
742
+
743
+ override_time_frame: TimeFrame | None
744
+ """The time period the data encompasses."""
745
+
746
+ def __init__(self, time_frame: TimeFrame | None = None):
747
+ self.override_time_frame = time_frame
748
+
749
+ @override
750
+ def evaluate_adrio(self) -> NDArray[np.float64]:
751
+ scope = _validate_scope(self.scope)
752
+ return _fetch_deaths_state(
753
+ "covid_19_deaths",
754
+ scope,
755
+ self.override_time_frame or self.time_frame,
756
+ self.progress,
757
+ )
758
+
759
+
760
+ @adrio_cache
761
+ class InfluenzaDeathsState(ADRIO[np.float64]):
762
+ """
763
+ Creates a TxN matrix of tuples, containing a date and a float representing the
764
+ weekly total of influenza deaths from the state level dataset.
765
+ """
766
+
767
+ override_time_frame: TimeFrame | None
768
+ """The time period the data encompasses."""
769
+
770
+ def __init__(self, time_frame: TimeFrame | None = None):
771
+ self.override_time_frame = time_frame
772
+
773
+ @override
774
+ def evaluate_adrio(self) -> NDArray[np.float64]:
775
+ scope = _validate_scope(self.scope)
776
+ return _fetch_deaths_state(
777
+ "influenza_deaths",
778
+ scope,
779
+ self.override_time_frame or self.time_frame,
780
+ self.progress,
781
+ )