issue_comments: 418188977
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/1844#issuecomment-418188977 | https://api.github.com/repos/pydata/xarray/issues/1844 | 418188977 | MDEyOklzc3VlQ29tbWVudDQxODE4ODk3Nw== | 6628425 | 2018-09-03T20:30:45Z | 2018-09-03T20:30:45Z | MEMBER | No worries @chiaral; I agree on the xarray side this isn't so well documented (you have to follow the link to the pandas description of the datetime components). Unfortunately there is not a simple attribute for grouping by matching month and day. It is possible to define your own vector of integers for this purpose, however. Perhaps you've already found a workaround, but just in case, here is one way to define a "modified ordinal day" that you can use in a In [2]: from datetime import datetime In [3]: dates = [datetime(1999, 1, 1), datetime(1999, 3, 1), ...: datetime(2000, 1, 1), datetime(2000, 3, 1)] ...: In [4]: da = xr.DataArray([1, 2, 3, 4], coords=[dates], dims=['time']) In [5]: not_leap_year = xr.DataArray(~da.indexes['time'].is_leap_year, coords=da.coords) In [6]: march_or_later = da.time.dt.month >= 3 In [7]: ordinal_day = da.time.dt.dayofyear In [8]: modified_ordinal_day = ordinal_day + (not_leap_year & march_or_later) In [9]: modified_ordinal_day = modified_ordinal_day.rename('modified_ordinal_day') In [10]: modified_ordinal_day Out[10]: <xarray.DataArray 'modified_ordinal_day' (time: 4)> array([ 1, 61, 1, 61]) Coordinates: * time (time) datetime64[ns] 1999-01-01 1999-03-01 2000-01-01 2000-03-01 In [11]: da.groupby(modified_ordinal_day).mean('time')
Out[11]:
<xarray.DataArray (modified_ordinal_day: 2)>
array([2., 3.])
Coordinates:
* modified_ordinal_day (modified_ordinal_day) int64 1 61
In [13]: da.groupby(ordinal_day).mean('time') Out[13]: <xarray.DataArray (dayofyear: 3)> array([2., 2., 4.]) Coordinates: * dayofyear (dayofyear) int64 1 60 61 ``` |
{ "total_count": 5, "+1": 5, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
290023410 |