issues: 335015296
This data as json
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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
335015296 | MDU6SXNzdWUzMzUwMTUyOTY= | 2247 | Indexing preserves outdated attrs which cause trouble downstream | 290082 | open | 0 | 3 | 2018-06-22T20:51:33Z | 2020-04-05T20:32:19Z | NONE | Code Sample, a copy-pastable example if possible```python import xarray as xr Load a global grid with 1 degree spacing distributed by GMTwhole = xr.open_dataarray('earth_relief_60m.grd') print("Global grid:\n", whole) The grid coordinates have metadata regarding the range (actual_range).This is used to detect if the grid is pixel or node registered.print("\nMetadata for global coordinates:", whole.lat.attrs) Select only between latitudes -40 and 40part = whole.sel(lat=slice(-40, 40)) print("\nSliced grid:\n", part) Slicing preserves the coordinate metadata and now the actual_range is incorrect.This is preserved when saving to netCDF and causes errors that are difficult todiagnose and fix when passing it along to GMT for plotting.print("\nMetadata for sliced coordinates:", part.lat.attrs)
Metadata for global coordinates: OrderedDict([('long_name', 'latitude'), ('units', 'degrees_north'), ('actual_range', array([-90., 90.]))]) Sliced grid: <xarray.DataArray 'z' (lat: 81, lon: 361)> array([[-3062., -3451., -3695., ..., -1504., -3226., -3062.], [-3559., -3515., -3773., ..., -128., -2991., -3559.], [-3552., -3498., -3459., ..., 519., -1149., -3552.], ..., [-5425., -5389., -5268., ..., -5162., -5399., -5425.], [-5385., -5499., -5580., ..., -5407., -5497., -5385.], [-5325., -5937., -5557., ..., -5602., -5572., -5325.]], dtype=float32) Coordinates: * lon (lon) float64 -180.0 -179.0 -178.0 -177.0 -176.0 -175.0 -174.0 ... * lat (lat) float64 -40.0 -39.0 -38.0 -37.0 -36.0 -35.0 -34.0 -33.0 ... Attributes: long_name: z actual_range: [-8425. 5551.] Metadata for sliced coordinates: OrderedDict([('long_name', 'latitude'), ('units', 'degrees_north'), ('actual_range', array([-90., 90.]))]) ``` Problem descriptionIndexing seems to preserve the Expected OutputI would expect indexing to drop Output of
|
{ "url": "https://api.github.com/repos/pydata/xarray/issues/2247/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
13221727 | issue |