Skip to content

Commit

Permalink
fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
chengzhuzhang committed Dec 12, 2023
1 parent 494acb4 commit 83d83a4
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions e3sm_diags/derivations/derivations.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
),
(("pr",), lambda pr: qflxconvert_units(rename(pr))),
(("PRECC", "PRECL"), lambda precc, precl: prect(precc, precl)),
(("sat_gauge_precip",), rename),
]
),
"PRECST": OrderedDict(
Expand Down
8 changes: 5 additions & 3 deletions e3sm_diags/driver/utils/dataset_xr.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,8 @@ def get_ref_climo_dataset(
# TODO: This logic was carried over from legacy implementation. It
# can probably be improved on by setting `ds_ref = None` and not
# performing unnecessary operations on `ds_ref` for model-only runs,
# since it is the same as `ds_test``.
# since it is the same as `ds_test``. In addition, returning ds_test makes it difficult for trouble shooting

if self.data_type == "ref":
try:
ds_ref = self.get_climo_dataset(var_key, season)
Expand All @@ -303,6 +304,7 @@ def get_ref_climo_dataset(
self.model_only = True

logger.info("Cannot process reference data, analyzing test data only.")

else:
raise RuntimeError(
"`Dataset._get_ref_dataset` only works with "
Expand Down Expand Up @@ -382,7 +384,7 @@ def _get_climo_dataset(self, season: str) -> xr.Dataset:
using other datasets.
"""
filepath = self._get_climo_filepath(season)
ds = xr.open_dataset(filepath, use_cftime=True)
ds = xc.open_dataset(filepath, use_cftime=True, add_bounds=["X", "Y"])

if self.var in ds.variables:
pass
Expand Down Expand Up @@ -645,7 +647,7 @@ def _get_matching_climo_src_vars(
return {tuple(var_list): target_variable_map[var_tuple]}

raise IOError(
f"The dataset file has no matching souce variables for {target_var}"
f"The dataset file has no matching source variables for {target_var}"
)

# --------------------------------------------------------------------------
Expand Down
5 changes: 4 additions & 1 deletion e3sm_diags/driver/zonal_mean_xy_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from scipy import interpolate

from e3sm_diags.driver.utils.dataset_xr import Dataset

# TODO
from e3sm_diags.driver.utils.io import _save_data_metrics_and_plots
from e3sm_diags.driver.utils.regrid import (
Expand Down Expand Up @@ -64,7 +65,9 @@ def run_diag(parameter: CoreParameter) -> CoreParameter:
parameter._set_name_yrs_attrs(test_ds, ref_ds, season)

ds_test = test_ds.get_climo_dataset(var_key, season)
# TODO consider to refactor the behavior of get_ref_climo_dataset
ds_ref = ref_ds.get_ref_climo_dataset(var_key, season, ds_test)
# ds_ref = ref_ds.get_ref_climo_dataset(var_key, season)

# Store the variable's DataArray objects for reuse.
dv_test = ds_test[var_key]
Expand Down Expand Up @@ -323,6 +326,6 @@ def regrid_to_lower_res_1d(

else:
interpf = interpolate.interp1d(ds_ref_1d.lat, ds_ref_1d.values)
ds_ref_1d_new = ds_test_1d.copy(data=interpf(ds_ref_1d.lat))
ds_ref_1d_new = ds_test_1d.copy(data=interpf(ds_test_1d.lat))
ds_diff_1d = ds_test_1d - ds_ref_1d_new
return ds_diff_1d
2 changes: 1 addition & 1 deletion examples/test_refactor/diags.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ sets = ["zonal_mean_xy"]
case_id = "GPCP_v3.2"
variables = ["PRECT"]
ref_name = "GPCP_v3.2"
reference_name = "GPCP v2.2"
reference_name = "GPCP v3.2"
seasons = ["ANN"]
regions = ["global"]

Expand Down
2 changes: 1 addition & 1 deletion examples/test_refactor/ex5.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
param.short_test_name = "beta0.FC5COSP.ne30"

# What plotsets to run the diags on.
param.sets = ["lat_lon"]
#param.sets = ["lat_lon"]
# Name of the folder where the results are stored.
# Change `prefix` to use your directory.
prefix = "/global/cfs/cdirs/e3sm/www/chengzhu/test_e3sm_refactor"
Expand Down

0 comments on commit 83d83a4

Please sign in to comment.