home / github / issues

Menu
  • Search all tables
  • GraphQL API

issues: 394625579

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
394625579 MDU6SXNzdWUzOTQ2MjU1Nzk= 2636 open_mfdataset change the attributes of Coordinates 30388627 closed 0     6 2018-12-28T12:24:01Z 2018-12-29T23:47:42Z 2018-12-29T23:47:42Z NONE      

Code Sample

```python import xarray as xr import numpy as np from netCDF4 import Dataset

temp = np.random.randn(2, 2, 3) precip = np.random.rand(2, 2, 3) lon = [[-99.83, -99.32], [-99.79, -99.23]] lat = [[42.25, 42.21], [42.63, 42.59]]

attrs = {'units': 'hours since 2015-01-01'} ds_1 = xr.Dataset({'temperature': (['x', 'y', 'time'], temp)}, coords={'lon': (['x', 'y'], lon), 'lat': (['x', 'y'], lat), 'time': ('time', [100, 101, 102], attrs)})

ds_2 = xr.Dataset({'temperature': (['x', 'y', 'time'], temp+1)}, coords={'lon': (['x', 'y'], lon), 'lat': (['x', 'y'], lat), 'time': ('time', [200, 201, 202], attrs)})

ds_1.to_netcdf('ds1.nc') ds_2.to_netcdf('ds2.nc')

ds = xr.open_mfdataset('ds*.nc') ds.to_netcdf('merge.nc')

with xr.open_dataset('merge.nc') as f: print (f,'\n') print ('---------------------------')

ds_1 = Dataset('ds1.nc') print ('keys of ds_1:') print (ds_1.variables.keys(),'\n') print ('time of ds_1:') print (ds_1.variables['time'],'\n') print ('---------------------------')

merge = Dataset('merge.nc') print ('keys of merge:') print (merge.variables.keys(),'\n') print ('time of merge:') print (merge.variables['time'],'\n')

```

Problem description

As time is the coordinate in xarray.Dataset, it's variable in netCDF4. When netCDF4 is used to read time of merged file , the units is hours since 2015-01-05 04:00:00. I want to keep the attributes of time as hours since 2015-01-01.

Output of all print()

``` <xarray.Dataset> Dimensions: (time: 6, x: 2, y: 2) Coordinates: lon (x, y) float64 ... lat (x, y) float64 ... * time (time) datetime64[ns] 2015-01-05T04:00:00 ... Dimensions without coordinates: x, y Data variables: temperature (x, y, time) float64 ...


keys of ds_1: odict_keys(['temperature', 'lon', 'lat', 'time'])

time of ds_1: <class 'netCDF4._netCDF4.Variable'> int64 time(time) units: hours since 2015-01-01 unlimited dimensions: current shape = (3,) filling on, default _FillValue of -9223372036854775806 used


keys of merge: odict_keys(['lon', 'lat', 'temperature', 'time'])

time of merge: <class 'netCDF4._netCDF4.Variable'> int64 time(time) units: hours since 2015-01-05 04:00:00 calendar: proleptic_gregorian unlimited dimensions: current shape = (6,) filling on, default _FillValue of -9223372036854775806 used ```

{
    "url": "https://api.github.com/repos/pydata/xarray/issues/2636/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
  • 6 rows from issue in issue_comments
Powered by Datasette · Queries took 477.062ms · About: xarray-datasette