Skip to content

Commit

Permalink
Merge branch 'master' into update-prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
erikvansebille authored Dec 22, 2023
2 parents 5f27939 + a3d90da commit 861feca
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ repos:
- id: nbqa-check-ast
- id: nbqa-isort
- repo: https://github.com/pycqa/isort
rev: 5.12.0
rev: 5.13.2
hooks:
- id: isort
name: isort (python)
Expand Down
68 changes: 30 additions & 38 deletions docs/examples/documentation_unstuck_Agrid.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/examples/tutorial_timestamps.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Note, by the way, that adding the `time_periodic=True` argument to `Field.from_netcdf()` will also mean that the climatology can be cycled for multiple years.\n"
"Note, by the way, that adding the `time_periodic` argument to `Field.from_netcdf()` will also mean that the climatology can be cycled for multiple years.\n"
]
},
{
Expand Down
6 changes: 3 additions & 3 deletions parcels/particlefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def _create_variables_attribute_dict(self):

if self.time_origin.calendar is not None:
attrs['time']['units'] = "seconds since " + str(self.time_origin)
attrs['time']['calendar'] = 'standard' if self.time_origin.calendar == 'np_datetime64' else self.time_origin.calendar
attrs['time']['calendar'] = _set_calendar(self.time_origin.calendar)

for vname in self.vars_to_write:
if vname not in ['time', 'lat', 'lon', 'depth', 'id']:
Expand Down Expand Up @@ -183,7 +183,7 @@ def _extend_zarr_dims(self, Z, store, dtype, axis):
if len(obs) == Z.shape[1]:
obs.append(np.arange(self.chunks[1])+obs[-1]+1)
else:
extra_trajs = max(self.maxids - Z.shape[0], self.chunks[0])
extra_trajs = self.maxids - Z.shape[0]
if len(Z.shape) == 2:
a = np.full((extra_trajs, Z.shape[1]), self.fill_value_map[dtype], dtype=dtype)
else:
Expand Down Expand Up @@ -233,7 +233,7 @@ def write(self, pset, time, indices=None):
if (self.maxids > len(ids)) or (self.maxids > self.chunks[0]):
arrsize = (self.maxids, self.chunks[1])
else:
arrsize = (len(ids), 1)
arrsize = (len(ids), self.chunks[1])
ds = xr.Dataset(attrs=self.metadata, coords={"trajectory": ("trajectory", pids),
"obs": ("obs", np.arange(arrsize[1], dtype=np.int32))})
attrs = self._create_variables_attribute_dict()
Expand Down
19 changes: 19 additions & 0 deletions tests/test_particlefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,25 @@ def IncrLon(particle, fieldset, time):
ds.close()


@pytest.mark.parametrize('mode', ['scipy', 'jit'])
@pytest.mark.parametrize('repeatdt', [1, 2])
@pytest.mark.parametrize('nump', [1, 10])
def test_pfile_chunks_repeatedrelease(fieldset, mode, repeatdt, nump, tmpdir):
runtime = 8
pset = ParticleSet(fieldset, pclass=ptype[mode], lon=np.zeros((nump, 1)),
lat=np.zeros((nump, 1)), repeatdt=repeatdt)
outfilepath = tmpdir.join("pfile_chunks_repeatedrelease.zarr")
chunks = (20, 10)
pfile = pset.ParticleFile(outfilepath, outputdt=1, chunks=chunks)

def DoNothing(particle, fieldset, time):
pass

pset.execute(DoNothing, dt=1, runtime=runtime, output_file=pfile)
ds = xr.open_zarr(outfilepath)
assert ds['time'].shape == (int(nump*runtime/repeatdt), chunks[1])


@pytest.mark.parametrize('mode', ['scipy', 'jit'])
def test_write_timebackward(fieldset, mode, tmpdir):
outfilepath = tmpdir.join("pfile_write_timebackward.zarr")
Expand Down

0 comments on commit 861feca

Please sign in to comment.