Skip to content

Commit 76d1dd1

Browse files
authored
Merge pull request #162 from falconstryker/devel
MarsPlot inspect wasn't being flexible and some emars dummy data was improperly generated
2 parents 2397fe4 + afd577d commit 76d1dd1

File tree

2 files changed

+85
-64
lines changed

2 files changed

+85
-64
lines changed

amescap/Script_utils.py

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ def print_varContent(fileNcdf, list_varfull, print_stat=False):
182182
f"{Nclr}")
183183

184184
for varfull in list_varfull:
185+
Wmean = None # Initialize before try block
185186
try:
186187
slice = "[:]"
187188
if "[" in varfull:
@@ -193,24 +194,31 @@ def print_varContent(fileNcdf, list_varfull, print_stat=False):
193194
varname = f"f.variables['{cmd_txt}']{slice}"
194195
f = Dataset(fileNcdf.name, "r")
195196
var = eval(varname)
196-
197+
197198
# Get the full latitude array (not sliced)
198-
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
199205

200206

201207
if print_stat:
202208
Min = np.nanmin(var)
203209
Mean = np.nanmean(var)
204210
Max = np.nanmax(var)
205-
206-
try:
207-
weight = area_weights_deg(var.shape, lat)
208-
Wmean = np.nanmean(var * weight) # print at end
209-
last_wmean = Wmean # Store it
210-
last_varfull = varfull # Store variable name
211-
except:
212-
# For non-spatial variables or if weighting fails, use regular mean
213-
Wmean = Mean
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
214222

215223
print(f"{Cyan}{varfull:>26s}|{Min:>15g}|{Mean:>15g}|"
216224
f"{Max:>15g}|{Nclr}")
@@ -249,9 +257,9 @@ def print_varContent(fileNcdf, list_varfull, print_stat=False):
249257
print(f"{Cyan}__________________________|_______________|__"
250258
f"_____________|_______________|")
251259
# Only print weighted mean if we successfully calculated one
252-
if last_wmean is not None:
253-
print(f" Global area-weighted mean {last_varfull}: "
254-
f"{last_wmean:.3f}{Nclr}\n")
260+
if Wmean is not None:
261+
print(f" Global area-weighted mean {varfull}: "
262+
f"{Wmean:.3f}{Nclr}\n")
255263
f.close()
256264

257265

tests/create_gcm_files.py

Lines changed: 63 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -285,56 +285,66 @@ def generate_earth_seconds(length):
285285
]
286286

287287
earth_minute = [
288-
40., 41., 43., 45., 46., 48., 50., 51., 53., 54., 56., 58., 59., 1., 3.,
289-
4., 6., 8., 9., 11., 13., 14., 16., 18., 19., 21., 23., 24., 26., 27., 29.,
290-
31., 32., 34., 36., 37., 39., 41., 42., 44., 46., 47., 49., 51., 52., 54., 56.,
291-
57., 59., 0., 2., 4., 5., 7., 9., 10., 12., 14., 15., 17., 19., 20., 22., 24.,
292-
25., 27., 29., 30., 32., 33., 35., 37., 38., 40., 42., 43., 45., 47., 48., 50.,
293-
52., 53., 55., 57., 58., 0., 2., 3., 5., 6., 8., 10., 11., 13., 15., 16., 18.,
294-
20., 21., 23., 25., 26., 28., 30., 31., 33., 34., 36., 38., 39., 41., 43., 44.,
295-
46., 48., 49., 51., 53., 54., 56., 58., 59., 1., 3., 4., 6., 7., 9., 11., 12.,
296-
14., 16., 17., 19., 21., 22., 24., 26., 27., 29., 31., 32., 34., 36., 37., 39.,
297-
40., 42., 44., 45., 47., 49., 50., 52., 54., 55., 57., 59., 0., 2., 4., 5., 7.,
298-
9., 10., 12., 13., 15., 17., 18., 20., 22., 23., 25., 27., 28., 30., 32., 33.,
299-
35., 37., 38., 40., 42., 43., 45., 46., 48., 50., 51., 53., 55., 56., 58., 0.,
300-
1., 3., 5., 6., 8., 10., 11., 13., 14., 16., 18., 19., 21., 23., 24., 26., 28.,
301-
29., 31., 33., 34., 36., 38., 39., 41., 43., 44., 46., 47., 49., 51., 52., 54.,
302-
56., 57., 59., 1., 2., 4., 6., 7., 9., 11., 12., 14., 16., 17., 19., 20., 22.,
303-
24., 25., 27., 29., 30., 32., 34., 35., 37., 39., 40., 42., 44., 45., 47., 49.,
304-
50., 52., 53., 55., 57., 58., 0., 2., 3., 5., 7., 8., 10., 12., 13., 15., 17.,
305-
18., 20., 22., 23., 25., 26., 28., 30., 31., 33., 35., 36., 38., 40., 41., 43.,
306-
45., 46., 48., 50., 51., 53., 54., 56., 58., 59., 1., 3., 4., 6., 8., 9., 11.,
307-
13., 14., 16., 18., 19., 21., 23., 24., 26., 27., 29., 31., 32., 34., 36., 37.,
308-
39., 41., 42., 44., 46., 47., 49., 51., 52., 54., 56., 57., 59., 0., 2., 4.,
309-
5., 7., 9., 10., 12., 14., 15., 17., 19., 20., 22., 24., 25., 27., 29., 30.,
310-
32., 33., 35., 37., 38., 40., 42., 43., 45., 47., 48., 50., 52., 53., 55., 57.,
311-
58., 0., 2., 3., 5., 6., 8., 10., 11., 13., 15., 16., 18., 20., 21., 23., 25.,
312-
26., 28., 30., 31., 33., 34., 36., 38., 39., 41., 43., 44., 46., 48., 49., 51.,
313-
53., 54., 56., 58., 59., 1., 3., 4., 6., 7., 9., 11., 12., 14., 16., 17., 19.,
314-
21., 22., 24., 26., 27., 29., 31., 32., 34., 36., 37., 39., 40., 42., 44., 45.,
315-
47., 49., 50., 52., 54., 55., 57., 59., 0., 2., 4., 5., 7., 9., 10., 12., 13.,
316-
15., 17., 18., 20., 22., 23., 25., 27., 28., 30., 32., 33., 35., 37., 38., 40.,
317-
42., 43., 45., 46., 48., 50., 51., 53., 55., 56., 58., 0., 1., 3., 5., 6., 8.,
318-
10., 11., 13., 14., 16., 18., 19., 21., 23., 24., 26., 28., 29., 31., 33., 34.,
319-
36., 38., 39., 41., 43., 44., 46., 47., 49., 51., 52., 54., 56., 57., 59., 1.,
320-
2., 4., 6., 7., 9., 11., 12., 14., 16., 17., 19., 20., 22., 24., 25., 27., 29.,
321-
30., 32., 34., 35., 37., 39., 40., 42., 44., 45., 47., 49., 50., 52., 53., 55.,
322-
57., 58., 0., 2., 3., 5., 7., 8., 10., 12., 13., 15., 17., 18., 20., 22., 23.,
323-
25., 26., 28., 30., 31., 33., 35., 36., 38., 40., 41., 43., 45., 46., 48., 50.,
324-
51., 53., 54., 56., 58., 59., 1., 3., 4., 6., 8., 9., 11., 13., 14., 16., 18.,
325-
19., 21., 23., 24., 26., 27., 29., 31., 32., 34., 36., 37., 39., 41., 42., 44.,
326-
46., 47., 49., 51., 52., 54., 56., 57., 59., 0., 2., 4., 5., 7., 9., 10., 12.,
327-
14., 15., 17., 19., 20., 22., 24., 25., 27., 29., 30., 32., 33., 35., 37., 38.,
328-
40., 42., 43., 45., 47., 48., 50., 52., 53., 55., 57., 58., 0., 2., 3., 5., 6.,
329-
8., 10., 11., 13., 15., 16., 18., 20., 21., 23., 25., 26., 28., 30., 31., 33.,
330-
34., 36., 38., 39., 41., 43., 44., 46., 48., 49., 51., 53., 54., 56., 58., 59.,
331-
1., 3., 4., 6., 7., 9., 11., 12., 14., 16., 17., 19., 21., 22., 24., 26., 27.,
332-
29., 31., 32., 34., 36., 37., 39., 40., 42., 44., 45., 47., 49., 50., 52., 54.,
333-
55., 57., 59., 0., 2., 4., 5., 7., 9., 10., 12., 13., 15., 17., 18., 20., 22.,
334-
23., 25., 27., 28., 30., 32., 33., 35., 37., 38., 40., 42., 43., 45., 46., 48.,
335-
50., 51., 53., 55., 56., 58., 0., 1., 3., 5., 6., 8., 10., 11., 13., 14., 16.,
336-
18., 19., 21., 23., 24., 26., 28., 29., 31., 33., 34., 36., 38., 39., 41., 43.,
337-
44., 46., 47., 49., 51., 52., 54., 56., 57., 59.
288+
40., 41., 43., 45., 46., 48., 50., 51., 53., 54., 56., 58., 59., 1., 3., 4., 6., 8., 9.,
289+
11., 13., 14., 16., 18., 19., 21., 23., 24., 26., 27., 29., 31., 32., 34., 36., 37., 39.,
290+
41., 42., 44., 46., 47., 49., 51., 52., 54., 56., 57., 59., 0., 2., 4., 5., 7., 9., 10.,
291+
12., 14., 15., 17., 19., 20., 22., 24., 25., 27., 29., 30., 32., 33., 35., 37., 38., 40.,
292+
42., 43., 45., 47., 48., 50., 52., 53., 55., 57., 58., 0., 2., 3., 5., 6., 8., 10., 11.,
293+
13., 15., 16., 18., 20., 21., 23., 25., 26., 28., 30., 31., 33., 34., 36., 38., 39., 41.,
294+
43., 44., 46., 48., 49., 51., 53., 54., 56., 58., 59., 1., 3., 4., 6., 7., 9., 11., 12.,
295+
14., 16., 17., 19., 21., 22., 24., 26., 27., 29., 31., 32., 34., 36., 37., 39., 40., 42.,
296+
44., 45., 47., 49., 50., 52., 54., 55., 57., 59., 0., 2., 4., 5., 7., 9., 10., 12., 13.,
297+
15., 17., 18., 20., 22., 23., 25., 27., 28., 30., 32., 33., 35., 37., 38., 40., 42., 43.,
298+
45., 46., 48., 50., 51., 53., 55., 56., 58., 0., 1., 3., 5., 6., 8., 10., 11., 13., 14.,
299+
16., 18., 19., 21., 23., 24., 26., 28., 29., 31., 33., 34., 36., 38., 39., 41., 43., 44.,
300+
46., 47., 49., 51., 52., 54., 56., 57., 59., 1., 2., 4., 6., 7., 9., 11., 12., 14., 16.,
301+
17., 19., 20., 22., 24., 25., 27., 29., 30., 32., 34., 35., 37., 39., 40., 42., 44., 45.,
302+
47., 49., 50., 52., 53., 55., 57., 58., 0., 2., 3., 5., 7., 8., 10., 12., 13., 15., 17.,
303+
18., 20., 22., 23., 25., 26., 28., 30., 31., 33., 35., 36., 38., 40., 41., 43., 45.,
304+
46., 48., 50., 51., 53., 54., 56., 58., 59., 1., 3., 4., 6., 8., 9., 11., 13., 14.,
305+
16., 18., 19., 21., 23., 24., 26., 27., 29., 31., 32., 34., 36., 37., 39., 41., 42.,
306+
44., 46., 47., 49., 51., 52., 54., 56., 57., 59., 0., 2., 4., 5., 7., 9., 10., 12., 14.,
307+
15., 17., 19., 20., 22., 24., 25., 27., 29., 30., 32., 33., 35., 37., 38., 40., 42., 43.,
308+
45., 47., 48., 50., 52., 53., 55., 57., 58., 0., 2., 3., 5., 6., 8., 10., 11., 13., 15.,
309+
16., 18., 20., 21., 23., 25., 26., 28., 30., 31., 33., 34., 36., 38., 39., 41., 43., 44.,
310+
46., 48., 49., 51., 53., 54., 56., 58., 59., 1., 3., 4., 6., 7., 9., 11., 12., 14., 16.,
311+
17., 19., 21., 22., 24., 26., 27., 29., 31., 32., 34., 36., 37., 39., 40., 42., 44., 45.,
312+
47., 49., 50., 52., 54., 55., 57., 59., 0., 2., 4., 5., 7., 9., 10., 12., 13., 15., 17.,
313+
18., 20., 22., 23., 25., 27., 28., 30., 32., 33., 35., 37., 38., 40., 42., 43., 45., 46.,
314+
48., 50., 51., 53., 55., 56., 58., 0., 1., 3., 5., 6., 8., 10., 11., 13., 14., 16., 18.,
315+
19., 21., 23., 24., 26., 28., 29., 31., 33., 34., 36., 38., 39., 41., 43., 44., 46., 47.,
316+
49., 51., 52., 54., 56., 57., 59., 1., 2., 4., 6., 7., 9., 11., 12., 14., 16., 17., 19.,
317+
20., 22., 24., 25., 27., 29., 30., 32., 34., 35., 37., 39., 40., 42., 44., 45., 47., 49.,
318+
50., 52., 53., 55., 57., 58., 0., 2., 3., 5., 7., 8., 10., 12., 13., 15., 17., 18., 20.,
319+
22., 23., 25., 26., 28., 30., 31., 33., 35., 36., 38., 40., 41., 43., 45., 46., 48., 50.,
320+
51., 53., 54., 56., 58., 59., 1., 3., 4., 6., 8., 9., 11., 13., 14., 16., 18., 19., 21.,
321+
23., 24., 26., 27., 29., 31., 32., 34., 36., 37., 39., 41., 42., 44., 46., 47., 49., 51.,
322+
52., 54., 56., 57., 59., 0., 2., 4., 5., 7., 9., 10., 12., 14., 15., 17., 19., 20., 22.,
323+
24., 25., 27., 29., 30., 32., 33., 35., 37., 38., 40., 42., 43., 45., 47., 48., 50., 52.,
324+
53., 55., 57., 58., 0., 2., 3., 5., 6., 8., 10., 11., 13., 15., 16., 18., 20., 21., 23.,
325+
25., 26., 28., 30., 31., 33., 34., 36., 38., 39., 41., 43., 44., 46., 48., 49., 51., 53.,
326+
54., 56., 58., 59., 1., 3., 4., 6., 7., 9., 11., 12., 14., 16., 17., 19., 21., 22., 24.,
327+
26., 27., 29., 31., 32., 34., 36., 37., 39., 40., 42., 44., 45., 47., 49., 50., 52., 54.,
328+
55., 57., 59., 0., 2., 4., 5., 7., 9., 10., 12., 13., 15., 17., 18., 20., 22., 23., 25.,
329+
27., 28., 30., 32., 33., 35., 37., 38., 40., 42., 43., 45., 46., 48., 50., 51., 53., 55.,
330+
56., 58., 0., 1., 3., 5., 6., 8., 10., 11., 13., 14., 16., 18., 19., 21., 23., 24., 26.,
331+
28., 29., 31., 33., 34., 36., 38., 39., 41., 43., 44., 46., 47., 49., 51., 52., 54.,
332+
56., 57.,59., 1., 2., 4., 6., 7., 9., 11., 12., 14., 16., 17., 19., 20., 22., 24., 25.,
333+
27., 29., 30., 32., 34., 35., 37., 39., 40., 42., 44., 45., 47., 49., 50., 52., 53., 55.,
334+
57., 58., 0., 2., 3., 5., 7., 8., 10., 12., 13., 15., 17., 18., 20., 22., 23., 25., 26.,
335+
28., 30., 31., 33., 35., 36., 38., 40., 41., 43., 45., 46., 48., 50., 51., 53., 54., 56.,
336+
58., 59., 1., 3., 4., 6., 8., 9., 11., 13., 14., 16., 18., 19., 21., 23., 24., 26., 27.,
337+
29., 31., 32., 34., 36., 37., 39., 41., 42., 44., 46., 47., 49., 51., 52., 54., 56.,
338+
57., 59., 0., 2., 4., 5., 7., 9., 10., 12., 14., 15., 17., 19., 20., 22., 24., 25., 27.,
339+
29., 30., 32., 33., 35., 37., 38., 40., 42., 43., 45., 47., 48., 50., 52., 53., 55., 57.,
340+
58., 0., 2., 3., 5., 6., 8., 10., 11., 13., 15., 16., 18., 20., 21., 23., 25., 26., 28.,
341+
30., 31., 33., 34., 36., 38., 39., 41., 43., 44., 46., 48., 49., 51., 53., 54., 56., 58.,
342+
59., 1., 3., 4., 6., 7., 9., 11., 12., 14., 16., 17., 19., 21., 22., 24., 26., 27., 29.,
343+
31., 32., 34., 36., 37., 39., 40., 42., 44., 45., 47., 49., 50., 52., 54., 55., 57., 59.,
344+
0., 2., 4., 5., 7., 9., 10., 12., 13., 15., 17., 18., 20., 22., 23., 25., 27., 28., 30.,
345+
32., 33., 35., 37., 38., 40., 42., 43., 45., 46., 48., 50., 51., 53., 55., 56., 58., 0.,
346+
1., 3., 5., 6., 8., 10., 11., 13., 14., 16., 18., 19., 21., 23., 24., 26., 28., 29.,
347+
31., 33., 34., 36., 38., 39., 41., 43., 44., 46., 47., 49., 51., 52., 54., 56., 57., 59.
338348
]
339349
# emars_sol: Values from 3995 to 4040 with each value repeating 24 times
340350
def generate_emars_sol(length):
@@ -437,6 +447,9 @@ def generate_mars_soy(length):
437447
7.31135861e+00, 7.46358670e+00, 7.57229980e+00, 7.64819446e+00,
438448
7.70000000e+00]
439449

450+
earth_day_var[:] = earth_day
451+
earth_hour_var[:] = earth_hour
452+
earth_minute_var[:] = earth_minute
440453
earth_month_var[:] = earth_month_values
441454
earth_second_var[:] = earth_second_values
442455
emars_sol_var[:] = emars_sol_values

0 commit comments

Comments
 (0)