Skip to content

Commit

Permalink
Convert temp plot units from K to F (#577)
Browse files Browse the repository at this point in the history
Co-authored-by: shannon shields <[email protected]>
  • Loading branch information
ShannonShields-NOAA and shannon shields authored Oct 3, 2024
1 parent 039a687 commit f86afbc
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions ush/subseasonal/subseasonal_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4143,6 +4143,7 @@ def build_df(logger, input_dir, output_dir, model_info_dict,
fhr - forecast hour (string)
Returns:
all_model_df - dataframe of all the information
"""
met_version_line_type_col_list = get_met_line_type_cols(
logger, met_info_dict['root'], met_info_dict['version'], line_type
Expand Down Expand Up @@ -4337,6 +4338,71 @@ def build_df(logger, input_dir, output_dir, model_info_dict,
[model_stat_file_df_valid_date_idx_list[0]]\
[:]
)
# Do conversions if needed
#### K to F
if fcst_var_name in ['TMP_ANOM_WEEKLYAVG',
'TMP_ANOM_DAYS6_10AVG',
'TMP_ANOM_WEEKS3_4AVG', 'SST_DAILYAVG',
'SST_WEEKLYAVG', 'SST_MONTHLYAVG'] \
and fcst_var_level in ['Z0', 'Z2'] \
and line_type in ['SL1L2', 'SAL1L2']:
coef = np.divide(9., 5.)
if fcst_var_name in ['TMP_ANOM_WEEKLYAVG',
'TMP_ANOM_DAYS6_10AVG',
'TMP_ANOM_WEEKS3_4AVG']:
const = 0
elif line_type == 'SAL1L2':
const = 0
else:
const = ((-273.15)*9./5.)+32.
convert = True
units_old = 'K'
units_new = 'F'
else:
convert = False
if convert:
if line_type == 'SL1L2':
fcst_avg_old = model_num_df.loc[
model_num_df['FCST_UNITS'] == units_old, 'FBAR'
]
obs_avg_old = model_num_df.loc[
model_num_df['FCST_UNITS'] == units_old, 'OBAR'
]
col1_list = ['FBAR', 'OBAR']
col2_list = ['FOBAR', 'FFBAR', 'OOBAR']
elif line_type == 'SAL1L2':
fcst_avg_old = model_num_df.loc[
model_num_df['FCST_UNITS'] == units_old, 'FABAR'
]
obs_avg_old = model_num_df.loc[
model_num_df['FCST_UNITS'] == units_old, 'OABAR'
]
col1_list = ['FABAR', 'OABAR']
col2_list = ['FOABAR', 'FFABAR', 'OOABAR']
for col in col1_list:
model_num_df.loc[
model_num_df['FCST_UNITS'] == units_old, col
] = (coef
* model_num_df.loc[model_num_df['FCST_UNITS'] \
== units_old, col]) \
+ const
for col in col2_list:
if col in ['FOBAR', 'FOABAR']:
const2 = ((coef * const * fcst_avg_old)
+ (coef * const * obs_avg_old))
elif col in ['FFBAR', 'FFABAR']:
const2 = 2 * (coef * const * fcst_avg_old)
elif col in ['OOBAR', 'OOABAR']:
const2 = 2 * (coef * const * obs_avg_old)
model_num_df.loc[
model_num_df['FCST_UNITS'] == units_old, col
] = (coef**2
*model_num_df.loc[model_num_df['FCST_UNITS'] \
== units_old, col]) \
+ const2 + const**2
model_num_df.loc[
model_num_df['FCST_UNITS'] == units_old, 'FCST_UNITS'
] = units_new
else:
logger.warning(f"{parsed_model_stat_file} does not exist")
if model_num == 'model1':
Expand Down

0 comments on commit f86afbc

Please sign in to comment.