Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
davidhassell opened this issue Feb 19, 2024 · 0 comments · Fixed by #714
Closed

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

davidhassell opened this issue Feb 19, 2024 · 0 comments · Fixed by #714
Labels
bug Something isn't working
Milestone

Comments

@davidhassell
Copy link
Collaborator

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
@davidhassell davidhassell added the bug Something isn't working label Feb 19, 2024
@davidhassell davidhassell added this to the 3.17.0 milestone Feb 19, 2024
@davidhassell davidhassell changed the title Bug in cf.Field.subspace and cf.Field.__getitem__ for cyclic subspaces Bug in cf.Field.subspace and cf.Field.__getitem__ for some cyclic subspaces Feb 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
1 participant