Skip to content

Bug in cf.Field.subspace and cf.Field.__getitem__ for some cyclic subspaces #713

@davidhassell

Description

@davidhassell

Between v3.14.0 and v3.16.0, there is a bug which incorrectly positions the data for cyclic subspaces that span the edges of the array - the coordinate metadata are correct but the data array is anchored on its origin left-hand edge, rather than the new origin.

For subspaces derived from 2-d coordinates (e.g. the latitude and longitude of tripolar ocean grids) thee is no problem.

For example:

>>> import cf
>>> f = cf.example_field(0)
>>> g = f[:, -3:-5:1]
>>> print(f)
Field: specific_humidity (ncvar%q)
----------------------------------
Data            : specific_humidity(latitude(5), longitude(8)) 1
Cell methods    : area: mean
Dimension coords: latitude(5) = [-75.0, ..., 75.0] degrees_north
                : longitude(8) = [22.5, ..., 337.5] degrees_east
                : time(1) = [2019-01-01 00:00:00]
>>> print(g)
Field: specific_humidity (ncvar%q)
----------------------------------
Data            : specific_humidity(latitude(5), longitude(6)) 1
Cell methods    : area: mean
Dimension coords: latitude(5) = [-75.0, ..., 75.0] degrees_north
                : longitude(6) = [-112.5, ..., 112.5] degrees_east
                : time(1) = [2019-01-01 00:00:00]g = f[:, -3:-5:1]
>>> f[:, :6].data.equals(g[:, :6].data, verbose=2)  # THIS SHOULD BE False
True
>>> f[:, -3:].data.equals(g[:, :3].data, verbose=2)  # THIS SHOULD BE True
False

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions