home / github

Menu
  • Search all tables
  • GraphQL API

issues

Table actions
  • GraphQL API for issues

1 row where user = 46776466 sorted by updated_at descending

✎ View and edit SQL

This data as json, CSV (advanced)

Suggested facets: created_at (date), updated_at (date), closed_at (date)

type 1

  • issue 1

state 1

  • closed 1

repo 1

  • xarray 1
id node_id number title user state locked assignee milestone comments created_at updated_at ▲ closed_at author_association active_lock_reason draft pull_request body reactions performed_via_github_app state_reason repo type
1550569947 I_kwDOAMm_X85ca9Hb 7462 xarray add coordinates to mapping variables yrobink 46776466 closed 0     2 2023-01-20T09:47:39Z 2023-01-24T07:13:45Z 2023-01-24T07:13:45Z NONE      

What happened?

When a netcdf file containing a mapping variable and a height coordinates is opened, the height coordinates is added to the mapping variable.

The minimal example generates a netcdf similar to CMIP6 data remapped on a curvilinear grid (for this example in fact it is also a lat / lon grid), where the curvilinear coordinates x / y are connected to lat / lon and tas with the PlateCarree variable. The PlateCarree variable doesn't contains any coordinates when the netcdf is created, and it is also the case when the netcdf is read with netCDF4. But when it is read with xr.open_dataset, the height coordinates is added to the PlateCarree variable.

What did you expect to happen?

Variables without coordinates should not have any after reading with xarray

Minimal Complete Verifiable Example

```Python import sys,os

import numpy as np import pandas as pd import xarray as xr import netCDF4

Functions

def build_data(): ## Start by build the coordinates x = np.arange( -5 , 10 + 0.1 , 1 ) y = np.arange( 41 , 52 + 0.1 , 1 ) lon,lat = np.meshgrid(x,y) time = pd.date_range( "2000-01-01" , "2005-12-31" ).values

lon = xr.DataArray( lon , dims = ["y","x"] , coords = [y,x] )
lat = xr.DataArray( lat , dims = ["y","x"] , coords = [y,x] )


## Variables
T = xr.DataArray( np.random.normal( size = (time.size,y.size,x.size) ) , dims = ["time","y","x"]  , coords = { "time" : time , "y" : y , "x" : x , "lat" : lat , "lon" : lon } )

## Dataset
odata = xr.Dataset( { "tas" : T , "height" : 2. , "PlateCarree" : 1 } )

## Add attributes
odata.lon.attrs["axis"]          = "x"
odata.lon.attrs["long_name"]     = "longitude coordinate"
odata.lon.attrs["standard_name"] = "longitude"
odata.lon.attrs["units"]         = "degrees_east"

odata.lat.attrs["axis"]          = "y"
odata.lat.attrs["long_name"]     = "latitude coordinate"
odata.lat.attrs["standard_name"] = "latitude"
odata.lat.attrs["units"]         = "degrees_north"

odata.x.attrs["units"]         = "degrees_north"
odata.x.attrs["long_name"]     = "x coordinate of projection"
odata.x.attrs["standard_name"] = "projection_x_coordinate"

odata.y.attrs["units"]         = "degrees_east"
odata.y.attrs["long_name"]     = "y coordinate of projection"
odata.y.attrs["standard_name"] = "projection_y_coordinate"

odata.time.attrs["axis"]          = "T"
odata.time.attrs["standard_name"] = "time"
odata.time.attrs["long_name"]     = "Time axis"

odata.PlateCarree.attrs["grid_mapping_name"] = "plate_carree"
odata.PlateCarree.attrs["epsg"]              = "4326"

odata.tas.attrs["grid_mapping"]  = "PlateCarree"
odata.tas.attrs["standard_name"] = "air_temperature"
odata.tas.attrs["long_name"]     = "Daily Mean Near-Surface Air Temperature"
odata.tas.attrs["units"]         = "Kelvin"
odata.tas.attrs["coordinates"]   = "height lat lon"

odata.height.attrs["standard_name"] = "height"
odata.height.attrs["long_name"] = "height"
odata.height.attrs["units"] = "m"
odata.height.attrs["positive"] = "up"
odata.height.attrs["axis"] = "Z"
odata.height.attrs["name"] = "height"

## Encoding
ny = y.size
nx = x.size
encoding = { "time" : { "dtype" : "double"  , "zlib" : True , "complevel" : 5 , "chunksizes" : (1,) , "units" : "days since 1950-01-01" , "calendar" : "standard" } , 
             "y"    : { "dtype" : "double"  , "zlib" : True , "complevel" : 5 , "chunksizes" : (ny,) } , 
             "x"    : { "dtype" : "double"  , "zlib" : True , "complevel" : 5 , "chunksizes" : (nx,) } , 
             "lat"  : { "dtype" : "double"  , "zlib" : True , "complevel" : 5 , "chunksizes" : (ny,nx) } , 
             "lon"  : { "dtype" : "double"  , "zlib" : True , "complevel" : 5 , "chunksizes" : (ny,nx) } , 
             "tas"  : { "dtype" : "float32" , "zlib" : True , "complevel" : 5 , "chunksizes" : (1,ny,nx) } , 
          "height"  : { "dtype" : "double" } , 
     "PlateCarree"  : { "dtype" : "int32" } }

odata.to_netcdf( "test.nc" , encoding = encoding )

main

if name == "main":

## Start by generate data
build_data()

## Open with xarray
data = xr.open_dataset("test.nc").load()

print("With xarray:")
print(data.PlateCarree) ## height is a coordinate of 'PlateCarree'

## And open with netCDF4
print("="*80)
print("With netCDF4")
with netCDF4.Dataset( "test.nc" , mode = "r" ) as ncfile:
    print(ncfile.variables["PlateCarree"].get_dims()) ## height is not a coordinate of 'PlateCarree'

```

MVCE confirmation

  • [X] Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray.
  • [X] Complete example — the example is self-contained, including all data and the text of any traceback.
  • [X] Verifiable example — the example copy & pastes into an IPython prompt or Binder notebook, returning the result.
  • [X] New issue — a search of GitHub Issues suggests this is not a duplicate.

Relevant log output

No response

Anything else we need to know?

No response

Environment

INSTALLED VERSIONS ------------------ commit: None python: 3.9.12 | packaged by conda-forge | (main, Mar 24 2022, 23:24:38) [Clang 12.0.1 ] python-bits: 64 OS: Darwin OS-release: 22.2.0 machine: arm64 processor: arm byteorder: little LC_ALL: None LANG: fr_FR.UTF-8 LOCALE: ('fr_FR', 'UTF-8') libhdf5: 1.12.1 libnetcdf: 4.8.1 xarray: 2022.9.0 pandas: 1.4.2 numpy: 1.23.2 scipy: 1.8.1 netCDF4: 1.5.8 pydap: None h5netcdf: None h5py: None Nio: None zarr: 2.11.3 cftime: 1.6.0 nc_time_axis: 1.4.1 PseudoNetCDF: None rasterio: None cfgrib: 0.9.10.1 iris: None bottleneck: 1.3.5 dask: 2022.11.0 distributed: 2022.11.0 matplotlib: 3.5.2 cartopy: 0.20.2 seaborn: 0.11.2 numbagg: None fsspec: 2022.5.0 cupy: None pint: 0.19.2 sparse: None flox: None numpy_groupies: None setuptools: 62.3.2 pip: 22.1.1 conda: None pytest: None IPython: 7.31.1 sphinx: 4.5.0
{
    "url": "https://api.github.com/repos/pydata/xarray/issues/7462/reactions",
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  completed xarray 13221727 issue

Advanced export

JSON shape: default, array, newline-delimited, object

CSV options:

CREATE TABLE [issues] (
   [id] INTEGER PRIMARY KEY,
   [node_id] TEXT,
   [number] INTEGER,
   [title] TEXT,
   [user] INTEGER REFERENCES [users]([id]),
   [state] TEXT,
   [locked] INTEGER,
   [assignee] INTEGER REFERENCES [users]([id]),
   [milestone] INTEGER REFERENCES [milestones]([id]),
   [comments] INTEGER,
   [created_at] TEXT,
   [updated_at] TEXT,
   [closed_at] TEXT,
   [author_association] TEXT,
   [active_lock_reason] TEXT,
   [draft] INTEGER,
   [pull_request] TEXT,
   [body] TEXT,
   [reactions] TEXT,
   [performed_via_github_app] TEXT,
   [state_reason] TEXT,
   [repo] INTEGER REFERENCES [repos]([id]),
   [type] TEXT
);
CREATE INDEX [idx_issues_repo]
    ON [issues] ([repo]);
CREATE INDEX [idx_issues_milestone]
    ON [issues] ([milestone]);
CREATE INDEX [idx_issues_assignee]
    ON [issues] ([assignee]);
CREATE INDEX [idx_issues_user]
    ON [issues] ([user]);
Powered by Datasette · Queries took 2241.1ms · About: xarray-datasette