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/3053#issuecomment-508995115,https://api.github.com/repos/pydata/xarray/issues/3053,508995115,MDEyOklzc3VlQ29tbWVudDUwODk5NTExNQ==,21049064,2019-07-07T12:17:12Z,2019-07-07T12:17:12Z,NONE,Thanks closing!,"{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,462010865
https://github.com/pydata/xarray/issues/3053#issuecomment-508992414,https://api.github.com/repos/pydata/xarray/issues/3053,508992414,MDEyOklzc3VlQ29tbWVudDUwODk5MjQxNA==,6628425,2019-07-07T11:36:04Z,2019-07-07T11:36:04Z,MEMBER,Glad I could help! Feel free to close this issue if you don't have any further questions on this topic (you'll still be able to refer to it later).,"{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,462010865
https://github.com/pydata/xarray/issues/3053#issuecomment-508544556,https://api.github.com/repos/pydata/xarray/issues/3053,508544556,MDEyOklzc3VlQ29tbWVudDUwODU0NDU1Ng==,21049064,2019-07-04T17:29:25Z,2019-07-04T17:29:25Z,NONE,"This is the greatest thing since sliced bread thankyou @spencerkclark !!
I have been referring to this constantly for the last week :D ","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,462010865
https://github.com/pydata/xarray/issues/3053#issuecomment-506747197,https://api.github.com/repos/pydata/xarray/issues/3053,506747197,MDEyOklzc3VlQ29tbWVudDUwNjc0NzE5Nw==,6628425,2019-06-28T14:07:40Z,2019-06-28T14:07:40Z,MEMBER,"Sure thing -- that's a valid concern. Perhaps it makes sense then to retain the MultiIndex that gets created through stacking:
```
stacked = ds.stack(time=('initialisation_date', 'forecast_horizon'))
```
Then you can select via the MultiIndex levels, e.g.
```
>>> stacked.sel(forecast_horizon=np.timedelta64(28, 'D'))
Dimensions: (initialisation_date: 12, lat: 36, lon: 45, number: 51)
Coordinates:
* lon (lon) float64 33.5 33.7 33.9 34.1 ... 41.85 42.05 42.25
* lat (lat) float64 -5.175 -5.176 -5.177 ... -5.201 -5.202
* number (number) int64 0 1 2 3 4 5 6 7 ... 44 45 46 47 48 49 50
valid_time (initialisation_date) datetime64[ns] 2018-02-28 ... 2019-01-28
* initialisation_date (initialisation_date) datetime64[ns] 2018-01-31 ... 2018-12-31
Data variables:
precip (number, lat, lon, initialisation_date) float64 0.4954 ... 0.5873
```
Or, if you prefer to select using the `'valid_time'` coordinate, you can do:
```
>>> stacked.swap_dims({'time': 'valid_time'}).sel(valid_time='2018-04')
Dimensions: (lat: 36, lon: 45, number: 51, valid_time: 7)
Coordinates:
* lon (lon) float64 33.5 33.7 33.9 34.1 ... 41.65 41.85 42.05 42.25
* lat (lat) float64 -5.175 -5.176 -5.177 -5.177 ... -5.2 -5.201 -5.202
* number (number) int64 0 1 2 3 4 5 6 7 8 ... 42 43 44 45 46 47 48 49 50
* valid_time (valid_time) datetime64[ns] 2018-04-02 2018-04-03 ... 2018-04-30
time (valid_time) object (Timestamp('2018-01-31 00:00:00', freq='M'), Timedelta('61 days 00:00:00')) ... (Timestamp('2018-03-31 00:00:00', freq='M'), Timedelta('30 days 00:00:00'))
Data variables:
precip (number, lat, lon, valid_time) float64 -1.084 0.8517 ... 1.784
```","{""total_count"": 1, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 1, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,462010865
https://github.com/pydata/xarray/issues/3053#issuecomment-506730153,https://api.github.com/repos/pydata/xarray/issues/3053,506730153,MDEyOklzc3VlQ29tbWVudDUwNjczMDE1Mw==,21049064,2019-06-28T13:17:04Z,2019-06-28T13:17:42Z,NONE,"Thanks! Your assumption was correct, apologies for the mistake!
This might be asking for too much but is there any way I can keep track of the `forecast_horizon` or `initialisation_date`? The only issue I can foresee is that I won't be able to distinguish between the forecasts for the same date, even though those initialised closest to the `valid_time` will likely have more information in them than those initialised a long time before.
What I'm asking is can I add a new dimension to my original `ds` so that I have the OPTION to select by either `valid_time`/`time` or by `forecast_horizon`/`initialisation_date`
## So I would be looking for something like:
```
Dimensions: (forecast_horizon: 24, initialisation_date: 12, lat: 36, lon: 45, number: 51, time: 288)
Coordinates:
* lon (lon) float64 33.5 33.7 33.9 34.1 34.3 ... 41.65 41.85 42.05 42.25
* lat (lat) float64 -5.175 -5.176 -5.177 -5.177 ... -5.2 -5.201 -5.202
* number (number) int64 0 1 2 3 4 5 6 7 8 9 ... 42 43 44 45 46 47 48 49 50
* initialisation_date (initialisation_date) datetime64[ns] 2018-01-31 ... 2018-12-31
* forecast_horizon (forecast_horizon) timedelta64[ns] 28 days ... 215 days
* time (time) datetime64[ns] 2018-04-02 2018-04-03 ... 2018-04-30
Data variables:
precip (forecast_horizon, initialisation_date, number, lat, lon, time) float64 0.2684 0.8408 ... 1.7 -0.383
```","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,462010865
https://github.com/pydata/xarray/issues/3053#issuecomment-506725234,https://api.github.com/repos/pydata/xarray/issues/3053,506725234,MDEyOklzc3VlQ29tbWVudDUwNjcyNTIzNA==,6628425,2019-06-28T13:01:03Z,2019-06-28T13:01:58Z,MEMBER,"Thanks for the easy to copy and paste example. In the `'valid_time'` DataArray, should the dimension named `'step'` instead be named `'forecast_horizon'`?
Under that assumption, I think the simplest approach is to stack the `'initialisation_date'` and `'forecast_horizon'` dimensions, and assign the stacked version of `'valid_time'` as the coordinate:
```python
stacked = ds.stack(time=('initialisation_date', 'forecast_horizon'))
stacked['time'] = stacked.valid_time
stacked = stacked.drop('valid_time')
```
Then you can select times as normal, e.g. `stacked.sel(time='2018-04')` returns:
```
Dimensions: (lat: 36, lon: 45, number: 51, time: 7)
Coordinates:
* lon (lon) float64 33.5 33.7 33.9 34.1 34.3 ... 41.65 41.85 42.05 42.25
* lat (lat) float64 -5.175 -5.176 -5.177 -5.177 ... -5.2 -5.201 -5.202
* number (number) int64 0 1 2 3 4 5 6 7 8 9 ... 42 43 44 45 46 47 48 49 50
* time (time) datetime64[ns] 2018-04-02 2018-04-03 ... 2018-04-30
Data variables:
precip (number, lat, lon, time) float64 0.2684 0.8408 ... 1.7 -0.383
```","{""total_count"": 1, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 1, ""rocket"": 0, ""eyes"": 0}",,462010865