parcels
parcels copied to clipboard
Slicing `ParticleSet` object
Currently indexing a particleset doesn't work with slice objects.
pset[0]
- > gives first particle
pset[:7]
self = <parcels.particledata.ParticleData object at 0x1620e3110>, index = slice(None, 7, None)
def get_single_by_index(self, index):
"""Get a particle object from the ParticleData instance based on its index."""
> assert type(index) in [
int,
np.int32,
np.intp,
], f"Trying to get a particle by index, but index {index} is not a 32-bit integer - invalid operation."
E AssertionError: Trying to get a particle by index, but index slice(None, 7, None) is not a 32-bit integer - invalid operation.
It would be a nice quality of life change for pset to support slicing