From d85406c834016d4cc7c595565c2f5dee0ea4c3c7 Mon Sep 17 00:00:00 2001 From: Antonio Stanziola Date: Thu, 22 Jun 2023 16:49:01 +0100 Subject: [PATCH] Update deps (#179) * removed flake8 + updates on libraries * removed history file in favor of changelog * removed pytest.ini as in in pyproject.toml * removed flake8 * update coverage settings * added imageio and tqdm to dev dependencies (for testing) * made explicit the need for extra dependencies on the extras module * added tests for save_video --- .gitchangelog.rc | 303 ------------------------------------ CHANGELOG.md | 4 +- HISTORY.md | 59 ------- Makefile | 3 - jwave/extras/export.py | 9 +- mypy.ini | 12 -- pyproject.toml | 12 +- pytest.ini | 4 - setup.cfg | 59 ------- tests/test_extras_export.py | 55 +++++++ 10 files changed, 70 insertions(+), 450 deletions(-) delete mode 100644 .gitchangelog.rc delete mode 100644 HISTORY.md delete mode 100755 mypy.ini delete mode 100644 pytest.ini delete mode 100644 setup.cfg create mode 100644 tests/test_extras_export.py diff --git a/.gitchangelog.rc b/.gitchangelog.rc deleted file mode 100644 index c380600..0000000 --- a/.gitchangelog.rc +++ /dev/null @@ -1,303 +0,0 @@ -# -*- coding: utf-8; mode: python -*- -## -## Format -## -## ACTION: [AUDIENCE:] COMMIT_MSG [!TAG ...] -## -## Description -## -## ACTION is one of 'chg', 'fix', 'new' -## -## Is WHAT the change is about. -## -## 'chg' is for refactor, small improvement, cosmetic changes... -## 'fix' is for bug fixes -## 'new' is for new features, big improvement -## -## AUDIENCE is optional and one of 'dev', 'usr', 'pkg', 'test', 'doc' -## -## Is WHO is concerned by the change. -## -## 'dev' is for developpers (API changes, refactors...) -## 'usr' is for final users (UI changes) -## 'pkg' is for packagers (packaging changes) -## 'test' is for testers (test only related changes) -## 'doc' is for doc guys (doc only changes) -## -## COMMIT_MSG is ... well ... the commit message itself. -## -## TAGs are additionnal adjective as 'refactor' 'minor' 'cosmetic' -## -## They are preceded with a '!' or a '@' (prefer the former, as the -## latter is wrongly interpreted in github.) Commonly used tags are: -## -## 'refactor' is obviously for refactoring code only -## 'minor' is for a very meaningless change (a typo, adding a comment) -## 'cosmetic' is for cosmetic driven change (re-indentation, 80-col...) -## 'wip' is for partial functionality but complete subfunctionality. -## -## Example: -## -## new: usr: support of bazaar implemented -## chg: re-indentend some lines !cosmetic -## new: dev: updated code to be compatible with last version of killer lib. -## fix: pkg: updated year of licence coverage. -## new: test: added a bunch of test around user usability of feature X. -## fix: typo in spelling my name in comment. !minor -## -## Please note that multi-line commit message are supported, and only the -## first line will be considered as the "summary" of the commit message. So -## tags, and other rules only applies to the summary. The body of the commit -## message will be displayed in the changelog without reformatting. - - -## -## ``ignore_regexps`` is a line of regexps -## -## Any commit having its full commit message matching any regexp listed here -## will be ignored and won't be reported in the changelog. -## -ignore_regexps = [ - r'@minor', r'!minor', - r'@cosmetic', r'!cosmetic', - r'@refactor', r'!refactor', - r'@wip', r'!wip', - r'^([cC]hg|[fF]ix|[nN]ew)\s*:\s*[p|P]kg:', - r'^([cC]hg|[fF]ix|[nN]ew)\s*:\s*[d|D]ev:', - r'^(.{3,3}\s*:)?\s*[fF]irst commit.?\s*$', - r'^$', ## ignore commits with empty messages -] - - -## ``section_regexps`` is a list of 2-tuples associating a string label and a -## list of regexp -## -## Commit messages will be classified in sections thanks to this. Section -## titles are the label, and a commit is classified under this section if any -## of the regexps associated is matching. -## -## Please note that ``section_regexps`` will only classify commits and won't -## make any changes to the contents. So you'll probably want to go check -## ``subject_process`` (or ``body_process``) to do some changes to the subject, -## whenever you are tweaking this variable. -## -section_regexps = [ - ('New', [ - r'^[nN]ew\s*:\s*((dev|use?r|pkg|test|doc)\s*:\s*)?([^\n]*)$', - ]), - ('Breaking changes', [ - r'^BREAKING\s*:\s*((dev|use?r|pkg|test|doc)\s*:\s*)?([^\n]*)$', - ]), - ('Changes', [ - r'^[cC]hg\s*:\s*((dev|use?r|pkg|test|doc)\s*:\s*)?([^\n]*)$', - ]), - ('Bug Fix', [ - r'^[fF]ix\s*:\s*((dev|use?r|pkg|test|doc)\s*:\s*)?([^\n]*)$', - ]), - ('Documentation', [ - r'^[dD]oc\s*:\s*((dev|use?r|pkg|test|doc)\s*:\s*)?([^\n]*)$', - ]), - ('Features', [ - r'^[fF]eat\s*:\s*((dev|use?r|pkg|test|doc)\s*:\s*)?([^\n]*)$', - ]), - ('Refactoring', [ - r'^[rR]efactor\s*:\s*((dev|use?r|pkg|test|doc)\s*:\s*)?([^\n]*)$', - ]), - ('Tests', [ - r'^[tT]est\s*:\s*((dev|use?r|pkg|test|doc)\s*:\s*)?([^\n]*)$', - ]), - ('Pull requests merged', [ - r'^^Merge pull request\s*:\s*((dev|use?r|pkg|test|doc)\s*:\s*)?([^\n]*)$', - ]), -] - - -## ``body_process`` is a callable -## -## This callable will be given the original body and result will -## be used in the changelog. -## -## Available constructs are: -## -## - any python callable that take one txt argument and return txt argument. -## -## - ReSub(pattern, replacement): will apply regexp substitution. -## -## - Indent(chars=" "): will indent the text with the prefix -## Please remember that template engines gets also to modify the text and -## will usually indent themselves the text if needed. -## -## - Wrap(regexp=r"\n\n"): re-wrap text in separate paragraph to fill 80-Columns -## -## - noop: do nothing -## -## - ucfirst: ensure the first letter is uppercase. -## (usually used in the ``subject_process`` pipeline) -## -## - final_dot: ensure text finishes with a dot -## (usually used in the ``subject_process`` pipeline) -## -## - strip: remove any spaces before or after the content of the string -## -## - SetIfEmpty(msg="No commit message."): will set the text to -## whatever given ``msg`` if the current text is empty. -## -## Additionally, you can `pipe` the provided filters, for instance: -#body_process = Wrap(regexp=r'\n(?=\w+\s*:)') | Indent(chars=" ") -#body_process = Wrap(regexp=r'\n(?=\w+\s*:)') -#body_process = noop -body_process = ReSub(r'((^|\n)[A-Z]\w+(-\w+)*: .*(\n\s+.*)*)+$', r'') | strip - - -## ``subject_process`` is a callable -## -## This callable will be given the original subject and result will -## be used in the changelog. -## -## Available constructs are those listed in ``body_process`` doc. -subject_process = (strip | - ReSub(r'^([cC]hg|[fF]ix|[nN]ew|[rR]efactor|[dD]oc|[fF]eat|[tT]est)\s*:\s*((dev|use?r|pkg|test|doc)\s*:\s*)?([^\n@]*)(@[a-z]+\s+)*$', r'\4') | - SetIfEmpty("No commit message.") | ucfirst | final_dot) - - -## ``tag_filter_regexp`` is a regexp -## -## Tags that will be used for the changelog must match this regexp. -## -tag_filter_regexp = r'^[0-9]+\.[0-9]+(\.[0-9]+)?$' - - -## ``unreleased_version_label`` is a string or a callable that outputs a string -## -## This label will be used as the changelog Title of the last set of changes -## between last valid tag and HEAD if any. -unreleased_version_label = "(latest)" - - -## ``output_engine`` is a callable -## -## This will change the output format of the generated changelog file -## -## Available choices are: -## -## - rest_py -## -## Legacy pure python engine, outputs ReSTructured text. -## This is the default. -## -## - mustache() -## -## Template name could be any of the available templates in -## ``templates/mustache/*.tpl``. -## Requires python package ``pystache``. -## Examples: -## - mustache("markdown") -## - mustache("restructuredtext") -## -## - makotemplate() -## -## Template name could be any of the available templates in -## ``templates/mako/*.tpl``. -## Requires python package ``mako``. -## Examples: -## - makotemplate("restructuredtext") -## -#output_engine = rest_py -#output_engine = mustache("restructuredtext") -output_engine = mustache("markdown") -#output_engine = makotemplate("markdown") - - -## ``include_merge`` is a boolean -## -## This option tells git-log whether to include merge commits in the log. -## The default is to include them. -include_merge = True - - -## ``log_encoding`` is a string identifier -## -## This option tells gitchangelog what encoding is outputed by ``git log``. -## The default is to be clever about it: it checks ``git config`` for -## ``i18n.logOutputEncoding``, and if not found will default to git's own -## default: ``utf-8``. -#log_encoding = 'utf-8' - - -## ``publish`` is a callable -## -## Sets what ``gitchangelog`` should do with the output generated by -## the output engine. ``publish`` is a callable taking one argument -## that is an interator on lines from the output engine. -## -## Some helper callable are provided: -## -## Available choices are: -## -## - stdout -## -## Outputs directly to standard output -## (This is the default) -## -## - FileInsertAtFirstRegexMatch(file, pattern, idx=lamda m: m.start()) -## -## Creates a callable that will parse given file for the given -## regex pattern and will insert the output in the file. -## ``idx`` is a callable that receive the matching object and -## must return a integer index point where to insert the -## the output in the file. Default is to return the position of -## the start of the matched string. -## -## - FileRegexSubst(file, pattern, replace, flags) -## -## Apply a replace inplace in the given file. Your regex pattern must -## take care of everything and might be more complex. Check the README -## for a complete copy-pastable example. -## -# publish = FileInsertIntoFirstRegexMatch( -# "CHANGELOG.rst", -# r'/(?P[0-9]+\.[0-9]+(\.[0-9]+)?)\s+\([0-9]+-[0-9]{2}-[0-9]{2}\)\n--+\n/', -# idx=lambda m: m.start(1) -# ) -#publish = stdout - - -## ``revs`` is a list of callable or a list of string -## -## callable will be called to resolve as strings and allow dynamical -## computation of these. The result will be used as revisions for -## gitchangelog (as if directly stated on the command line). This allows -## to filter exaclty which commits will be read by gitchangelog. -## -## To get a full documentation on the format of these strings, please -## refer to the ``git rev-list`` arguments. There are many examples. -## -## Using callables is especially useful, for instance, if you -## are using gitchangelog to generate incrementally your changelog. -## -## Some helpers are provided, you can use them:: -## -## - FileFirstRegexMatch(file, pattern): will return a callable that will -## return the first string match for the given pattern in the given file. -## If you use named sub-patterns in your regex pattern, it'll output only -## the string matching the regex pattern named "rev". -## -## - Caret(rev): will return the rev prefixed by a "^", which is a -## way to remove the given revision and all its ancestor. -## -## Please note that if you provide a rev-list on the command line, it'll -## replace this value (which will then be ignored). -## -## If empty, then ``gitchangelog`` will act as it had to generate a full -## changelog. -## -## The default is to use all commits to make the changelog. -#revs = ["^1.0.3", ] -#revs = [ -# Caret( -# FileFirstRegexMatch( -# "CHANGELOG.rst", -# r"(?P[0-9]+\.[0-9]+(\.[0-9]+)?)\s+\([0-9]+-[0-9]{2}-[0-9]{2}\)\n--+\n")), -# "HEAD" -#] -revs = [] diff --git a/CHANGELOG.md b/CHANGELOG.md index 36b38f3..900e021 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Changed +- updated documentation +- made imageio and tqdm optional dependencies ## [0.1.1] - 2023-06-22 ### Fixed @@ -58,4 +61,3 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), [0.0.3]: https://github.com/ucl-bug/jwave/compare/0.0.2...0.0.3 [0.0.2]: https://github.com/ucl-bug/jwave/compare/0.0.1...0.0.2 [0.0.1]: https://github.com/ucl-bug/jwave/releases/tag/0.0.1 - diff --git a/HISTORY.md b/HISTORY.md deleted file mode 100644 index 8feb47f..0000000 --- a/HISTORY.md +++ /dev/null @@ -1,59 +0,0 @@ -# Changelog - - -## (latest) - -### Bug Fix - -* Correctly handles Nyquist frequency for Helmholtz operator, to improve agreement with k-Wave. [Antonio Stanziola] - -* Incorrect domain size for angular spectrum. [Antonio Stanziola] - -* Angular spectrum is only dispatched on 'pressure' type. [Antonio Stanziola] - -### Features - -* Convergent born series. [Antonio Stanziola] - - -## 0.0.3 (2022-07-05) - -### Features - -* Angular spectrum method for single frequency sources. [Antonio Stanziola] - -* Differentiable rayleigh integral (from a plane) [Antonio Stanziola] - - -## 0.0.2 (2022-06-23) - -### Bug Fix - -* Helmholtz notebook parameters bug. [Antonio Stanziola] - -### Features - -* Generate TimeHarmonicSource from point sources. [Antonio Stanziola] - - -## 0.0.1 (2022-06-07) - -### Bug Fix - -* Using numpy operations in TimeAxis for static fields. [Antonio Stanziola] - -* Pml for 1D and 3D simulations. [Antonio Stanziola] - -* Plotting functions of jwave.utils now work with both Fields and arrays. [Antonio Stanziola] - -### Features - -* Finite differences helmholtz tested. [Antonio Stanziola] - -* Extract time varying params without running the simulation. [Antonio Stanziola] - -* Windows one-line installer. [Antonio Stanziola] - -### Tests - -* Removed flake8 testing for E111. [Antonio Stanziola] diff --git a/Makefile b/Makefile index c6b382a..abab817 100644 --- a/Makefile +++ b/Makefile @@ -50,9 +50,6 @@ jaxgpu: ## Installs jax for *nix systems with CUDA lint: ## Runs isort and mypy. @echo "Running isort ..." $(ENV_PREFIX)isort jwave/ - @echo "Running flake8 ..." - $(ENV_PREFIX)flake8 jwave/ --count --select=E9,F63,F7,F82 --show-source --statistics - $(ENV_PREFIX)flake8 jwave/ --count --ignore=E111 --exit-zero --max-complexity=10 --max-line-length=127 --statistics @echo "Running mypy ..." $(ENV_PREFIX)mypy --allow-redefinition --config-file=pyproject.toml jwave/*.py diff --git a/jwave/extras/export.py b/jwave/extras/export.py index 21543a3..8ca105a 100644 --- a/jwave/extras/export.py +++ b/jwave/extras/export.py @@ -15,10 +15,15 @@ import os -import imageio +try: + import imageio + from tqdm import trange +except ImportError: + raise ImportError( + "Please install imageio and tqdm to use use the extras module.") + import matplotlib.pyplot as plt from jaxdf import Field -from tqdm import trange def save_video( diff --git a/mypy.ini b/mypy.ini deleted file mode 100755 index 2d2a52e..0000000 --- a/mypy.ini +++ /dev/null @@ -1,12 +0,0 @@ -[mypy] -python_version = 3.7 -show_error_codes = True - -[mypy-matplotlib.*] -ignore_missing_imports = True - -[mypy-sympy.*] -ignore_missing_imports = True - -[mypy-hashids.*] -ignore_missing_imports = True diff --git a/pyproject.toml b/pyproject.toml index a1e0633..74c5acb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -56,12 +56,11 @@ matplotlib = "^3.0.0" [tool.poetry.group.dev.dependencies] coverage = "7.0.4" -flake8 = "5.0.4" pytest = "^7.2.0" pre-commit = "^2.20.0" -pycln = "2.1.1" +pycln = "^2.1.5" isort = "^5.12.0" -griffe = "^0.24.0" +griffe = "^0.29.1" mkdocs-material = "^9.1.16" mkdocstrings = "^0.22.0" mkdocs-jupyter = "^0.24.1" @@ -71,6 +70,9 @@ mkdocstrings-python = "^0.8.0" python-kacl = "^0.4.6" pymdown-extensions = "^10.0.1" plumkdocs = "0.0.2" +imageio = "^2.31.1" +tqdm = "^4.65.0" +imageio-ffmpeg = "^0.4.8" [build-system] requires = ["poetry-core>=1.0.0"] @@ -107,10 +109,6 @@ split_before_logical_operator = true [tool.pytest.ini_options] addopts = """\ - --cov jwave \ - --cov tests \ - --cov-report term-missing \ - --no-cov-on-fail \ --doctest-modules \ """ diff --git a/pytest.ini b/pytest.ini deleted file mode 100644 index feba049..0000000 --- a/pytest.ini +++ /dev/null @@ -1,4 +0,0 @@ -[pytest] -addopts = --doctest-modules -testpaths = - tests diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index ff2ce3d..0000000 --- a/setup.cfg +++ /dev/null @@ -1,59 +0,0 @@ -[flake8] -ignore = - # Line break occurred before a binary operator (W503) - # https://github.com/psf/black/issues/52 - W503, - # Line too long (E501) - # 1. black does not format comments - # https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#comments - # 2. long links in doc strings are an issue - E501 - # flake8-builtins - # the likelihood of running into an issue when shadowing a buildin - # with a class attribute is very low - A003, - # flake8-bugbear - # fastapi recommends to use `Depend()` as an argument default. - # Unfortunately, exceptions are hardcoded in bugbear. - # https://github.com/PyCQA/flake8-bugbear/issues/62 - B008, - - E114, # TODO: Needs comment - E111, # TODO: Needs comment - F811, # TODO: Needs comment - - -# pep8-naming -classmethod-decorators = - classmethod, # built-in - validator, # pydantic - root_validator, # pydantic - -enable-extensions= - G, # flake8-logging-format - -per-file-ignores = - # star imports in `__init__.py` files are ok - */__init__.py: F401 - acoustics/operators.py:F811 - -# Enables maccabe complexity checks -# see https://github.com/PyCQA/mccabe#plugin-for-flake8 -max-complexity = 10 - -exclude = - .git, - __pycache__, - old, - build, - dist, - docs, - htmlcov, - profiling, - scripts, - templates - .venv, - .vscode, - .eggs, - __pycache__, - .tox diff --git a/tests/test_extras_export.py b/tests/test_extras_export.py new file mode 100644 index 0000000..fbe24e8 --- /dev/null +++ b/tests/test_extras_export.py @@ -0,0 +1,55 @@ +import os + +import numpy as np +import pytest +from jaxdf import Domain, OnGrid + +from jwave.extras import save_video + +# Create mock field +domain = Domain(( + 64, + 64, +), ( + 1, + 1, +)) +field_params = np.random.rand(5, *domain.N, 1) +fields = OnGrid(field_params, domain) + +filenames = [ + 'video1.mp4', +] +fpss = [ + 30, +] +vmins = [ + 1, +] +vmaxs = [ + 2, +] +cmaps = [ + 'RdBu_r', +] +aspects = ['equal', 'auto'] + + +@pytest.mark.parametrize('filename', filenames) +@pytest.mark.parametrize('fps', fpss) +@pytest.mark.parametrize('vmin', vmins) +@pytest.mark.parametrize('vmax', vmaxs) +@pytest.mark.parametrize('cmap', cmaps) +@pytest.mark.parametrize('aspect', aspects) +def test_save_video(filename, fps, vmin, vmax, cmap, aspect): + save_video(fields, filename, fps, vmin, vmax, cmap, aspect) + assert os.path.exists(filename) # check if the file was created + assert filename.endswith('.mp4') # check if the file is an mp4 file + os.remove(filename) # remove the file after the test + + # Additional asserts can be added to test the video content. + # This is more complex and requires video processing libraries + # to analyze the video frames and properties. + + +pytest.main()