Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix/global_det_units #581

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions ush/global_det/global_det_atmos_plots_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions ush/global_det/global_det_atmos_plots_threshold_average.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 0 additions & 21 deletions ush/global_det/global_det_atmos_plots_time_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
111 changes: 111 additions & 0 deletions ush/global_det/global_det_atmos_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down