Skip to content

Commit

Permalink
Fix reading 2004 cpc precipitation outlook
Browse files Browse the repository at this point in the history
  • Loading branch information
jayqi committed Dec 1, 2023
1 parent 44e54a0 commit 3f0ac2b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## December 1, 2023

- Fixed bug in parsing CPC Precipitation Outlooks in `wsfr_read.climate.cpc_outlooks`. This now handles the case where the 2004 file has a slightly different format.

## November 29, 2023

- Added runtime items to the repository.
Expand Down
33 changes: 27 additions & 6 deletions data_reading/wsfr_read/climate/cpc_outlooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ def _table_data_generator(

TEMP_WIDTHS = (
(
5, # YEAR
3, # MN
4, # YEAR
4, # MN
4, # LEAD
4, # CD
5, # R
Expand Down Expand Up @@ -106,8 +106,8 @@ def _table_data_generator(

PRECIP_WIDTHS = (
(
5, # YEAR
3, # MN
4, # YEAR
4, # MN
4, # LEAD
4, # CD
5, # R
Expand All @@ -118,7 +118,7 @@ def _table_data_generator(
6, # CLIM
7, # FCST
7, # CLIM
5, # POWER
7, # POWER
)
)
PRECIP_COLUMNS = (
Expand Down Expand Up @@ -147,6 +147,24 @@ def _table_data_generator(
"POWER",
)

PRECIP_2004_WIDTHS = (
(
4, # YEAR
3, # MN
3, # LEAD
4, # CD
5, # R
)
+ (6,) * 13 # exceedances
+ (
6, # FCST
6, # CLIM
8, # FCST
8, # CLIM
8, # POWER
)
)


def _read_outlook_for_year(
year: int, variable: Literal["temp", "precip"] | Variable
Expand All @@ -160,7 +178,10 @@ def _read_outlook_for_year(
widths = TEMP_WIDTHS
elif variable == Variable.PRECIP:
columns = PRECIP_COLUMNS
widths = PRECIP_WIDTHS
if year == 2004:
widths = PRECIP_2004_WIDTHS
else:
widths = PRECIP_WIDTHS
dfs = {}
for issue_date, buffer in table_gen:
dfs[pd.to_datetime(issue_date)] = pd.read_fwf(
Expand Down

0 comments on commit 3f0ac2b

Please sign in to comment.