Skip to content

Commit

Permalink
Merge branch 'master' into fieldset_from_directory
Browse files Browse the repository at this point in the history
  • Loading branch information
erikvansebille authored May 27, 2024
2 parents 133426f + c2bf42c commit 846520b
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,17 @@ jobs:
user: __token__
password: ${{ secrets.PARCELS_PYPI_PROD_TOKEN }}
verbose: true

test-pypi-release:
needs: upload-to-pypi
runs-on: ubuntu-latest
steps:
- uses: conda-incubator/setup-miniconda@v3
with:
activate-environment: parcels
python-version: 3.8
channels: conda-forge
- run: conda install -c conda-forge c-compiler pip
- run: pip install parcels --no-cache
- run: curl https://raw.githubusercontent.com/OceanParcels/parcels/master/docs/examples/example_peninsula.py > example_peninsula.py
- run: python example_peninsula.py
27 changes: 19 additions & 8 deletions docs/examples/example_globcurrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,6 @@ def test_globcurrent_time_extrapolation_error(mode, use_xarray):
pset.execute(AdvectionRK4, runtime=delta(days=1), dt=delta(minutes=5))


@pytest.mark.parametrize('mode', ['scipy', 'jit'])
@pytest.mark.parametrize('use_xarray', [True, False])
def test_globcurrent_dt0(mode, use_xarray):
fieldset = set_globcurrent_fieldset(use_xarray=use_xarray)
pset = ParticleSet(fieldset, pclass=ptype[mode], lon=[25], lat=[-35])
pset.execute(AdvectionRK4, dt=0.)


@pytest.mark.parametrize('mode', ['scipy', 'jit'])
@pytest.mark.parametrize('dt', [-300, 300])
@pytest.mark.parametrize('with_starttime', [True, False])
Expand Down Expand Up @@ -260,3 +252,22 @@ def test_globcurrent_pset_fromfile(mode, dt, pid_offset, tmpdir):

for var in ['lon', 'lat', 'depth', 'time', 'id']:
assert np.allclose([getattr(p, var) for p in pset], [getattr(p, var) for p in pset_new])


@pytest.mark.parametrize('mode', ['scipy', 'jit'])
def test_error_outputdt_not_multiple_dt(mode, tmpdir):
# Test that outputdt is a multiple of dt
fieldset = set_globcurrent_fieldset()

filepath = tmpdir.join("pfile_error_outputdt_not_multiple_dt.zarr")

dt = 81.2584344538292 # number for which output writing fails

pset = ParticleSet(fieldset, pclass=ptype[mode], lon=[0], lat=[0])
ofile = pset.ParticleFile(name=filepath, outputdt=delta(days=1))

def DoNothing(particle, fieldset, time):
pass

with pytest.raises(ValueError):
pset.execute(DoNothing, runtime=delta(days=10), dt=dt, output_file=ofile)
2 changes: 1 addition & 1 deletion docs/examples/tutorial_parcels_structure.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@
"source": [
"### For more tutorials on MPI and parallelisation:\n",
"\n",
"- [Optimising the partitioning of the particles with a user-defined `partition_function`](https://docs.oceanparcels.org/en/latest/examples/documentation_MPI.html#Optimising-the-partitioning-of-the-particles-with-a-user-defined-partition_function)\n",
"- [Optimising the partitioning of the particles with a user-defined partition function](https://docs.oceanparcels.org/en/latest/examples/documentation_MPI.html#Optimising-the-partitioning-of-the-particles-with-a-user-defined-partition_function)\n",
"- [Future developments: load balancing](https://docs.oceanparcels.org/en/latest/examples/documentation_MPI.html#Future-developments:-load-balancing)"
]
},
Expand Down
4 changes: 3 additions & 1 deletion parcels/particleset.py
Original file line number Diff line number Diff line change
Expand Up @@ -878,8 +878,10 @@ def execute(self, pyfunc=AdvectionRK4, pyfunc_inter=None, endtime=None, runtime=
runtime = runtime.total_seconds()
if isinstance(dt, delta):
dt = dt.total_seconds()
if dt > 0 and dt <= 1e-6:
if abs(dt) <= 1e-6:
raise ValueError('Time step dt is too small')
if (dt * 1e6) % 1 != 0:
raise ValueError('Output interval should not have finer precision than 1e-6 s')
outputdt = output_file.outputdt if output_file else np.infty
if isinstance(outputdt, delta):
outputdt = outputdt.total_seconds()
Expand Down
15 changes: 15 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@ classifiers = [
"Topic :: Scientific/Engineering",
"Intended Audience :: Science/Research",
]
dependencies = [
"cgen",
"cftime",
"numpy",
"dask",
"cftime",
"psutil",
"netCDF4",
"zarr",
"tqdm",
"pymbolic",
"pytest",
"scipy",
"xarray",
]

[project.urls]
homepage = "https://oceanparcels.org/"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def f(p):

@pytest.mark.parametrize('runtime, dt',
[(1, 1e-2),
(1, -2.1234e-3),
(1, -2.123e-3),
(1, -3.12452-3)])
def test_pseudo_interaction(runtime, dt):
# A linear field where advected particles are moving at
Expand Down

0 comments on commit 846520b

Please sign in to comment.