From 3f0ac2b5e464d95ec28784c4900d2e60d3cb0a20 Mon Sep 17 00:00:00 2001 From: Jay Qi Date: Fri, 1 Dec 2023 10:46:53 -0500 Subject: [PATCH] Fix reading 2004 cpc precipitation outlook --- CHANGELOG.md | 4 +++ .../wsfr_read/climate/cpc_outlooks.py | 33 +++++++++++++++---- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c14ca1..cdeb832 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/data_reading/wsfr_read/climate/cpc_outlooks.py b/data_reading/wsfr_read/climate/cpc_outlooks.py index a190d2e..df8b2fe 100644 --- a/data_reading/wsfr_read/climate/cpc_outlooks.py +++ b/data_reading/wsfr_read/climate/cpc_outlooks.py @@ -65,8 +65,8 @@ def _table_data_generator( TEMP_WIDTHS = ( ( - 5, # YEAR - 3, # MN + 4, # YEAR + 4, # MN 4, # LEAD 4, # CD 5, # R @@ -106,8 +106,8 @@ def _table_data_generator( PRECIP_WIDTHS = ( ( - 5, # YEAR - 3, # MN + 4, # YEAR + 4, # MN 4, # LEAD 4, # CD 5, # R @@ -118,7 +118,7 @@ def _table_data_generator( 6, # CLIM 7, # FCST 7, # CLIM - 5, # POWER + 7, # POWER ) ) PRECIP_COLUMNS = ( @@ -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 @@ -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(