Open sruehs opened 1 week ago
Looks like the problem is in the C-conversion code in kernel.py
(perhaps not being able to handle the dataset for some reason?)
After some investigation from @sruehs and @michaeldenes it looks to be a problem with the data and not Parcels
From the periodic boundary conditions tutorial (https://docs.oceanparcels.org/en/latest/examples/tutorial_periodic_boundaries.html), the following lines are used to add the periodic halo:
fieldset.add_constant("halo_west", fieldset.U.grid.lon[0])
fieldset.add_constant("halo_east", fieldset.U.grid.lon[-1])
fieldset.add_periodic_halo(zonal=True)
The grid here is a RectilinearZGrid
, and when we print the shape of the grid we get:
print(fieldset.U.grid.lon.shape, fieldset.U.grid.lat.shape)
(110,) (50,)
i.e. 1D arrays.
So, when creating the halos, fieldset.halo_west
and fieldset.halo_east
are scalar values.
However, in @sruehs case, the shape of underlying grids are not 1D-arrays, rather 2D-arrays. When adding the two constants halo_west
and halo_east
, by providing fieldset.U.grid.lon[0]
and fieldset.U.grid.lon[-1]
, you are providing an array of values, not a single scalar value. This is why the error pops up.
In the past, using an Arakawa B-grid (and MOM5 data), I've used the exact same code to add the halo, so I'm not sure why it's not working here, unless the grid is weird...
Fieldset.add_constant()
needs to have the value being a float, so in the case of a 2D array ...lon[0]
would return an array instead of a single float. This isn't validated in the function hence the uninformative error message.
What is the usecase for having halo_west
being an array instead of a constant?
I still am a bit concerned about the format of this data (ie., 'why is lon a 2D array?'), and how it compares against other datasets we've used. I can block out some time to look at this properly
EDIT: I see now. Since its a curvilinear grid lon and lat aren't dimensions (more the dimensions are xi
and yi
which unique combinations provide lon and lat)
I don't think there is a use-case for halo_west
or halo_east
being an array, but I think the periodic BC tutorial should be updated to show how to implement periodic BC's for different models/grids.
I think parcels handles the periodicity in the nemo c-grids out of the box, but just to show as an example, if you load the data from the nemo tutorial (https://docs.oceanparcels.org/en/latest/examples/tutorial_nemo_3D.html), and print out the shapes of the grids:
print(fieldset.U.grid.lon.shape, fieldset.U.grid.lat.shape)
you get (201, 151) (201, 151)
.
Parcels version
3.0.3
Description
I encountered an error when running Parcels with b-SOSE (MITgcm) fields on Lorenz, which I have not seen before. It seems to be linked to some kind of conversion? Any help how to approach this is appreciated!
Code sample