From 0a9330298f53e38dae9dd975af64373aabc99994 Mon Sep 17 00:00:00 2001 From: zmoon Date: Mon, 28 Mar 2022 15:02:10 -0600 Subject: [PATCH 1/8] Initial pre-commit config from xgcm but quoting the versions --- .pre-commit-config.yaml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..da3af26 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,27 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: "v4.0.1" + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + + - repo: https://github.com/PyCQA/isort + rev: "5.8.0" + hooks: + - id: isort + + - repo: https://github.com/python/black + rev: "21.5b1" + hooks: + - id: black + + - repo: https://github.com/keewis/blackdoc + rev: "v0.3.4" + hooks: + - id: blackdoc + + - repo: https://gitlab.com/pycqa/flake8 + rev: "3.9.2" + hooks: + - id: flake8 From bc9f56686262362f889757792cd429fb21673a7f Mon Sep 17 00:00:00 2001 From: zmoon Date: Mon, 28 Mar 2022 15:04:21 -0600 Subject: [PATCH 2/8] Add pyupgrade to pre-commit config --- .pre-commit-config.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index da3af26..50314f5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,6 +6,12 @@ repos: - id: end-of-file-fixer - id: check-yaml + - repo: https://github.com/asottile/pyupgrade + rev: "v2.31.0" + hooks: + - id: pyupgrade + args: [--py37-plus] + - repo: https://github.com/PyCQA/isort rev: "5.8.0" hooks: From edcf8d2600e71257b81fc67a5a6e5af6a8f001e8 Mon Sep 17 00:00:00 2001 From: zmoon Date: Mon, 28 Mar 2022 15:05:23 -0600 Subject: [PATCH 3/8] Update pre-commit hooks --- .pre-commit-config.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 50314f5..6b8148c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,24 +1,24 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: "v4.0.1" + rev: "v4.1.0" hooks: - id: trailing-whitespace - id: end-of-file-fixer - id: check-yaml - repo: https://github.com/asottile/pyupgrade - rev: "v2.31.0" + rev: "v2.31.1" hooks: - id: pyupgrade args: [--py37-plus] - repo: https://github.com/PyCQA/isort - rev: "5.8.0" + rev: "5.10.1" hooks: - id: isort - repo: https://github.com/python/black - rev: "21.5b1" + rev: "22.3.0" hooks: - id: black From 6c306e93edcd1b935ac21470514fad895ba30d92 Mon Sep 17 00:00:00 2001 From: zmoon Date: Mon, 28 Mar 2022 15:10:01 -0600 Subject: [PATCH 4/8] pre-commit tool configs based on xgcm but adding line-length for black to match current xmovie flake8 setting --- pyproject.toml | 2 ++ setup.cfg | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 pyproject.toml diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..6aabc91 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,2 @@ +[tool.black] +line-length = 105 diff --git a/setup.cfg b/setup.cfg index fff527c..eba7d5e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -17,9 +17,17 @@ ignore = [flake8] max-line-length = 105 select = C,E,F,W,B,B950 -ignore = E203, E501, W503 +ignore = E203, E402, E501, E731, W503, E265, F811 exclude = xmovie/_version.py +[isort] +profile = black +force_to_top = true +default_section = THIRDPARTY +known_first_party = xmovie +skip = + docs/conf.py + [metadata] name = xmovie From 1a47d0494c63e5809f26d8284a2d034309bfb8e6 Mon Sep 17 00:00:00 2001 From: Zachary Moon Date: Tue, 3 May 2022 11:10:45 -0400 Subject: [PATCH 5/8] Add pre-commit.ci badge to readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 63c72fc..0d5d339 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # xmovie [![Build Status](https://img.shields.io/github/workflow/status/jbusecke/xmovie/CI?logo=github)](https://github.com/jbusecke/xmovie/actions) [![Documentation Status](https://readthedocs.org/projects/xmovie/badge/?version=latest)](https://xmovie.readthedocs.io/en/latest/) +[![pre-commit.ci Status](https://results.pre-commit.ci/badge/github/jbusecke/xmovie/master.svg)](https://results.pre-commit.ci/latest/github/jbusecke/xmovie/master) [![codecov %](https://codecov.io/gh/jbusecke/xmovie/branch/master/graph/badge.svg)](https://codecov.io/gh/jbusecke/xmovie) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![DOI](https://zenodo.org/badge/124968397.svg)](https://zenodo.org/badge/latestdoi/124968397) From afa7d1a8e082b9639f4718a9721bbfc6916c9113 Mon Sep 17 00:00:00 2001 From: zmoon Date: Tue, 3 May 2022 09:22:31 -0600 Subject: [PATCH 6/8] Initial formatting changes via pre-commit from black, isort, etc. --- .github/workflows/ci.yaml | 4 +- .gitignore | 4 +- docs/api.rst | 2 +- docs/api/xmovie.Movie.rst | 12 ++---- docs/api/xmovie.presets.basic.rst | 2 +- docs/api/xmovie.rotating_globe.rst | 2 +- docs/conf.py | 27 +++++++------- docs/index.rst | 6 +-- docs/whats-new.rst | 2 +- setup.py | 2 - xmovie/__init__.py | 1 - xmovie/core.py | 59 ++++++++++------------------- xmovie/presets.py | 20 ++++------ xmovie/test/test_core.py | 60 ++++++++++++------------------ xmovie/test/test_presets.py | 9 +++-- 15 files changed, 82 insertions(+), 130 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 553b4f5..f4ccccc 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -22,8 +22,8 @@ jobs: matrix: os: ["ubuntu-latest", "macos-latest"] python-version: ["3.7", "3.8", "3.9"] - - + + steps: - name: Cancel previous runs uses: styfle/cancel-workflow-action@0.9.1 diff --git a/.gitignore b/.gitignore index b6ef967..4f9bec2 100644 --- a/.gitignore +++ b/.gitignore @@ -71,9 +71,9 @@ target/ **/dask-worker-space # movie and picture files -*.png +*.png *.mov -*.mp4 +*.mp4 *.gif !docs/examples/*.gif !docs/examples/*.png diff --git a/docs/api.rst b/docs/api.rst index dc9f537..b33c233 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -22,7 +22,7 @@ They have a signature of the type: .. code-block:: - plotfunc(da, fig, timestamp, framedim, **kwargs): + def plotfunc(da, fig, timestamp, framedim, **kwargs): ... .. autosummary:: diff --git a/docs/api/xmovie.Movie.rst b/docs/api/xmovie.Movie.rst index df90a67..bd050ec 100644 --- a/docs/api/xmovie.Movie.rst +++ b/docs/api/xmovie.Movie.rst @@ -5,23 +5,17 @@ .. autoclass:: Movie - + .. automethod:: __init__ - + .. rubric:: Methods .. autosummary:: - + ~Movie.__init__ ~Movie.preview ~Movie.render_single_frame ~Movie.save ~Movie.save_frames_parallel ~Movie.save_frames_serial - - - - - - \ No newline at end of file diff --git a/docs/api/xmovie.presets.basic.rst b/docs/api/xmovie.presets.basic.rst index 761438c..aeba2ed 100644 --- a/docs/api/xmovie.presets.basic.rst +++ b/docs/api/xmovie.presets.basic.rst @@ -3,4 +3,4 @@ xmovie.presets.basic .. currentmodule:: xmovie.presets -.. autofunction:: basic \ No newline at end of file +.. autofunction:: basic diff --git a/docs/api/xmovie.rotating_globe.rst b/docs/api/xmovie.rotating_globe.rst index 6b4c013..95167f8 100644 --- a/docs/api/xmovie.rotating_globe.rst +++ b/docs/api/xmovie.rotating_globe.rst @@ -3,4 +3,4 @@ xmovie.rotating\_globe .. currentmodule:: xmovie -.. autofunction:: rotating_globe \ No newline at end of file +.. autofunction:: rotating_globe diff --git a/docs/conf.py b/docs/conf.py index a5f4905..1ee735d 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -23,9 +23,9 @@ # -- Project information ----------------------------------------------------- current_year = datetime.datetime.now().year -project = 'xmovie' -copyright = f'2018\u2013{current_year}, xmovie maintainers' -author = 'Julius Busecke' +project = "xmovie" +copyright = f"2018\u2013{current_year}, xmovie maintainers" +author = "Julius Busecke" # The short X.Y version version = ".".join(xmovie.__version__.split(".")[:2]) @@ -33,7 +33,6 @@ release = xmovie.__version__ - # -- General configuration --------------------------------------------------- # If your documentation needs a minimal Sphinx version, state it here. @@ -44,9 +43,9 @@ # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ - 'sphinx.ext.autodoc', - 'sphinx.ext.autosummary', - 'sphinx.ext.extlinks', + "sphinx.ext.autodoc", + "sphinx.ext.autosummary", + "sphinx.ext.extlinks", "sphinx.ext.intersphinx", "sphinx.ext.napoleon", "sphinx.ext.autosectionlabel", @@ -59,16 +58,16 @@ ] # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = ["_templates"] # The suffix(es) of source filenames. # You can specify multiple suffix as a list of string: # # source_suffix = ['.rst', '.md'] -source_suffix = '.rst' +source_suffix = ".rst" # The master toctree document. -master_doc = 'index' +master_doc = "index" # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -80,16 +79,16 @@ # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This pattern also affects html_static_path and html_extra_path . -exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] +exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] # The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'sphinx' +pygments_style = "sphinx" # -- Extension configuration ------------------------------------------------- autodoc_typehints = "description" -autodoc_default_options ={ +autodoc_default_options = { "members": True, } @@ -123,4 +122,4 @@ # -- Options for HTML output ------------------------------------------------- -html_theme = 'sphinx_book_theme' +html_theme = "sphinx_book_theme" diff --git a/docs/index.rst b/docs/index.rst index 18366bc..a6a9848 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -88,13 +88,13 @@ If you want to install the latest version from GitHub, simply run pip install git+https://github.com/jbusecke/xmovie.git .. note:: - + If you dont have `ssh keys set up `_, you can use - + .. prompt:: bash - + git clone https://github.com/jbusecke/xmovie.git` and enter your github password. diff --git a/docs/whats-new.rst b/docs/whats-new.rst index 72c899c..e19b031 100644 --- a/docs/whats-new.rst +++ b/docs/whats-new.rst @@ -18,7 +18,7 @@ Documentation By `zmoon `_. - Add more readme badges (:pull:`72`). By `zmoon `_. - + Breaking Changes ~~~~~~~~~~~~~~~~ - Removed support for python 3.6 (:pull:`80`). diff --git a/setup.py b/setup.py index 6188be1..0998a31 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,5 @@ - from setuptools import setup - setup( use_scm_version={ "write_to": "xmovie/_version.py", diff --git a/xmovie/__init__.py b/xmovie/__init__.py index 96fea1d..1e9dc94 100644 --- a/xmovie/__init__.py +++ b/xmovie/__init__.py @@ -1,7 +1,6 @@ from .core import Movie from .presets import rotating_globe - try: from ._version import __version__ diff --git a/xmovie/core.py b/xmovie/core.py index 12ed538..25faa1f 100644 --- a/xmovie/core.py +++ b/xmovie/core.py @@ -1,17 +1,18 @@ import matplotlib as mpl mpl.use("Agg") -import re +import gc +import glob import os +import re import sys -import glob import warnings -import gc +from subprocess import PIPE, STDOUT, Popen + +import matplotlib.pyplot as plt import xarray as xr from .presets import _check_input, basic -from subprocess import Popen, PIPE, STDOUT -import matplotlib.pyplot as plt try: from tqdm.auto import tqdm @@ -28,7 +29,6 @@ # import dask.bag as db import dask.array as dsa - # is it a good idea to set these here? # Needs to be dependent on dpi and videosize plt.rcParams.update({"font.size": 14}) @@ -92,11 +92,7 @@ def _check_ffmpeg_version(): else: # parse version number try: - found = ( - re.search("ffmpeg version (.+?) Copyright", str(output)) - .group(1) - .replace(" ", "") - ) + found = re.search("ffmpeg version (.+?) Copyright", str(output)).group(1).replace(" ", "") return found except AttributeError: # ffmpeg version, Copyright not found in the original string @@ -141,9 +137,7 @@ def _check_ffmpeg_execute(command, verbose=False): ) -def _combine_ffmpeg_command( - sourcefolder, moviename, framerate, frame_pattern, ffmpeg_options -): +def _combine_ffmpeg_command(sourcefolder, moviename, framerate, frame_pattern, ffmpeg_options): # we need `-y` because i can not properly diagnose the errors here... command = 'ffmpeg -r %i -i "%s" -y %s -r %i "%s"' % ( framerate, @@ -172,9 +166,7 @@ def convert_gif( ): if gif_palette: - palette_filter = ( - '-filter_complex "[0:v] split [a][b];[a] palettegen [p];[b][p] paletteuse"' - ) + palette_filter = '-filter_complex "[0:v] split [a][b];[a] palettegen [p];[b][p] paletteuse"' else: palette_filter = "" @@ -205,9 +197,7 @@ def combine_frames_into_movie( framerate=20, ): - command = _combine_ffmpeg_command( - sourcefolder, moviename, framerate, frame_pattern, ffmpeg_options - ) + command = _combine_ffmpeg_command(sourcefolder, moviename, framerate, frame_pattern, ffmpeg_options) p = _check_ffmpeg_execute(command, verbose=verbose) print("Movie created at %s" % (moviename)) @@ -227,7 +217,7 @@ def combine_frames_into_movie( def save_single_frame(fig, frame, odir=None, frame_pattern="frame_%05d.png", dpi=100): - """ Saves a single frame of data from an already-created figure and then closes the figure """ + """Saves a single frame of data from an already-created figure and then closes the figure""" fig.savefig( os.path.join(odir, frame_pattern % (frame)), dpi=dpi, @@ -341,9 +331,7 @@ def render_single_frame(self, timestep): # produce dummy output for ax and pp if the plotfunc does not provide them if self.plotfunc_n_outargs == 2: # this should be the case for all presets provided by xmovie - ax, pp = self.plotfunc( - self.data, fig, timestep, self.framedim, **self.kwargs - ) + ax, pp = self.plotfunc(self.data, fig, timestep, self.framedim, **self.kwargs) else: warnings.warn( "The provided `plotfunc` does not provide the expected number of output arguments.\ @@ -362,9 +350,7 @@ def preview(self, timestep): timestep : int Timestep (frame) to preview. """ - with plt.rc_context( - {"figure.dpi": self.dpi, "figure.figsize": [self.width, self.height]} - ): + with plt.rc_context({"figure.dpi": self.dpi, "figure.figsize": [self.width, self.height]}): fig, ax, pp = self.render_single_frame(timestep) def save_frames_serial(self, odir, progress=False): @@ -386,9 +372,7 @@ def save_frames_serial(self, odir, progress=False): for timestep in frame_range: fig, ax, pp = self.render_single_frame(timestep) - save_single_frame( - fig, timestep, odir=odir, frame_pattern=self.frame_pattern, dpi=self.dpi - ) + save_single_frame(fig, timestep, odir=odir, frame_pattern=self.frame_pattern, dpi=self.dpi) def save_frames_parallel(self, odir, parallel_compute_kwargs=dict()): """ @@ -401,8 +385,8 @@ def save_frames_parallel(self, odir, parallel_compute_kwargs=dict()): parallel_compute_kwargs : dict Keyword arguments to pass to Dask's :meth:`~dask.array.Array.compute`. """ - import numpy as np import dask.array as darray + import numpy as np da = self.data framedim = self.framedim @@ -418,7 +402,7 @@ def save_frames_parallel(self, odir, parallel_compute_kwargs=dict()): elif type(da) is xr.Dataset: framedim_chunks = da.chunks[framedim] else: - raise(TypeError("`da` must be either an xarray.DataArray or xarray.Dataset")) + raise (TypeError("`da` must be either an xarray.DataArray or xarray.Dataset")) if not all([chunk == 1 for chunk in framedim_chunks]): raise ValueError( @@ -434,9 +418,7 @@ def _save_single_frame_parallel(xr_array, framedim): ) # get index of chunk in framedim fig, ax, pp = self.render_single_frame(timestep) - save_single_frame( - fig, timestep, odir=odir, frame_pattern=self.frame_pattern, dpi=self.dpi - ) + save_single_frame(fig, timestep, odir=odir, frame_pattern=self.frame_pattern, dpi=self.dpi) return time_of_chunk @@ -532,8 +514,7 @@ def save( if os.path.exists(mpath): if not overwrite_existing: raise RuntimeError( - "File `%s` already exists. Set `overwrite_existing` to True to overwrite." - % (mpath) + "File `%s` already exists. Set `overwrite_existing` to True to overwrite." % (mpath) ) if isgif: if os.path.exists(gpath): @@ -545,9 +526,7 @@ def save( # print frames if parallel: - self.save_frames_parallel( - dirname, parallel_compute_kwargs=parallel_compute_kwargs - ) + self.save_frames_parallel(dirname, parallel_compute_kwargs=parallel_compute_kwargs) else: self.save_frames_serial(dirname, progress=progress) diff --git a/xmovie/presets.py b/xmovie/presets.py index eeb4d71..1a349de 100644 --- a/xmovie/presets.py +++ b/xmovie/presets.py @@ -1,13 +1,13 @@ import warnings -import numpy as np -import xarray as xr -from cartopy.mpl import geoaxes + import cartopy.crs as ccrs import cartopy.feature as cfeature - -import shapely.geometry as sgeom import matplotlib.pyplot as plt import matplotlib.ticker as mticker +import numpy as np +import shapely.geometry as sgeom +import xarray as xr +from cartopy.mpl import geoaxes def _check_input(da, fieldname): @@ -15,9 +15,7 @@ def _check_input(da, fieldname): if isinstance(da, xr.Dataset): if fieldname is None: fieldname = list(da.data_vars)[0] - warnings.warn( - "No `fieldname` supplied. Defaults to `%s`" % fieldname, UserWarning - ) + warnings.warn("No `fieldname` supplied. Defaults to `%s`" % fieldname, UserWarning) data = da[fieldname] elif isinstance(da, xr.DataArray): data = da @@ -65,7 +63,7 @@ def _core_plot(ax, data, plotmethod=None, **kwargs): def _base_plot(ax, base_data, timestamp, framedim, plotmethod=None, **kwargs): - data = base_data.isel({framedim:timestamp}) + data = base_data.isel({framedim: timestamp}) p = _core_plot(ax, data, plotmethod=plotmethod, **kwargs) return p @@ -293,9 +291,7 @@ def rotating_globe( # proj = ccrs.Orthographic(lon[timestamp], lat[timestamp]) # proj = _smooth_boundary_globe(proj) # This looks more like a 3D globe in my opinion - proj = ccrs.NearsidePerspective( - central_longitude=lon[timestamp], central_latitude=lat[timestamp] - ) + proj = ccrs.NearsidePerspective(central_longitude=lon[timestamp], central_latitude=lat[timestamp]) proj = _smooth_boundary_NearsidePerspective(proj) subplot_kw = dict(projection=proj) diff --git a/xmovie/test/test_core.py b/xmovie/test/test_core.py index e3fc3e4..ec89d76 100644 --- a/xmovie/test/test_core.py +++ b/xmovie/test/test_core.py @@ -1,24 +1,26 @@ +import os + +import cv2 +import dask.array as dsa +import matplotlib as mpl +import matplotlib.pyplot as plt +import numpy as np +import pytest +import xarray as xr +from PIL import Image + from xmovie.core import ( - _parse_plot_defaults, + Movie, + _check_ffmpeg_execute, _check_plotfunc_output, _combine_ffmpeg_command, _execute_command, - _check_ffmpeg_execute, - save_single_frame, + _parse_plot_defaults, combine_frames_into_movie, convert_gif, - Movie, + save_single_frame, ) from xmovie.presets import basic, rotating_globe -import pytest -import matplotlib as mpl -import matplotlib.pyplot as plt -from PIL import Image -import numpy as np -import xarray as xr -import os -import cv2 -import dask.array as dsa def test_parse_plot_defaults(): @@ -82,9 +84,7 @@ def test_check_ffmpeg_version(): pass -@pytest.mark.parametrize( - "dir, fname, path", [("", "file", "file"), ("foo", "file", "foo/file")] -) +@pytest.mark.parametrize("dir, fname, path", [("", "file", "file"), ("foo", "file", "foo/file")]) @pytest.mark.parametrize("frame_pattern", ["frame_%05d.png", "test%05d.png"]) @pytest.mark.parametrize("framerate", [5, 25]) @pytest.mark.parametrize( @@ -94,9 +94,7 @@ def test_check_ffmpeg_version(): "-c:v libx264 -preset slow -crf 15 -pix_fmt yuv420p", ], ) -def test_combine_ffmpeg_command( - dir, fname, path, frame_pattern, framerate, ffmpeg_options -): +def test_combine_ffmpeg_command(dir, fname, path, frame_pattern, framerate, ffmpeg_options): cmd = _combine_ffmpeg_command(dir, fname, framerate, frame_pattern, ffmpeg_options) assert cmd == 'ffmpeg -r %i -i "%s" -y %s -r %i "%s"' % ( framerate, @@ -179,9 +177,7 @@ def test_write_movie(tmpdir, moviename, remove_frames, framerate, ffmpeg_options @pytest.mark.parametrize("gifname", ["movie.gif"]) @pytest.mark.parametrize("remove_movie", [True, False]) @pytest.mark.parametrize("gif_framerate", [10, 15]) -def test_convert_gif( - tmpdir, moviename, remove_movie, gif_palette, gifname, gif_framerate -): +def test_convert_gif(tmpdir, moviename, remove_movie, gif_palette, gifname, gif_framerate): m = tmpdir.join(moviename) mpath = m.strpath g = tmpdir.join(gifname) @@ -242,9 +238,7 @@ def test_Movie(plotfunc, framedim, frame_pattern, dpi, pixelheight, pixelwidth): assert mov.plotfunc == basic else: assert mov.plotfunc == plotfunc - assert mov.plotfunc_n_outargs == _check_plotfunc_output( - mov.plotfunc, mov.data, framedim - ) + assert mov.plotfunc_n_outargs == _check_plotfunc_output(mov.plotfunc, mov.data, framedim) assert mov.dpi == dpi assert mov.framedim == framedim @@ -268,9 +262,7 @@ def test_Movie(plotfunc, framedim, frame_pattern, dpi, pixelheight, pixelwidth): assert mov.kwargs == {} # there are no kwargs set that are not used by Movie -@pytest.mark.parametrize( - "plotfunc, expected_empty", [(dummy_plotfunc, True), (basic, False)] -) +@pytest.mark.parametrize("plotfunc, expected_empty", [(dummy_plotfunc, True), (basic, False)]) def test_movie_render_frame(plotfunc, expected_empty): da = test_dataarray() mov = Movie(da, plotfunc=plotfunc) @@ -284,9 +276,7 @@ def test_movie_render_frame(plotfunc, expected_empty): else: fig, ax, pp = mov.render_single_frame(1) - assert isinstance( - ax, mpl.axes.Axes - ) # this needs to be tested for the projections aswell + assert isinstance(ax, mpl.axes.Axes) # this needs to be tested for the projections aswell assert isinstance(fig, mpl.figure.Figure) # This needs to be tested more exensively, especially whith multiple axes @@ -320,9 +310,7 @@ def test_movie_save_frames(tmpdir, frame_pattern): "-c:v libx264 -preset slow -crf 15 -pix_fmt yuv420p", ], ) -def test_movie_save( - tmpdir, parallel, filename, gif_palette, framerate, gif_framerate, ffmpeg_options -): +def test_movie_save(tmpdir, parallel, filename, gif_palette, framerate, gif_framerate, ffmpeg_options): print(gif_palette) # Need more tests for progress, verbose, overwriting path = tmpdir.join(filename) @@ -366,9 +354,7 @@ def test_movie_save_parallel_no_dask(tmpdir): parallel=True, ) - assert "Input data needs to be a dask array to save in parallel" in str( - excinfo.value - ) + assert "Input data needs to be a dask array to save in parallel" in str(excinfo.value) def test_movie_save_parallel_wrong_chunk(tmpdir): diff --git a/xmovie/test/test_presets.py b/xmovie/test/test_presets.py index 6afd21a..f27af11 100644 --- a/xmovie/test/test_presets.py +++ b/xmovie/test/test_presets.py @@ -1,14 +1,15 @@ -import xarray as xr +import cartopy.crs as ccrs +import matplotlib as mpl +import matplotlib.pyplot as plt import numpy as np import pytest +import xarray as xr + from xmovie.presets import ( _check_input, _core_plot, _smooth_boundary_NearsidePerspective, ) -import matplotlib as mpl -import matplotlib.pyplot as plt -import cartopy.crs as ccrs def test_check_input(): From 5dbc4e8b705a75a99681848a244935edf0d6330d Mon Sep 17 00:00:00 2001 From: zmoon Date: Tue, 3 May 2022 09:27:13 -0600 Subject: [PATCH 7/8] Resolve flake8 warnings --- xmovie/core.py | 7 ++----- xmovie/presets.py | 4 +++- xmovie/test/test_presets.py | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/xmovie/core.py b/xmovie/core.py index 25faa1f..186b046 100644 --- a/xmovie/core.py +++ b/xmovie/core.py @@ -12,13 +12,13 @@ import matplotlib.pyplot as plt import xarray as xr -from .presets import _check_input, basic +from .presets import basic try: from tqdm.auto import tqdm tqdm_avail = True -except: +except Exception: warnings.warn( "Optional dependency `tqdm` not found. This will make progressbars a lot nicer. \ Install with `conda install -c conda-forge tqdm`" @@ -385,9 +385,6 @@ def save_frames_parallel(self, odir, parallel_compute_kwargs=dict()): parallel_compute_kwargs : dict Keyword arguments to pass to Dask's :meth:`~dask.array.Array.compute`. """ - import dask.array as darray - import numpy as np - da = self.data framedim = self.framedim diff --git a/xmovie/presets.py b/xmovie/presets.py index 1a349de..e508cee 100644 --- a/xmovie/presets.py +++ b/xmovie/presets.py @@ -210,7 +210,9 @@ def _add_coast(ax, style): ax.add_feature(feature) -### Presets (should proabably put all others into a submodule) +# Presets (should proabably put all others into a submodule) + + def basic( da, fig, timestamp, framedim="time", plotmethod=None, plot_variable=None, subplot_kw=None, **kwargs ): diff --git a/xmovie/test/test_presets.py b/xmovie/test/test_presets.py index f27af11..de89ba9 100644 --- a/xmovie/test/test_presets.py +++ b/xmovie/test/test_presets.py @@ -39,7 +39,7 @@ def test_core_plot(plotmethod, expected_type, filled): fig, ax = plt.subplots() pp = _core_plot(ax, da, plotmethod=plotmethod) assert isinstance(pp, expected_type) - if not filled is None: + if filled is not None: assert pp.filled == filled From 60ae494c7c59fb6387c587d36bbfb0b014ff4498 Mon Sep 17 00:00:00 2001 From: Julius Busecke Date: Tue, 3 May 2022 14:09:27 -0400 Subject: [PATCH 8/8] Update xmovie/core.py Co-authored-by: Zachary Moon --- xmovie/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xmovie/core.py b/xmovie/core.py index 186b046..03a1282 100644 --- a/xmovie/core.py +++ b/xmovie/core.py @@ -399,7 +399,7 @@ def save_frames_parallel(self, odir, parallel_compute_kwargs=dict()): elif type(da) is xr.Dataset: framedim_chunks = da.chunks[framedim] else: - raise (TypeError("`da` must be either an xarray.DataArray or xarray.Dataset")) + raise TypeError("`da` must be either an xarray.DataArray or xarray.Dataset") if not all([chunk == 1 for chunk in framedim_chunks]): raise ValueError(