Skip to content

Commit afd577d

Browse files
committed
marsplot's inspect function wasn't flexible for the name of the lat variable
1 parent 5714a95 commit afd577d

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

amescap/Script_utils.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -194,24 +194,31 @@ def print_varContent(fileNcdf, list_varfull, print_stat=False):
194194
varname = f"f.variables['{cmd_txt}']{slice}"
195195
f = Dataset(fileNcdf.name, "r")
196196
var = eval(varname)
197-
197+
198198
# Get the full latitude array (not sliced)
199-
lat = f.variables['lat'][:]
199+
# Try common latitude variable names
200+
lat = None
201+
for lat_name in ['lat', 'latitude', 'latu', 'latv']:
202+
if lat_name in f.variables:
203+
lat = f.variables[lat_name][:]
204+
break
200205

201206

202207
if print_stat:
203208
Min = np.nanmin(var)
204209
Mean = np.nanmean(var)
205210
Max = np.nanmax(var)
206-
207-
try:
208-
weight = area_weights_deg(var.shape, lat)
209-
Wmean = np.nanmean(var * weight) # print at end
210-
# last_wmean = Wmean # Store it
211-
# last_varfull = varfull # Store variable name
212-
except:
213-
# If weighting fails, don't print
214-
Wmean = None
211+
212+
# Only attempt weighted mean if latitude was found
213+
if lat is not None:
214+
try:
215+
weight = area_weights_deg(var.shape, lat)
216+
Wmean = np.nanmean(var * weight) # print at end
217+
# last_wmean = Wmean # Store it
218+
# last_varfull = varfull # Store variable name
219+
except:
220+
# If weighting fails, don't print
221+
Wmean = None
215222

216223
print(f"{Cyan}{varfull:>26s}|{Min:>15g}|{Mean:>15g}|"
217224
f"{Max:>15g}|{Nclr}")

0 commit comments

Comments
 (0)