Skip to content

Commit

Permalink
Merge pull request #1252 from knutfrode/dev
Browse files Browse the repository at this point in the history
markersize as input to animation method can now be an element propert…
  • Loading branch information
knutfrode authored Mar 13, 2024
2 parents 10903f9 + e9db9e7 commit 271123d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 30 deletions.
1 change: 1 addition & 0 deletions examples/example_chemicaldrift.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@

o.animation(color='specie',
markersize='mass',
markersize_scaling=100,
vmin=0,vmax=o.nspecies-1,
colorbar=False,
fast = True,
Expand Down
2 changes: 1 addition & 1 deletion examples/example_shyfem.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@

#%%
# .. image:: /gallery/animations/example_shyfem_0.gif
# .. image:: /gallery/animations/example_shyfem_1.gif
o.plot(fast=True, buffer = 1., corners=[12.2, 12.6, 45.1, 45.5])

36 changes: 7 additions & 29 deletions opendrift/models/basemodel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2529,6 +2529,7 @@ def animation(self,
lcs=None,
surface_only=False,
markersize=20,
markersize_scaling=1,
origin_marker=None,
legend=None,
legend_loc='best',
Expand All @@ -2552,16 +2553,6 @@ def animation(self,
compare)
kwargs.update(compare_args)

markersizebymass = False
if isinstance(markersize, str):
if markersize.startswith('mass'):
markersizebymass = True
if markersize[len('mass'):] == '':
# default initial size if not specified
markersize = 100
else:
markersize = int(markersize[len('mass'):])

start_time = datetime.now()
if cmap is None:
cmap = 'jet'
Expand Down Expand Up @@ -2660,22 +2651,9 @@ def plot_timestep(i):
np.c_[x_deactive[index_of_last_deactivated < i],
y_deactive[index_of_last_deactivated < i]])

if markersizebymass:
if 'chemicaldrift' in self.__module__:
points.set_sizes(
markersize *
(self.history['mass'][:, i] /
(self.history['mass'][:, i] +
self.history['mass_degraded'][:, i] +
self.history['mass_volatilized'][:, i])))
elif 'openoil' in self.__module__:
points.set_sizes(
markersize *
(self.history['mass_oil'][:, i] /
(self.history['mass_oil'][:, i] +
self.history['mass_biodegraded'][:, i] +
self.history['mass_dispersed'][:, i] +
self.history['mass_evaporated'][:, i])))
if isinstance(markersize, str):
points.set_sizes(markersize_scaling *
(self.history[markersize][:, i] / self.history[markersize].compressed()[0]))

if color is not False: # Update colors
points.set_array(colorarray[:, i])
Expand Down Expand Up @@ -2801,7 +2779,7 @@ def plot_timestep(i):
else:
c = []

if markersizebymass:
if isinstance(markersize, str):
points = ax.scatter([], [],
c=c,
zorder=10,
Expand Down Expand Up @@ -2843,13 +2821,13 @@ def plot_timestep(i):
ax.legend(markers, legend, loc=legend_loc)

# Plot deactivated elements, with transparency
if markersizebymass:
if isinstance(markersize, str):
points_deactivated = ax.scatter([], [],
c=c,
zorder=9,
vmin=vmin,
vmax=vmax,
s=markersize,
s=markersize_scaling,
cmap=cmap,
edgecolor=[],
alpha=0,
Expand Down

0 comments on commit 271123d

Please sign in to comment.