Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More EAMXX var support #849

Draft
wants to merge 42 commits into
base: cdat-migration-fy24
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
ae8c525
CDAT Migration Phase 2: Refactor core utilities and `lat_lon` set (#…
tomvothecoder Oct 10, 2023
273b289
Regression testing for lat_lon variables `NET_FLUX_SRF` and `RESTOM` …
tomvothecoder Dec 5, 2023
4b23a9b
Update regression test notebook to show validation of all vars
tomvothecoder Dec 5, 2023
cb070e2
Add `subset_and_align_datasets()` to regrid.py (#776)
tomvothecoder Jan 8, 2024
988b31d
Add template run scripts
tomvothecoder Jan 24, 2024
5797101
CDAT Migration Phase: Refactor `cosp_histogram` set (#748)
tomvothecoder Jan 30, 2024
d679c18
CDAT Migration Phase 2: Refactor `zonal_mean_2d()` and `zonal_mean_2d…
tomvothecoder Feb 14, 2024
d1a6acd
Refactor 654 zonal mean xy (#752)
chengzhuzhang Feb 15, 2024
ea9e871
CDAT Migration - Update run script output directory to NERSC public w…
tomvothecoder Feb 26, 2024
8d76992
[PR]: CDAT Migration: Refactor `aerosol_aeronet` set (#788)
tomvothecoder Feb 27, 2024
43647f3
CDAT Migration: Test `lat_lon` set with run script and debug any issu…
tomvothecoder Mar 12, 2024
83a4a9e
CDAT Migration: Refactor `polar` set (#749)
forsyth2 Mar 14, 2024
d5054a9
Align order of calls to `_set_param_output_attrs`
tomvothecoder Mar 19, 2024
5151f61
CDAT Migration: Refactor `meridional_mean_2d` set (#795)
tomvothecoder Mar 25, 2024
f446637
CDAT Migration: Refactor `aerosol_budget` (#800)
tomvothecoder May 13, 2024
8b4043a
Add `acme.py` changes from PR #712 (#814)
tomvothecoder May 13, 2024
008f374
Refactor area_mean_time_series and add ccb slice flag feature (#750)
forsyth2 May 30, 2024
815450f
[Refactor]: Validate fix in PR #750 for #759 (#815)
tomvothecoder Jun 3, 2024
419594a
CDAT Migration Phase 2: Refactor `diurnal_cycle` set (#819)
tomvothecoder Jul 22, 2024
4b1f782
CDAT Migration: Refactor annual_cycle_zonal_mean set (#798)
chengzhuzhang Jul 25, 2024
eed8a29
CDAT Migration Phase 2: Refactor `qbo` set (#826)
tomvothecoder Jul 30, 2024
e0e3bab
CDAT Migration Phase 2: Refactor tc_analysis set (#829)
chengzhuzhang Aug 19, 2024
defce25
CDAT Migration Phase 2: Refactor `enso_diags` set (#832)
tomvothecoder Aug 22, 2024
6f889f8
CDAT Migration Phase 2: Refactor `streamflow` set (#837)
tomvothecoder Aug 26, 2024
e772620
clean up arm_diags annual-cycle subset
chengzhuzhang Aug 26, 2024
0d90635
update climo_xr for supporting annual cycle and performance
chengzhuzhang Aug 26, 2024
c651621
more updates on climo_xr
chengzhuzhang Aug 28, 2024
2b7e09e
finish annual_cycle(2d)
chengzhuzhang Aug 29, 2024
7f7244b
complete diurnal cycle (2d);enhance diurnal_cycle_xr performance
chengzhuzhang Aug 29, 2024
ed44374
update diurnal cycle zt
chengzhuzhang Sep 5, 2024
47d7aea
update convection onset
chengzhuzhang Sep 5, 2024
58d61c4
update aerosol activation
chengzhuzhang Sep 6, 2024
ef44fc6
Add `.load()` to `_get_dataset_with_source_vars()` to improve perform…
tomvothecoder Sep 9, 2024
016b1a3
Clean up run script
tomvothecoder Sep 13, 2024
d71a06f
Revert `.load()` in `_get_dataset_with_source_vars()`
tomvothecoder Sep 13, 2024
14927e1
Replace `fastAllGridFT` with `_fft_all_grid`
tomvothecoder Sep 13, 2024
2c248fb
Code clean up and fix pre-commit issues
tomvothecoder Sep 13, 2024
839096c
Update `fastAllGridFT` to `_fft_all_grid`
tomvothecoder Sep 13, 2024
6293a0d
add png regression test script
chengzhuzhang Sep 10, 2024
1114301
add png regression test script
chengzhuzhang Sep 18, 2024
fb74e89
fix CI for a missing file
chengzhuzhang Sep 18, 2024
578af4c
support more EAMXX vars
chengzhuzhang Sep 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactor 654 zonal mean xy (#752)
Co-authored-by: Tom Vo <[email protected]>
  • Loading branch information
chengzhuzhang and tomvothecoder committed Aug 21, 2024
commit d1a6acdbe4990014aea7cd08bcecb36123579598

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)

Large diffs are not rendered by default.

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

SET_NAME = "zonal_mean_xy"
SET_DIR = "debug-654-zonal_mean_xy"
# CFG_PATH = "auxiliary_tools/cdat_regression_testing/654-zonal_mean_xy/debug_zonal_mean_xy_model_vs_obs.cfg"

run_set(SET_NAME, SET_DIR)
# run_set(SET_NAME, SET_DIR, CFG_PATH, multiprocessing=False)
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
[#]
sets = ["zonal_mean_xy"]
case_id = "Cloud ISCCP"
variables = ["CLDTOT_TAU1.3_ISCCP"]
ref_name = "ISCCPCOSP"
reference_name = "ISCCP"
seasons = ["ANN", "DJF", "MAM", "JJA", "SON"]

[#]
sets = ["zonal_mean_xy"]
case_id = "Cloud ISCCP"
variables = ["CLDTOT_TAU1.3_9.4_ISCCP"]
ref_name = "ISCCPCOSP"
reference_name = "ISCCP"
seasons = ["ANN", "DJF", "MAM", "JJA", "SON"]

[#]
sets = ["zonal_mean_xy"]
case_id = "Cloud ISCCP"
variables = ["CLDTOT_TAU9.4_ISCCP"]
ref_name = "ISCCPCOSP"
reference_name = "ISCCP"
seasons = ["ANN", "DJF", "MAM", "JJA", "SON"]


[#]
sets = ["zonal_mean_xy"]
case_id = "Cloud MODIS"
variables = ["CLDTOT_TAU1.3_MODIS"]
ref_name = "MODISCOSP"
reference_name = "MODIS Simulator"
seasons = ["ANN", "DJF", "MAM", "JJA", "SON"]

[#]
sets = ["zonal_mean_xy"]
case_id = "Cloud MODIS"
variables = ["CLDTOT_TAU1.3_9.4_MODIS"]
ref_name = "MODISCOSP"
reference_name = "MODIS Simulator"
seasons = ["ANN", "DJF", "MAM", "JJA", "SON"]

[#]
sets = ["zonal_mean_xy"]
case_id = "Cloud MODIS"
variables = ["CLDTOT_TAU9.4_MODIS"]
ref_name = "MODISCOSP"
reference_name = "MODIS Simulator"
seasons = ["ANN", "DJF", "MAM", "JJA", "SON"]

[#]
sets = ["zonal_mean_xy"]
case_id = "Cloud MODIS"
variables = ["CLDHGH_TAU1.3_MODIS"]
ref_name = "MODISCOSP"
reference_name = "MODIS Simulator"
seasons = ["ANN", "DJF", "MAM", "JJA", "SON"]

[#]
sets = ["zonal_mean_xy"]
case_id = "Cloud MODIS"
variables = ["CLDHGH_TAU1.3_9.4_MODIS"]
ref_name = "MODISCOSP"
reference_name = "MODIS Simulator"
seasons = ["ANN", "DJF", "MAM", "JJA", "SON"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
[#]
sets = ["zonal_mean_xy"]
case_id = "CERES-EBAF-surface-v4.1"
variables = ["FLNS"]
ref_name = "ceres_ebaf_surface_v4.1"
reference_name = "CERES-EBAF v4.1"
seasons = ["ANN"]

[#]
sets = ["zonal_mean_xy"]
case_id = "MERRA2"
variables = ["TMQ"]
ref_name = "MERRA2"
reference_name = "MERRA2 Reanalysis"
seasons = ["ANN"]

#[#]
#sets = ["zonal_mean_xy"]
#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"]
#case_id = "COREv2_Flux"
#variables = ["PminusE"]
#ref_name = "COREv2_Flux"
#reference_name = "COREv2_Flux"
#seasons = ["ANN"]
#
#
#[#]
#sets = ["zonal_mean_xy"]
#case_id = "GPCP_v3.2"
#variables = ["PRECT"]
#ref_name = "GPCP_v3.2"
#reference_name = "GPCP v3.2"
#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]
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import os
import sys

from e3sm_diags.parameter.core_parameter import CoreParameter
from e3sm_diags.run import runner

param = CoreParameter()

# Location of the data.
param.reference_data_path = (
"/global/cfs/cdirs/e3sm/e3sm_diags/obs_for_e3sm_diags/climatology/"
)
param.test_data_path = (
"/global/cfs/cdirs/e3sm/e3sm_diags/postprocessed_e3sm_v2_data_for_e3sm_diags/20210528.v2rc3e.piControl.ne30pg2_EC30to60E2r2.chrysalis/climatology/rgr"
)
# Name of the test model data, used to find the climo files.
param.test_name = "20210528.v2rc3e.piControl.ne30pg2_EC30to60E2r2.chrysalis"
# An optional, shorter name to be used instead of the test_name.
param.short_test_name = "v2rc3e"

# What plotsets to run the diags on.
#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"
param.results_dir = os.path.join(prefix, "ex5_model_to_obs")

# Below are more optional arguments.

# Title of the difference plots.
param.diff_title = "Model - Obs."
# Save the netcdf files for each of the ref, test, and diff plot.
param.save_netcdf = True
# For running with multiprocessing.
# param.multiprocessing = True
# param.num_workers = 32
# Use the specified `.cfg` file for debugging
CFG_PATH = "examples/test_refactor/diags.cfg"
sys.argv.extend(["-d", CFG_PATH])

runner.sets_to_run = ["zonal_mean_xy"]
runner.run_diags([param])
17 changes: 11 additions & 6 deletions auxiliary_tools/cdat_regression_testing/base_run_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# flake8: noqa E501

import os
import sys
from typing import List, Tuple, TypedDict

from mache import MachineInfo
Expand Down Expand Up @@ -44,7 +45,15 @@ class MachinePaths(TypedDict):
tc_test: str


def run_set(set_name: str, set_dir: str):
def run_set(
set_name: str,
set_dir: str,
cfg_path: str | None = None,
multiprocessing: bool = True,
):
if cfg_path is not None:
sys.argv.extend(["--diags", cfg_path])

machine_paths: MachinePaths = _get_machine_paths()

param = CoreParameter()
Expand All @@ -58,7 +67,7 @@ def run_set(set_name: str, set_dir: str):
] # Default setting: seasons = ["ANN", "DJF", "MAM", "JJA", "SON"]

param.results_dir = os.path.join(BASE_RESULTS_DIR, set_dir)
param.multiprocessing = True
param.multiprocessing = multiprocessing
param.num_workers = 5

# Make sure to save the netCDF files to compare outputs.
Expand Down Expand Up @@ -251,7 +260,3 @@ def _get_test_data_dirs(machine: str) -> Tuple[str, str]:
)

return test_data_dirs # type: ignore


if __name__ == "__main__":
run_set()
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,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\" 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 `DEV_PATH` and `MAIN_PATH` in the copy of your notebook.\n",
"5. Run all cells IN ORDER.\n",
Expand Down
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
30 changes: 24 additions & 6 deletions auxiliary_tools/cdat_regression_testing/template_run_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,23 @@
"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.

8. <OPTIONAL> Update `CFG_PATH` to a custom cfg file to debug specific variables.
- It is useful to create a custom cfg based on the default diags to debug
specific variables that are running into problems.
- For example, copy `zonal_mean_xy_model_vs_model.cfg` into the same directory
as the copy of this script, then modify it to specific variables. Afterwards
update `CFG_PATH` to the path of that .cfg file.
- Tip: Use VS Code to step through the code with the Python debugger.
"""
from auxiliary_tools.cdat_regression_testing.base_run_script import run_set

Expand All @@ -30,4 +40,12 @@
# Example: "671-lat-lon"
SET_DIR = ""

run_set(SET_NAME, SET_DIR)
# TODO: <OPTIONAL> UPDATE CFG_PATH if using a custom cfg file for debugging.
# Example: "auxiliary_tools/cdat_regression_testing/654_zonal_mean_xy.cfg"
CFG_PATH: str | None = None

# TODO: <OPTIONAL> Update MULTIPROCESSING based on whether to run in parallel or
# serial. For debugging purposes, set to False to run serially.
MULTIPROCESSING = True

run_set(SET_NAME, SET_DIR, CFG_PATH, MULTIPROCESSING)
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
Loading