FieldOutOfBoundError at beginning of integration #2200
-
QuestionQuestionHi all 👋 I am working with SOSE 5-day output (it 155, year 2022) available here which covers longitude 0 to 360 (stored as 0 to 360) and latitude -78 to -30. To begin with I was initialising a large number of particles but in the minimum working example below I still have the problem when initialising a single particle. Through attempting to solve the problem I have found that I can get simulation to run if I only load part of the dataset using the I'm a bit stuck at how to proceed with this and would appreciate any help to get things going in the right direction again! Thanks for your time. Ryan Supporting code/error messages
Error:
Minimum Working Exampleimport matplotlib.pyplot as plt
import xarray as xr
import parcels
from datetime import timedelta
# set up fieldset
grid = 'grid.nc'
filenames = {
'U': {'data': 'Uvel_bsoseI155_2022_5day.nc',
'lon': grid,
'lat': grid,
'depth': grid
},
'V': {'data': 'Vvel_bsoseI155_2022_5day.nc',
'lon': grid,
'lat': grid,
'depth': grid
},
}
variables = {'U': 'UVEL', 'V': 'VVEL'}
dimensions = {'U': {'lon': 'XG', 'lat': 'YG', 'time': 'time', 'depth': 'RC'},
'V': {'lon': 'XG', 'lat': 'YG', 'time': 'time', 'depth': 'RC'}}
fieldset = parcels.FieldSet.from_mitgcm(filenames,
variables,
dimensions,
indices={'depth': [0],
# 'lon': range(945, 2160)
}
)
# set up particles
lon = [226]
lat = [-60]
time = [0]
pset = parcels.ParticleSet.from_list(fieldset=fieldset,
pclass=parcels.JITParticle,
lon=lon,
lat=lat,
time=time)
name = 'mwe_parcels.zarr'
outputdt = timedelta(hours=1)
output_file = pset.ParticleFile(name=name, outputdt=outputdt)
# Plot the field and initial position
fieldset.computeTimeChunk()
plt.pcolormesh(fieldset.U.grid.lon,
fieldset.U.grid.lat,
fieldset.U.data[0, :, :])
for p in pset:
plt.scatter(p.lon, p.lat, c='r')
plt.show()
# set kernels and integration settings
kernels = [parcels.AdvectionRK4]
runtime = timedelta(days=6)
dt = timedelta(minutes=5)
# execute the integration
pset.execute(kernels, runtime=runtime, dt=dt, output_file=output_file)
# plot the trajectory
ds = xr.open_zarr(output_file.fname)
plt.plot(ds.lon.T, ds.lat.T, ".-")
plt.show() Further InformationOutput of the First Plot![]() Controlling Field with IndicesDifferent combinations of loaded longitudes and particle initialisation longitudes can be tested by uncommenting the line in the fieldset creation. longitude indices ![]()
Running with longitude indices
If I maintain the same longitude indices
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Hi @RyMole, If I recall correctly from last year, @sruehs was using the same (or similar) dataset, and the problem was not with parcels, but the grid provided with the data. See this comment from last year #1685 (comment) You can see the issue when you plot your data using pcolormesh, there are grid cells defined near [0,0] that shouldn't exist. To solve the problem you will need to find or correct the grid you use when creating your fieldset. EDIT: I realise the link to the other issue seems unrelated, but I do remember the same issue popped up in subsequent discussions, hence the link. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
I think the issue may be caused in the grid search part of the code, where perhaps when iterating through the grid to find which cell the particle is in, it encounters one of these [0,0] cells, and ultimately can't find the right cell and throws an out of bounds error. This is me speculating though, if you can try a corrected grid (or manufacture a grid?) to see if that works?