home / github / issues

Menu
  • GraphQL API
  • Search all tables

issues: 323359733

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
323359733 MDU6SXNzdWUzMjMzNTk3MzM= 2135 use CF conventions to enhance plot labels 1197350 closed 0     4 2018-05-15T19:53:51Z 2018-06-02T00:10:26Z 2018-06-02T00:10:26Z MEMBER      

Elsewhere in xarray we use CF conventions to help with automatic decoding of datasets. Here I propose we consider using CF metadata conventions to improve the automatic labelling of plots. If datasets declare long_name, standard_name, and units attributes, we could use these instead of the variable name to label the relevant axes / colorbars. This feature would have helped me avoid several past mistakes due to my failure to examine the units attribute (e.g. data given in cm when I assumed m).

Code Sample, a copy-pastable example if possible

Here I create some data with relevant attributes

python import xarray as xr import numpy as np ds = xr.Dataset({'foo': ('x', np.random.rand(10), {'long_name': 'height', 'units': 'm'})}, coords={'x': ('x', np.arange(10), {'long_name': 'distance', 'units': 'km'})}) ds.foo.plot()

Problem description

We have neglected the variable attributes, which would provide better axis labels.

Expected Output

Consider this instead: python def label_from_attrs(da): attrs = da.attrs if 'long_name' in attrs: name = attrs['long_name'] elif 'standard_name' in attrs: name = attrs['standard_name'] else: name = da.name if 'units' in da.attrs: units = ' [{}]'.format(da.attrs['units']) label = name + units return label ds.foo.plot() plt.xlabel(label_from_attrs(ds.x)) plt.ylabel(label_from_attrs(ds.foo))

I feel like this would be a sensible default. But it would be a breaking change. We could make it optional with a keyword like labels_from_attrs=True.

Output of xr.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 3.6.5.final.0 python-bits: 64 OS: Linux OS-release: 4.4.111+ machine: x86_64 processor: x86_64 byteorder: little LC_ALL: en_US.UTF-8 LANG: en_US.UTF-8 LOCALE: en_US.UTF-8 xarray: 0.10.3+dev13.g98373f0 pandas: 0.22.0 numpy: 1.14.3 scipy: 1.0.1 netCDF4: 1.3.1 h5netcdf: 0.5.1 h5py: 2.7.1 Nio: None zarr: 2.2.1.dev2 bottleneck: 1.2.1 cyordereddict: None dask: 0.17.4 distributed: 1.21.8 matplotlib: 2.2.2 cartopy: None seaborn: None setuptools: 39.1.0 pip: 9.0.1 conda: 4.3.29 pytest: 3.5.1 IPython: 6.3.1 sphinx: None
{
    "url": "https://api.github.com/repos/pydata/xarray/issues/2135/reactions",
    "total_count": 1,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 1,
    "rocket": 0,
    "eyes": 0
}
  completed 13221727 issue

Links from other tables

  • 2 rows from issues_id in issues_labels
  • 4 rows from issue in issue_comments
Powered by Datasette · Queries took 0.707ms · About: xarray-datasette