Skip to content

Commit 8091c1f

Browse files
Removing write_latest_location
As not necessary anymore now that the last time is written to file
1 parent c145154 commit 8091c1f

File tree

2 files changed

+1
-24
lines changed

2 files changed

+1
-24
lines changed

docs/examples_v3/tutorial_kernelloop.ipynb

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -257,13 +257,7 @@
257257
"### 2. Be careful with updating particle variables that do not depend on Fields.\n",
258258
"While assigning the interpolated value of a `Field` to a Particle goes well in the loop above, this is not necessarily so for assigning other attributes. For example, a line like `particle.age += particle.dt` is executed directly so may result in the age being `dt` at `time = 0` in the output file. \n",
259259
"\n",
260-
"A workaround is to either initialise the age to `-dt`, or to increase the `age` only when `particle.time > 0` (using an `np.where` statement).\n",
261-
"\n",
262-
"\n",
263-
"### 3. The last time is not written to file\n",
264-
"Because the location at the start of the loop is written at the end of the Kernel loop, the last `particle.time` of the particle is not written to file. This is similar behaviour to e.g. `np.arange(start, stop)`, which also doesn't include the `stop` value itself. \n",
265-
"\n",
266-
"If you do want to write the last time to file, you can increase the `runtime` or `endtime` by `dt` (although this may cause a TimeExtrapolationError if your run was to the end of the available hydrodynamic data), or you can call `pfile.write_latest_locations(pset, time=pset[0].time+pset[0].dt)`. Note that in the latter case, the particle locations (longitude, latitude and z) will be updated, but other variables will _not_ be updated as the Kernels are not run again."
260+
"A workaround is to either initialise the age to `-dt`, or to increase the `age` only when `particle.time > 0` (using an `np.where` statement)."
267261
]
268262
},
269263
{

src/parcels/_core/particlefile.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -242,23 +242,6 @@ def _write_particle_data(self, *, particle_data, pclass, time_interval, time, in
242242

243243
particle_data["obs_written"][indices_to_write] = obs + 1
244244

245-
def write_latest_locations(self, pset, time):
246-
"""Write the current (latest) particle locations to zarr file.
247-
This can be useful at the end of a pset.execute(), when the last locations are not written yet.
248-
Note that this only updates the locations, not any of the other Variables. Therefore, use with care.
249-
250-
Parameters
251-
----------
252-
pset :
253-
ParticleSet object to write
254-
time :
255-
Time at which to write ParticleSet. Note that typically this would be pset.time + pset.dt
256-
"""
257-
for var in ["lon", "lat", "z"]:
258-
pset._data[f"{var}"] += pset._data[f"d{var}"]
259-
pset._data["time"] += pset._data["dt"]
260-
self.write(pset, time)
261-
262245

263246
def _get_store_from_pathlike(path: Path | str) -> DirectoryStore:
264247
path = str(Path(path)) # Ensure valid path, and convert to string

0 commit comments

Comments
 (0)