Skip to content

Commit 0233432

Browse files
chengzhuzhangtomvothecoder
authored andcommitted
Refactor Jill's initial PR for maintainability
add testing script and cfg file Move METRICS_DEFAULT_VALUE to /driver/__init__.py Refactor `default_viewer.py` and `main.py` Move `run_native_grid_test.py` to `debug/968-native-grid-vis` Refactor `lat_lon_native_parameter.py` and `core_parameter.py` - Update type annotations, re-order methods in `LatLonNativeParameter` class Add a comment for granulation in `core_parser.py` Extract code from LatLonNativeDriver into NativeDataset class - Move `TimeSlice` and `TimeSelection` into `type_annotations.py` and update all references Add type annotations and comments Add fixme and todo comments in driver and plotter Update run script to use single run
1 parent 60f1084 commit 0233432

File tree

17 files changed

+979
-809
lines changed

17 files changed

+979
-809
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[#]
2+
sets = ["lat_lon_native"]
3+
case_id = "model_vs_model"
4+
variables = ["TGCLDLWP"]
5+
seasons = ["ANN", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "DJF", "MAM", "JJA", "SON"]
6+
regions = ["global", "30S30N-150E90W"]
7+
#test_colormap = "Blues"
8+
#reference_colormap = "Blues"
9+
diff_colormap = "RdBu"
10+
#contour_levels = [ 1.25892541, 2.26754313, 4.08423865, 7.35642254, 13.25019355, 23.86589787, 42.98662347, 77.42636827, 139.45832492, 251.18864315]
11+
diff_levels = [-35, -30, -25, -20, -15, -10, -5, 5, 10, 15, 20, 25, 30, 35]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[#]
2+
sets = ["lat_lon_native"]
3+
case_id = "model_vs_model"
4+
variables = ["PRECT"]
5+
seasons = ["ANN", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "DJF", "MAM", "JJA", "SON"]
6+
regions = ["global", "60S60N", "30S30N-150E90W"]
7+
test_colormap = "WhiteBlueGreenYellowRed.rgb"
8+
reference_colormap = "WhiteBlueGreenYellowRed.rgb"
9+
diff_colormap = "BrBG"
10+
contour_levels = [0.5, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13, 14, 15, 16]
11+
diff_levels = [-2.5, -2, -1.5, -1, -0.5, -0.25, 0.25, 0.5, 1, 1.5, 2, 2.5]
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/usr/bin/env python3
2+
"""
3+
This script runs e3sm_diags with the lat_lon_native set to visualize native grid data.
4+
"""
5+
6+
import os
7+
import sys
8+
9+
from e3sm_diags.parameter.lat_lon_native_parameter import LatLonNativeParameter
10+
from e3sm_diags.run import runner
11+
12+
# Create parameter object
13+
param = LatLonNativeParameter()
14+
15+
# Basic parameters
16+
param.results_dir = "/lcrc/group/e3sm/public_html/diagnostic_output/ac.tvo/tests/lat_lon_native_file"
17+
# Create results directory if it doesn't exist
18+
if not os.path.exists(param.results_dir):
19+
os.makedirs(param.results_dir)
20+
21+
22+
# Model data
23+
24+
##(1)
25+
#param.test_data_path = "/home/ac.zhang40/test"
26+
#param.test_name = "v3.LR.amip_0101"
27+
#param.short_test_name = "v3.LR.amip_0101"
28+
#param.reference_data_path = "/home/ac.zhang40/test"
29+
#param.ref_name = "v3.HR.test4"
30+
#param.short_ref_name = "v3.HR.test4"
31+
#param.seasons = ["DJF"]
32+
33+
34+
##(2)
35+
#param.test_data_path = "/home/ac.zhang40/test"
36+
#param.test_file = "v3.LR.amip_0101_DJF_climo.nc"
37+
#param.short_test_name = "v3.LR.amip_0101"
38+
#param.reference_data_path = "/home/ac.zhang40/test"
39+
#param.ref_file = "v3.HR.test4_DJF_climo.nc"
40+
#param.short_ref_name = "v3.HR.test4"
41+
#param.seasons = ["DJF"]
42+
##(3)
43+
param.test_data_path = "/lcrc/group/e3sm2/ac.wlin/E3SMv3/v3.LR.historical_0051/archive/atm/hist"
44+
param.test_file = "v3.LR.historical_0051.eam.h0.1989-12.nc"
45+
#param.short_test_name = "v3.LR.amip_0101"
46+
param.reference_data_path = "/lcrc/group/e3sm2/ac.wlin/E3SMv3/v3.LR.historical_0051/archive/atm/hist"
47+
param.ref_file = "v3.LR.historical_0051.eam.h0.1989-12.nc"
48+
#param.reference_data_path = "/lcrc/group/e3sm2/ac.jwolfe/E3SMv3_dev/20250404.wcycl1850.ne120pg2_r025_RRSwISC6to18E3r5.test4.chrysalis/archive/atm/hist/"
49+
#param.ref_file = "20250404.wcycl1850.ne120pg2_r025_RRSwISC6to18E3r5.test4.chrysalis.eam.h0.0018-12.nc"
50+
param.short_ref_name = "v3.HR.test4"
51+
#param.seasons = ["DJF"]
52+
param.time_slices=["0"]
53+
54+
55+
param.case_id = "model_vs_model"
56+
57+
58+
# Native grid settings
59+
param.test_grid_file = "/lcrc/group/e3sm/diagnostics/grids/ne30pg2.nc"
60+
param.ref_grid_file = "/lcrc/group/e3sm/diagnostics/grids/ne30pg2.nc"
61+
#param.ref_grid_file = "/lcrc/group/e3sm/diagnostics/grids/ne120pg2.nc"
62+
63+
param.split_periodic_elements = True
64+
param.antialiased = False
65+
66+
# param.model_only = True
67+
param.run_type = "model_vs_model"
68+
69+
# Run the single diagnostic, comment out for complete diagnostics.
70+
cfg_path = "auxiliary_tools/debug/968-native-grid-vis/run_lat_lon_native.cfg"
71+
72+
sys.argv.extend(["--diags", cfg_path])
73+
74+
runner.sets_to_run = ["lat_lon_native"]
75+
runner.run_diags([param])
76+
77+

e3sm_diags/driver/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,9 @@
99
# The keys for the land and ocean fraction variables in the
1010
# `LAND_OCEAN_MASK_PATH` file.
1111
FRAC_REGION_KEYS = {"land": ("LANDFRAC", "landfrac"), "ocean": ("OCNFRAC", "ocnfrac")}
12+
13+
# The default value for metrics if it is not calculated. This value was
14+
# preserved from the legacy CDAT codebase because the viewer expects this
15+
# value for metrics that aren't calculated.
16+
# TODO: Update `lat_lon_viewer.py` to handle missing metrics with None value.
17+
METRICS_DEFAULT_VALUE = 999.999

e3sm_diags/driver/lat_lon_driver.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import xarray as xr
66

7+
from e3sm_diags.driver import METRICS_DEFAULT_VALUE
78
from e3sm_diags.driver.utils.climo_xr import ClimoFreq
89
from e3sm_diags.driver.utils.dataset_xr import Dataset
910
from e3sm_diags.driver.utils.io import _save_data_metrics_and_plots
@@ -25,12 +26,6 @@
2526
if TYPE_CHECKING:
2627
from e3sm_diags.parameter.core_parameter import CoreParameter
2728

28-
# The default value for metrics if it is not calculated. This value was
29-
# preserved from the legacy CDAT codebase because the viewer expects this
30-
# value for metrics that aren't calculated.
31-
# TODO: Update `lat_lon_viewer.py` to handle missing metrics with None value.
32-
METRICS_DEFAULT_VALUE = 999.999
33-
3429

3530
def run_diag(parameter: CoreParameter) -> CoreParameter:
3631
"""Get metrics for the lat_lon diagnostic set.

0 commit comments

Comments
 (0)