diff --git a/requirements.txt b/requirements.txt index 2df45747..cd273591 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,7 @@ xarray >= 0.12.2 dask[array] >= 1.0.0 natsort >= 5.5.0 -matplotlib >= 2.2 +matplotlib >= 3.0.3 animatplot >= 0.3 netcdf4 >= 1.4.0 +Pillow >= 6.1.0 diff --git a/setup.py b/setup.py index a9925e1f..a805e44a 100644 --- a/setup.py +++ b/setup.py @@ -24,8 +24,9 @@ 'xarray>=v0.10.0', 'dask[array]>=1.0.0', 'natsort>=5.5.0', - 'matplotlib>=2.2', - 'animatplot>=0.3' + 'matplotlib>=3.0.3', + 'animatplot>=0.3', + 'Pillow>=6.1.0' ], extras_require={ 'tests': ['pytest >= 3.3.0'], diff --git a/xbout/plotting/animate.py b/xbout/plotting/animate.py index 64731215..5124bbf9 100644 --- a/xbout/plotting/animate.py +++ b/xbout/plotting/animate.py @@ -4,7 +4,7 @@ import animatplot as amp from .utils import plot_separatrix - +from matplotlib.animation import PillowWriter def animate_imshow(data, animate_over='t', x='x', y='y', animate=True, vmin=None, vmax=None, fps=10, save_as=None, @@ -93,9 +93,7 @@ def animate_imshow(data, animate_over='t', x='x', y='y', animate=True, if not save_as: save_as = "{}_over_{}".format(variable, animate_over) - # TODO save using PillowWriter instead once matplotlib 3.1 comes out - # see https://github.com/t-makaro/animatplot/issues/24 - anim.save(save_as + '.gif', writer='imagemagick') + anim.save(save_as + '.gif', writer=PillowWriter(fps=fps)) return imshow_block @@ -178,8 +176,6 @@ def animate_line(data, animate_over='t', animate=True, if not save_as: save_as = "{}_over_{}".format(variable, animate_over) - # TODO save using PillowWriter instead once matplotlib 3.1 comes out - # see https://github.com/t-makaro/animatplot/issues/24 - anim.save(save_as + '.gif', writer='imagemagick') + anim.save(save_as + '.gif', writer=PillowWriter(fps=fps)) return line_block diff --git a/xbout/tests/test_animate.py b/xbout/tests/test_animate.py new file mode 100644 index 00000000..45ffbca6 --- /dev/null +++ b/xbout/tests/test_animate.py @@ -0,0 +1,39 @@ +import pytest + +from xbout import open_boutdataset +from xbout.boutdataarray import BoutDataArrayAccessor + +from animatplot.blocks import Imshow, Line + +# Path to test dmp files +DATA_PATH = './xbout/tests/data/dump_files/along_x/BOUT.dmp.*.nc' + + +@pytest.fixture +def create_test_file(tmpdir_factory): + + # Create temp dir for output of animate1D/2D + save_dir = tmpdir_factory.mktemp("test_data") + ds = open_boutdataset(DATA_PATH).squeeze(drop=True) # Open test data + + return save_dir, ds + + +class TestAnimate: + """ + Set of tests to check whether animate1D() and animate2D() are running properly + and PillowWriter is saving each animation correctly + """ + def test_animate2D(self, create_test_file): + + save_dir, ds = create_test_file + animation = ds['T'].bout.animate2D(y='z', save_as="%s/test" % save_dir) + + assert isinstance(animation, Imshow) + + def test_animate1D(self, create_test_file): + + save_dir, ds = create_test_file + animation = ds['T'][:, :, 0].bout.animate1D(save_as="%s/test" % save_dir) + + assert isinstance(animation, Line)