Skip to content

Commit 2a6c86d

Browse files
Initial commit for adding SAL1L2 linetype; mods to METdbLoad/ush/constants.py and METreformat/write_stat_ascii.py.
1 parent 72daaec commit 2a6c86d

2 files changed

Lines changed: 77 additions & 1 deletion

File tree

METdbLoad/ush/constants.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1614,6 +1614,13 @@
16141614
LC_SL1L2_SPECIFIC]
16151615
SL1L2_HEADERS = LC_COMMON_STAT_HEADER + ['total'] + SL1L2_STATISTICS_HEADERS
16161616

1617+
#### SAL1L2 Line type ####
1618+
1619+
LC_SAL1L2_SPECIFIC = ['fabar', 'oabar', 'foabar', 'ffabar', 'ooabar', 'mae']
1620+
SAL1L2_STATISTICS_HEADERS = [cur_stat_header.upper() for cur_stat_header in
1621+
LC_SAL1L2_SPECIFIC]
1622+
SAL1L2_HEADERS = LC_COMMON_STAT_HEADER + ['total'] + SAL1L2_STATISTICS_HEADERS
1623+
16171624
#### VL1L2 Line type ####
16181625

16191626
LC_VL1L2_SPECIFIC = ['ufbar', 'vfbar', 'uobar', 'vobar', 'uvfobar', 'uvffbar',

METreformat/write_stat_ascii.py

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def write_stat_ascii(self, stat_data: pd.DataFrame, parms: dict) -> pd.DataFrame
111111
# Subset data to requested line type
112112
# ----------------------------------
113113
supported_linetypes = [cn.FHO, cn.CNT, cn.VCNT, cn.CTC,
114-
cn.CTS, cn.MCTS, cn.SL1L2, cn.ECNT, cn.PCT,
114+
cn.CTS, cn.MCTS, cn.SL1L2, cn.SAL1L2, cn.ECNT, cn.PCT,
115115
cn.RHIST, cn.TCDIAG, cn.MPR, cn.DMAP]
116116

117117
# Different formats based on the line types. Most METplotpy plots accept the long format where
@@ -283,6 +283,14 @@ def process_by_stat_linetype(self, linetype: str, stat_data: pd.DataFrame, is_ag
283283
linetype_data: pd.DataFrame = self.process_sl1l2_for_agg(
284284
stat_data)
285285

286+
# SAL1L2 Scalar Anomaly Partial sums
287+
elif linetype == cn.SAL1L2:
288+
if is_aggregated:
289+
linetype_data: pd.DataFrame = self.process_sal1l2(stat_data)
290+
else:
291+
linetype_data: pd.DataFrame = self.process_sal1l2_for_agg(
292+
stat_data)
293+
286294
# VL1L2 Scalar Partial sums
287295
elif linetype == cn.VL1L2:
288296
if is_aggregated:
@@ -1303,6 +1311,67 @@ def process_sl1l2_for_agg(self, stat_data: pd.DataFrame) -> pd.DataFrame:
13031311

13041312
raise NotImplementedError
13051313

1314+
def process_sal1l2(self, stat_data: pd.DataFrame) -> pd.DataFrame:
1315+
"""
1316+
Reshape the data from the original MET output file (stat_data) into new
1317+
statistics columns:
1318+
stat_name, stat_value specifically for the SAL1L2 line type data.
1319+
1320+
Arguments:
1321+
@param stat_data: the dataframe containing all the data from the MET
1322+
.stat file.
1323+
1324+
Returns:
1325+
linetype_data: the reshaped pandas dataframe with statistics data
1326+
reorganized into the stat_name and
1327+
stat_value columns.
1328+
1329+
"""
1330+
1331+
# Relevant columns for the SAL1L2 line type
1332+
linetype: str = cn.SAL1L2
1333+
end = cn.NUM_STAT_SAL1L2_COLS
1334+
sal1l2_columns_to_use: List[str] = (
1335+
np.arange(0, end).tolist())
1336+
1337+
# Subset original dataframe to one containing only the SAL1L2 data
1338+
sal1l2_df: pd.DataFrame = stat_data[stat_data['line_type'] == linetype].iloc[:,
1339+
sal1l2_columns_to_use]
1340+
1341+
# Add the stat columns header names for the SAL1L2 line type
1342+
sal1l2_columns: List[str] = cn.SAL1L2_HEADERS
1343+
sal1l2_df.columns: List[str] = sal1l2_columns
1344+
1345+
# Create another index column to preserve the index values from the stat_data
1346+
# dataframe (i.e. the dataframe containing the original data from the MET output file).
1347+
idx = list(sal1l2_df.index)
1348+
1349+
# Work on a copy to avoid a possible PerformanceWarning from a fragmented dataframe.
1350+
sal1l2_df_copy = sal1l2_df.copy()
1351+
sal1l2_df_copy.insert(loc=0, column='Idx', value=idx)
1352+
1353+
# Columns we don't want to stack (treated as a multi index)
1354+
id_vars_list = ['Idx'] + cn.LC_COMMON_STAT_HEADER + ['total']
1355+
reshaped = sal1l2_df_copy.melt(id_vars=id_vars_list,
1356+
value_vars=cn.SAL1L2_STATISTICS_HEADERS,
1357+
var_name='stat_name',
1358+
value_name='stat_value').sort_values('Idx')
1359+
1360+
# SAL1L2 line type doesn't have bcl/bcu stat values (same as SL1L2) -- set to NA
1361+
na_column: List[str] = ['NA' for _ in range(0, reshaped.shape[0])]
1362+
1363+
reshaped['stat_ncl']: pd.Series = na_column
1364+
reshaped['stat_ncu']: pd.Series = na_column
1365+
reshaped['stat_bcl']: pd.Series = na_column
1366+
reshaped['stat_bcu']: pd.Series = na_column
1367+
1368+
return reshaped
1369+
1370+
def process_sal1l2_for_agg(self, stat_data: pd.DataFrame) -> pd.DataFrame:
1371+
# Matches the current state of SL1L2, VL1L2, CTC, CTS, CNT, VCNT, MCTS, FHO, RHIST --
1372+
# raw-input aggregation via METcalcpy's agg_stat is a separate, not-yet-built path.
1373+
raise NotImplementedError
1374+
13061375
def process_vl1l2(self, stat_data: pd.DataFrame) -> pd.DataFrame:
13071376
"""
13081377
Reshape the data from the original MET output file (stat_data) into new

0 commit comments

Comments
 (0)