Season Axis
influpaint.utils.season_axis
SeasonAxis
A SeasonAxis object manages locations and flu season temporal coordinates. Allow to convert from array to dataframe, or to plot array.
This class serves two related purposes:
-
Abstract Temporal Coordinates (for arrays/training):
- get_season_week(): Maps dates to season week numbers (1-53)
- Provides consistent temporal alignment across flu seasons
- Used for creating arrays, training models, seasonal overlays
-
Calendar Mapping (for forecasting):
- get_week_dates(): Returns actual date ranges for specific weeks/years
- week_to_saturday(): Maps season weeks to specific Saturday dates
- get_season_calendar(): Full calendar for a specific flu season year
- Used for converting model predictions to real calendar dates
Parameters: - locations (pd.DataFrame): DataFrame with location information - season_start_month (int, optional): Start month for flu seasons. Defaults to 8 (August). - season_start_day (int, optional): Start day for flu seasons. Defaults to 1.
Attributes: - locations_df (pd.DataFrame): DataFrame containing location information - locations (list): List of location codes in order - season_start_month (int): Start month for flu seasons (1-12) - season_start_day (int): Start day for flu seasons (1-31)
Key Methods:
Abstract Temporal: - get_season_week(ts): Season week number (like epiweek but for flu seasons) - get_fluseason_year(ts): Flu season year for a given date - get_fluseason_fraction(ts): Fraction of flu season elapsed (0.0-1.0)
Concrete Calendar:
- get_week_dates(year, week): Actual date range for week N in year Y
- week_to_saturday(year, week): Saturday date for week N in year Y
- get_season_calendar(year): Full calendar mapping for a specific season
Utilities: - get_location_name(code): Location name for a given code - from_flusight(): Create from FluSight location data
Example
Abstract temporal coordinate (for arrays)
week = season_setup.get_season_week("2023-11-25") # Returns 17
Concrete calendar mapping (for forecasting)
start, end = season_setup.get_week_dates(2023, 17) # Nov 19-25, 2023 saturday = season_setup.week_to_saturday(2024, 17) # Nov 23, 2024
Source code in influpaint/utils/season_axis.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 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 | |
get_season_calendar(season_year)
Get full calendar mapping for a specific flu season.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
season_year
|
int
|
The year the flu season starts |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: Calendar with [season_week, start_date, end_date, saturday] |
Source code in influpaint/utils/season_axis.py
get_season_week(ts)
Get season week number (like epiweek but for flu seasons).
Maps dates to week numbers using fixed 7-day bins from season start. This is the primary temporal coordinate for arrays and seasonal alignment. Can return 1-53 depending on calendar alignment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ts
|
Date to convert |
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
Season week number (1-53) |
Source code in influpaint/utils/season_axis.py
get_week_dates(season_year, week_number)
Get actual start and end dates for a specific week in a specific season.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
season_year
|
int
|
The year the flu season starts (e.g., 2023 for 2023-2024 season) |
required |
week_number
|
int
|
Season week number (1-53) |
required |
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
tuple[date, date]
|
(start_date, end_date) for that week |
Source code in influpaint/utils/season_axis.py
week_to_saturday(season_year, week_number)
Get the Saturday date for a specific season week in a specific year.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
season_year
|
int
|
The year the flu season starts |
required |
week_number
|
int
|
Season week number (1-53) |
required |
Returns:
| Type | Description |
|---|---|
date
|
datetime.date: The Saturday of that week |
Source code in influpaint/utils/season_axis.py
get_season_week(ts, start_month=8, start_day=1)
Calculate the flu-season week number using fixed 7-day bins from season start.
This function assigns a 1-based week number relative to a season defined by its start date (default: August 1). Each week corresponds to a contiguous 7-day period since the season start. All dates before the official start are clamped to Week 1.
Parameters
ts : str or datetime.date or datetime.datetime The date to be converted. Strings must follow 'YYYY-MM-DD' format. start_month : int, optional Month that marks the beginning of the flu season, by default 8. start_day : int, optional Day of the start month that begins the flu season, by default 1.
Returns
int The week number within the flu season (1–53).
Notes
- A 365-day non-leap year yields 52 weeks plus 1 day (partial week).
- A leap year yields a possible week 53 if the season crosses Feb 29.
- Weeks are fixed 7-day bins. E.g., Week 1 = Aug 1–7, Week 2 = Aug 8–14, etc.
Examples
get_season_week("2023-08-01") 1 get_season_week(datetime.date(2023, 8, 10)) 2 get_season_week("2023-07-30") # before season start 1