Skip to content

Commit 253a202

Browse files
committed
add awful changes for new gridded data time mess
1 parent 6c9f031 commit 253a202

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

gridded_plots.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,21 @@ def multiplotter(dataset, variables, plots_dir, glider='', mission='', grid=True
212212
213213
The intended use of the plotter function is to iterate over a list of variables,
214214
plotting a pcolormesh style plot for each variable, where each variable has a colourmap assigned using a dict"""
215+
216+
if 'profile' in dataset.dims:
217+
time = dataset.time.values
218+
dataset = dataset.drop_dims('time')
219+
dataset['time'] = ('profile', time)
215220
if not grid:
216221
# Quick fix for if glider has rebooted and 1970s datestamps have appeared mid mission
217222
dataset = dataset.sortby("time")
218-
dataset = dataset.where(dataset.profile_direction < 0.)
219-
end = pandas.to_datetime(dataset.time.values[-1])
220-
dataset = dataset.sel(time=slice(end - datetime.timedelta(days=7), end))
223+
if 'profile_direction' in dataset.variables:
224+
dataset = dataset.where(dataset.profile_direction < 0.)
225+
end = np.nanmax(dataset.time.values)
226+
argmin =np.nanargmin(np.abs(dataset.time.mean(dim='depth')- (end -np.timedelta64(7, 'D'))) / np.timedelta64(1, 's'))
227+
start = dataset.profile[argmin]
228+
end = dataset.profile.max()
229+
dataset = dataset.sel(profile=slice(start, end))
221230
num_variables = len(variables)
222231
fig, axs = plt.subplots(num_variables, 1, figsize=(12, 3.5 * num_variables), sharex="col")
223232
axs = axs.ravel()
@@ -258,11 +267,9 @@ def multiplotter(dataset, variables, plots_dir, glider='', mission='', grid=True
258267
if grid:
259268
pcol = ax.pcolor(ds.time.values, ds.depth, ds.values, cmap=colormap, shading='auto')
260269
else:
261-
time = ds.time.values
262-
depth = ds.depth.values[::-1]
263-
depth_grid = np.tile(depth, (len(time), 1)).T
264-
time_grid = np.tile(time, (len(depth), 1))
265-
pcol = ax.scatter(time_grid, depth_grid, c=ds.values[::-1, :], cmap=colormap)
270+
time = dataset.time.values.T
271+
depth = np.tile(dataset.depth.values, (len(dataset.profile), 1)).T
272+
pcol = ax.scatter(time, depth, c=ds.values, cmap=colormap)
266273

267274
var_sum = np.sum(~np.isnan(dataset[variable].data),axis=1)
268275
valid_depths = dataset[variable].depth.data[var_sum != 0.0]

0 commit comments

Comments
 (0)