Skip to content

Commit

Permalink
display_complex_field (#193)
Browse files Browse the repository at this point in the history
* deprecation warning for plot_complex_field in favor of display_complex_field
* updated save_video and notebooks
* made actions more granular
  • Loading branch information
astanziola committed Jun 29, 2023
1 parent 2366bf8 commit 7d895b1
Show file tree
Hide file tree
Showing 16 changed files with 302 additions and 665 deletions.
3 changes: 3 additions & 0 deletions .github/actions/python-poetry-env/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ runs:
- name: Create virtual environment
run: poetry install --with=dev
shell: bash
- name: Install jaxlib
run: poetry run pip install jax[cpu]
shell: bash
23 changes: 23 additions & 0 deletions .github/workflows/build_docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# This is a workflow that runs whenever a pull request
# changes some documentation files or the mkdocs.yml file. It
# checks that the documentation builds correctly.

name: Build Docs

on:
pull_request:
paths:
- 'docs/**'
- 'mkdocs.yml'
- '**.md'
- '**.ipynb'
- '**.sh'

jobs:
build-and-publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./.github/actions/python-poetry-env
- name: Build docs
run: poetry run mkdocs build
34 changes: 34 additions & 0 deletions .github/workflows/ci_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# This workflow runs both the regression tests and the unit/integration tests.
# It is triggered on push to the main branch.

name: CI

on:
push:
branches: [ main ]

jobs:
full_tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/python-poetry-env
- name: Downloading test data
run: |
make get_test_data
- name: Running Regression Tests
run: |
poetry run coverage run --source=jwave -m pytest -xvs ./tests/regression_tests
- name: Remove coverage data from regression tests
run: |
rm ./.coverage
- name: Running Unit and Integration tests
run: |
poetry run coverage run --source=jwave -m pytest -xvs --ignore=tests/regression_tests
poetry run coverage xml
- name: "Upload coverage to Codecov"
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.xml
name: codecov-umbrella
20 changes: 20 additions & 0 deletions .github/workflows/regression_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# This is a workflow for Regression Tests.
# It is triggered by a pull request to the main branch.

name: Regression Tests

on:
pull_request:
branches: [ main ]

jobs:
regression_tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/python-poetry-env
- name: Downloading test data
run: |
make get_test_data
- name: Running tests
run: poetry run coverage run --source=jwave -m pytest -xvs ./tests/regression_tests
76 changes: 0 additions & 76 deletions .github/workflows/tests.yml

This file was deleted.

33 changes: 33 additions & 0 deletions .github/workflows/unit_integration_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This is a workflow for Unit, Integration, and Regression Tests
# It is used to test the code on every pull request, whenever a
# python, matlab, yaml, makefile, or markdown file is changed.

name: Unit and Integration Tests

on:
pull_request:
paths:
- '**.py'
- '**.m'
- '**.yaml'
- '**Makefile'

jobs:
unit_and_integration_tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/python-poetry-env
- name: Downloading test data
run: |
make get_test_data
- name: Running tests
run: |
poetry run coverage run --source=jwave -m pytest -xvs --ignore=tests/regression_tests
poetry run coverage xml
- name: "Upload coverage to Codecov"
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.xml
name: codecov-umbrella
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ 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
- Refactored `save_video` to use opencv.

### Deprecated
- `plot_complex_field` has been deprecated in favor of `display_complex_field`

### Removed
- Removed the uncertainty propagation notebook example. For a more in depth example of using linear uncertainty propagation see [this repository](https://github.com/ucl-bug/linear-uncertainty)

## [0.1.3] - 2023-06-28
### Added
Expand Down Expand Up @@ -69,4 +77,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

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

[![Support](https://dcbadge.vercel.app/api/server/VtUb4fFznt?style=flat)](https://discord.gg/VtUb4fFznt)
[![License: LGPL v3](https://img.shields.io/badge/License-LGPL_v3-blue.svg)](LICENSE)
[![Continous Integration](https://github.com/ucl-bug/jwave/actions/workflows/tests.yml/badge.svg)](https://github.com/ucl-bug/jwave/actions/workflows/tests.yml)
[![Continous Integration](https://github.com/ucl-bug/jwave/actions/workflows/ci_tests.yml/badge.svg)](https://github.com/ucl-bug/jwave/actions/workflows/ci_tests.yml)
[![codecov](https://codecov.io/gh/ucl-bug/jwave/branch/main/graph/badge.svg?token=6J03OMVJS1)](https://codecov.io/gh/ucl-bug/jwave)
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/ucl-bug/jwave/main?labpath=docs%2Fnotebooks%2Fivp%2Fhomogeneous_medium.ipynb)
[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1xAHAognF1v9un6GNvaGPSfdVeCDK8l9z?usp=sharing)
Expand Down
Binary file removed docs/notebooks/others/sample_video.mp4
Binary file not shown.
73 changes: 28 additions & 45 deletions docs/notebooks/others/save_video.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,69 +7,44 @@
"source": [
"# Save video\n",
"\n",
"Note that the `save_video` funcion requires [`imageio`](https://imageio.readthedocs.io/en/stable/) and [`tqdm`](https://tqdm.github.io/), which are not installed by default. \n",
"\n",
":warning: Note that his function also **deletes** and uses the temporary folder `/tmp/jwave_video`."
]
},
{
"cell_type": "markdown",
"id": "51cb654b-3517-434e-ad67-1a459c08854e",
"metadata": {},
"source": [
"⚠️ Run the next cell only if you don't have `imageio-ffmpeg` installed, otherwise it will be reinstalled"
"⚠️ The `save_video` funcion requires [`opencv`](https://pypi.org/project/opencv-python/) and (optionally) [`tqdm`](https://tqdm.github.io/), which are not installed by default. "
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "7bb6d056-f7f7-4372-97fe-29ec292ead0b",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Collecting imageio-ffmpeg\n",
" Using cached imageio_ffmpeg-0.4.7-py3-none-manylinux2010_x86_64.whl (26.9 MB)\n",
"Installing collected packages: imageio-ffmpeg\n",
"Successfully installed imageio-ffmpeg-0.4.7\n"
]
}
],
"source": [
"!pip install imageio-ffmpeg"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "52df5536-f518-4b65-aaa7-6f99327bce93",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"from jax import jit\n",
"from jax import numpy as jnp\n",
"from jaxdf import FourierSeries\n",
"from matplotlib import pyplot as plt\n",
"\n",
"from jwave import FourierSeries\n",
"from jwave.geometry import Domain, Medium, TimeAxis\n",
"from jwave.acoustics import simulate_wave_propagation\n",
"from jwave.geometry import *\n",
"from jwave.geometry import _circ_mask\n",
"from jwave.utils import show_field, show_positive_field\n",
"\n",
"domain = Domain((128, 128), (0.1e-3, 0.1e-3))"
]
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 2,
"id": "8bbe4e23-f7d6-4c50-97df-44a437069445",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"No GPU/TPU found, falling back to CPU. (Set TF_CPP_MIN_LOG_LEVEL=0 and rerun for more info.)\n"
]
}
],
"source": [
"# Defining an heterogeneous density map\n",
"density = np.ones(domain.N) * 1000\n",
"density[50:90, 65:100] = 2300\n",
"density = FourierSeries(np.expand_dims(density, -1), domain)\n",
Expand All @@ -86,7 +61,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 3,
"id": "e5386fc6-cbe7-43c8-a5ec-e6a150c6fed9",
"metadata": {},
"outputs": [],
Expand All @@ -97,31 +72,39 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 4,
"id": "513ae3ad-8ae0-4d7f-8e65-71b89eff7abf",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|█████████████████████████████████████████████████████████████████████████████████████| 600/600 [01:02<00:00, 9.62it/s]\n"
"100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 599/599 [00:01<00:00, 347.57it/s]\n"
]
}
],
"source": [
"from jwave.extras.export import save_video\n",
"\n",
"save_video(pressure, './sample_video.mp4', vmax=0.1, vmin=-0.1, fps=50)"
"save_video(pressure, './sample_video.mp4', vmax=0.05, vmin=-0.05, fps=50)"
]
},
{
"cell_type": "markdown",
"id": "de9580f7-3460-49bc-9fea-aef4af8bfc33",
"id": "1230bbf5-48f3-4039-902e-d0532f1164c4",
"metadata": {},
"source": [
"<video src=\"./sample_video.mp4\" controls=\"controls\"></video>"
"You can now find a video in the same folder as this notebook"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "18f77b37-eff6-4b40-9486-1b7c4a856e5f",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -140,7 +123,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.5"
"version": "3.11.4"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 7d895b1

Please sign in to comment.