home / github / issue_comments

Menu
  • Search all tables
  • GraphQL API

issue_comments: 319296663

This data as json

html_url issue_url id node_id user created_at updated_at author_association body reactions performed_via_github_app issue
https://github.com/pydata/xarray/issues/1467#issuecomment-319296663 https://api.github.com/repos/pydata/xarray/issues/1467 319296663 MDEyOklzc3VlQ29tbWVudDMxOTI5NjY2Mw== 6926916 2017-08-01T07:54:43Z 2017-08-01T07:54:43Z NONE

In order to construct a netcdf file with a 2D field on a monthly resolution (for X number of years), I currently use the lines of code mentioned below. Since I do not care about the type of calendar, I just use 360_day, in which each month of the year has 30 days. Perhaps this can be useful for others. In case a better solution is available, please let me know!

``` import numpy as np import pandas as pd import xarray as xr

51 years, saving first day of each month.

mmhours = np.arange(0,(5136024),30*24) attrs = {'units': 'Hours since 1955-01-01T12:00:00', 'calendar' : '360_day'}

target = np.random.rand(len(mmhours),10,10) lat = np.arange(50,51,0.1) lon = np.arange(3,4,0.1)

target_xr = xr.Dataset({'test': (['time', 'lat', 'lon'], target)}, coords={'time': ('time', mmhours, attrs) ,'lat': lat, 'lon': lon})

target_xr.to_netcdf('test.nc', encoding={'test': {'zlib': True}})

```

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  238990919
Powered by Datasette · Queries took 0.539ms · About: xarray-datasette