From ed267dbe69815d77d2f5c8c04ff5b78c2a8c14db Mon Sep 17 00:00:00 2001 From: gregordecristoforo Date: Tue, 4 Jul 2023 11:10:20 +0200 Subject: [PATCH 1/3] replace save parameter with gif_name --- blobmodel/plotting.py | 10 ++++------ tests/test_show_model.py | 4 ++-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/blobmodel/plotting.py b/blobmodel/plotting.py index f26a7e8..1c66076 100644 --- a/blobmodel/plotting.py +++ b/blobmodel/plotting.py @@ -5,14 +5,14 @@ import numpy as np import xarray as xr from matplotlib import animation +from typing import Union def show_model( dataset: xr.Dataset, variable: str = "n", interval: int = 100, - save: bool = False, - gif_name: str = "blobs.gif", + gif_name: Union[str, None] = None, fps: int = 10, ) -> None: """ @@ -26,10 +26,8 @@ def show_model( Variable to be animated (default: "n"). interval : int, optional Time interval between frames in milliseconds (default: 100). - save : bool, optional - If True, save the animation as a GIF (default: False). gif_name : str, optional - Set the name for the saved GIF (default: "blobs.gif"). + If not None, save the animation as a GIF and name it acoridingly. fps : int, optional Set the frames per second for the saved GIF (default: 10). @@ -103,7 +101,7 @@ def animate_2d(i: int) -> None: fig, animate_2d, frames=dataset["t"].values.size, interval=interval ) - if save: + if gif_name: ani.save(gif_name, writer="ffmpeg", fps=fps) plt.show() diff --git a/tests/test_show_model.py b/tests/test_show_model.py index fd24690..4d08b9d 100644 --- a/tests/test_show_model.py +++ b/tests/test_show_model.py @@ -22,7 +22,7 @@ @patch("matplotlib.pyplot.show") def test_plot_2d(mock_show): warnings.filterwarnings("ignore") - show_model(dataset=ds_2d, interval=100, save=False, fps=10) + show_model(dataset=ds_2d, interval=100, gif_name=None, fps=10) bm_1d = Model( @@ -44,7 +44,7 @@ def test_plot_2d(mock_show): @patch("matplotlib.pyplot.show") def test_plot_1d(mock_show): warnings.filterwarnings("ignore") - show_model(dataset=ds_1d, interval=100, save=False, fps=10) + show_model(dataset=ds_1d, interval=100, gif_name=None, fps=10) test_plot_2d() From 939b460a9c139cfc230ccd44abd7cef0512a0f24 Mon Sep 17 00:00:00 2001 From: gregordecristoforo Date: Tue, 4 Jul 2023 11:24:53 +0200 Subject: [PATCH 2/3] adjust examples --- examples/1d_animation.py | 2 +- examples/2d_animation.py | 2 +- examples/compare_to_analytical_sol.py | 2 +- examples/single_blob.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/1d_animation.py b/examples/1d_animation.py index 6ae010f..352c181 100644 --- a/examples/1d_animation.py +++ b/examples/1d_animation.py @@ -17,4 +17,4 @@ ) ds = bm.make_realization(speed_up=True, error=1e-2) -show_model(dataset=ds, interval=100, save=True) +show_model(dataset=ds, interval=100, gif_name="1d_animation.gif") diff --git a/examples/2d_animation.py b/examples/2d_animation.py index 4952886..ebb0a1e 100644 --- a/examples/2d_animation.py +++ b/examples/2d_animation.py @@ -18,4 +18,4 @@ # create data ds = bm.make_realization(speed_up=True, error=1e-2) # show animation and save as gif -show_model(dataset=ds, interval=100, save=True, gif_name="example.gif", fps=10) +show_model(dataset=ds, interval=100, gif_name="2d_animation.gif", fps=10) diff --git a/examples/compare_to_analytical_sol.py b/examples/compare_to_analytical_sol.py index 87fe113..2ea7088 100644 --- a/examples/compare_to_analytical_sol.py +++ b/examples/compare_to_analytical_sol.py @@ -21,7 +21,7 @@ blob_factory=bf, ) -ds = tmp.make_realization(file_name="profile_comparison.nc", speed_up=True, error=1e-2) +ds = tmp.make_realization(file_name="profile_comparison.nc", speed_up=False, error=1e-4) def plot_convergence_to_analytical_solution(ds): diff --git a/examples/single_blob.py b/examples/single_blob.py index 421393b..4efb8d5 100644 --- a/examples/single_blob.py +++ b/examples/single_blob.py @@ -66,4 +66,4 @@ def is_one_dimensional(self) -> bool: ds = bm.make_realization(speed_up=True, error=1e-2) # show animation and save as gif -show_model(dataset=ds, interval=100, save=True, gif_name="example.gif", fps=10) +show_model(dataset=ds, interval=100, gif_name="example.gif", fps=10) From 2aff0747f0a65e6b526608fa0b50228764eba55e Mon Sep 17 00:00:00 2001 From: gregordecristoforo Date: Fri, 14 Jul 2023 13:41:44 +0200 Subject: [PATCH 3/3] fix black issues --- tests/test_show_model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_show_model.py b/tests/test_show_model.py index e3517fd..4e78741 100644 --- a/tests/test_show_model.py +++ b/tests/test_show_model.py @@ -46,4 +46,4 @@ def test_plot_2d(mock_show): @patch("matplotlib.pyplot.show") def test_plot_1d(mock_show): warnings.filterwarnings("ignore") - show_model(dataset=ds_1d, interval=100, gif_name=None, fps=10) \ No newline at end of file + show_model(dataset=ds_1d, interval=100, gif_name=None, fps=10)