Skip to content

Commit fa544da

Browse files
Merge branch 'master' into harmonise_field_interp_order
2 parents bb7d6c8 + d0cfe42 commit fa544da

File tree

8 files changed

+35
-55
lines changed

8 files changed

+35
-55
lines changed

.github/release.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
changelog:
2+
exclude:
3+
authors:
4+
- dependabot
5+
- pre-commit-ci

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
coverage run -m pytest -v -s --html=${{ matrix.os }}_${{ matrix.python-version }}_unit_test_report.html --self-contained-html tests
4646
coverage xml
4747
- name: Codecov
48-
uses: codecov/codecov-action@v5.0.7
48+
uses: codecov/codecov-action@v5.1.2
4949
env:
5050
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
5151
if: matrix.python-version == '3.13'
@@ -80,7 +80,7 @@ jobs:
8080
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
8181
coverage xml
8282
- name: Codecov
83-
uses: codecov/codecov-action@v5.0.7
83+
uses: codecov/codecov-action@v5.1.2
8484
env:
8585
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
8686
with:
@@ -117,7 +117,7 @@ jobs:
117117
run: |
118118
mypy --install-types --non-interactive parcels --cobertura-xml-report mypy_report
119119
- name: Upload mypy coverage to Codecov
120-
uses: codecov/codecov-action@v5.0.7
120+
uses: codecov/codecov-action@v5.1.2
121121
if: ${{ always() }} # Upload even on error of mypy
122122
env:
123123
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

.github/workflows/pypi-release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ jobs:
7272
7373
- name: Publish package to TestPyPI
7474
if: github.event_name == 'push'
75-
uses: pypa/[email protected].2
75+
uses: pypa/[email protected].3
7676
with:
7777
user: __token__
7878
password: ${{ secrets.PARCELS_PYPI_TEST_TOKEN }}
@@ -89,7 +89,7 @@ jobs:
8989
name: releases
9090
path: dist
9191
- name: Publish package to PyPI
92-
uses: pypa/[email protected].2
92+
uses: pypa/[email protected].3
9393
with:
9494
user: __token__
9595
password: ${{ secrets.PARCELS_PYPI_PROD_TOKEN }}

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ repos:
1010
types: [text]
1111
files: \.(json|ipynb)$
1212
- repo: https://github.com/astral-sh/ruff-pre-commit
13-
rev: v0.8.3
13+
rev: v0.8.6
1414
hooks:
1515
- id: ruff
1616
name: ruff lint (.py)

docs/examples/tutorial_periodic_boundaries.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"cell_type": "markdown",
4343
"metadata": {},
4444
"source": [
45-
"In case of 'simple' models on an A-grid, the idea in Parcels is to do two things:\n",
45+
"If you have a 'simple' `Rectilinear` A-grid, you can create periodic boundaries in Parcels in two steps:\n",
4646
"\n",
4747
"1. Extend the fieldset with a small 'halo'\n",
4848
"2. Add a periodic boundary kernel to the `.execute`\n"

parcels/grid.py

Lines changed: 3 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -694,53 +694,9 @@ def add_periodic_halo(self, zonal, meridional, halosize=5):
694694
halosize : int
695695
size of the halo (in grid points). Default is 5 grid points
696696
"""
697-
if zonal:
698-
lonshift = self.lon[:, -1] - 2 * self.lon[:, 0] + self.lon[:, 1]
699-
if not np.allclose(self.lon[:, 1] - self.lon[:, 0], self.lon[:, -1] - self.lon[:, -2]):
700-
warnings.warn(
701-
"The zonal halo is located at the east and west of current grid, "
702-
"with a dx = lon[1]-lon[0] between the last nodes of the original grid and the first ones of the halo. "
703-
"In your grid, lon[1]-lon[0] != lon[-1]-lon[-2]. Is the halo computed as you expect?",
704-
FieldSetWarning,
705-
stacklevel=2,
706-
)
707-
self._lon = np.concatenate(
708-
(
709-
self.lon[:, -halosize:] - lonshift[:, np.newaxis],
710-
self.lon,
711-
self.lon[:, 0:halosize] + lonshift[:, np.newaxis],
712-
),
713-
axis=len(self.lon.shape) - 1,
714-
)
715-
self._lat = np.concatenate(
716-
(self.lat[:, -halosize:], self.lat, self.lat[:, 0:halosize]), axis=len(self.lat.shape) - 1
717-
)
718-
self._zonal_periodic = True
719-
self._zonal_halo = halosize
720-
if meridional:
721-
if not np.allclose(self.lat[1, :] - self.lat[0, :], self.lat[-1, :] - self.lat[-2, :]):
722-
warnings.warn(
723-
"The meridional halo is located at the north and south of current grid, "
724-
"with a dy = lat[1]-lat[0] between the last nodes of the original grid and the first ones of the halo. "
725-
"In your grid, lat[1]-lat[0] != lat[-1]-lat[-2]. Is the halo computed as you expect?",
726-
FieldSetWarning,
727-
stacklevel=2,
728-
)
729-
latshift = self.lat[-1, :] - 2 * self.lat[0, :] + self.lat[1, :]
730-
self._lat = np.concatenate(
731-
(
732-
self.lat[-halosize:, :] - latshift[np.newaxis, :],
733-
self.lat,
734-
self.lat[0:halosize, :] + latshift[np.newaxis, :],
735-
),
736-
axis=len(self.lat.shape) - 2,
737-
)
738-
self._lon = np.concatenate(
739-
(self.lon[-halosize:, :], self.lon, self.lon[0:halosize, :]), axis=len(self.lon.shape) - 2
740-
)
741-
self._meridional_halo = halosize
742-
if isinstance(self, CurvilinearSGrid):
743-
self._add_Sdepth_periodic_halo(zonal, meridional, halosize)
697+
raise NotImplementedError(
698+
"CurvilinearGrid does not support add_periodic_halo. See https://github.com/OceanParcels/Parcels/pull/1811"
699+
)
744700

745701

746702
class CurvilinearZGrid(CurvilinearGrid):

tests/test_fieldset.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,8 @@ def test_curv_fieldset_add_periodic_halo():
565565
dimensions = {"dx": {"lon": "glamu", "lat": "gphiu"}, "dy": {"lon": "glamu", "lat": "gphiu"}}
566566
fieldset = FieldSet.from_nemo(filenames, variables, dimensions)
567567

568-
fieldset.add_periodic_halo(zonal=3, meridional=2)
568+
with pytest.raises(NotImplementedError):
569+
fieldset.add_periodic_halo(zonal=3, meridional=2)
569570

570571

571572
@pytest.mark.parametrize("mesh", ["flat", "spherical"])

tests/test_particlefile.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,24 @@ def Update_lon(particle, fieldset, time):
334334
assert np.allclose(pset.lon, 0.6)
335335

336336

337+
@pytest.mark.parametrize("mode", ["scipy", "jit"])
338+
def test_correct_misaligned_outputdt_dt(fieldset, mode, tmp_zarrfile):
339+
"""Testing that outputdt does not need to be a multiple of dt."""
340+
341+
def Update_lon(particle, fieldset, time):
342+
particle_dlon += particle.dt # noqa
343+
344+
pset = ParticleSet(fieldset, pclass=ptype[mode], lon=[0], lat=[0], lonlatdepth_dtype=np.float64)
345+
ofile = pset.ParticleFile(name=tmp_zarrfile, outputdt=3)
346+
pset.execute(pset.Kernel(Update_lon), endtime=11, dt=2, output_file=ofile)
347+
348+
ds = xr.open_zarr(tmp_zarrfile)
349+
assert np.allclose(ds.lon.values, [0, 3, 6, 9])
350+
assert np.allclose(
351+
ds.time.values[0, :], [np.timedelta64(t, "s") for t in [0, 3, 6, 9]], atol=np.timedelta64(1, "ns")
352+
)
353+
354+
337355
def setup_pset_execute(*, fieldset: FieldSet, outputdt: timedelta, execute_kwargs, particle_class=ScipyParticle):
338356
npart = 10
339357

0 commit comments

Comments
 (0)