Skip to content

Commit 861feca

Browse files
Merge branch 'master' into update-prettier
2 parents 5f27939 + a3d90da commit 861feca

5 files changed

Lines changed: 54 additions & 43 deletions

File tree

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ repos:
2424
- id: nbqa-check-ast
2525
- id: nbqa-isort
2626
- repo: https://github.com/pycqa/isort
27-
rev: 5.12.0
27+
rev: 5.13.2
2828
hooks:
2929
- id: isort
3030
name: isort (python)

docs/examples/documentation_unstuck_Agrid.ipynb

Lines changed: 30 additions & 38 deletions
Large diffs are not rendered by default.

docs/examples/tutorial_timestamps.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@
155155
"cell_type": "markdown",
156156
"metadata": {},
157157
"source": [
158-
"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"
158+
"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"
159159
]
160160
},
161161
{

parcels/particlefile.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def _create_variables_attribute_dict(self):
142142

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

147147
for vname in self.vars_to_write:
148148
if vname not in ['time', 'lat', 'lon', 'depth', 'id']:
@@ -183,7 +183,7 @@ def _extend_zarr_dims(self, Z, store, dtype, axis):
183183
if len(obs) == Z.shape[1]:
184184
obs.append(np.arange(self.chunks[1])+obs[-1]+1)
185185
else:
186-
extra_trajs = max(self.maxids - Z.shape[0], self.chunks[0])
186+
extra_trajs = self.maxids - Z.shape[0]
187187
if len(Z.shape) == 2:
188188
a = np.full((extra_trajs, Z.shape[1]), self.fill_value_map[dtype], dtype=dtype)
189189
else:
@@ -233,7 +233,7 @@ def write(self, pset, time, indices=None):
233233
if (self.maxids > len(ids)) or (self.maxids > self.chunks[0]):
234234
arrsize = (self.maxids, self.chunks[1])
235235
else:
236-
arrsize = (len(ids), 1)
236+
arrsize = (len(ids), self.chunks[1])
237237
ds = xr.Dataset(attrs=self.metadata, coords={"trajectory": ("trajectory", pids),
238238
"obs": ("obs", np.arange(arrsize[1], dtype=np.int32))})
239239
attrs = self._create_variables_attribute_dict()

tests/test_particlefile.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,25 @@ def IncrLon(particle, fieldset, time):
244244
ds.close()
245245

246246

247+
@pytest.mark.parametrize('mode', ['scipy', 'jit'])
248+
@pytest.mark.parametrize('repeatdt', [1, 2])
249+
@pytest.mark.parametrize('nump', [1, 10])
250+
def test_pfile_chunks_repeatedrelease(fieldset, mode, repeatdt, nump, tmpdir):
251+
runtime = 8
252+
pset = ParticleSet(fieldset, pclass=ptype[mode], lon=np.zeros((nump, 1)),
253+
lat=np.zeros((nump, 1)), repeatdt=repeatdt)
254+
outfilepath = tmpdir.join("pfile_chunks_repeatedrelease.zarr")
255+
chunks = (20, 10)
256+
pfile = pset.ParticleFile(outfilepath, outputdt=1, chunks=chunks)
257+
258+
def DoNothing(particle, fieldset, time):
259+
pass
260+
261+
pset.execute(DoNothing, dt=1, runtime=runtime, output_file=pfile)
262+
ds = xr.open_zarr(outfilepath)
263+
assert ds['time'].shape == (int(nump*runtime/repeatdt), chunks[1])
264+
265+
247266
@pytest.mark.parametrize('mode', ['scipy', 'jit'])
248267
def test_write_timebackward(fieldset, mode, tmpdir):
249268
outfilepath = tmpdir.join("pfile_write_timebackward.zarr")

0 commit comments

Comments
 (0)