IndexError when including fields on the T-grid #1968
-
QuestionQuestionHello, I've been trying to update my scripts to use them with v3.1.2. Previously, it all worked with v2.3.1. While executing, I get the error message I hope you can help me with that, thank you! Supporting code/error messagesdef fieldset_defintions(
list_of_filenames_U, list_of_filenames_V,
list_of_filenames_W, list_of_filenames_T,
mesh_mask
):
filenames = {'U': {'lon': (mesh_mask), 'lat': (mesh_mask), 'depth': list_of_filenames_W[0],
'data': list_of_filenames_U},
'V': {'lon': (mesh_mask), 'lat': (mesh_mask), 'depth': list_of_filenames_W[0],
'data': list_of_filenames_V},
'W': {'lon': (mesh_mask), 'lat': (mesh_mask), 'depth': list_of_filenames_W[0],
'data': list_of_filenames_W},
'T': {'lon': (mesh_mask), 'lat': (mesh_mask), 'depth': list_of_filenames_T[0],
'data': list_of_filenames_T},
}
variables = {'U': 'vozocrtx',
'V': 'vomecrty',
'W': 'vovecrtz',
'T': 'votemper',
}
dimensions = {'U': {'lon': 'glamf', 'lat': 'gphif', 'depth': 'depthw',
'time': 'time_counter'},
'V': {'lon': 'glamf', 'lat': 'gphif', 'depth': 'depthw',
'time': 'time_counter'},
'W': {'lon': 'glamf', 'lat': 'gphif', 'depth': 'depthw',
'time': 'time_counter'},
'T': {'lon': 'glamt', 'lat': 'gphit', 'depth': 'deptht',
'time': 'time_counter'},
}
return FieldSet.from_nemo(
filenames, variables, dimensions,
chunksize=False,
mesh='spherical',
tracer_interp_method='cgrid_tracer',
allow_time_extrapolation=True,
)
def create_fieldset(
data_path=data_path, experiment_name=experiment_name,
fname_U=fname_U, fname_V=fname_V, fname_W=fname_W, fname_T=fname_T,
mesh_mask = mesh_mask
):
files_U = list(sorted((data_path / 'output').glob(fname_U)))
files_V = list(sorted((data_path / 'output').glob(fname_V)))
files_W = list(sorted((data_path / 'output').glob(fname_W)))
files_T = list(sorted((data_path / 'output').glob(fname_T)))
fieldset = fieldset_defintions(
files_U, files_V,
files_W, files_T, mesh_mask)
return fieldset
OW_eddy = Field.from_netcdf(
filenames=OW_path,
variable=("OW_eddy", "type"),
dimensions={"lon": "nav_lon", "lat": "nav_lat", "depth": "nav_lev", "time": "time_counter"},
interp_method="nearest",
)
fieldset.add_field(OW_eddy)
OW_area = Field.from_netcdf(
filenames=OW_path,
variable=("OW_area", "area"),
dimensions={"lon": "nav_lon", "lat": "nav_lat", "depth": "nav_lev", "time": "time_counter"},
interp_method="nearest",
)
fieldset.add_field(OW_area)
OW_scale = Field.from_netcdf(
filenames=OW_path,
variable=("OW_scale", "scale"),
dimensions={"lon": "nav_lon", "lat": "nav_lat", "depth": "nav_lev", "time": "time_counter"},
interp_method="nearest",
)
fieldset.add_field(OW_scale)
fieldset = create_fieldset()
fieldset.computeTimeChunk(0,1)
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
I think I should've shown everything above... I also read in MLD and SSH (the same way I did for T), but they of course don't have a depth dimension. So this is working now. For the OW-variables, the depth axis is different (48 instead of the 120 levels which the others have) and the order of dimensions in the ncs is different. |
Beta Was this translation helpful? Give feedback.
-
Thanks for raising this problem, @LeonMock. Do you use the released conda version 3.1.2, or the latest I haven't seen this problem before, but it could be that the issue is because your files contain multiple timeslices. What happens if you try to load only one of your files? Does that work? Also, in your code above I'm wondering how you can first add the OW fields to a FieldSet, and only create the fieldset itself later. Is this really the code you use? Since the details might matter, please use an actually working/breaking code for us to look at. Finally, would it be possible to share some of the files (perhaps a subset in space?) via a file transfer facility, so that we can have a look ourselves and see what's going wrong? |
Beta Was this translation helpful? Give feedback.
-
Thank you @erikvansebille for your help! |
Beta Was this translation helpful? Give feedback.
Hi @LeonMock, sorry for the confusion; I didn't realise indeed that depth and time were swapped; so the
dimensions
fix isn't a real fix, indeed.What could be a proper solution, though, is to swap
time
anddepth
in your OW files. If dods = ds.transpose("time_counter", "z", "y", "x")
and then save the new dataset, the code seems to work. Could you try too?Note that this time of problem is exactly why we want to move to stronger leverage of
xarray
in the new Parcels v4...