From 48ab3578dc00f422d91ae87419ae270073cb7615 Mon Sep 17 00:00:00 2001 From: Rhys Doyle Date: Tue, 10 Sep 2019 22:07:11 +0100 Subject: [PATCH 01/16] Animation Writer changed to PillowWriter in animate1D and animate2D --- xbout/plotting/animate.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/xbout/plotting/animate.py b/xbout/plotting/animate.py index 64731215..298419d1 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,8 @@ 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 +177,7 @@ 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 From 283d098b8b20fe65f0a8ca0abec72e0bd92007d7 Mon Sep 17 00:00:00 2001 From: Rhys Doyle <48983334+rdoyle45@users.noreply.github.com> Date: Wed, 11 Sep 2019 11:00:33 +0100 Subject: [PATCH 02/16] Update xbout/plotting/animate.py --- xbout/plotting/animate.py | 1 - 1 file changed, 1 deletion(-) diff --git a/xbout/plotting/animate.py b/xbout/plotting/animate.py index 298419d1..55e68d06 100644 --- a/xbout/plotting/animate.py +++ b/xbout/plotting/animate.py @@ -93,7 +93,6 @@ def animate_imshow(data, animate_over='t', x='x', y='y', animate=True, if not save_as: save_as = "{}_over_{}".format(variable, animate_over) - anim.save(save_as + '.gif', writer=PillowWriter(fps=fps)) return imshow_block From 6e72dd8189a9c773d53ac393ebc9260f3a371f08 Mon Sep 17 00:00:00 2001 From: Rhys Doyle <48983334+rdoyle45@users.noreply.github.com> Date: Thu, 12 Sep 2019 12:11:56 +0100 Subject: [PATCH 03/16] Update xbout/plotting/animate.py --- xbout/plotting/animate.py | 1 - 1 file changed, 1 deletion(-) diff --git a/xbout/plotting/animate.py b/xbout/plotting/animate.py index 55e68d06..5124bbf9 100644 --- a/xbout/plotting/animate.py +++ b/xbout/plotting/animate.py @@ -176,7 +176,6 @@ def animate_line(data, animate_over='t', animate=True, if not save_as: save_as = "{}_over_{}".format(variable, animate_over) - anim.save(save_as + '.gif', writer=PillowWriter(fps=fps)) return line_block From ef8f2111cff6cf3b48d2c0ff2bb8af6f70b3a7c7 Mon Sep 17 00:00:00 2001 From: Rhys Doyle <48983334+rdoyle45@users.noreply.github.com> Date: Thu, 12 Sep 2019 17:29:29 +0100 Subject: [PATCH 04/16] Update to required Matplotlib version To allow for the use of PillowWriter in plotting/animate.py --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 2df45747..af512084 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ xarray >= 0.12.2 dask[array] >= 1.0.0 natsort >= 5.5.0 -matplotlib >= 2.2 +matplotlib >= 3.1 animatplot >= 0.3 netcdf4 >= 1.4.0 From 75ebd07f83ef7f380235a21843faf384f9cb9378 Mon Sep 17 00:00:00 2001 From: Rhys Doyle <48983334+rdoyle45@users.noreply.github.com> Date: Thu, 12 Sep 2019 18:10:07 +0100 Subject: [PATCH 05/16] Python 3.5 doesn't support Matplotlib 3.1.0 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index af512084..377a1347 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ xarray >= 0.12.2 dask[array] >= 1.0.0 natsort >= 5.5.0 -matplotlib >= 3.1 +matplotlib >= 3.0.3 animatplot >= 0.3 netcdf4 >= 1.4.0 From f9848d0a0756a8676ef87bd2497fa9fb69b39815 Mon Sep 17 00:00:00 2001 From: Rhys Doyle Date: Thu, 12 Sep 2019 20:00:33 +0100 Subject: [PATCH 06/16] Test file for animate1D and 2D --- xbout/tests/test_animate.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 xbout/tests/test_animate.py diff --git a/xbout/tests/test_animate.py b/xbout/tests/test_animate.py new file mode 100644 index 00000000..f8ba8357 --- /dev/null +++ b/xbout/tests/test_animate.py @@ -0,0 +1,34 @@ +import pytest +from os import remove + +from xbout import open_boutdataset +from xbout.boutdataarray import BoutDataArrayAccessor + +DATA_PATH = './data/dump_files/along_x/BOUT.dmp.*.nc' + +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): + + bd = open_boutdataset(DATA_PATH).squeeze(drop=True) + + anim_creator = str(bd['T'].bout.animate2D(y='z')) + checker = ' Date: Thu, 12 Sep 2019 20:06:40 +0100 Subject: [PATCH 07/16] PEP8 issues fixed --- xbout/tests/test_animate.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/xbout/tests/test_animate.py b/xbout/tests/test_animate.py index f8ba8357..98f8572a 100644 --- a/xbout/tests/test_animate.py +++ b/xbout/tests/test_animate.py @@ -16,10 +16,10 @@ def test_animate2D(self): bd = open_boutdataset(DATA_PATH).squeeze(drop=True) anim_creator = str(bd['T'].bout.animate2D(y='z')) - checker = ' Date: Thu, 12 Sep 2019 20:08:14 +0100 Subject: [PATCH 08/16] PEP8 issues fixed --- xbout/tests/test_animate.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/xbout/tests/test_animate.py b/xbout/tests/test_animate.py index 98f8572a..9e0e60c2 100644 --- a/xbout/tests/test_animate.py +++ b/xbout/tests/test_animate.py @@ -6,6 +6,7 @@ DATA_PATH = './data/dump_files/along_x/BOUT.dmp.*.nc' + class TestAnimate: """ Set of tests to check whether animate1D() and animate2D() are running properly @@ -25,7 +26,7 @@ def test_animate1D(self): bd = open_boutdataset(DATA_PATH).squeeze(drop=True) - anim_creator = str(bd['T'][:,:,0].bout.animate1D()) + anim_creator = str(bd['T'][:, :, 0].bout.animate1D()) print(anim_creator) checker = ' Date: Thu, 12 Sep 2019 20:10:37 +0100 Subject: [PATCH 09/16] Path to data incorrect --- xbout/tests/test_animate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xbout/tests/test_animate.py b/xbout/tests/test_animate.py index 9e0e60c2..9e80a9a5 100644 --- a/xbout/tests/test_animate.py +++ b/xbout/tests/test_animate.py @@ -4,7 +4,7 @@ from xbout import open_boutdataset from xbout.boutdataarray import BoutDataArrayAccessor -DATA_PATH = './data/dump_files/along_x/BOUT.dmp.*.nc' +DATA_PATH = './xbout/tests/data/dump_files/along_x/BOUT.dmp.*.nc' class TestAnimate: From 33d85a8e926dd9f59e3f87d0d7c1839daaa492ed Mon Sep 17 00:00:00 2001 From: Rhys Doyle Date: Thu, 12 Sep 2019 20:38:24 +0100 Subject: [PATCH 10/16] Removal of unwanted line --- xbout/tests/test_animate.py | 1 - 1 file changed, 1 deletion(-) diff --git a/xbout/tests/test_animate.py b/xbout/tests/test_animate.py index 9e80a9a5..b857bd49 100644 --- a/xbout/tests/test_animate.py +++ b/xbout/tests/test_animate.py @@ -27,7 +27,6 @@ def test_animate1D(self): bd = open_boutdataset(DATA_PATH).squeeze(drop=True) anim_creator = str(bd['T'][:, :, 0].bout.animate1D()) - print(anim_creator) checker = ' Date: Thu, 12 Sep 2019 20:48:06 +0100 Subject: [PATCH 11/16] Pillow required for PillowWriter --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 377a1347..cd273591 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,4 @@ natsort >= 5.5.0 matplotlib >= 3.0.3 animatplot >= 0.3 netcdf4 >= 1.4.0 +Pillow >= 6.1.0 From 45245c29d724dc28a0bf03400fcf74786e51403f Mon Sep 17 00:00:00 2001 From: Rhys Doyle <48983334+rdoyle45@users.noreply.github.com> Date: Sun, 15 Sep 2019 01:04:49 +0100 Subject: [PATCH 12/16] Dependency update --- setup.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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'], From 88868d0c14c53a9bb46cca21064140b49b37e3f5 Mon Sep 17 00:00:00 2001 From: Rhys Doyle Date: Sun, 13 Oct 2019 11:50:55 +0100 Subject: [PATCH 13/16] Improved use of python functions for pytest and added use of pytest fixture to create temporary directory to deal with the output of subsequent animate function --- xbout/tests/test_animate.py | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/xbout/tests/test_animate.py b/xbout/tests/test_animate.py index b857bd49..5b5aecb5 100644 --- a/xbout/tests/test_animate.py +++ b/xbout/tests/test_animate.py @@ -1,33 +1,36 @@ import pytest -from os import remove from xbout import open_boutdataset from xbout.boutdataarray import BoutDataArrayAccessor -DATA_PATH = './xbout/tests/data/dump_files/along_x/BOUT.dmp.*.nc' +from animatplot.blocks import Imshow, Line +DATA_PATH = './xbout/tests/data/dump_files/along_x/BOUT.dmp.*.nc' # Path to test dmp files + +@pytest.fixture +def create_test_file(tmpdir_factory): + + save_dir = tmpdir_factory.mktemp("test_data") # Create temp dir for output of animate1D/2D + 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): - - bd = open_boutdataset(DATA_PATH).squeeze(drop=True) + def test_animate2D(self, create_test_file): - anim_creator = str(bd['T'].bout.animate2D(y='z')) - checker = ' Date: Sun, 13 Oct 2019 14:21:16 +0100 Subject: [PATCH 14/16] PEP8 fixes --- xbout/tests/test_animate.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/xbout/tests/test_animate.py b/xbout/tests/test_animate.py index 5b5aecb5..1dd27ceb 100644 --- a/xbout/tests/test_animate.py +++ b/xbout/tests/test_animate.py @@ -5,16 +5,20 @@ from animatplot.blocks import Imshow, Line -DATA_PATH = './xbout/tests/data/dump_files/along_x/BOUT.dmp.*.nc' # Path to test dmp files +# 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): - save_dir = tmpdir_factory.mktemp("test_data") # Create temp dir for output of animate1D/2D - ds = open_boutdataset(DATA_PATH).squeeze(drop=True) # Open test data + # 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 @@ -34,3 +38,4 @@ def test_animate1D(self, create_test_file): assert isinstance(animation, Line) + From 6447865e189676af11bff6dd4eb676d33f797e8a Mon Sep 17 00:00:00 2001 From: Rhys Doyle Date: Sun, 13 Oct 2019 14:23:09 +0100 Subject: [PATCH 15/16] PEP8 fixes --- xbout/tests/test_animate.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/xbout/tests/test_animate.py b/xbout/tests/test_animate.py index 1dd27ceb..e161cbf9 100644 --- a/xbout/tests/test_animate.py +++ b/xbout/tests/test_animate.py @@ -37,5 +37,3 @@ def test_animate1D(self, create_test_file): animation = ds['T'][:, :, 0].bout.animate1D(save_as="%s/test.gif" % save_dir) assert isinstance(animation, Line) - - From bfad80e7126a268a7956affa8ab79ae51843d1e6 Mon Sep 17 00:00:00 2001 From: Rhys Doyle <48983334+rdoyle45@users.noreply.github.com> Date: Mon, 14 Oct 2019 11:56:08 +0100 Subject: [PATCH 16/16] Remove .gif suffix from test --- xbout/tests/test_animate.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xbout/tests/test_animate.py b/xbout/tests/test_animate.py index e161cbf9..45ffbca6 100644 --- a/xbout/tests/test_animate.py +++ b/xbout/tests/test_animate.py @@ -27,13 +27,13 @@ class TestAnimate: def test_animate2D(self, create_test_file): save_dir, ds = create_test_file - animation = ds['T'].bout.animate2D(y='z', save_as="%s/test.gif" % save_dir) + 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.gif" % save_dir) + animation = ds['T'][:, :, 0].bout.animate1D(save_as="%s/test" % save_dir) assert isinstance(animation, Line)