Skip to content

Commit

Permalink
Merge branch 'master' into CROCO_fix_sigma_calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
erikvansebille authored Dec 5, 2024
2 parents 9b3fe7e + ef9eaa9 commit 4c92221
Show file tree
Hide file tree
Showing 51 changed files with 329 additions and 268 deletions.
23 changes: 14 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ jobs:
fail-fast: false
matrix:
os: [macos, ubuntu, windows]
python-version: ["3.12"]
python-version: ["3.13"]
include:
- os: ubuntu
python-version: "3.10"
- os: ubuntu
python-version: "3.11"
- os: ubuntu
python-version: "3.12"
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -43,10 +45,10 @@ jobs:
coverage run -m pytest -v -s --html=${{ matrix.os }}_${{ matrix.python-version }}_unit_test_report.html --self-contained-html tests
coverage xml
- name: Codecov
uses: codecov/codecov-action@v4.6.0
uses: codecov/codecov-action@v5.0.7
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
if: matrix.python-version == '3.12'
if: matrix.python-version == '3.13'
with:
flags: unit-tests
- name: Upload test results
Expand All @@ -62,7 +64,10 @@ jobs:
fail-fast: false
matrix:
os: [macos, ubuntu, windows]
python-version: ["3.12"]
python-version: ["3.13"]
include:
- os: ubuntu
python-version: "3.10"
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -72,10 +77,10 @@ jobs:
environment-file: environment.yml
- name: Integration test
run: |
coverage run -m pytest -v -s --nbval-lax -k "not documentation" --html="${{ matrix.os }}_integration_test_report.html" --self-contained-html docs/examples
coverage run -m pytest -v -s --nbval-lax -k "not documentation" --html="${{ matrix.os }}_${{ matrix.python-version }}_integration_test_report.html" --self-contained-html docs/examples
coverage xml
- name: Codecov
uses: codecov/codecov-action@v4.6.0
uses: codecov/codecov-action@v5.0.7
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
Expand All @@ -84,8 +89,8 @@ jobs:
if: ${{ always() }} # Always run this step, even if tests fail
uses: actions/upload-artifact@v4
with:
name: Integration test report ${{ matrix.os }}
path: ${{ matrix.os }}_integration_test_report.html
name: Integration test report ${{ matrix.os }}-${{ matrix.python-version }}
path: ${{ matrix.os }}_${{ matrix.python-version }}_integration_test_report.html
merge-test-artifacts:
runs-on: ubuntu-latest
needs:
Expand All @@ -112,7 +117,7 @@ jobs:
run: |
mypy --install-types --non-interactive parcels --cobertura-xml-report mypy_report
- name: Upload mypy coverage to Codecov
uses: codecov/codecov-action@v4.6.0
uses: codecov/codecov-action@v5.0.7
if: ${{ always() }} # Upload even on error of mypy
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pypi-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:
- name: Publish package to TestPyPI
if: github.event_name == 'push'
uses: pypa/gh-action-pypi-publish@v1.11.0
uses: pypa/gh-action-pypi-publish@v1.12.2
with:
user: __token__
password: ${{ secrets.PARCELS_PYPI_TEST_TOKEN }}
Expand All @@ -89,7 +89,7 @@ jobs:
name: releases
path: dist
- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@v1.11.0
uses: pypa/gh-action-pypi-publish@v1.12.2
with:
user: __token__
password: ${{ secrets.PARCELS_PYPI_PROD_TOKEN }}
Expand Down
8 changes: 5 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,20 @@ repos:
types: [text]
files: \.(json|ipynb)$
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.4
rev: v0.8.1
hooks:
- id: ruff
name: ruff lint (.py)
args: [--fix, --show-fixes]
types_or: [python]
- id: ruff
name: ruff (isort jupyter)
name: ruff isort (.ipynb)
args: [--select, I, --fix]
types_or: [jupyter]
- id: ruff-format
types_or: [python, jupyter]
- repo: https://github.com/rbubley/mirrors-prettier # Update mirror as official mirror is deprecated
rev: v3.3.3
rev: v3.4.1
hooks:
- id: prettier

Expand Down
2 changes: 1 addition & 1 deletion docs/examples/documentation_indexing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@
"metadata": {},
"outputs": [],
"source": [
"import warnings\n",
"from glob import glob\n",
"from os import path\n",
"import warnings\n",
"\n",
"import numpy as np\n",
"\n",
Expand Down
3 changes: 2 additions & 1 deletion docs/examples/example_brownian.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from datetime import timedelta

import numpy as np
import parcels
import pytest

import parcels

ptype = {"scipy": parcels.ScipyParticle, "jit": parcels.JITParticle}


Expand Down
5 changes: 3 additions & 2 deletions docs/examples/example_dask_chunk_OCMs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

import dask
import numpy as np
import parcels
import pytest

import parcels
from parcels.tools.statuscodes import DaskChunkingError

ptype = {"scipy": parcels.ScipyParticle, "jit": parcels.JITParticle}
Expand Down Expand Up @@ -246,7 +247,7 @@ def test_pop(mode, chunk_mode):
filenames = str(data_folder / "t.x1_SAMOC_flux.1690*.nc")
variables = {"U": "UVEL", "V": "VVEL", "W": "WVEL"}
timestamps = np.expand_dims(
np.array([np.datetime64("2000-%.2d-01" % m) for m in range(1, 7)]), axis=1
np.array([np.datetime64(f"2000-{m:02d}-01") for m in range(1, 7)]), axis=1
)
dimensions = {"lon": "ULON", "lat": "ULAT", "depth": "w_dep"}
chs = False
Expand Down
3 changes: 2 additions & 1 deletion docs/examples/example_decaying_moving_eddy.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from datetime import timedelta

import numpy as np
import parcels
import pytest

import parcels

ptype = {"scipy": parcels.ScipyParticle, "jit": parcels.JITParticle}

# Define some constants.
Expand Down
3 changes: 2 additions & 1 deletion docs/examples/example_globcurrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
from glob import glob

import numpy as np
import parcels
import pytest
import xarray as xr

import parcels

ptype = {"scipy": parcels.ScipyParticle, "jit": parcels.JITParticle}


Expand Down
22 changes: 14 additions & 8 deletions docs/examples/example_mitgcm.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
from datetime import timedelta
from pathlib import Path
from typing import Literal

import numpy as np
import parcels
import xarray as xr

import parcels

ptype = {"scipy": parcels.ScipyParticle, "jit": parcels.JITParticle}


def run_mitgcm_zonally_reentrant(mode):
def run_mitgcm_zonally_reentrant(mode: Literal["scipy", "jit"], path: Path):
"""Function that shows how to load MITgcm data in a zonally periodic domain."""
data_folder = parcels.download_example_dataset("MITgcm_example_data")
filenames = {
Expand Down Expand Up @@ -41,7 +44,7 @@ def periodicBC(particle, fieldset, time):
size=10,
)
pfile = parcels.ParticleFile(
"MIT_particles_" + str(mode) + ".zarr",
str(path),
pset,
outputdt=timedelta(days=1),
chunks=(len(pset), 1),
Expand All @@ -52,12 +55,15 @@ def periodicBC(particle, fieldset, time):
)


def test_mitgcm_output_compare():
run_mitgcm_zonally_reentrant("scipy")
run_mitgcm_zonally_reentrant("jit")
def test_mitgcm_output_compare(tmpdir):
def get_path(mode: Literal["scipy", "jit"]) -> Path:
return tmpdir / f"MIT_particles_{mode}.zarr"

for mode in ["scipy", "jit"]:
run_mitgcm_zonally_reentrant(mode, get_path(mode))

ds_jit = xr.open_zarr("MIT_particles_jit.zarr")
ds_scipy = xr.open_zarr("MIT_particles_scipy.zarr")
ds_jit = xr.open_zarr(get_path("jit"))
ds_scipy = xr.open_zarr(get_path("scipy"))

np.testing.assert_allclose(ds_jit.lat.data, ds_scipy.lat.data)
np.testing.assert_allclose(ds_jit.lon.data, ds_scipy.lon.data)
7 changes: 4 additions & 3 deletions docs/examples/example_moving_eddies.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
from datetime import timedelta

import numpy as np
import parcels
import pytest

import parcels

ptype = {"scipy": parcels.ScipyParticle, "jit": parcels.JITParticle}
method = {
"RK4": parcels.AdvectionRK4,
Expand Down Expand Up @@ -145,7 +146,7 @@ def moving_eddies_example(

# Execute for 1 week, with 1 hour timesteps and hourly output
runtime = timedelta(days=7)
print("MovingEddies: Advecting %d particles for %s" % (npart, str(runtime)))
print(f"MovingEddies: Advecting {npart} particles for {runtime}")
pset.execute(
method,
runtime=runtime,
Expand Down Expand Up @@ -176,7 +177,7 @@ def test_moving_eddies_fwdbwd(mode, mesh, tmpdir, npart=2):
runtime = timedelta(days=1)
dt = timedelta(minutes=5)
outputdt = timedelta(hours=1)
print("MovingEddies: Advecting %d particles for %s" % (npart, str(runtime)))
print(f"MovingEddies: Advecting {npart} particles for {runtime}")
outfile = tmpdir.join("EddyParticlefwd")
pset.execute(
method,
Expand Down
3 changes: 2 additions & 1 deletion docs/examples/example_nemo_curvilinear.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
from glob import glob

import numpy as np
import parcels
import pytest

import parcels

ptype = {"scipy": parcels.ScipyParticle, "jit": parcels.JITParticle}
advection = {"RK4": parcels.AdvectionRK4, "AA": parcels.AdvectionAnalytical}

Expand Down
3 changes: 2 additions & 1 deletion docs/examples/example_ofam.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
from datetime import timedelta

import numpy as np
import parcels
import pytest
import xarray as xr

import parcels

ptype = {"scipy": parcels.ScipyParticle, "jit": parcels.JITParticle}


Expand Down
5 changes: 3 additions & 2 deletions docs/examples/example_peninsula.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
from datetime import timedelta

import numpy as np
import parcels
import pytest

import parcels

ptype = {"scipy": parcels.ScipyParticle, "jit": parcels.JITParticle}
method = {
"RK4": parcels.AdvectionRK4,
Expand Down Expand Up @@ -167,7 +168,7 @@ def peninsula_example(
out = (
pset.ParticleFile(name=outfile, outputdt=timedelta(hours=1)) if output else None
)
print("Peninsula: Advecting %d particles for %s" % (npart, str(time)))
print(f"Peninsula: Advecting {npart} particles for {time}")
pset.execute(k_adv + k_p, runtime=time, dt=dt, output_file=out)

if verbose:
Expand Down
3 changes: 2 additions & 1 deletion docs/examples/example_radial_rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
from datetime import timedelta

import numpy as np
import parcels
import pytest

import parcels

ptype = {"scipy": parcels.ScipyParticle, "jit": parcels.JITParticle}


Expand Down
5 changes: 3 additions & 2 deletions docs/examples/example_stommel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
from datetime import timedelta

import numpy as np
import parcels
import pytest

import parcels

ptype = {"scipy": parcels.ScipyParticle, "jit": parcels.JITParticle}
method = {
"RK4": parcels.AdvectionRK4,
Expand Down Expand Up @@ -159,7 +160,7 @@ def stommel_example(

maxage = runtime.total_seconds() if maxage is None else maxage
fieldset.add_constant("maxage", maxage)
print("Stommel: Advecting %d particles for %s" % (npart, runtime))
print(f"Stommel: Advecting {npart} particles for {runtime}")
parcels.timer.psetinit.stop()
parcels.timer.psetrun = parcels.timer.Timer("Pset_run", parent=parcels.timer.pset)
pset.execute(
Expand Down
6 changes: 4 additions & 2 deletions docs/examples/tutorial_croco_3D.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@
"outputs": [],
"source": [
"import os\n",
"import parcels\n",
"import numpy as np\n",
"\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import xarray as xr\n",
"\n",
"import parcels\n",
"\n",
"example_dataset_folder = parcels.download_example_dataset(\"CROCOidealized_data\")\n",
"file = os.path.join(example_dataset_folder, \"CROCO_idealized.nc\")"
]
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/tutorial_nemo_3D.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@
}
],
"source": [
"import warnings\n",
"from datetime import timedelta\n",
"from glob import glob\n",
"import warnings\n",
"\n",
"import matplotlib.pyplot as plt\n",
"import xarray as xr\n",
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/tutorial_timestamps.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"metadata": {},
"outputs": [],
"source": [
"from glob import glob\n",
"import warnings\n",
"from glob import glob\n",
"\n",
"import numpy as np\n",
"\n",
Expand Down
2 changes: 1 addition & 1 deletion parcels/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

__version__ = version

import parcels.rng as ParcelsRandom # noqa
import parcels.rng as ParcelsRandom # noqa: F401
from parcels.application_kernels import *
from parcels.field import *
from parcels.fieldset import *
Expand Down
Loading

0 comments on commit 4c92221

Please sign in to comment.