Skip to content

Commit 29a4309

Browse files
Merge pull request #2210 from OceanParcels/some_renaming_of_particle_to_particles
Internal renaming of `particle` to `particles`
2 parents bacd187 + 79a2d8d commit 29a4309

File tree

5 files changed

+33
-33
lines changed

5 files changed

+33
-33
lines changed

parcels/basegrid.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ def search(self, z: float, y: float, x: float, ei=None) -> dict[str, tuple[int,
5454
- Unstructured grid: {"Z": (zi, zeta), "FACE": (fi, bcoords)}
5555
5656
Where:
57-
- index (int): The cell position of a particle along the given axis
57+
- index (int): The cell position of the particles along the given axis
5858
- barycentric_coordinates (float or np.ndarray): The coordinates defining
59-
a particle's position within the grid cell. For structured grids, this
59+
the particles positions within the grid cell. For structured grids, this
6060
is a single coordinate per axis; for unstructured grids, this can be
6161
an array of coordinates for the face polygon.
6262

parcels/field.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def _deal_with_errors(error, key, vector_type: VectorType):
4141
elif isinstance(key[-1], KernelParticle):
4242
key[-1].state = AllParcelsErrorCodes[type(error)]
4343
else:
44-
raise RuntimeError(f"{error}. Error could not be handled because particle was not part of the Field Sampling.")
44+
raise RuntimeError(f"{error}. Error could not be handled because particles was not part of the Field Sampling.")
4545

4646
if vector_type and "3D" in vector_type:
4747
return (0, 0, 0)
@@ -205,7 +205,7 @@ def _check_velocitysampling(self):
205205
stacklevel=2,
206206
)
207207

208-
def eval(self, time: datetime, z, y, x, particle=None, applyConversion=True):
208+
def eval(self, time: datetime, z, y, x, particles=None, applyConversion=True):
209209
"""Interpolate field values in space and time.
210210
211211
We interpolate linearly in time and apply implicit unit
@@ -219,11 +219,11 @@ def eval(self, time: datetime, z, y, x, particle=None, applyConversion=True):
219219

220220
tau, ti = _search_time_index(self, time)
221221
position = self.grid.search(z, y, x, ei=_ei)
222-
_update_particle_states_position(particle, position)
222+
_update_particle_states_position(particles, position)
223223

224224
value = self._interp_method(self, ti, position, tau, time, z, y, x)
225225

226-
_update_particle_states_interp_value(particle, value)
226+
_update_particle_states_interp_value(particles, value)
227227

228228
if applyConversion:
229229
value = self.units.to_target(value, z, y, x)
@@ -287,7 +287,7 @@ def vector_interp_method(self, method: Callable):
287287
_assert_same_function_signature(method, ref=ZeroInterpolator_Vector, context="Interpolation")
288288
self._vector_interp_method = method
289289

290-
def eval(self, time: datetime, z, y, x, particle=None, applyConversion=True):
290+
def eval(self, time: datetime, z, y, x, particles=None, applyConversion=True):
291291
"""Interpolate field values in space and time.
292292
293293
We interpolate linearly in time and apply implicit unit
@@ -301,7 +301,7 @@ def eval(self, time: datetime, z, y, x, particle=None, applyConversion=True):
301301

302302
tau, ti = _search_time_index(self.U, time)
303303
position = self.grid.search(z, y, x, ei=_ei)
304-
_update_particle_states_position(particle, position)
304+
_update_particle_states_position(particles, position)
305305

306306
if self._vector_interp_method is None:
307307
u = self.U._interp_method(self.U, ti, position, tau, time, z, y, x)
@@ -319,7 +319,7 @@ def eval(self, time: datetime, z, y, x, particle=None, applyConversion=True):
319319
(u, v, w) = self._vector_interp_method(self, ti, position, tau, time, z, y, x, applyConversion)
320320

321321
for vel in (u, v, w):
322-
_update_particle_states_interp_value(particle, vel)
322+
_update_particle_states_interp_value(particles, vel)
323323

324324
if applyConversion and ("3D" in self.vector_type):
325325
w = self.W.units.to_target(w, z, y, x) if self.W else 0.0
@@ -339,34 +339,34 @@ def __getitem__(self, key):
339339
return _deal_with_errors(error, key, vector_type=self.vector_type)
340340

341341

342-
def _update_particle_states_position(particle, position):
342+
def _update_particle_states_position(particles, position):
343343
"""Update the particle states based on the position dictionary."""
344-
if particle: # TODO also support uxgrid search
344+
if particles: # TODO also support uxgrid search
345345
for dim in ["X", "Y"]:
346346
if dim in position:
347-
particle.state = np.maximum(
348-
np.where(position[dim][0] == -1, StatusCode.ErrorOutOfBounds, particle.state), particle.state
347+
particles.state = np.maximum(
348+
np.where(position[dim][0] == -1, StatusCode.ErrorOutOfBounds, particles.state), particles.state
349349
)
350-
particle.state = np.maximum(
351-
np.where(position[dim][0] == GRID_SEARCH_ERROR, StatusCode.ErrorGridSearching, particle.state),
352-
particle.state,
350+
particles.state = np.maximum(
351+
np.where(position[dim][0] == GRID_SEARCH_ERROR, StatusCode.ErrorGridSearching, particles.state),
352+
particles.state,
353353
)
354354
if "Z" in position:
355-
particle.state = np.maximum(
356-
np.where(position["Z"][0] == RIGHT_OUT_OF_BOUNDS, StatusCode.ErrorOutOfBounds, particle.state),
357-
particle.state,
355+
particles.state = np.maximum(
356+
np.where(position["Z"][0] == RIGHT_OUT_OF_BOUNDS, StatusCode.ErrorOutOfBounds, particles.state),
357+
particles.state,
358358
)
359-
particle.state = np.maximum(
360-
np.where(position["Z"][0] == LEFT_OUT_OF_BOUNDS, StatusCode.ErrorThroughSurface, particle.state),
361-
particle.state,
359+
particles.state = np.maximum(
360+
np.where(position["Z"][0] == LEFT_OUT_OF_BOUNDS, StatusCode.ErrorThroughSurface, particles.state),
361+
particles.state,
362362
)
363363

364364

365-
def _update_particle_states_interp_value(particle, value):
365+
def _update_particle_states_interp_value(particles, value):
366366
"""Update the particle states based on the interpolated value, but only if state is not an Error already."""
367-
if particle:
368-
particle.state = np.maximum(
369-
np.where(np.isnan(value), StatusCode.ErrorInterpolation, particle.state), particle.state
367+
if particles:
368+
particles.state = np.maximum(
369+
np.where(np.isnan(value), StatusCode.ErrorInterpolation, particles.state), particles.state
370370
)
371371

372372

parcels/particleset.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424

2525

2626
class ParticleSet:
27-
"""Class for storing particle and executing kernel over them.
27+
"""Class for storing particles and executing kernel over them.
2828
2929
Please note that this currently only supports fixed size particle sets, meaning that the particle set only
3030
holds the particles defined on construction. Individual particles can neither be added nor deleted individually,
31-
and individual particles can only be deleted as a set procedurally (i.e. by 'particle.delete()'-call during
32-
kernel execution).
31+
and individual particles can only be deleted as a set procedurally (i.e. by changing their state to 'StatusCode.Delete'
32+
during kernel execution).
3333
3434
Parameters
3535
----------

parcels/tools/statuscodes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ def _raise_time_extrapolation_error(time: float, field=None):
110110

111111

112112
class KernelError(RuntimeError):
113-
"""General particle kernel error with optional custom message."""
113+
"""General particles kernel error with optional custom message."""
114114

115-
def __init__(self, particle, fieldset=None, msg=None):
116-
message = f"{particle.state}\nParticle {particle}\nTime: {particle.time}\ntimestep dt: {particle.dt}\n"
115+
def __init__(self, particles, fieldset=None, msg=None):
116+
message = f"{particles.state}\nParticle {particles}\nTime: {particles.time}\ntimestep dt: {particles.dt}\n"
117117
if msg:
118118
message += msg
119119
super().__init__(message)

parcels/xgrid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ def _search_1d_array(
508508
x: float,
509509
) -> tuple[int, int]:
510510
"""
511-
Searches for the particle location in a 1D array and returns barycentric coordinate along dimension.
511+
Searches for particle locations in a 1D array and returns barycentric coordinate along dimension.
512512
513513
Assumptions:
514514
- array is strictly monotonically increasing.

0 commit comments

Comments
 (0)