MetOffice / cube_helper

A Python module, for easier manipulation of Cubes with Iris
https://cube-helper.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
2 stars 4 forks source link

Constrained loading fails if more than one variable in a file #38

Open jonseddon opened 4 years ago

jonseddon commented 4 years ago
var_con = iris.Constraint(cube_func=(lambda c: c.var_name == 'vo'))
vo = ch.load(['nemo_ay652o_1m_19500101-19500201_grid-V.nc'], constraints=var_con) 

fails with

ConstraintMismatchError: failed to merge into a single cube.
  cube.long_name differs: 'VS' != 'VV'
  cube.var_name differs: 'vso' != 'v2o'
  cube.units differs: Unit('unknown') != Unit('m/s')
  cube.attributes keys differ: 'invalid_units'

because in load_from_filelist() line 283:

--> 284                                           iris.load_cube(paths[0])):

iris.load_cube() will fail because there are multiple variables in the file. A new test should be introduced that contains multiple variables in a file. This isn't like CMIP6 data, but many users outside of CMIP6 analysis could work like this.

jonseddon commented 4 years ago

Even with release 2.0.6 loading two raw NEMO files with this constraint fails:

cube aux coordinates differ: 

cube attributes differ: 

    file_name, name, TimeStamp and timeStamp attibutes inconsistent

Deleting file_name, name, TimeStamp and timeStamp attributes from cubes

There was an error in concatenation

---------------------------------------------------------------------------
ConcatenateError                          Traceback (most recent call last)
<ipython-input-5-4578006dbe9b> in <module>
----> 1 mslp = ch.load(glob.glob('nemo_ay652o_1m_*_grid-V.nc'), constraints=var_con)

.../cube_helper-2.0.6/cube_helper/cube_help.py in load(directory, filetype, constraints)
     61             result = iris.cube.CubeList(result)
     62             try:
---> 63                 result = result.concatenate_cube()
     64                 return result
     65             except iris.exceptions.ConcatenateError:

.../iris/cube.py in concatenate_cube(self, check_aux_coords)
    526                 msgs.append('Expected only a single cube, '
    527                             'found {}.'.format(n_res_cubes))
--> 528                 raise iris.exceptions.ConcatenateError(msgs)
    529         else:
    530             msgs = []

ConcatenateError: failed to concatenate into a single cube.
  An unexpected problem prevented concatenation.
  Expected only a single cube, found 2.