home / github / issues

Menu
  • GraphQL API
  • Search all tables

issues: 33272937

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
33272937 MDU6SXNzdWUzMzI3MjkzNw== 121 virtual variables not available when using open_dataset 2443309 closed 0     5 2014-05-11T23:11:21Z 2014-05-16T00:37:39Z 2014-05-16T00:37:39Z MEMBER      

The tutorial provides an example of how to use xray's virtual_variables. The same functionality is not availble from a Dataset object created by open_dataset.

Tutorial:

``` python In [135]: foo_values = np.random.RandomState(0).rand(3, 4) times = pd.date_range('2000-01-01', periods=3) ds = xray.Dataset({'time': ('time', times), 'foo': (['time', 'space'], foo_values)}) ds['time.dayofyear']

Out[135]: <xray.DataArray 'time.dayofyear' (time: 3)> array([1, 2, 3], dtype=int32) Attributes: Empty ```

however, reading a time coordinate / variable from a netCDF4 file, and applying the same logic raises an error:

``` In [136]: ds = xray.open_dataset('sample_for_xray.nc') ds['time']

Out[136]: <xray.DataArray 'time' (time: 4)> array([1979-09-16 12:00:00, 1979-10-17 00:00:00, 1979-11-16 12:00:00, 1979-12-17 00:00:00], dtype=object) Attributes: dimensions: 1 long_name: time type_preferred: int

In [137]: ds['time.dayofyear']


ValueError Traceback (most recent call last) <ipython-input-137-bfe1ae778782> in <module>() ----> 1 ds['time.dayofyear']

/Users/jhamman/anaconda/lib/python2.7/site-packages/xray-0.2.0.dev_cc5e1b2-py2.7.egg/xray/dataset.pyc in getitem(self, key) 408 """Access the given variable name in this dataset as a DataArray. 409 """ --> 410 return data_array.DataArray._constructor(self, key) 411 412 def setitem(self, key, value):

/Users/jhamman/anaconda/lib/python2.7/site-packages/xray-0.2.0.dev_cc5e1b2-py2.7.egg/xray/data_array.pyc in _constructor(cls, dataset, name) 95 if name not in dataset and name not in dataset.virtual_variables: 96 raise ValueError('name %r must be a variable in dataset %r' ---> 97 % (name, dataset)) 98 obj._dataset = dataset 99 obj._name = name

ValueError: name 'time.dayofyear' must be a variable in dataset <xray.Dataset> Dimensions: (time: 4, x: 275, y: 205) Coordinates: time X
x X
y X
Noncoordinates: Wind 0 2 1
Attributes:

sample data for xray from RASM project ```

Is there a reason that the virtual time variables are only available if the dataset is created from a pandas date_range? Lastly, this could be related to the #118 .

{
    "url": "https://api.github.com/repos/pydata/xarray/issues/121/reactions",
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  completed 13221727 issue

Links from other tables

  • 0 rows from issues_id in issues_labels
  • 5 rows from issue in issue_comments
Powered by Datasette · Queries took 0.625ms · About: xarray-datasette