Skip to content

Commit 1c1cbe3

Browse files
[#2034] Remove repeatdt references
1 parent d7ff31e commit 1c1cbe3

1 file changed

Lines changed: 4 additions & 68 deletions

File tree

parcels/particleset.py

Lines changed: 4 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from parcels.grid import GridType
1515
from parcels.interaction.interactionkernel import InteractionKernel
1616
from parcels.kernel import Kernel
17-
from parcels.particle import Particle, Variable
17+
from parcels.particle import Particle
1818
from parcels.particledata import ParticleData, ParticleDataIterator
1919
from parcels.particlefile import ParticleFile
2020
from parcels.tools.converters import _get_cftime_calendars, convert_to_flat_array
@@ -54,8 +54,6 @@ class ParticleSet:
5454
Optional list of initial depth values for particles. Default is 0m
5555
time :
5656
Optional list of initial time values for particles. Default is fieldset.U.grid.time[0]
57-
repeatdt : datetime.timedelta or float, optional
58-
Optional interval on which to repeat the release of the ParticleSet. Either timedelta object, or float in seconds.
5957
lonlatdepth_dtype :
6058
Floating precision for lon, lat, depth particle coordinates.
6159
It is either np.float32 or np.float64. Default is np.float32 if fieldset.U.interp_method is 'linear'
@@ -84,49 +82,12 @@ def __init__(
8482
**kwargs,
8583
):
8684
self.particledata = None
87-
self._repeat_starttime = None
88-
self._repeatlon = None
89-
self._repeatlat = None
90-
self._repeatdepth = None
91-
self._repeatpclass = None
92-
self._repeatkwargs = None
9385
self._kernel = None
9486
self._interaction_kernel = None
9587

9688
self.fieldset = fieldset
9789
self._pclass = pclass
9890

99-
# ==== first: create a new subclass of the pclass that includes the required variables ==== #
100-
# ==== see dynamic-instantiation trick here: https://www.python-course.eu/python3_classes_and_type.php ==== #
101-
class_name = pclass.__name__
102-
array_class = None
103-
if class_name not in dir():
104-
105-
def ArrayClass_init(self, *args, **kwargs):
106-
fieldset = kwargs.get("fieldset", None)
107-
ngrids = kwargs.get("ngrids", None)
108-
if type(self).ngrids.initial < 0:
109-
numgrids = ngrids
110-
if numgrids is None and fieldset is not None:
111-
numgrids = fieldset.gridset_size
112-
assert numgrids is not None, "Neither fieldsets nor number of grids are specified - exiting."
113-
type(self).ngrids.initial = numgrids
114-
self.ngrids = type(self).ngrids.initial
115-
if self.ngrids >= 0:
116-
self.ei = np.zeros(self.ngrids, dtype=np.int32)
117-
super(type(self), self).__init__(*args, **kwargs)
118-
119-
array_class_vdict = {
120-
"ngrids": Variable("ngrids", dtype=np.int32, to_write=False, initial=-1),
121-
"ei": Variable("ei", dtype=np.int32, to_write=False),
122-
"__init__": ArrayClass_init,
123-
}
124-
array_class = type(class_name, (pclass,), array_class_vdict)
125-
else:
126-
array_class = locals()[class_name]
127-
# ==== dynamic re-classing completed ==== #
128-
_pclass = array_class
129-
13091
lon = np.empty(shape=0) if lon is None else convert_to_flat_array(lon)
13192
lat = np.empty(shape=0) if lat is None else convert_to_flat_array(lat)
13293

@@ -171,7 +132,7 @@ def ArrayClass_init(self, *args, **kwargs):
171132
), f"{kwvar} and positions (lon, lat, depth) don't have the same lengths."
172133

173134
self.particledata = ParticleData(
174-
_pclass,
135+
self._pclass,
175136
lon=lon,
176137
lat=lat,
177138
depth=depth,
@@ -356,9 +317,7 @@ def populate_indices(self):
356317
self.particledata.data["ei"][:, i] = idx # assumes that we are in the surface layer (zi=0)
357318

358319
@classmethod
359-
def from_list(
360-
cls, fieldset, pclass, lon, lat, depth=None, time=None, repeatdt=None, lonlatdepth_dtype=None, **kwargs
361-
):
320+
def from_list(cls, fieldset, pclass, lon, lat, depth=None, time=None, lonlatdepth_dtype=None, **kwargs):
362321
"""Initialise the ParticleSet from lists of lon and lat.
363322
364323
Parameters
@@ -375,8 +334,6 @@ def from_list(
375334
Optional list of initial depth values for particles. Default is 0m
376335
time :
377336
Optional list of start time values for particles. Default is fieldset.U.time[0]
378-
repeatdt :
379-
Optional interval (in seconds) on which to repeat the release of the ParticleSet (Default value = None)
380337
lonlatdepth_dtype :
381338
Floating precision for lon, lat, depth particle coordinates.
382339
It is either np.float32 or np.float64. Default is np.float32 if fieldset.U.interp_method is 'linear'
@@ -392,7 +349,6 @@ def from_list(
392349
lat=lat,
393350
depth=depth,
394351
time=time,
395-
repeatdt=repeatdt,
396352
lonlatdepth_dtype=lonlatdepth_dtype,
397353
**kwargs,
398354
)
@@ -407,7 +363,6 @@ def from_line(
407363
size,
408364
depth=None,
409365
time=None,
410-
repeatdt=None,
411366
lonlatdepth_dtype=None,
412367
**kwargs,
413368
):
@@ -433,8 +388,6 @@ def from_line(
433388
Optional list of initial depth values for particles. Default is 0m
434389
time :
435390
Optional start time value for particles. Default is fieldset.U.time[0]
436-
repeatdt :
437-
Optional interval (in seconds) on which to repeat the release of the ParticleSet (Default value = None)
438391
lonlatdepth_dtype :
439392
Floating precision for lon, lat, depth particle coordinates.
440393
It is either np.float32 or np.float64. Default is np.float32 if fieldset.U.interp_method is 'linear'
@@ -451,7 +404,6 @@ def from_line(
451404
lat=lat,
452405
depth=depth,
453406
time=time,
454-
repeatdt=repeatdt,
455407
lonlatdepth_dtype=lonlatdepth_dtype,
456408
**kwargs,
457409
)
@@ -528,7 +480,6 @@ def from_field(
528480
mode="monte_carlo",
529481
depth=None,
530482
time=None,
531-
repeatdt=None,
532483
lonlatdepth_dtype=None,
533484
):
534485
"""Initialise the ParticleSet randomly drawn according to distribution from a field.
@@ -549,8 +500,6 @@ def from_field(
549500
Optional list of initial depth values for particles. Default is 0m
550501
time :
551502
Optional start time value for particles. Default is fieldset.U.time[0]
552-
repeatdt :
553-
Optional interval (in seconds) on which to repeat the release of the ParticleSet (Default value = None)
554503
lonlatdepth_dtype :
555504
Floating precision for lon, lat, depth particle coordinates.
556505
It is either np.float32 or np.float64. Default is np.float32 if fieldset.U.interp_method is 'linear'
@@ -566,12 +515,11 @@ def from_field(
566515
depth=depth,
567516
time=time,
568517
lonlatdepth_dtype=lonlatdepth_dtype,
569-
repeatdt=repeatdt,
570518
)
571519

572520
@classmethod
573521
def from_particlefile(
574-
cls, fieldset, pclass, filename, restart=True, restarttime=None, repeatdt=None, lonlatdepth_dtype=None, **kwargs
522+
cls, fieldset, pclass, filename, restart=True, restarttime=None, lonlatdepth_dtype=None, **kwargs
575523
):
576524
"""Initialise the ParticleSet from a zarr ParticleFile.
577525
This creates a new ParticleSet based on locations of all particles written
@@ -592,24 +540,13 @@ def from_particlefile(
592540
time at which the Particles will be restarted. Default is the last time written.
593541
Alternatively, restarttime could be a time value (including np.datetime64) or
594542
a callable function such as np.nanmin. The last is useful when running with dt < 0.
595-
repeatdt : datetime.timedelta or float, optional
596-
Optional interval on which to repeat the release of the ParticleSet. Either timedelta object, or float in seconds.
597543
lonlatdepth_dtype :
598544
Floating precision for lon, lat, depth particle coordinates.
599545
It is either np.float32 or np.float64. Default is np.float32 if fieldset.U.interp_method is 'linear'
600546
and np.float64 if the interpolation method is 'cgrid_velocity'
601547
**kwargs :
602548
Keyword arguments passed to the particleset constructor.
603549
"""
604-
if repeatdt is not None:
605-
warnings.warn(
606-
f"Note that the `repeatdt` argument is not retained from {filename}, and that "
607-
"setting a new repeatdt will start particles from the _new_ particle "
608-
"locations.",
609-
ParticleSetWarning,
610-
stacklevel=2,
611-
)
612-
613550
pfile = xr.open_zarr(str(filename))
614551
pfile_vars = [v for v in pfile.data_vars]
615552

@@ -675,7 +612,6 @@ def from_particlefile(
675612
time=vars["time"],
676613
pid_orig=vars["id"],
677614
lonlatdepth_dtype=lonlatdepth_dtype,
678-
repeatdt=repeatdt,
679615
**kwargs,
680616
)
681617

0 commit comments

Comments
 (0)