Skip to content

Commit

Permalink
Propose a change for floating number format for mean climate metrics …
Browse files Browse the repository at this point in the history
…output

Current compute_metrics.py used either ".5f" or ".3f" to form the
floating numbers for the output from the mean climate driver. As the
magnitude of the model variable can range from 1e5 (e.g pressure ) to
1e-3 (e.g. humidity), used the ".5f" and ".3f" can sometimes truncate
the small values to zero. It seems that using  a standard scientific
notation can be benificial in case the user processed the data without
converting the unit data ahead. In this way, it also provide
possibilities for users to convert the units within the diagnostic
datasets.
  • Loading branch information
zhangshixuan1987 committed Sep 24, 2024
1 parent 04e1f76 commit 6ffdf1a
Showing 1 changed file with 35 additions and 38 deletions.
73 changes: 35 additions & 38 deletions pcmdi_metrics/mean_climate/lib/compute_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ def compute_metrics(Var, dm, do, debug=False, time_dim_sync=False):
dm = dm.bounds.add_missing_bounds()
do = do.bounds.add_missing_bounds()

if var in ["hus"]:
sig_digits = ".5f"
else:
sig_digits = ".3f"
float_format = "{:.5e}"

# CALCULATE ANNUAL CYCLE SPACE-TIME RMS, CORRELATIONS and STD
print("metrics-CALCULATE ANNUAL CYCLE SPACE-TIME RMS, CORRELATIONS and STD")
Expand Down Expand Up @@ -156,23 +153,23 @@ def compute_metrics(Var, dm, do, debug=False, time_dim_sync=False):
):
metrics_dictionary[stat] = OrderedDict()

metrics_dictionary["mean-obs_xy"]["ann"] = format(meanObs_xy, sig_digits)
metrics_dictionary["mean_xy"]["ann"] = format(mean_xy, sig_digits)
metrics_dictionary["std-obs_xy"]["ann"] = format(stdObs_xy, sig_digits)
metrics_dictionary["std_xy"]["ann"] = format(std_xy, sig_digits)
metrics_dictionary["std-obs_xyt"]["ann"] = format(stdObs_xyt, sig_digits)
metrics_dictionary["std_xyt"]["ann"] = format(std_xyt, sig_digits)
metrics_dictionary["std-obs_xy_devzm"]["ann"] = format(stdObs_xy_devzm, sig_digits)
metrics_dictionary["std_xy_devzm"]["ann"] = format(std_xy_devzm, sig_digits)
metrics_dictionary["rms_xyt"]["ann"] = format(rms_xyt, sig_digits)
metrics_dictionary["rms_xy"]["ann"] = format(rms_xy, sig_digits)
metrics_dictionary["rmsc_xy"]["ann"] = format(rmsc_xy, sig_digits)
metrics_dictionary["cor_xy"]["ann"] = format(cor_xy, sig_digits)
metrics_dictionary["bias_xy"]["ann"] = format(bias_xy, sig_digits)
metrics_dictionary["mae_xy"]["ann"] = format(mae_xy, sig_digits)
metrics_dictionary["mean-obs_xy"]["ann"] = float_format.format(meanObs_xy)
metrics_dictionary["mean_xy"]["ann"] = float_format.format(mean_xy)
metrics_dictionary["std-obs_xy"]["ann"] = float_format.format(stdObs_xy)
metrics_dictionary["std_xy"]["ann"] = float_format.format(std_xy)
metrics_dictionary["std-obs_xyt"]["ann"] = float_format.format(stdObs_xyt)
metrics_dictionary["std_xyt"]["ann"] = float_format.format(std_xyt)
metrics_dictionary["std-obs_xy_devzm"]["ann"] = float_format.format(stdObs_xy_devzm)
metrics_dictionary["std_xy_devzm"]["ann"] = float_format.format(std_xy_devzm)
metrics_dictionary["rms_xyt"]["ann"] = float_format.format(rms_xyt)
metrics_dictionary["rms_xy"]["ann"] = float_format.format(rms_xy)
metrics_dictionary["rmsc_xy"]["ann"] = float_format.format(rmsc_xy)
metrics_dictionary["cor_xy"]["ann"] = float_format.format(cor_xy)
metrics_dictionary["bias_xy"]["ann"] = float_format.format(bias_xy)
metrics_dictionary["mae_xy"]["ann"] = float_format.format(mae_xy)
# ZONAL MEAN CONTRIBUTIONS
metrics_dictionary["rms_y"]["ann"] = format(rms_y, sig_digits)
metrics_dictionary["rms_devzm"]["ann"] = format(rms_xy_devzm, sig_digits)
metrics_dictionary["rms_y"]["ann"] = float_format.format(rms_y)
metrics_dictionary["rms_devzm"]["ann"] = float_format.format(rms_xy_devzm)

# CALCULATE SEASONAL MEANS
for sea in ["djf", "mam", "jja", "son"]:
Expand All @@ -194,15 +191,15 @@ def compute_metrics(Var, dm, do, debug=False, time_dim_sync=False):
meanObs_xy_sea = stats.mean_xy(do_sea, var)
mean_xy_sea = stats.mean_xy(dm_sea, var)

metrics_dictionary["bias_xy"][sea] = format(bias_sea, sig_digits)
metrics_dictionary["rms_xy"][sea] = format(rms_sea, sig_digits)
metrics_dictionary["rmsc_xy"][sea] = format(rmsc_sea, sig_digits)
metrics_dictionary["cor_xy"][sea] = format(cor_sea, sig_digits)
metrics_dictionary["mae_xy"][sea] = format(mae_sea, sig_digits)
metrics_dictionary["std-obs_xy"][sea] = format(stdObs_xy_sea, sig_digits)
metrics_dictionary["std_xy"][sea] = format(std_xy_sea, sig_digits)
metrics_dictionary["mean-obs_xy"][sea] = format(meanObs_xy_sea, sig_digits)
metrics_dictionary["mean_xy"][sea] = format(mean_xy_sea, sig_digits)
metrics_dictionary["bias_xy"][sea] = float_format.format(bias_sea)
metrics_dictionary["rms_xy"][sea] = float_format.format(rms_sea)
metrics_dictionary["rmsc_xy"][sea] = float_format.format(rmsc_sea)
metrics_dictionary["cor_xy"][sea] = float_format.format(cor_sea)
metrics_dictionary["mae_xy"][sea] = float_format.format(mae_sea)
metrics_dictionary["std-obs_xy"][sea] = float_format.format(stdObs_xy_sea)
metrics_dictionary["std_xy"][sea] = float_format.format(std_xy_sea)
metrics_dictionary["mean-obs_xy"][sea] = float_format.format(meanObs_xy_sea)
metrics_dictionary["mean_xy"][sea] = float_format.format(mean_xy_sea)

rms_mo_l = []
rmsc_mo_l = []
Expand Down Expand Up @@ -248,15 +245,15 @@ def compute_metrics(Var, dm, do, debug=False, time_dim_sync=False):
meanObs_xy_mo = stats.mean_xy(do_mo, var)
mean_xy_mo = stats.mean_xy(dm_mo, var)

rms_mo_l.append(format(rms_mo, sig_digits))
rmsc_mo_l.append(format(rmsc_mo, sig_digits))
cor_mo_l.append(format(cor_mo, sig_digits))
mae_mo_l.append(format(mae_mo, sig_digits))
bias_mo_l.append(format(bias_mo, sig_digits))
stdObs_xy_mo_l.append(format(stdObs_xy_mo, sig_digits))
std_xy_mo_l.append(format(std_xy_mo, sig_digits))
meanObs_xy_mo_l.append(format(meanObs_xy_mo, sig_digits))
mean_xy_mo_l.append(format(mean_xy_mo, sig_digits))
rms_mo_l.append(float_format.format(rms_mo))
rmsc_mo_l.append(float_format.format(rmsc_mo))
cor_mo_l.append(float_format.format(cor_mo))
mae_mo_l.append(float_format.format(mae_mo))
bias_mo_l.append(float_format.format(bias_mo))
stdObs_xy_mo_l.append(float_format.format(stdObs_xy_mo))
std_xy_mo_l.append(float_format.format(std_xy_mo))
meanObs_xy_mo_l.append(float_format.format(meanObs_xy_mo))
mean_xy_mo_l.append(float_format.format(mean_xy_mo))

metrics_dictionary["bias_xy"]["CalendarMonths"] = bias_mo_l
metrics_dictionary["rms_xy"]["CalendarMonths"] = rms_mo_l
Expand Down

0 comments on commit 6ffdf1a

Please sign in to comment.