Out of boundaries error #1086
Replies: 3 comments 14 replies
-
Dear @mainarabgouveia. You will have to include a recovery kernel to your execution: pset.execute(..., recovery={ErrorCode.ErrorOutOfBounds: DeleteParticle}) And then create a Recovery Kernel to delete the particle: def DeleteParticle(particle, fieldset, time):
particle.delete() See also https://github.com/OceanParcels/parcels/blob/master/parcels/examples/tutorial_Agulhasparticles.ipynb for a full example |
Beta Was this translation helpful? Give feedback.
-
Tks for your help and time. |
Beta Was this translation helpful? Give feedback.
-
Hi, I have a similar problem. I am getting def CheckOutOfBounds(particle, fieldset, time):
if particle.state == StatusCode.ErrorOutOfBounds:
particle.delete()
kernels = [parcels.AdvectionRK4,CheckOutOfBounds]
pset.execute(kernels,
runtime=timedelta(hours=72),
dt=timedelta(minutes=5),
output_file=output_file,
) I am still getting another error message:
If anyone can help? Thank you. This is my code: import math
from datetime import timedelta as delta
from datetime import datetime,timedelta
from operator import attrgetter
from glob import glob
import matplotlib.pyplot as plt
import numpy as np
import trajan as ta
import xarray as xr
from IPython.display import HTML
from matplotlib.animation import FuncAnimation
import parcels
from parcels import StatusCode
data_folder = '.'
hydrofiles = sorted(glob(f"{data_folder}/Strait_2004*.nc"))
def DeleteParticle(particle, fieldset, time):
particle.delete()
def CheckOutOfBounds(particle, fieldset, time):
if particle.state == StatusCode.ErrorOutOfBounds:
particle.delete()
filenames = {
"U": hydrofiles,
"V": hydrofiles,
"W": hydrofiles,
}
variables = {"U": "UVEL", "V": "VVEL", "W": "WVEL"}
dimensions = {
"U": {"lon": "XG", "lat": "YG", "depth": "Z", "time": "time"},
"V": {"lon": "XG", "lat": "YG", "depth": "Z", "time": "time"},
"W": {"lon": "XG", "lat": "YG", "depth": "Z", "time": "time"},}
fieldset = parcels.FieldSet.from_mitgcm(
filenames, variables, dimensions, mesh="spherical",
allow_time_extrapolation=True,)
advection_duration = 48
ReleaseTime=0
day_start = datetime(2004,1,1,1,0)
day_end = day_start+delta(hours=advection_duration)
nptc=10
npart=8
lonp = [115.00,115.25,115.5,115.75,116,116.25,116.5,116.75]
latp = -8.0*np.ones(npart)
lonp=np.array(lonp)
latp=np.array(latp)
depthp = -1.0*np.ones(npart)
releaseTimes = np.arange(0, advection_duration) * delta(hours=1)
releaseTimes += day_start
particles_t = np.array([])
particles_lat = np.array([])
particles_lon = np.array([])
particles_depth = np.array([])
for i1,time in enumerate(releaseTimes):
for i2 in range(nptc):
particles_t = np.append(particles_t,np.array([(time-day_start).total_seconds() for i in range(len(lonp))]))
particles_lat = np.append(particles_lat,latp)
particles_lon = np.append(particles_lon,lonp)
particles_depth=np.append(particles_depth,depthp)
time_origin = datetime.utcfromtimestamp(np.datetime64(str(fieldset.time_origin)).astype(int)*1e-9)
time_start = day_start - time_origin
particles_t += time_start.total_seconds()
pset = parcels.ParticleSet(fieldset = fieldset,
pclass = parcels.JITParticle,
lon = particles_lon,
lat = particles_lat,
depth=particles_depth,
time = particles_t,)
output_file = pset.ParticleFile(name="test.zarr", outputdt=timedelta(minutes=30))
kernels = [parcels.AdvectionRK4,CheckOutOfBounds]
pset.execute(kernels,
runtime=timedelta(hours=72),
dt=timedelta(minutes=5),
output_file=output_file,
) |
Beta Was this translation helpful? Give feedback.
-
Hi,
How do I make my released particles that leave the domain or arrive on the land don't cause my simulations to stop?
I'm getting this error:
INFO: Compiled ArrayJITParticleAdvectionRK45AdvectionDiffusionM1 ==> /tmp/parcels-1000/lib77962480406540cb0477e74d24ef8364_0.so
98% (14938200.0 of 15120000.0) |####### | Elapsed Time: 0:15:43 ETA: 0:00:11
OutOfBoundsError Traceback (most recent call last)
/tmp/ipykernel_32755/3033041448.py in
1 # Now run the remaining ParticleSet (using less accurate Euler Forward for speedup)
2
----> 3 pset.execute(pset.Kernel(AdvectionRK45) + AdvectionDiffusionM1, # the kernel (which defines how particles move)
4 runtime=timedelta(days=175), # the total length of the run
5 dt=-timedelta(minutes=5), # the timestep of the kernel (negative timestep for backwards run)
~/anaconda3/envs/py3_parcels/lib/python3.9/site-packages/parcels/particleset/baseparticleset.py in execute(self, pyfunc, pyfunc_inter, endtime, runtime, dt, moviedt, recovery, output_file, movie_background_field, verbose_progress, postIterationCallbacks, callbackdt)
456 # If we don't perform interaction, only execute the normal kernel efficiently.
457 if self.interaction_kernel is None:
--> 458 self.kernel.execute(self, endtime=next_time, dt=dt, recovery=recovery, output_file=output_file,
459 execute_once=execute_once)
460 # Interaction: interleave the interaction and non-interaction kernel for each time step.
~/anaconda3/envs/py3_parcels/lib/python3.9/site-packages/parcels/kernel/kernelsoa.py in execute(self, pset, endtime, dt, recovery, output_file, execute_once)
225 recovery_kernel = recovery_map[p.state]
226 p.set_state(StateCode.Success)
--> 227 recovery_kernel(p, self.fieldset, p.time)
228 if p.isComputed():
229 p.reset_state()
~/anaconda3/envs/py3_parcels/lib/python3.9/site-packages/parcels/tools/statuscodes.py in recovery_kernel_out_of_bounds(particle, fieldset, time)
194 # TODO: JIT does not yet provide the context that created
195 # the exception. We need to pass that info back from C.
--> 196 raise OutOfBoundsError(particle, fieldset)
197 else:
198 error = particle.exception
OutOfBoundsError: 0
Particle P[4](lon=17.006130, lat=-29.650196, depth=0.000000, time=36208800.000000)
Time: 2021-02-23T02:30:00.000000000, timestep dt: -3600.000000
Out-of-bounds sampling by particle at (17.006130, -29.650196, 0.000000)
Beta Was this translation helpful? Give feedback.
All reactions