Hi,
i looked everywhere on the metoffice website, iris documentation and github, but i found no email to send question or request...
i try to use Iris to analyse some NEMO outputs, and i don't want to load all my output with iris.load(), because the files are quite big. So i tried with load.cube, to load only the variable i am interested in.
A problem with NEMO outputs is that the "long name", used as standard name within iris.load, is used a simple description name by NEMO developpers, and these long names are often identical. They will be the same for 2 temperature fields, or 2 salinity fields... So i got errors when using iris.load.cube(file_name,'long_name')
var_name is the one used to identify the variables.
But it seems it is not possible to use the var_name to load a variable with iris.load.cube... am i right ?
Or do you have a trick to use the var_name within the iris.load.cube(s) functions ?
and if not, is it possible to consider it like a possible issue to solve ?
It would so much practical and safer that way.
Many thanks!
Cheers,
Julien
You can send questions to the Iris Users group on google groups, listed on the community page of the SciTools site: http://scitools.org.uk/iris/community.html.
Iris loads data from netcdf in an as-needed way, meaning loading the whole file will only read headers, and the actual data are deferred and loaded as needed. You should be able to use iris.load and load everything, then just select the cube you want and work with that. I don't believe we have a convenient way to load based on var_name. You may be able to do what you need with a load callback which can ignore cubes by raising an IgnoreCubeException. Within the callback you can access the var_name of a cube, and if it is not the one you want just raise iris.exceptions.IgnoreCubeException.
I found this a bit surprising at first as well, a workaround I use to select a particular variable is to create a constraint and pass that to load:
from iris import load, Constraint
variable_constraint = Constraint(cube_func=(lambda c: c.var_name == 'my_variable_name'))
cube = load('...', constraints=variable_constraint)
@duncanwp How about using this in load_cube?
Update:
This one works fine. Thank you!
variable = load_cube('...', constraint=variable_constraint)
Most helpful comment
I found this a bit surprising at first as well, a workaround I use to select a particular variable is to create a constraint and pass that to load: