From f86afbc7f061a64ecac3b968979261cd37c69c4e Mon Sep 17 00:00:00 2001 From: ShannonShields-NOAA <66634320+ShannonShields-NOAA@users.noreply.github.com> Date: Thu, 3 Oct 2024 14:34:33 -0400 Subject: [PATCH] Convert temp plot units from K to F (#577) Co-authored-by: shannon shields --- ush/subseasonal/subseasonal_util.py | 66 +++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/ush/subseasonal/subseasonal_util.py b/ush/subseasonal/subseasonal_util.py index 935d463e3b..08053d9797 100644 --- a/ush/subseasonal/subseasonal_util.py +++ b/ush/subseasonal/subseasonal_util.py @@ -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 @@ -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':