Skip to content

Commit 5ead54f

Browse files
CopilotSierd
andcommitted
Improve dimension validation and dictionary access robustness
Co-authored-by: Sierd <[email protected]>
1 parent 68d3b13 commit 5ead54f

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

aeolis/gui.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -736,13 +736,15 @@ def plot_1d_transect(self):
736736
if 'time' in var.dimensions:
737737
# Load all time steps
738738
var_data = var[:]
739-
if var_data.ndim < 1:
740-
continue # Skip scalar variables
739+
# Need at least 3 dimensions: (time, n, s)
740+
if var_data.ndim < 3:
741+
continue # Skip variables without spatial dimensions
741742
n_times = max(n_times, var_data.shape[0])
742743
else:
743744
# Single time step - validate shape
744-
if var.ndim < 2:
745-
continue # Skip variables with insufficient dimensions
745+
# Need exactly 2 spatial dimensions: (n, s)
746+
if var.ndim != 2:
747+
continue # Skip variables without 2D spatial dimensions
746748
var_data = var[:, :]
747749
var_data = np.expand_dims(var_data, axis=0) # Add time dimension
748750

@@ -773,8 +775,9 @@ def plot_1d_transect(self):
773775
self.time_slider_1d.set(0)
774776

775777
# Configure transect slider based on data shape
776-
# Get shape from first available variable (already validated above)
777-
first_var = next(iter(var_data_dict.values()))
778+
# Get shape from first available variable (already validated to be non-empty above)
779+
# Use dict.values() directly instead of next(iter()) for clarity
780+
first_var = list(var_data_dict.values())[0]
778781
if self.transect_direction_var.get() == 'cross-shore':
779782
# Fix y-index, vary along x (s dimension)
780783
max_idx = first_var.shape[1] - 1 # n dimension

0 commit comments

Comments
 (0)