Data¶
data
¶
Example datasets and data getting utilities.
This module contains functions for either reading in sample datasets or pulling data from external data providers.
coordinates_from_incidence(incidence)
¶
Extract model coordinates from an incidence pandas DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
incidence
|
DataFrame
|
A formatted incidence pandas DataFrame. |
required |
Returns:
| Type | Description |
|---|---|
dict[Literal['season', 'region', 'strata', 'observation'], list[str]]
|
A dictionary of coordinates that can be provided to xarray. |
Source code in src/vaxflux/data.py
create_logistic_sample_dataset(parameters, time, epsilon, error='gamma', seed=0)
¶
Create a synthetic logistic incidence dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parameters
|
DataFrame
|
A pandas DataFrame with the columns 'season', 'strata', 'region', 'm', 'r', and 's'. |
required |
time
|
NDArray[float64]
|
A numpy array of the time steps to generate a dataset for. |
required |
epsilon
|
float
|
The standard deviation to use in the resulting observations. |
required |
error
|
Literal['gamma', 'normal'] | None
|
The error distribution to use in generating the observed incidences or
|
'gamma'
|
seed
|
int
|
An integer corresponding to the random seed to use when generating a dataset for consistency across calls. |
0
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
A formatted incidence dataset. |
Examples:
>>> import numpy as np
>>> import pandas as pd
>>> from vaxflux.data import create_logistic_sample_dataset
>>> parameters = pd.DataFrame(
... data={
... "season": ["2023/24"],
... "strata": ["All stratas"],
... "region": ["All regions"],
... "m": [0.5],
... "r": [0.3],
... "s": [20.0],
... },
... )
>>> parameters
season strata region m r s
0 2023/24 All stratas All regions 0.5 0.3 20.0
>>> time = np.arange(40, step=3)
>>> create_logistic_sample_dataset(parameters, time, 0.001)
season strata region time value
0 2023/24 All stratas All regions 0.0 0.000128
1 2023/24 All stratas All regions 3.0 0.001984
2 2023/24 All stratas All regions 6.0 0.005459
3 2023/24 All stratas All regions 9.0 0.007348
4 2023/24 All stratas All regions 12.0 0.014066
5 2023/24 All stratas All regions 15.0 0.027984
6 2023/24 All stratas All regions 18.0 0.044186
7 2023/24 All stratas All regions 21.0 0.046088
8 2023/24 All stratas All regions 24.0 0.033544
9 2023/24 All stratas All regions 27.0 0.019666
10 2023/24 All stratas All regions 30.0 0.008194
11 2023/24 All stratas All regions 33.0 0.001570
12 2023/24 All stratas All regions 36.0 0.001995
13 2023/24 All stratas All regions 39.0 0.000210
Source code in src/vaxflux/data.py
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 | |
format_incidence_dataframe(incidence)
¶
Format an incidence pandas DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
incidence
|
DataFrame
|
A DataFrame with at least the columns 'time' and 'incidence' and optionally 'season', 'strata', 'region'. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
A pandas DataFrame with the columns |
Examples:
>>> import pandas as pd
>>> df = pd.DataFrame(
... data={
... "time": [1.0, 1.5, 2.0],
... "incidence": [0.01, 0.02, 0.015],
... }
... )
>>> df
time incidence
0 1.0 0.010
1 1.5 0.020
2 2.0 0.015
>>> format_incidence_dataframe(df)
season strata region time incidence
0 All Seasons All Stratas All Regions 1.0 0.010
1 All Seasons All Stratas All Regions 1.5 0.020
2 All Seasons All Stratas All Regions 2.0 0.015
Source code in src/vaxflux/data.py
get_ncird_nis_frvm_flu_vaccination_coverage(*, include_age_groups=False)
¶
Get NCIRD NIS/FRVM flu vaccination coverage formatted for VaxfluxModel.
This uses the CDC dataset Weekly Influenza Vaccination Coverage and Intent
for Vaccination Among Adults 18 Years and Older
<https://data.cdc.gov/Flu-Vaccinations/Weekly-Influenza-Vaccination-Coverage-and-Intent-f/sw5n-wg2p/about_data>_.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
include_age_groups
|
bool
|
Whether to return an age-stratified output. When
|
False
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
A pandas DataFrame with columns required by |
DataFrame
|
meth: |
DataFrame
|
|
DataFrame
|
|
DataFrame
|
when |
Source code in src/vaxflux/data.py
get_ncird_weekly_cumulative_vaccination_coverage()
¶
Get weekly cumulative vaccination coverage data provided by NCIRD.
More information about this data can be found on the CDC data page for this
dataset: Weekly Cumulative Influenza Vaccination Coverage, Adults 18 and Older, United States <https://data.cdc.gov/Flu-Vaccinations/Weekly-Cumulative-Influenza-Vaccination-Coverage-A/2v3t-r3np/about_data>_.
Returns:
| Type | Description |
|---|---|
DataFrame
|
A pandas DataFrame with the columns 'geographic_level', 'geographic_name', |
DataFrame
|
'demographic_level', 'demographic_name', 'indicator_label', |
DataFrame
|
'indicator_category_label', 'month_week', 'nd_weekly_estimate', |
DataFrame
|
'ci_half_width_95pct', 'n_unweighted', 'suppression_flag', |
DataFrame
|
'current_season_week_ending', 'influenza_season', 'legend', |
DataFrame
|
'indicator_category_label_sort', 'demographic_level_sort', |
DataFrame
|
'demographic_name_sort', 'geographic_sort', 'season_sort', |
DataFrame
|
'legend_sort', '95_ci_lower', and '95_ci_upper'. |
Source code in src/vaxflux/data.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 | |
sample_dataset(curve, season_ranges, date_ranges, covariate_categories, parameters, epsilon, noise='gamma', random_seed=1)
¶
Generate a sample dataset from the given incidence curve.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
curve
|
Curve
|
The incidence curve to sample from. |
required |
season_ranges
|
list[SeasonRange]
|
The season ranges to sample from. |
required |
date_ranges
|
list[DateRange]
|
The date ranges to generate observations for. |
required |
covariate_categories
|
list[CovariateCategories]
|
The covariate categories to sample from. |
required |
parameters
|
list[tuple[str | float, ...]]
|
The parameters to sample from. List of tuples with the first element being the curve parameter name, the second element being the season, and the following being the covariate categories and the last element being the value. |
required |
epsilon
|
float
|
The standard deviation to use in the resulting observations. |
required |
noise
|
Literal['gamma', 'normal']
|
The noise distribution to apply to the daily incidence values. |
'gamma'
|
random_seed
|
int
|
The random seed to use for reproducibility. |
1
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
A pandas DataFrame of observations with the columns 'season', |
DataFrame
|
'season_start_date', 'season_end_date', 'start_date', 'end_date', 'report_date', |
DataFrame
|
'type', and 'value' as well as the covariate categories covariate names. |
Source code in src/vaxflux/data.py
542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 | |