Skip to content

Commit

Permalink
Refactor zonal_mean_xy set
Browse files Browse the repository at this point in the history
  • Loading branch information
tomvothecoder committed Feb 15, 2024
1 parent 57b15fa commit 46a10ed
Show file tree
Hide file tree
Showing 17 changed files with 2,000 additions and 284 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from auxiliary_tools.cdat_regression_testing.base_run_script import run_set

SET_NAME = "zonal_mean_xy"
SET_DIR = "654-zonal_mean_xy"

run_set(SET_NAME, SET_DIR)
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"(dev and `main` branches).\n",
"\n",
"1. Make a copy of this notebook under `auxiliary_tools/cdat_regression_testing/<DIR_NAME>`.\n",
"2. Run `mamba create -n cdat_regression_test -y -c conda-forge \"python<3.12\" xarray dask pandas matplotlib-base ipykernel`\n",
"2. Run `mamba create -n cdat_regression_test -y -c conda-forge \"python<3.12\" xarray netcdf4 dask pandas matplotlib-base ipykernel`\n",
"3. Run `mamba activate cdat_regression_test`\n",
"4. Update `SET_DIR` and `SET_NAME` in the copy of your notebook.\n",
"5. Run all cells IN ORDER.\n",
Expand Down
12 changes: 7 additions & 5 deletions auxiliary_tools/cdat_regression_testing/template_run_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
"meridional_mean_2d", "annual_cycle_zonal_mean", "enso_diags", "qbo",
"area_mean_time_series", "diurnal_cycle", "streamflow", "arm_diags",
"tc_analysis", "aerosol_aeronet", "aerosol_budget", "mp_partition",
6. Run this script
- Make sure to run this command on NERSC perlmutter cpu:
`salloc --nodes 1 --qos interactive --time 01:00:00 --constraint cpu --account=e3sm
conda activate <NAME-OF-DEV-ENV>`
- python auxiliary_tools/cdat_regression_testing/<ISSUE-<SET_NAME>
6. Run this script as a Python module
- `auxiliary_tools` is not included in `setup.py`, so `-m` is required
to run the script as a Python module
- Command: python -m auxiliary_tools.cdat_regression_testing.<ISSUE>-<SET_NAME>.<SCRIPT-NAME>
- Example: python -m auxiliary_tools.cdat_regression_testing.660_cosp_histogram.run_script
7. Make a copy of the CDAT regression testing notebook in the same directory
as this script and follow the instructions there to start testing.
"""
Expand Down
3 changes: 2 additions & 1 deletion e3sm_diags/derivations/derivations.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
),
(("pr",), lambda pr: qflxconvert_units(rename(pr))),
(("PRECC", "PRECL"), lambda precc, precl: prect(precc, precl)),
(("sat_gauge_precip",), rename),
]
),
"PRECST": OrderedDict(
Expand Down Expand Up @@ -767,7 +768,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
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", "DJF", "MAM", "JJA", "SON"]
regions = ["global"]

Expand Down
7 changes: 6 additions & 1 deletion e3sm_diags/driver/utils/dataset_xr.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,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 @@ -304,6 +305,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 @@ -396,6 +398,9 @@ def _get_climo_dataset(self, season: str) -> xr.Dataset:
)

ds = self._squeeze_time_dim(ds)
# slat and slon are lat lon pair for staggered FV grid included in remapped files
if "slat" in ds.dims:
ds = ds.drop_dims(["slat", "slon"])

return ds

Expand Down
4 changes: 1 addition & 3 deletions e3sm_diags/driver/utils/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ def _save_data_metrics_and_plots(
logger.info(f"Metrics saved in {filepath}")

# Set the viewer description to the "long_name" attr of the variable.
parameter.viewer_descr[var_key] = ds_test[var_key].attrs.get(
"long_name", "No long_name attr in test data"
)
parameter.viewer_descr[var_key] = ds_test[var_key].attrs.get("long_name", var_key)

# Get the function arguments and pass to the set's plotting function.
args = [
Expand Down
Loading

0 comments on commit 46a10ed

Please sign in to comment.