From 6036a68541864e476feac0474349258ebabe36f5 Mon Sep 17 00:00:00 2001 From: Mallory Row Date: Thu, 3 Oct 2024 19:19:24 +0000 Subject: [PATCH] Fix unit conversions --- .../global_det_atmos_plots_specs.py | 8 -- ...lobal_det_atmos_plots_threshold_average.py | 4 + .../global_det_atmos_plots_time_series.py | 21 ---- ush/global_det/global_det_atmos_util.py | 111 ++++++++++++++++++ 4 files changed, 115 insertions(+), 29 deletions(-) diff --git a/ush/global_det/global_det_atmos_plots_specs.py b/ush/global_det/global_det_atmos_plots_specs.py index dbf427c14..43372e188 100644 --- a/ush/global_det/global_det_atmos_plots_specs.py +++ b/ush/global_det/global_det_atmos_plots_specs.py @@ -682,14 +682,6 @@ def get_plot_title(self, plot_info_dict, date_info_dict, units): if plot_info_dict['fcst_var_name'] == 'ICEEX_DAILYAVG' \ and units == '10^6_km^2': units = 'x'+units.replace('_', ' ') - elif plot_info_dict['fcst_var_name'] \ - in ['UGRD', 'VGRD', 'UGRD_VGRD', 'WNDSHR', 'GUST']: - units = 'kt' - elif plot_info_dict['fcst_var_name'] \ - in ['TMP', 'DPT', 'TMP_ANOM_DAILYAVG', 'SST_DAILYAVG', - 'TSOIL'] \ - and plot_info_dict['fcst_var_level'] in ['Z0', 'Z2', 'Z0.1-0']: - units = 'F' plot_title = plot_title+' '+'('+units+')' if var_thresh_for_title != 'NA': plot_title = plot_title+', '+var_thresh_for_title+' '+units diff --git a/ush/global_det/global_det_atmos_plots_threshold_average.py b/ush/global_det/global_det_atmos_plots_threshold_average.py index a67ad920c..c6122f3a0 100644 --- a/ush/global_det/global_det_atmos_plots_threshold_average.py +++ b/ush/global_det/global_det_atmos_plots_threshold_average.py @@ -306,6 +306,10 @@ def make_threshold_average(self): figsize=(plot_specs_ta.fig_size[0], plot_specs_ta.fig_size[1]), sharex=True) + if self.plot_info_dict['fcst_var_name'] == 'DPT' \ + and self.plot_info_dict['fcst_var_level'] == 'Z2': + plot_title = plot_title.replace('2 meter Dewpoint (K)', + '2 meter Dewpoint (F)') fig.suptitle(plot_title) ax1.grid(True) ax1.set_ylabel(stat_plot_name) diff --git a/ush/global_det/global_det_atmos_plots_time_series.py b/ush/global_det/global_det_atmos_plots_time_series.py index bcea79ac3..d5ce4cf1c 100644 --- a/ush/global_det/global_det_atmos_plots_time_series.py +++ b/ush/global_det/global_det_atmos_plots_time_series.py @@ -387,27 +387,6 @@ def make_time_series(self): obar_model_num_avg_label = format( round(obar_model_num_avg, 3), '.3f' ) - ############################################################ - # For FBAR stats, do the following unit conversions: - # TMP/Z2: K to F - # TSOIL/Z0.1-0: K to F - # UGRD/Z10: m/s to kt - # VGRD/Z10: m/s to kt - if self.plot_info_dict['stat'] == 'FBAR': - if self.plot_info_dict['fcst_var_name'] \ - in ['TMP', 'TSOIL'] \ - and self.plot_info_dict['fcst_var_level'] \ - in ['Z2', 'Z0.1-0']: - masked_model_num_data = ( - (((masked_model_num_data-273.15)*9)/5)+32 - ) - elif self.plot_info_dict['fcst_var_name'] \ - in ['UGRD', 'VGRD'] \ - and self.plot_info_dict['fcst_var_level'] == 'Z10': - masked_model_num_data = ( - masked_model_num_data * 1.94384449412 - ) - ############################################################ ax.plot_date( np.ma.compressed(masked_plot_dates), np.ma.compressed(masked_model_num_data), diff --git a/ush/global_det/global_det_atmos_util.py b/ush/global_det/global_det_atmos_util.py index b6cdffb8d..1bd689d91 100644 --- a/ush/global_det/global_det_atmos_util.py +++ b/ush/global_det/global_det_atmos_util.py @@ -2959,6 +2959,117 @@ 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', 'DPT', 'TMP_ANOM_DAILYAVG', + 'SST_DAILYAVG', 'TSOIL'] \ + and fcst_var_level in ['Z0', 'Z2', 'Z0.1-0'] \ + and line_type in ['SL1L2', 'SAL1L2']: + coef = np.divide(9., 5.) + if fcst_var_name == 'TMP_ANOM_DAILYAVG': + const = 0 + elif line_type == 'SAL1L2': + const = 0 + else: + const = ((-273.15)*9./5.)+32. + convert = True + units_old = 'K' + units_new = 'F' + #### m/s to knots + elif fcst_var_name in ['UGRD', 'VGRD', 'UGRD_VGRD', + 'WNDSHR', 'GUST'] \ + and line_type in ['SL1L2', 'SAL1L2', + 'VL1L2', 'VAL1L2']: + coef = 1.94384449412 + const = 0 + convert = True + units_old = 'm/s' + units_new = 'kt' + 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'] + elif line_type == 'VL1L2': + uf_avg_old = model_num_df.loc[ + model_num_df['FCST_UNITS'] == units_old, 'UFBAR' + ] + vf_avg_old = model_num_df.loc[ + model_num_df['FCST_UNITS'] == units_old, 'VFBAR' + ] + uo_avg_old = model_num_df.loc[ + model_num_df['FCST_UNITS'] == units_old, 'UOBAR' + ] + vo_avg_old = model_num_df.loc[ + model_num_df['FCST_UNITS'] == units_old, 'VOBAR' + ] + col1_list = ['UFBAR', 'VFBAR', 'UOBAR', 'VOBAR'] + col2_list = ['UVFOBAR', 'UVFFBAR', 'UVOOBAR'] + elif line_type == 'VAL1L2': + uf_avg_old = model_num_df.loc[ + model_num_df['FCST_UNITS'] == units_old, 'UFABAR' + ] + vf_avg_old = model_num_df.loc[ + model_num_df['FCST_UNITS'] == units_old, 'VFABAR' + ] + uo_avg_old = model_num_df.loc[ + model_num_df['FCST_UNITS'] == units_old, 'UOABAR' + ] + vo_avg_old = model_num_df.loc[ + model_num_df['FCST_UNITS'] == units_old, 'VOABAR' + ] + col1_list = ['UFABAR', 'VFABAR', 'UOABAR', 'VOABAR'] + col2_list = ['UVFOABAR', 'UVFFABAR', 'UVOOABAR'] + 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) + elif col in ['UVFOBAR', 'UVFOABAR']: + const2 = (coef * const \ + * (uf_avg_old+vf_avg_old + +uo_avg_old+vo_avg_old)) + elif col in ['UVFFBAR', 'UVFFABAR']: + const2 = 2 * (coef * const * \ + (uf_avg_old+vf_avg_old)) + elif col in ['UVOOBAR', 'UVOOABAR']: + const2 = 2 * (coef * const * \ + (uo_avg_old+vo_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.debug(f"{parsed_model_stat_file} does not exist") if model_num == 'model1':