Skip to content

Commit

Permalink
Merge pull request #1068 from PCMDI/mean_clim_bug_fix_e3sm_v2.1
Browse files Browse the repository at this point in the history
mean climate bug fix for E3SMv2.1 evaluation
  • Loading branch information
lee1043 committed Mar 11, 2024
2 parents d51ca9b + 3310892 commit a9e2876
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
4 changes: 4 additions & 0 deletions pcmdi_metrics/mean_climate/lib/compute_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ def compute_metrics(Var, dm, do, debug=False, time_dim_sync=False):

metrics_dictionary = OrderedDict()

# QC for bounds
dm = dm.bounds.add_missing_bounds()
do = do.bounds.add_missing_bounds()

if var in ["hus"]:
sig_digits = ".5f"
else:
Expand Down
21 changes: 17 additions & 4 deletions pcmdi_metrics/mean_climate/lib/load_and_regrid.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
import xcdat as xc

from pcmdi_metrics.io import xcdat_open
from pcmdi_metrics.io import get_latitude, get_longitude, xcdat_open


def load_and_regrid(
Expand Down Expand Up @@ -40,9 +40,14 @@ def load_and_regrid(
# SET CONDITIONAL ON INPUT VARIABLE
if varname == "pr":
print("Adjust units for pr")
if ds[varname_in_file].units == "kg m-2 s-1":
ds[varname_in_file] = ds[varname_in_file] * 86400
print("pr units adjusted to [mm d-1] from [kg m-2 s-1] by 86400 multiplied")
if "units" in ds[varname_in_file].attrs:
if ds[varname_in_file].units == "kg m-2 s-1":
ds[varname_in_file] = ds[varname_in_file] * 86400
print(
"pr units adjusted to [mm d-1] from [kg m-2 s-1] by 86400 multiplied"
)
else:
ds[varname_in_file] = ds[varname_in_file] * 86400 # Assumed as kg m-2 s-1

"""
# calendar quality check
Expand Down Expand Up @@ -118,6 +123,14 @@ def load_and_regrid(
print("ERROR: load and regrid can not complete")
return

# axis
lat = get_latitude(ds)
lon = get_longitude(ds)
if "axis" not in lat.attrs:
ds[lat.name].attrs["axis"] = "Y"
if "axis" not in lon.attrs:
ds[lon.name].attrs["axis"] = "X"

# regrid
if regrid_tool == "regrid2":
ds_regridded = ds.regridder.horizontal(
Expand Down
3 changes: 2 additions & 1 deletion pcmdi_metrics/mean_climate/mean_climate_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@
ds_test_dict[region],
ds_ref_dict[region],
debug=debug,
time_dim_sync=True,
)
except Exception:
result_dict["RESULTS"][model][ref][run][
Expand All @@ -407,7 +408,7 @@
ds_test_dict[region],
ds_ref_dict[region],
debug=debug,
time_dim_sync=True,
time_dim_sync=False,
)

# write individual JSON
Expand Down

0 comments on commit a9e2876

Please sign in to comment.