CF coordinates get forgotten after operation modifying coordinates

Open
#396 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

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

Research direction

Start by reproducing the shown DataArray example and compare d.cf.coordinates with d.mean("time").cf.coordinates. Trace how CF coordinates are identified before and after the time reduction; done means the reduced result keeps TLON as longitude and TLAT as latitude without adding ULON or ULAT.

Written by the indexing model from the issue text.

Description

I have a DataArray that's similar, but not quite the same as the popds example dataset (the axes aren't labelled, and it has a time dimension):

<xarray.DataArray 'Tair_m' (time: 1, nj: 1080, ni: 1440)>
array([[[nan, nan, ..., nan, nan],
        [nan, nan, ..., nan, nan],
        ...,
        [nan, nan, ..., nan, nan],
        [nan, nan, ..., nan, nan]]], dtype=float32)
Coordinates:
  * time     (time) datetime64[ns] 2255-01-01
    TLON     (nj, ni) float32 nan nan nan nan nan nan ... nan nan nan nan nan
    TLAT     (nj, ni) float32 nan nan nan nan nan nan ... nan nan nan nan nan
    ULON     (nj, ni) float32 nan nan nan nan nan nan ... nan nan nan nan nan
    ULAT     (nj, ni) float32 nan nan nan nan nan nan ... nan nan nan nan nan
Dimensions without coordinates: nj, ni
Attributes:
    units:          C
    long_name:      air temperature
    cell_measures:  area: tarea
    cell_methods:   time: mean
    time_rep:       averaged

And of course, the coordinates get correctly decoded:

>>> d.cf.coordinates
{'longitude': ['TLON'], 'latitude': ['TLAT']}

But if I take the time mean of this dataset, the correct coordinates get forgotten:

>>> d.mean("time").cf.coordinates
{'longitude': ['TLON', 'ULON'], 'latitude': ['TLAT', 'ULAT']}
Dominant language
Python
Stars
181
Forks
49
Avg merge
43m
Merged PRs (30d)
1

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from xarray-contrib/cf-xarray

All issues in xarray-contrib/cf-xarray

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.