Skip to content

Commit

Permalink
revert some derived variable logic; fix one derived variable
Browse files Browse the repository at this point in the history
  • Loading branch information
chengzhuzhang committed Jan 24, 2024
1 parent ef0be45 commit 8a23975
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 25 deletions.
2 changes: 1 addition & 1 deletion e3sm_diags/derivations/derivations.py
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@
"QFLX",
),
lambda precc, precl, qflx: pminuse_convert_units(
prect(precc, precl) - pminuse_convert_units(qflx)
prect(precc, precl) - qflxconvert_units(qflx)
),
),
(
Expand Down
19 changes: 10 additions & 9 deletions e3sm_diags/derivations/formulas.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,16 @@ def qflx_convert_to_lhflx_approxi(var: xr.DataArray):


def pminuse_convert_units(var: xr.DataArray):
if (
var.attrs["units"] == "kg/m2/s"
or var.attrs["units"] == "kg m-2 s-1"
or var.attrs["units"] == "kg/s/m^2"
):
# need to find a solution for units not included in udunits
# var = convert_units( var, 'kg/m2/s' )
var = var * 3600.0 * 24 # convert to mm/day
var.attrs["units"] = "mm/day"
if hasattr(var, "units"):
if (
var.attrs["units"] == "kg/m2/s"
or var.attrs["units"] == "kg m-2 s-1"
or var.attrs["units"] == "kg/s/m^2"
):
# need to find a solution for units not included in udunits
# var = convert_units( var, 'kg/m2/s' )
var = var * 3600.0 * 24 # convert to mm/day
var.attrs["units"] = "mm/day"
var.attrs["long_name"] = "precip. flux - evap. flux"
return var

Expand Down
6 changes: 3 additions & 3 deletions e3sm_diags/driver/utils/dataset_xr.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,10 @@ def _get_climo_dataset(self, season: str) -> xr.Dataset:
filepath = self._get_climo_filepath(season)
ds = xc.open_dataset(filepath, use_cftime=True, add_bounds=["X", "Y"])

if self.var in ds.variables:
pass
elif self.var in self.derived_vars_map:
if self.var in self.derived_vars_map:
ds = self._get_dataset_with_derived_climo_var(ds)
elif self.var in ds.variables:
pass
else:
raise IOError(
f"Variable '{self.var}' was not in the file '{filepath}', nor was "
Expand Down
32 changes: 20 additions & 12 deletions examples/test_refactor/diags.cfg
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
#[#]
#sets = ["zonal_mean_xy"]
#case_id = "GPCP_OAFLux"
#variables = ["PminusE"]
#ref_name = "GPCP_OAFLux"
#reference_name = "PRECT(GPCP) minus QFLX(OAFLux)"
#case_id = "MERRA2"
#variables = ["TREFHT"]
#regions = ["global"]
#ref_name = "MERRA2"
#reference_name = "MERRA2 Reanalysis"
#seasons = ["ANN"]
[#]
sets = ["zonal_mean_xy"]
case_id = "GPCP_OAFLux"
variables = ["PminusE"]
ref_name = "GPCP_OAFLux"
reference_name = "PRECT(GPCP) minus QFLX(OAFLux)"
seasons = ["ANN"]
#
#[#]
#sets = ["zonal_mean_xy"]
Expand All @@ -24,11 +32,11 @@
#seasons = ["ANN"]
#regions = ["global"]

[#]
sets = ["zonal_mean_xy"]
case_id = "ERA5"
variables = ["T"]
ref_name = "ERA5"
reference_name = "ERA5 Reanalysis"
seasons = ["ANN"]
plevs = [850.0]
#[#]
#sets = ["zonal_mean_xy"]
#case_id = "ERA5"
#variables = ["T"]
#ref_name = "ERA5"
#reference_name = "ERA5 Reanalysis"
#seasons = ["ANN"]
#plevs = [850.0]

0 comments on commit 8a23975

Please sign in to comment.