Skip to content

Commit 96bd9b8

Browse files
committed
final touches and fix time_plots re-use
1 parent aaf64b2 commit 96bd9b8

File tree

2 files changed

+28
-24
lines changed

2 files changed

+28
-24
lines changed

dorado/lagrangian_walker.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,19 +204,17 @@ def make_weight(Particles):
204204
# modify the weight by the depth and theta weighting parameter
205205
weight = depth_ind ** Particles.theta * weight
206206

207-
# if the depth is below the minimum depth then location is not
208-
# considered therefore set the associated weight to nan
207+
# if the depth is below the minimum depth then set weight to 0
209208
weight[(depth_ind <= Particles.dry_depth) | (ct_ind == 2)] = 0
210209

211210
# if it's a dead end with only nans and 0's, choose deepest cell
212211
zero_weights = tile_domain_array((np.nansum(weight, axis=2) <= 0))
213-
deepest_cells = (depth_ind == tile_domain_array(np.max(depth_ind, axis=2)))
212+
deepest_cells = (depth_ind == tile_domain_array(np.max(depth_ind,axis=2)))
214213
choose_deep_cells = (zero_weights & deepest_cells)
215214
weight[choose_deep_cells] = 1.0
216215

217216
# Final checks, eliminate invalid choices
218217
clear_borders(weight)
219-
# weight[:,:,4] = 0. # Should particles be allowed to stand still?
220218

221219
# set weight in the true weight array
222220
Particles.weight = weight

dorado/routines.py

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -322,30 +322,36 @@ def time_plots(particle, num_iter, folder_name=None):
322322
walk_data = particle.run_iteration()
323323

324324
# collect latest travel times
325-
x0, y0, t0 = get_state(walk_data, 0)
326325
xi, yi, temptimes = get_state(walk_data)
327326

328-
# set colorbar using 10th and 90th percentile values
329-
cm = matplotlib.cm.colors.Normalize(vmax=np.percentile(temptimes, 90),
330-
vmin=np.percentile(temptimes, 10))
331-
332-
fig = plt.figure(dpi=200)
333-
ax = plt.gca()
334-
plt.title('Depth - Particle Iteration ' + str(i))
335-
ax.scatter(y0, x0, c='b', s=0.75)
336-
sc = ax.scatter(yi, xi, c=temptimes, s=0.75, cmap='coolwarm', norm=cm)
337-
divider = make_axes_locatable(ax)
338-
cax = divider.append_axes("right", size="5%", pad=0.05)
339-
cbar = plt.colorbar(sc, cax=cax)
340-
cbar.set_label('Particle Travel Times [s]')
341-
im = ax.imshow(particle.depth)
342-
divider = make_axes_locatable(ax)
343-
cax = divider.append_axes("bottom", size="5%", pad=0.5)
344-
cbar2 = plt.colorbar(im, cax=cax, orientation='horizontal')
345-
cbar2.set_label('Water Depth [m]')
327+
if i == 0:
328+
x0, y0, t0 = get_state(walk_data, 0)
329+
# Initialize figure
330+
fig = plt.figure(dpi=200)
331+
ax = plt.gca()
332+
im = ax.imshow(particle.depth)
333+
orig = ax.scatter(y0, x0, c='b', s=0.75)
334+
sc = ax.scatter(yi, xi, c=temptimes, s=0.75, cmap='coolwarm')
335+
sc.set_clim(np.percentile(temptimes,90),
336+
np.percentile(temptimes,10))
337+
divider = make_axes_locatable(ax)
338+
cax = divider.append_axes("right", size="5%", pad=0.05)
339+
cbar = plt.colorbar(sc, cax=cax)
340+
cbar.set_label('Particle Travel Times [s]')
341+
divider = make_axes_locatable(ax)
342+
cax = divider.append_axes("bottom", size="5%", pad=0.5)
343+
cbar2 = plt.colorbar(im, cax=cax, orientation='horizontal')
344+
cbar2.set_label('Water Depth [m]')
345+
else:
346+
# Update figure with new locations
347+
sc.set_offsets(np.array([yi,xi]).T) # Location
348+
sc.set_array(np.array(temptimes)) # Color values
349+
sc.set_clim(np.percentile(temptimes,90),
350+
np.percentile(temptimes,10)) # Color limits
351+
plt.draw()
352+
ax.set_title('Depth - Particle Iteration ' + str(i))
346353
plt.savefig(folder_name+os.sep+'figs'+os.sep+'output'+str(i)+'.png',
347354
bbox_inches='tight')
348-
plt.close()
349355

350356
# save data as a json text file - technically human readable
351357
fpath = folder_name+os.sep+'data'+os.sep+'data.txt'

0 commit comments

Comments
 (0)