Stopping particle tracking at different times #1344
-
I want to run a simulation where I release particles from the same location at different times, but also stop tracking them at different times, so that they are all advected for the same amount of time. For example, the first set of particles is released at |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I see two ways that this could be done. With kernels, or using post-processing with xarray. Custom kernelsYou can add an "age" to particles (e.g. in seconds as shown below) which tracks how old each particle is. If above a threshold it gets deleted. Here's an code snippet illustrating what I mean. class AgingParticle(JITParticle):
# Age in seconds
age = Variable(
'age', dtype=np.float32,
initial=0.0,
)
def aging_kernel(particle, fieldset, time):
particle.age = particle.age + particle.dt
def delete_old_particle_kernel(particle, fieldset, time):
if particle.age > 25.0:
particle.delete()
fieldset = ...
lon = ...
lat = ...
pset = ParticleSet(fieldset, pclass=AgingParticle, lon=lon, lat=lat)
combined_kernel = pset.Kernel(aging_kernel) + AdvectionRK4 + pset.Kernel(delete_old_particle_kernel)
... Post-processingYou can add a variable tracking age (as above), but rather than deleting the particle, you can keep the particle in the simulation. Then once the simulation is done, you can open the data in xarray and select the observations where This takes up more space and computation, but adds flexibility to not have to run the simulation again should you want to change the cutoff. Let me know how you go, or if you want me to elaborate😄 |
Beta Was this translation helpful? Give feedback.
I see two ways that this could be done. With kernels, or using post-processing with xarray.
Custom kernels
You can add an "age" to particles (e.g. in seconds as shown below) which tracks how old each particle is. If above a threshold it gets deleted.
Here's an code snippet illustrating what I mean.