@@ -89,6 +89,8 @@ def tape_recorder(adfobj):
89
89
# Filter the list to include only strings that are exactly in the substrings list
90
90
base_hist_strs = [string for string in baseline_hist_strs if string in substrings ]
91
91
hist_strs = case_hist_strs + base_hist_strs
92
+ else :
93
+ hist_strs = case_hist_strs
92
94
#End if
93
95
94
96
if not case_ts_locs :
@@ -126,6 +128,7 @@ def tape_recorder(adfobj):
126
128
127
129
#This may have to change if other variables are desired in this plot type?
128
130
plot_name = plot_loc / f"{ var } _TapeRecorder_ANN_Special_Mean.{ plot_type } "
131
+
129
132
print (f"\t - Plotting annual tape recorder for { var } " )
130
133
131
134
# Check redo_plot. If set to True: remove old plot, if it already exists:
@@ -138,11 +141,8 @@ def tape_recorder(adfobj):
138
141
elif (redo_plot ) and plot_name .is_file ():
139
142
plot_name .unlink ()
140
143
141
- #Make dictionary for case names and associated timeseries file locations and hist strings
142
- runs_LT2 = {}
143
- for i ,val in enumerate (test_nicknames ):
144
- runs_LT2 [val ] = [case_ts_locs [i ], hist_strs [i ]]
145
-
144
+ # Plotting
145
+ #---------
146
146
# MLS data
147
147
mls = xr .open_dataset (obs_loc / "mls_h2o_latNpressNtime_3d_monthly_v5.nc" )
148
148
mls = mls .rename (x = 'lat' , y = 'lev' , t = 'time' )
@@ -158,38 +158,7 @@ def tape_recorder(adfobj):
158
158
era5 = era5 .groupby ('time.month' ).mean ('time' )
159
159
era5_data = era5 .Q
160
160
161
- alldat = []
162
- runname_LT = []
163
- for idx ,key in enumerate (runs_LT2 ):
164
- # Search for files
165
- ts_loc = Path (runs_LT2 [key ][0 ])
166
- hist_str = runs_LT2 [key ][1 ]
167
- fils = sorted (ts_loc .glob (f'*{ hist_str } .{ var } .*.nc' ))
168
- dat = pf .load_dataset (fils )
169
- if not dat :
170
- dmsg = f"\t No data for `{ var } ` found in { fils } , case will be skipped in tape recorder plot."
171
- print (dmsg )
172
- adfobj .debug_log (dmsg )
173
- continue
174
- dat = fixcesmtime (dat ,start_years [idx ],end_years [idx ])
175
- datzm = dat .mean ('lon' )
176
- dat_tropics = cosweightlat (datzm [var ], - 10 , 10 )
177
- dat_mon = dat_tropics .groupby ('time.month' ).mean ('time' ).load ()
178
- alldat .append (dat_mon )
179
- runname_LT .append (key )
180
-
181
- #Check to see if any cases were successful
182
- if runname_LT :
183
- runname_LT = xr .DataArray (runname_LT , dims = 'run' , coords = [np .arange (0 ,len (runname_LT ),1 )], name = 'run' )
184
- alldat_concat_LT = xr .concat (alldat , dim = runname_LT )
185
- else :
186
- msg = f"WARNING: No cases seem to be available, please check time series files for { var } ."
187
- msg += "\n \t No tape recorder plots will be made."
188
- print (msg )
189
- #End tape recorder plotting script:
190
- return
191
-
192
- #Set up figure for plots
161
+ #Set up figure and plot MLS and ERA5 data
193
162
fig = plt .figure (figsize = (16 ,16 ))
194
163
x1 , x2 , y1 , y2 = get5by5coords_zmplots ()
195
164
@@ -205,15 +174,42 @@ def tape_recorder(adfobj):
205
174
'ERA5' ,x1 [1 ],x2 [1 ],y1 [1 ],y2 [1 ], cmap = cmap , paxis = 'pre' ,
206
175
taxis = 'month' ,climo_yrs = "1980-2020" )
207
176
177
+
208
178
#Loop over case(s) and start count at 2 to account for MLS and ERA5 plots above
179
+ runname_LT = []
209
180
count = 2
210
- for irun in np .arange (0 ,alldat_concat_LT .run .size ,1 ):
211
- title = f"{ alldat_concat_LT .run .isel (run = irun ).values } "
212
- ax = plot_pre_mon (fig , alldat_concat_LT .isel (run = irun ),
213
- plot_step , plot_min , plot_max , title ,
181
+ for idx ,key in enumerate (test_nicknames ):
182
+ # Search for files
183
+ ts_loc = Path (case_ts_locs [idx ])
184
+ hist_str = hist_strs [idx ]
185
+ fils = sorted (ts_loc .glob (f'*{ hist_str } .{ var } .*.nc' ))
186
+ dat = adfobj .data .load_timeseries_dataset (fils )
187
+
188
+ if not dat :
189
+ dmsg = f"\t No data for `{ var } ` found in { fils } , case will be skipped in tape recorder plot."
190
+ print (dmsg )
191
+ adfobj .debug_log (dmsg )
192
+ continue
193
+
194
+ #Grab time slice based on requested years (if applicable)
195
+ dat = dat .sel (time = slice (str (start_years [idx ]).zfill (4 ),str (end_years [idx ]).zfill (4 )))
196
+ datzm = dat .mean ('lon' )
197
+ dat_tropics = cosweightlat (datzm [var ], - 10 , 10 )
198
+ dat_mon = dat_tropics .groupby ('time.month' ).mean ('time' ).load ()
199
+ ax = plot_pre_mon (fig , dat_mon ,
200
+ plot_step , plot_min , plot_max , key ,
214
201
x1 [count ],x2 [count ],y1 [count ],y2 [count ],cmap = cmap , paxis = 'lev' ,
215
- taxis = 'month' ,climo_yrs = f"{ start_years [irun ]} -{ end_years [irun ]} " )
202
+ taxis = 'month' ,climo_yrs = f"{ start_years [idx ]} -{ end_years [idx ]} " )
216
203
count = count + 1
204
+ runname_LT .append (key )
205
+
206
+ #Check to see if any cases were successful
207
+ if not runname_LT :
208
+ msg = f"WARNING: No cases seem to be available, please check time series files for { var } ."
209
+ msg += "\n \t No tape recorder plots will be made."
210
+ print (msg )
211
+ #End tape recorder plotting script:
212
+ return
217
213
218
214
#Shift colorbar if there are less than 5 subplots
219
215
# There will always be at least 2 (MLS and ERA5)
@@ -348,17 +344,6 @@ def precip_cmap(n, nowhite=False):
348
344
349
345
#########
350
346
351
- def fixcesmtime (dat ,syear ,eyear ):
352
- """
353
- Fix the CESM timestamp with a simple set of dates
354
- """
355
- timefix = pd .date_range (start = f'1/1/{ syear } ' , end = f'12/1/{ eyear } ' , freq = 'MS' ) # generic time coordinate from a non-leap-year
356
- dat = dat .assign_coords ({"time" :timefix })
357
-
358
- return dat
359
-
360
- #########
361
-
362
347
def get5by5coords_zmplots ():
363
348
"""
364
349
positioning for 5x5 plots
0 commit comments