Skip to content

Commit 60f1084

Browse files
committed
update granulation list to avoid looping over seasons; fix viewer
1 parent 8fa1800 commit 60f1084

File tree

3 files changed

+64
-11
lines changed

3 files changed

+64
-11
lines changed

e3sm_diags/parameter/lat_lon_native_parameter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,9 @@ def _set_time_slice_attrs(self, test_ds, ref_ds, time_slice: str):
131131
time_slice : str
132132
The time slice specification.
133133
"""
134-
# Use the time slice as the "season" for naming purposes
135-
# This ensures compatibility with existing file naming conventions
136-
self.current_set = time_slice
134+
# Store the time slice info but keep current_set as the diagnostic set name
135+
# current_set should remain as "lat_lon_native" for proper directory structure
136+
# The time slice will be used in filename generation via other attributes
137137

138138
# Set the time slice info for potential use in plotting/output
139139
self.current_time_slice = time_slice

e3sm_diags/parser/core_parser.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,19 @@ def _granulate(self, parameters):
10311031
delattr(param, module)
10321032

10331033
# Granulate param.
1034-
vars_to_granulate = param.granulate # Ex: ['seasons', 'plevs']
1034+
vars_to_granulate = param.granulate.copy() # Ex: ['seasons', 'plevs']
1035+
1036+
# Special handling for lat_lon_native: if time_slices is specified, remove seasons from granulation
1037+
if (
1038+
hasattr(param, "time_slices")
1039+
and hasattr(param, "seasons")
1040+
and len(param.time_slices) > 0
1041+
and "seasons" in vars_to_granulate
1042+
):
1043+
vars_to_granulate.remove("seasons")
1044+
# Also clear default seasons to avoid conflicts
1045+
param.seasons = []
1046+
10351047
# Check that all of the vars_to_granulate are iterables.
10361048
# Ex: {'season': ['ANN', 'DJF', 'MAM'], 'plevs': [850.0, 250.0]}
10371049
vals_to_granulate = collections.OrderedDict()

e3sm_diags/viewer/default_viewer.py

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
]
6060

6161

62-
def create_viewer(root_dir, parameters):
62+
def create_viewer(root_dir, parameters): # noqa: C901
6363
"""
6464
Given a set of parameters for a certain set of diagnostics,
6565
create a single page.
@@ -99,7 +99,16 @@ def create_viewer(root_dir, parameters):
9999
# ref_name-variable-plev'mb'-season-region
100100
ref_name = getattr(parameter, "ref_name", "")
101101
for var in parameter.variables:
102-
for season in parameter.seasons:
102+
# Handle either seasons or time_slices
103+
time_periods = (
104+
parameter.time_slices
105+
if (
106+
hasattr(parameter, "time_slices") and len(parameter.time_slices) > 0
107+
)
108+
else parameter.seasons
109+
)
110+
111+
for season in time_periods:
103112
for region in parameter.regions:
104113
# Since some parameters have plevs, there might be
105114
# more than one row_name, filename pair.
@@ -177,10 +186,25 @@ def create_viewer(root_dir, parameters):
177186
"..", "{}".format(set_name), parameter.case_id, fnm
178187
)
179188
print(
180-
os.path.join(
189+
f"DEBUG VIEWER: var={var}, season={season}, region={region}"
190+
)
191+
print(f"DEBUG VIEWER: fnm={fnm}")
192+
print(
193+
"DEBUG VIEWER: expected_path="
194+
+ os.path.join(
181195
"..", "{}".format(set_name), parameter.case_id, fnm
182196
)
183197
)
198+
199+
# Check what files actually exist
200+
actual_dir = os.path.join(
201+
parameter.results_dir, set_name, parameter.case_id
202+
)
203+
if os.path.exists(actual_dir):
204+
actual_files = os.listdir(actual_dir)
205+
print(f"DEBUG VIEWER: actual files: {actual_files}")
206+
else:
207+
print(f"DEBUG VIEWER: directory missing: {actual_dir}")
184208
ROW_INFO[set_name][parameter.case_id][row_name][season][
185209
"metadata"
186210
] = create_metadata(parameter)
@@ -224,11 +248,28 @@ def create_viewer(root_dir, parameters):
224248

225249
def seasons_used(parameters):
226250
"""
227-
Get a list of the seasons used for this set of parameters.
251+
Get a list of the seasons/time_slices used for this set of parameters.
252+
Supports either seasons OR time_slices (mutually exclusive).
228253
"""
229-
seasons_used = set([s for p in parameters for s in p.seasons])
230-
# Make sure this list is ordered by SEASONS.
231-
return [season for season in SEASONS if season in seasons_used]
254+
# Check if any parameter uses time_slices
255+
uses_time_slices = any(
256+
hasattr(p, "time_slices") and len(p.time_slices) > 0 for p in parameters
257+
)
258+
259+
if uses_time_slices:
260+
# Collect all time slices
261+
time_slices_used = set()
262+
for p in parameters:
263+
if hasattr(p, "time_slices"):
264+
time_slices_used.update(p.time_slices)
265+
266+
# Sort time slices for consistent ordering
267+
return sorted(time_slices_used)
268+
else:
269+
# Use standard seasons logic
270+
seasons_used = set([s for p in parameters for s in p.seasons])
271+
# Make sure this list is ordered by SEASONS.
272+
return [season for season in SEASONS if season in seasons_used]
232273

233274

234275
def _get_description(var, parameters):

0 commit comments

Comments
 (0)