You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importxarrayasxr# 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 to# diagnose and fix when passing it along to GMT for plotting.print("\nMetadata for sliced coordinates:", part.lat.attrs)
Indexing seems to preserve the attrs. If it contains information about the values, then this information will be outdated. Some software, like GMT rely on this information for certain operations. It can manage missing metadata but there is no way to guard against incorrect metadata.
Expected Output
I would expect indexing to drop attrs unless keep_attrs is specified. It's better to have no metadata than to have incorrect metadata.
@shoyer thanks, I missed that issue. I appreciate the complexity of the problem. For now, I'm dropping the actual_range attribute manually but I image other people will have this issue when using grids made with GMT. We're working on the GMT side to issue warnings if we detect that the metadata might be stale.
Code Sample, a copy-pastable example if possible
Output:
Problem description
Indexing seems to preserve the
attrs
. If it contains information about the values, then this information will be outdated. Some software, like GMT rely on this information for certain operations. It can manage missing metadata but there is no way to guard against incorrect metadata.Expected Output
I would expect indexing to drop
attrs
unlesskeep_attrs
is specified. It's better to have no metadata than to have incorrect metadata.Output of
xr.show_versions()
xarray: 0.10.2
pandas: 0.22.0
numpy: 1.14.2
scipy: 1.0.1
netCDF4: 1.3.1
h5netcdf: 0.5.0
h5py: 2.7.1
Nio: None
zarr: None
bottleneck: 1.2.1
cyordereddict: None
dask: 0.17.2
distributed: 1.21.4
matplotlib: 2.2.2
cartopy: None
seaborn: None
setuptools: 39.0.1
pip: 9.0.1
conda: None
pytest: 3.5.0
IPython: 6.2.1
sphinx: 1.7.2
The text was updated successfully, but these errors were encountered: