Skip to content

Commit 82c2312

Browse files
More cleanup of the code
1 parent 1a95c23 commit 82c2312

File tree

2 files changed

+16
-21
lines changed

2 files changed

+16
-21
lines changed

parcels/kernel.py

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def __init__(
5555
self.funcvars = funcvars
5656
self.funccode = funccode
5757
self.py_ast = py_ast # TODO v4: check if this is needed
58-
self.scipy_positionupdate_kernels_added = False
58+
self._positionupdate_kernels_added = False
5959

6060
@property
6161
def ptype(self):
@@ -181,7 +181,7 @@ def pyfunc(self):
181181
def fieldset(self):
182182
return self._fieldset
183183

184-
def add_scipy_positionupdate_kernels(self):
184+
def add_positionupdate_kernels(self):
185185
# Adding kernels that set and update the coordinate changes
186186
def Setcoords(particle, fieldset, time): # pragma: no cover
187187
particle_dlon = 0 # noqa
@@ -324,23 +324,6 @@ def from_list(cls, fieldset, ptype, pyfunc_list, *args, **kwargs):
324324
pyfunc_list[0] = cls(fieldset, ptype, pyfunc_list[0], *args, **kwargs)
325325
return functools.reduce(lambda x, y: x + y, pyfunc_list)
326326

327-
def execute_python(self, pset, endtime, dt):
328-
"""Performs the core update loop via Python."""
329-
if self.fieldset is not None:
330-
for f in self.fieldset.get_fields():
331-
if isinstance(f, (VectorField, NestedField)):
332-
continue
333-
f.data = np.array(f.data)
334-
335-
if not self.scipy_positionupdate_kernels_added:
336-
self.add_scipy_positionupdate_kernels()
337-
self.scipy_positionupdate_kernels_added = True
338-
339-
for p in pset:
340-
self.evaluate_particle(p, endtime)
341-
if p.state == StatusCode.StopAllExecution:
342-
return StatusCode.StopAllExecution
343-
344327
def execute(self, pset, endtime, dt):
345328
"""Execute this Kernel over a ParticleSet for several timesteps."""
346329
pset.particledata.state[:] = StatusCode.Evaluate
@@ -359,7 +342,19 @@ def execute(self, pset, endtime, dt):
359342
g._load_chunk == g._chunk_loaded_touched, g._chunk_deprecated, g._load_chunk
360343
)
361344

362-
self.execute_python(pset, endtime, dt)
345+
for f in self.fieldset.get_fields():
346+
if isinstance(f, (VectorField, NestedField)):
347+
continue
348+
f.data = np.array(f.data)
349+
350+
if not self._positionupdate_kernels_added:
351+
self.add_positionupdate_kernels()
352+
self._positionupdate_kernels_added = True
353+
354+
for p in pset:
355+
self.evaluate_particle(p, endtime)
356+
if p.state == StatusCode.StopAllExecution:
357+
return StatusCode.StopAllExecution
363358

364359
# Remove all particles that signalled deletion
365360
self.remove_deleted(pset)

parcels/particledata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def __init__(self, pclass, lon, lat, depth, time, lonlatdepth_dtype, pid_orig, n
147147
self._data["id"][:] = pid
148148
self._data["obs_written"][:] = 0
149149

150-
# special case for exceptions which can only be handled from scipy
150+
# special case for exceptions which can only be handled from scipy # TODO v4: check if this can be removed now that JIT is dropped
151151
self._data["exception"] = np.empty(self._ncount, dtype=object)
152152

153153
initialised |= {

0 commit comments

Comments
 (0)