Skip to content

Commit 9bf4fcb

Browse files
committed
Add support for time series datasets via glob and fix enso_diags set (#866)
1 parent 70afe12 commit 9bf4fcb

File tree

15 files changed

+16400
-352
lines changed

15 files changed

+16400
-352
lines changed

auxiliary_tools/cdat_regression_testing/861-time-series-multiple/all-ts-datasets/nc.ipynb

Lines changed: 7408 additions & 0 deletions
Large diffs are not rendered by default.

auxiliary_tools/cdat_regression_testing/861-time-series-multiple/all-ts-datasets/png.ipynb

Lines changed: 2846 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 286 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,286 @@
1+
"""
2+
Make sure to run the machine-specific commands below before
3+
running this script:
4+
5+
Compy:
6+
srun --pty --nodes=1 --time=01:00:00 /bin/bash
7+
source /share/apps/E3SM/conda_envs/load_latest_e3sm_unified_compy.sh
8+
9+
LCRC:
10+
srun --pty --nodes=1 --time=01:00:00 /bin/bash
11+
source /lcrc/soft/climate/e3sm-unified/load_latest_e3sm_unified_chrysalis.sh
12+
Or: source /lcrc/soft/climate/e3sm-unified/load_latest_e3sm_unified_anvil.sh
13+
14+
NERSC perlmutter cpu:
15+
salloc --nodes 1 --qos interactive --time 01:00:00 --constraint cpu --account=e3sm
16+
source /global/common/software/e3sm/anaconda_envs/load_latest_e3sm_unified_pm-cpu.sh
17+
"""
18+
# flake8: noqa E501
19+
20+
import os
21+
from typing import Tuple, TypedDict
22+
23+
from mache import MachineInfo
24+
25+
from e3sm_diags.parameter.annual_cycle_zonal_mean_parameter import ACzonalmeanParameter
26+
from e3sm_diags.parameter.area_mean_time_series_parameter import (
27+
AreaMeanTimeSeriesParameter,
28+
)
29+
from e3sm_diags.parameter.arm_diags_parameter import ARMDiagsParameter
30+
from e3sm_diags.parameter.core_parameter import CoreParameter
31+
from e3sm_diags.parameter.diurnal_cycle_parameter import DiurnalCycleParameter
32+
from e3sm_diags.parameter.enso_diags_parameter import EnsoDiagsParameter
33+
from e3sm_diags.parameter.mp_partition_parameter import MPpartitionParameter
34+
from e3sm_diags.parameter.qbo_parameter import QboParameter
35+
from e3sm_diags.parameter.streamflow_parameter import StreamflowParameter
36+
from e3sm_diags.parameter.tc_analysis_parameter import TCAnalysisParameter
37+
from e3sm_diags.parameter.zonal_mean_2d_stratosphere_parameter import (
38+
ZonalMean2dStratosphereParameter,
39+
)
40+
from e3sm_diags.run import runner
41+
42+
43+
class MachinePaths(TypedDict):
44+
html_path: str
45+
obs_climo: str
46+
test_climo: str
47+
obs_ts: str
48+
test_ts: str
49+
dc_obs_climo: str
50+
dc_test_climo: str
51+
arm_obs: str
52+
arm_test: str
53+
tc_obs: str
54+
tc_test: str
55+
56+
57+
def run_all_sets():
58+
machine_paths: MachinePaths = _get_machine_paths()
59+
60+
param = CoreParameter()
61+
62+
param.reference_data_path = machine_paths["obs_climo"]
63+
param.test_data_path = machine_paths["test_climo"]
64+
param.test_name = "20210528.v2rc3e.piControl.ne30pg2_EC30to60E2r2.chrysalis"
65+
param.seasons = [
66+
"ANN",
67+
"JJA",
68+
] # Default setting: seasons = ["ANN", "DJF", "MAM", "JJA", "SON"]
69+
param.results_dir = (
70+
"/global/cfs/cdirs/e3sm/www/cdat-migration-fy24/861-time-series-multiple"
71+
)
72+
param.multiprocessing = True
73+
param.num_workers = 24
74+
75+
# Set specific parameters for new sets
76+
enso_param = EnsoDiagsParameter()
77+
enso_param.reference_data_path = machine_paths["obs_ts"]
78+
enso_param.test_data_path = machine_paths["test_ts"]
79+
enso_param.test_name = "e3sm_v2"
80+
enso_param.test_start_yr = "0051"
81+
enso_param.test_end_yr = "0060"
82+
# Enso obs data range from year 1979 to 2016
83+
enso_param.ref_start_yr = "2001"
84+
enso_param.ref_end_yr = "2010"
85+
86+
qbo_param = QboParameter()
87+
qbo_param.reference_data_path = machine_paths["obs_ts"]
88+
qbo_param.test_data_path = machine_paths["test_ts"]
89+
qbo_param.test_name = "e3sm_v2"
90+
qbo_param.start_yr = "0051"
91+
qbo_param.end_yr = "0060"
92+
# Qbo obs data range from year 1979 to 2019
93+
# Number of years of test and ref should match
94+
qbo_param.ref_start_yr = "2001"
95+
qbo_param.ref_end_yr = "2010"
96+
97+
ts_param = AreaMeanTimeSeriesParameter()
98+
ts_param.reference_data_path = machine_paths["obs_ts"]
99+
ts_param.test_data_path = machine_paths["test_ts"]
100+
ts_param.test_name = "e3sm_v2"
101+
ts_param.start_yr = "0051"
102+
ts_param.end_yr = "0060"
103+
104+
dc_param = DiurnalCycleParameter()
105+
dc_param.reference_data_path = machine_paths["dc_obs_climo"]
106+
dc_param.test_data_path = machine_paths["dc_test_climo"]
107+
dc_param.short_test_name = "e3sm_v2"
108+
# Plotting diurnal cycle amplitude on different scales. Default is True
109+
dc_param.normalize_test_amp = False
110+
111+
streamflow_param = StreamflowParameter()
112+
streamflow_param.reference_data_path = machine_paths["obs_ts"]
113+
streamflow_param.test_data_path = machine_paths["test_ts"]
114+
streamflow_param.short_test_name = "e3sm_v2"
115+
streamflow_param.test_start_yr = "0051"
116+
streamflow_param.test_end_yr = "0060"
117+
# Streamflow gauge station data range from year 1986 to 1995
118+
streamflow_param.ref_start_yr = "1986"
119+
streamflow_param.ref_end_yr = "1995"
120+
121+
arm_param = ARMDiagsParameter()
122+
arm_param.reference_data_path = machine_paths["arm_obs"]
123+
arm_param.ref_name = "armdiags"
124+
arm_param.test_data_path = machine_paths["arm_test"]
125+
arm_param.test_name = "e3sm_v2"
126+
# arm_param.test_start_yr = "1996"
127+
# arm_param.test_end_yr = "2010"
128+
arm_param.test_start_yr = "1985"
129+
arm_param.test_end_yr = "2014"
130+
# For model vs obs, the ref start and end year can be any four digit strings.
131+
# For now, will use all available years form obs
132+
arm_param.ref_start_yr = "0001"
133+
arm_param.ref_end_yr = "0001"
134+
135+
tc_param = TCAnalysisParameter()
136+
tc_param.reference_data_path = machine_paths["tc_obs"]
137+
tc_param.test_data_path = machine_paths["tc_test"]
138+
tc_param.short_test_name = "e3sm_v2"
139+
tc_param.test_start_yr = "0051"
140+
tc_param.test_end_yr = "0060"
141+
# For model vs obs, the ref start and end year can be any four digit strings.
142+
# For now, use all available years form obs by default.
143+
tc_param.ref_start_yr = "1979"
144+
tc_param.ref_end_yr = "2018"
145+
146+
ac_param = ACzonalmeanParameter()
147+
148+
zm_param = ZonalMean2dStratosphereParameter()
149+
150+
mp_param = MPpartitionParameter()
151+
# mp_param.reference_data_path = machine_paths["obs_ts"]
152+
mp_param.test_data_path = machine_paths["test_ts"]
153+
mp_param.short_test_name = "e3sm_v2"
154+
mp_param.test_start_yr = "0051"
155+
mp_param.test_end_yr = "0060"
156+
157+
param.save_netcdf = True
158+
runner.sets_to_run = [
159+
"lat_lon",
160+
"zonal_mean_xy",
161+
"zonal_mean_2d",
162+
"zonal_mean_2d_stratosphere",
163+
"polar",
164+
"cosp_histogram",
165+
"meridional_mean_2d",
166+
"annual_cycle_zonal_mean",
167+
"enso_diags",
168+
"qbo",
169+
"area_mean_time_series",
170+
"diurnal_cycle",
171+
"streamflow",
172+
"arm_diags",
173+
"tc_analysis",
174+
"aerosol_aeronet",
175+
"aerosol_budget",
176+
"mp_partition",
177+
]
178+
179+
runner.run_diags(
180+
[
181+
param,
182+
zm_param,
183+
ac_param,
184+
enso_param,
185+
qbo_param,
186+
ts_param,
187+
dc_param,
188+
streamflow_param,
189+
arm_param,
190+
tc_param,
191+
mp_param,
192+
]
193+
)
194+
195+
return param.results_dir
196+
197+
198+
def _get_machine_paths() -> MachinePaths:
199+
"""Returns the paths on the machine that are required to run e3sm_diags.
200+
201+
Returns
202+
-------
203+
MachinePaths
204+
A dictionary of paths on the machine, with the key being the path type
205+
and the value being the absolute path string.
206+
"""
207+
# Get the current machine's configuration info.
208+
machine_info = MachineInfo()
209+
machine = machine_info.machine
210+
211+
if machine not in [
212+
"anvil",
213+
"chrysalis",
214+
"compy",
215+
"pm-cpu",
216+
"cori-haswell",
217+
"cori-knl",
218+
]:
219+
raise ValueError(f"e3sm_diags is not supported on this machine ({machine}).")
220+
221+
# Path to the HTML outputs for the current user.
222+
web_portal_base_path = machine_info.config.get("web_portal", "base_path")
223+
html_path = f"{web_portal_base_path}/{machine_info.username}/"
224+
225+
# Path to the reference data directory.
226+
diags_base_path = machine_info.diagnostics_base
227+
ref_data_dir = f"{diags_base_path}/observations/Atm"
228+
229+
# Paths to the test data directories.
230+
test_data_dir, test_data_dir2 = _get_test_data_dirs(machine)
231+
232+
# Construct the paths required by e3sm_diags using the base paths above.
233+
machine_paths: MachinePaths = {
234+
"html_path": html_path,
235+
"obs_climo": f"{ref_data_dir}/climatology",
236+
"test_climo": f"{test_data_dir}/climatology/rgr/",
237+
"obs_ts": f"{ref_data_dir}/time-series/",
238+
"test_ts": f"{test_data_dir}/time-series/rgr/",
239+
"dc_obs_climo": f"{ref_data_dir}/climatology",
240+
"dc_test_climo": f"{test_data_dir}/diurnal_climatology/rgr",
241+
"arm_obs": f"{ref_data_dir}/arm-diags-data/",
242+
"arm_test": f"{test_data_dir2}/arm-diags-data/",
243+
"tc_obs": f"{ref_data_dir}/tc-analysis/",
244+
"tc_test": f"{test_data_dir}/tc-analysis/",
245+
}
246+
247+
return machine_paths
248+
249+
250+
def _get_test_data_dirs(machine: str) -> Tuple[str, str]:
251+
"""Get the directories for test data based on the machine.
252+
253+
The second path is for using the high frequency grid box output at ARM sites
254+
from another simulation when the output is available.
255+
256+
Parameters
257+
----------
258+
machine : str
259+
The name of the machine.
260+
261+
Returns
262+
-------
263+
Tuple[str, str]
264+
A tuple of two strings, each representing a test data directory path.
265+
"""
266+
test_data_dirs = None
267+
268+
# TODO: Update this function to use `mache` after the directories are updated.
269+
if machine in ["chrysalis", "anvil"]:
270+
base = "/lcrc/group/e3sm/public_html/e3sm_diags_test_data/postprocessed_e3sm_v2_data_for_e3sm_diags"
271+
elif machine in ["compy"]:
272+
base = "/compyfs/e3sm_diags_data/postprocessed_e3sm_v2_data_for_e3sm_diags"
273+
elif machine in ["cori-haswell", "cori-knl", "pm-cpu"]:
274+
base = "/global/cfs/cdirs/e3sm/e3sm_diags/postprocessed_e3sm_v2_data_for_e3sm_diags"
275+
276+
test_data_dirs = (
277+
f"{base}/20210528.v2rc3e.piControl.ne30pg2_EC30to60E2r2.chrysalis",
278+
# f"{base}/20210719.PhaseII.F20TR-P3.NGD.ne30pg2.compy",
279+
f"{base}/20221103.v2.LR.amip.NGD_v3atm.chrysalis",
280+
)
281+
282+
return test_data_dirs # type: ignore
283+
284+
285+
if __name__ == "__main__":
286+
run_all_sets()

0 commit comments

Comments
 (0)