Commit efc64cc4 authored by Pierre Augier's avatar Pierre Augier
Browse files

Merge branch 'topic/default/improve-animate' into 'branch/default'

animate: better default tmin and repeat can be integer

See merge request !226
Pipeline #22894 passed with stage
in 12 minutes and 6 seconds
......@@ -56,11 +56,11 @@ class MoviesBase:
tmax = self.sim.time_stepping.t
if tmin is None:
tmin = 0
tmin = self.phys_fields.set_of_phys_files.get_min_time()
if tmin > tmax:
raise ValueError(
"Error tmin > tmax. " "Value tmin should be smaller than tmax"
"Error tmin > tmax. Value tmin should be smaller than tmax"
)
if dt_equations is None:
......@@ -210,10 +210,17 @@ class MoviesBase:
self.init_animation(
key_field, numfig, dt_equations, tmin, tmax, fig_kw, **kwargs
)
if isinstance(repeat, int):
nb_repeat = repeat
repeat = False
else:
nb_repeat = 1
self._animation = animation.FuncAnimation(
self.fig,
self.update_animation,
len(self.ani_times),
nb_repeat * len(self.ani_times),
fargs=fargs.items(),
interval=dt_frame_in_sec * 1000,
blit=False,
......@@ -374,7 +381,7 @@ class MoviesBase1D(MoviesBase):
def update_animation(self, frame, **fargs):
"""Loads contour data and updates figure."""
print("update_animation for frame", frame, " ", end="\r")
time = self.ani_times[frame]
time = self.ani_times[frame % len(self.ani_times)]
get_field_to_plot = self.phys_fields.get_field_to_plot
y, time = get_field_to_plot(time=time, key=self.key_field)
x = self._get_axis_data()
......
......@@ -315,6 +315,11 @@ class SetOfPhysFieldFiles:
self.path_files = sorted(path_files)
self.times = np.array([time_from_path(path) for path in self.path_files])
def get_min_time(self):
if hasattr(self, "times"):
return self.times.min()
return 0.
def get_field_to_plot(
self,
time=None,
......
......@@ -167,7 +167,7 @@ class MoviesBasePhysFields2D(MoviesBase2D):
"""Loads data and updates figure."""
print("update_animation for frame", frame, " ", end="\r")
time = self.ani_times[frame]
time = self.ani_times[frame % len(self.ani_times)]
step = self._step
get_field_to_plot = self.phys_fields.get_field_to_plot
......@@ -227,7 +227,7 @@ class MoviesBasePhysFields2D(MoviesBase2D):
self._ani_cbar.set_ticks(ticks)
def _get_spatial_means(self, key_spatial="E"):
""" Get field for the inset plot."""
"""Get field for the inset plot."""
# Check if key_spatial can be loaded.
keys_spatial = ["E", "EK", "EA"]
if key_spatial not in keys_spatial:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment