Skip to content

Subspace ValueError with cyclic axis not spanned by data #756

@sadielbartholomew

Description

@sadielbartholomew

A ValueError: tuple.index(x): x not in tuple is raised when performing a subspace on a Field which should logically work, in the case that there is at least one domain axis construct not spanned by the data which is cyclic.

An example failure is shown below, which was raised in our VISION end-to-end script when it previously worked fine.

This seems to result from an issue introduced in #745, since a git blame shows that line has been changed there and the same subspace worked witout issue before that PR, corresponding to the time I noticed the VISION script throw the error. In which case, apologies I missed this during code review for that PR.

Fix to follow.

Example failure

For a subspace attempt on the following field:

Field: id%UM_m01s51i010_vn1105 (ncvar%UM_m01s51i010_vn1105)
-----------------------------------------------------------
Data            : id%UM_m01s51i010_vn1105(time(5), ncdim%obs(11160)) 1
Cell methods    : time(5): point
Dimension coords: time(5) = [2017-07-03 11:00:00, ..., 2017-07-03 15:00:00] standard
Auxiliary coords: time(ncdim%obs(11160)) = [2017-07-03 11:15:07, ..., 2017-07-03 14:21:06] standard
                : altitude(ncdim%obs(11160)) = [2577.927001953125, ..., 151.16905212402344] m
                : air_pressure(ncdim%obs(11160)) = [751.6758422851562, ..., 1006.53076171875] hPa
                : latitude(ncdim%obs(11160)) = [52.56147766113281, ..., 52.0729866027832] degree_north
                : longitude(ncdim%obs(11160)) = [0.3171832859516144, ..., -0.6249311566352844] degree_east

of:

s0 = m.subspace(
        **{
            f.auxiliary_coordinate("T", key=True): cf.wi(cf.dt(t1), cf.dt(t2)),
            f.dimension_coordinate("T", key=True): [index],
        }
    )

(specific t1, t2 and index values not relevant) results in:

Traceback (most recent call last):
  File "/home/slb93/vision-twine/local-work/cf-vision-flight-e2e.py", line 314, in <module>
    s0 = m.subspace(
         ^^^^^^^^^^^
  File "/home/slb93/git-repos/cf-python/cf/subspacefield.py", line 289, in __call__
    raise error
  File "/home/slb93/git-repos/cf-python/cf/subspacefield.py", line 284, in __call__
    out = field[indices]
          ~~~~~^^^^^^^^^
  File "/home/slb93/git-repos/cf-python/cf/field.py", line 446, in __getitem__
    data_axes.index(axis) for axis in new.cyclic() ###if axis in data_axes
    ^^^^^^^^^^^^^^^^^^^^^
ValueError: tuple.index(x): x not in tuple

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions