MetOffice / MetOffice/cube_helper

Constrained loading fails if more than one variable in a file

Open
#38 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
3
Forks
4
PR merge metrics
No merged PRs in 30d

Description

```
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:

``` 283 if not _constraint_compatible(constraint,
--> 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.

Contributor guide

Open the contributing guide

Research direction

Start at load_from_filelist() around line 283 and reproduce the constrained load with the example file containing multiple variables. Add a test fixture or case with multiple variables in one file, then verify that selecting the requested variable succeeds without the reported ConstraintMismatchError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.