Skip to content

Commit 4ad47a7

Browse files
committed
Add arm_diags and merra2 debug scripts
- Constraint `dask <2024.12.0`
1 parent b9da444 commit 4ad47a7

File tree

10 files changed

+1704
-1125
lines changed

10 files changed

+1704
-1125
lines changed
Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
"""
2+
This script sets up and runs a series of diagnostics for the E3SM model output.
3+
4+
The diagnostics include:
5+
- ENSO diagnostics
6+
- Tropical subseasonal variability diagnostics
7+
- QBO diagnostics
8+
- Diurnal cycle diagnostics
9+
- Streamflow diagnostics
10+
- Tropical cyclone analysis
11+
- ARM diagnostics
12+
13+
The script configures the parameters for each diagnostic, including paths to
14+
model output and observational data, time periods for analysis, and output
15+
settings. It then runs the diagnostics using the e3sm_diags package.
16+
17+
Parameters:
18+
- case: The name of the model case.
19+
- short_name: A short name for the model case.
20+
- results_dir: Directory where the results will be saved.
21+
- test_climo: Path to the model climatology data.
22+
- test_ts: Path to the model time-series data.
23+
- test_ts_daily_dir: Path to the model daily time-series data.
24+
- ref_climo: Path to the reference climatology data.
25+
- ref_ts: Path to the reference time-series data.
26+
- start_yr: Start year for the analysis.
27+
- end_yr: End year for the analysis.
28+
29+
The script uses multiprocessing to speed up the diagnostics computation.
30+
31+
Example usage:
32+
python complete_run_script.py
33+
"""
34+
import sys
35+
36+
from e3sm_diags.parameter.arm_diags_parameter import ARMDiagsParameter
37+
from e3sm_diags.parameter.core_parameter import CoreParameter
38+
from e3sm_diags.parameter.diurnal_cycle_parameter import DiurnalCycleParameter
39+
from e3sm_diags.parameter.enso_diags_parameter import EnsoDiagsParameter
40+
from e3sm_diags.parameter.qbo_parameter import QboParameter
41+
from e3sm_diags.parameter.streamflow_parameter import StreamflowParameter
42+
from e3sm_diags.parameter.tc_analysis_parameter import TCAnalysisParameter
43+
from e3sm_diags.parameter.tropical_subseasonal_parameter import (
44+
TropicalSubseasonalParameter,
45+
)
46+
from e3sm_diags.run import runner
47+
48+
case = "extendedOutput.v3.LR.historical_0101"
49+
short_name = "v3.LR.historical_0101"
50+
51+
# TODO: Update MAIN_DIR to match the current directory name.
52+
MAIN_DIR = "25-01-06-branch-907-debug-arm_diags"
53+
results_dir = f"/global/cfs/cdirs/e3sm/www/e3sm_diags/complete_run/{MAIN_DIR}/"
54+
55+
test_climo = "/global/cfs/cdirs/e3sm/chengzhu/tutorial2024/v3.LR.historical_0101/post/atm/180x360_aave/clim/15yr"
56+
test_ts = "/global/cfs/cdirs/e3sm/chengzhu/tutorial2024/v3.LR.historical_0101/post/atm/180x360_aave/ts/monthly/15yr"
57+
test_ts_daily_dir = "/global/cfs/cdirs/e3sm/chengzhu/tutorial2024/v3.LR.historical_0101/post/atm/180x360_aave/ts/daily/15yr"
58+
59+
ref_climo = "/global/cfs/cdirs/e3sm/diagnostics/observations/Atm/climatology/"
60+
ref_ts = "/global/cfs/cdirs/e3sm/diagnostics/observations/Atm/time-series"
61+
62+
start_yr = "2000"
63+
end_yr = "2014"
64+
65+
param = CoreParameter()
66+
67+
# Model
68+
param.test_data_path = test_climo
69+
param.test_name = case
70+
param.short_test_name = short_name
71+
72+
# Ref/Obs
73+
param.reference_data_path = ref_climo
74+
75+
# Output dir
76+
param.results_dir = results_dir
77+
78+
# Additional settings
79+
param.run_type = "model_vs_obs"
80+
param.diff_title = "Model - Observations"
81+
param.output_format = ["png"]
82+
param.output_format_subplot = []
83+
param.multiprocessing = True
84+
param.num_workers = 24
85+
param.save_netcdf = True
86+
param.seasons = ["ANN"]
87+
params = [param]
88+
89+
# Model
90+
enso_param = EnsoDiagsParameter()
91+
enso_param.test_data_path = test_ts
92+
# enso_param.test_name = short_name
93+
enso_param.test_start_yr = start_yr
94+
enso_param.test_end_yr = end_yr
95+
96+
# Obs
97+
enso_param.reference_data_path = ref_ts
98+
enso_param.ref_start_yr = start_yr
99+
enso_param.ref_end_yr = end_yr
100+
101+
enso_param.save_netcdf = True
102+
params.append(enso_param)
103+
104+
trop_param = TropicalSubseasonalParameter()
105+
trop_param.test_data_path = test_ts_daily_dir
106+
# trop_param.test_name = short_name
107+
trop_param.test_start_yr = start_yr
108+
trop_param.test_end_yr = end_yr
109+
110+
# Obs
111+
trop_param.reference_data_path = ref_ts
112+
trop_param.ref_start_yr = "2001"
113+
trop_param.ref_end_yr = "2010"
114+
115+
trop_param.save_netcdf = True
116+
params.append(trop_param)
117+
118+
qbo_param = QboParameter()
119+
qbo_param.test_data_path = test_ts
120+
# qbo_param.test_name = short_name
121+
qbo_param.test_start_yr = start_yr
122+
qbo_param.test_end_yr = end_yr
123+
qbo_param.ref_start_yr = start_yr
124+
qbo_param.ref_end_yr = end_yr
125+
126+
# Obs
127+
qbo_param.reference_data_path = ref_ts
128+
129+
qbo_param.save_netcdf = True
130+
params.append(qbo_param)
131+
132+
dc_param = DiurnalCycleParameter()
133+
dc_param.test_data_path = "/global/cfs/cdirs/e3sm/chengzhu/tutorial2024/v3.LR.historical_0101/post/atm/180x360_aave/clim_diurnal_8xdaily/"
134+
# dc_param.short_test_name = short_name
135+
# Plotting diurnal cycle amplitude on different scales. Default is True
136+
dc_param.normalize_test_amp = False
137+
138+
# Obs
139+
dc_param.reference_data_path = ref_climo
140+
141+
dc_param.save_netcdf = True
142+
params.append(dc_param)
143+
144+
streamflow_param = StreamflowParameter()
145+
streamflow_param.reference_data_path = ref_ts
146+
streamflow_param.test_data_path = "/global/cfs/cdirs/e3sm/chengzhu/tutorial2024/v3.LR.historical_0101/post/rof/native/ts/monthly/15yr/"
147+
# streamflow_param.test_name = short_name
148+
streamflow_param.test_start_yr = start_yr
149+
streamflow_param.test_end_yr = end_yr
150+
151+
# Obs
152+
streamflow_param.reference_data_path = ref_ts
153+
streamflow_param.ref_start_yr = (
154+
"1986" # Streamflow gauge station data range from year 1986 to 1995
155+
)
156+
streamflow_param.ref_end_yr = "1995"
157+
158+
streamflow_param.save_netcdf = True
159+
params.append(streamflow_param)
160+
161+
tc_param = TCAnalysisParameter()
162+
tc_param.test_data_path = "/global/cfs/cdirs/e3sm/chengzhu/tutorial2024/v3.LR.historical_0101/post/atm/tc-analysis_2000_2014"
163+
# tc_param.short_test_name = short_name
164+
tc_param.test_start_yr = start_yr
165+
tc_param.test_end_yr = end_yr
166+
167+
# Obs
168+
tc_param.reference_data_path = (
169+
"/global/cfs/cdirs/e3sm/diagnostics/observations/Atm/tc-analysis/"
170+
)
171+
# For model vs obs, the ref start and end year can be any four digit strings
172+
# For now, use all available years from obs by default
173+
tc_param.ref_start_yr = "1979"
174+
tc_param.ref_end_yr = "2018"
175+
176+
tc_param.save_netcdf = True
177+
params.append(tc_param)
178+
179+
arm_param = ARMDiagsParameter()
180+
arm_param.reference_data_path = (
181+
"/global/cfs/cdirs/e3sm/diagnostics/observations/Atm/arm-diags-data"
182+
)
183+
arm_param.ref_name = "armdiags"
184+
arm_param.test_data_path = (
185+
"/global/cfs/cdirs/e3sm/chengzhu/tutorial2024/v3.LR.historical_0101/post/atm/site"
186+
)
187+
arm_param.test_name = short_name
188+
arm_param.test_start_yr = start_yr
189+
arm_param.test_end_yr = end_yr
190+
# For model vs obs, the ref start and end year can be any four digit strings.
191+
# For now, will use all available years form obs
192+
arm_param.ref_start_yr = "0001"
193+
arm_param.ref_end_yr = "0001"
194+
195+
arm_param.save_netcdf = True
196+
params.append(arm_param)
197+
198+
# Run
199+
runner.sets_to_run = [
200+
"arm_diags",
201+
]
202+
203+
cfg_path = "auxiliary_tools/cdat_regression_testing/906-v3_complete_run/debug-missing-arm-files/debug-missing.cfg"
204+
sys.arv.extend(["--diags", cfg_path])
205+
206+
runner.run_diags(params)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[#]
2+
sets = ["lat_lon"]
3+
case_id = "MERRA2"
4+
variables = ["LHFLX"]
5+
ref_name = "MERRA2"
6+
reference_name = "MERRA2 Reanalysis"
7+
seasons = ["ANN", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "DJF", "MAM", "JJA", "SON"]
8+
contour_levels = [0,5, 15, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300]
9+
diff_levels = [-150, -120, -90, -60, -30, -20, -10, -5, 5, 10, 20, 30, 60, 90, 120, 150]
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import os
2+
import filecmp
3+
4+
def get_png_files(directory):
5+
"""Get a list of .png files in the given directory."""
6+
png_files = []
7+
for root, _, files in os.walk(directory):
8+
for file in files:
9+
if file.endswith(".png"):
10+
png_files.append(os.path.join(root, file))
11+
return png_files
12+
13+
def compare_directories(dir1, dir2):
14+
"""Compare .png files between two directories."""
15+
png_files_dir1 = get_png_files(dir1)
16+
png_files_dir2 = get_png_files(dir2)
17+
18+
# Create a dictionary with relative paths as keys
19+
png_files_dict1 = {os.path.relpath(file, dir1): file for file in png_files_dir1}
20+
png_files_dict2 = {os.path.relpath(file, dir2): file for file in png_files_dir2}
21+
22+
# Find common files
23+
common_files = set(png_files_dict1.keys()).intersection(set(png_files_dict2.keys()))
24+
25+
# Compare common files
26+
for file in common_files:
27+
if not filecmp.cmp(png_files_dict1[file], png_files_dict2[file], shallow=False):
28+
print(f"Difference found in file: {file}")
29+
30+
# Find files only in dir1
31+
only_in_dir1 = sorted(set(png_files_dict1.keys()) - set(png_files_dict2.keys()))
32+
if only_in_dir1:
33+
print(f"Files only in {dir1}:")
34+
for file in only_in_dir1:
35+
print(file)
36+
37+
# Find files only in dir2
38+
only_in_dir2 = sorted(set(png_files_dict2.keys()) - set(png_files_dict1.keys()))
39+
if only_in_dir2:
40+
print(f"Files only in {dir2}:")
41+
for file in only_in_dir2:
42+
print(file)
43+
44+
if __name__ == "__main__":
45+
dir1 = "/global/cfs/cdirs/e3sm/www/e3sm_diags/complete_run/25-01-06-branch-907-arm-diags-only/arm_diags"
46+
dir2 = "/global/cfs/cdirs/e3sm/www/e3sm_diags/complete_run/v2.12.1v2/arm_diags"
47+
compare_directories(dir1, dir2)

0 commit comments

Comments
 (0)