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/2547#issuecomment-436695050,https://api.github.com/repos/pydata/xarray/issues/2547,436695050,MDEyOklzc3VlQ29tbWVudDQzNjY5NTA1MA==,6628425,2018-11-07T16:53:14Z,2018-11-07T16:53:14Z,MEMBER,"The `_FillValue` encoding seems to be preserved with your desired value in my example:
```
$ ncdump -h result.nc
netcdf result {
dimensions:
time = 366 ;
y = 200 ;
x = 200 ;
variables:
int64 time(time) ;
time:units = ""days since 2000-01-01 00:00:00"" ;
time:calendar = ""proleptic_gregorian"" ;
short Rg(time, y, x) ;
Rg:_FillValue = -1s ;
Rg:long_name = ""HWSD sub sum content"" ;
Rg:units = ""percent wt"" ;
Rg:valid_range = 97., 103. ;
double latitude(y, x) ;
latitude:_FillValue = -99999. ;
double longitude(y, x) ;
longitude:_FillValue = -99999. ;
// global attributes:
:Conventions = ""CF-1.0"" ;
:content = ""HARMONIZED WORLD SOIL DATABASE; first it was aggregated to one global file; then the missing areas were filled with interpolated data; then separate tiles were extracted"" ;
:scaling_factor = ""20"" ;
```
Is the time encoding important for your land surface model? That does change in my example (see the units attribute); you might need some special logic to handle that.","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,377947810
https://github.com/pydata/xarray/issues/2547#issuecomment-436679811,https://api.github.com/repos/pydata/xarray/issues/2547,436679811,MDEyOklzc3VlQ29tbWVudDQzNjY3OTgxMQ==,6628425,2018-11-07T16:14:27Z,2018-11-07T16:14:27Z,MEMBER,"Thanks @tommylees112 -- note that the `reindex` and `ffill` methods do not operate in-place, so you'll need to assign the results of them to new variables. You can also do them all in one step:
```
In [1]: import xarray as xr; import pandas as pd; import numpy as np
In [2]: ds = xr.open_dataset('Rg_dummy.nc')
In [3]: times = pd.date_range(""2000-01-01"", ""2000-12-31"", name=""time"")
In [4]: ds['time'] = np.array([times[0]])
In [5]: ds2 = ds.reindex(time=times, method='ffill')
In [6]: ds2.to_netcdf('result.nc')
```
Regarding the issue saving to files -- I can reproduce that issue with older xarray versions. It is related to
#2512 and was fixed in #2513 (i.e. it works with the master version of xarray). The good news is this bug only applies to saving `ds` in my example, not `ds2`, so you should be able to do this with your current setup just fine.","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,377947810
https://github.com/pydata/xarray/issues/2547#issuecomment-436638944,https://api.github.com/repos/pydata/xarray/issues/2547,436638944,MDEyOklzc3VlQ29tbWVudDQzNjYzODk0NA==,6628425,2018-11-07T14:23:42Z,2018-11-07T14:23:42Z,MEMBER,"@tommylees112 I had a look at your dataset and noticed that the time coordinate was not encoded in a way that allows xarray to automatically decode the time values into datetimes. Specifically, the units attribute is not in the format of some unit of time (e.g. 'seconds') since a given reference date.
```
$ ncdump -h Rg_dummy.nc
netcdf Rg_dummy {
dimensions:
time = 1 ;
y = 200 ;
x = 200 ;
variables:
double time(time) ;
time:_FillValue = NaN ;
time:standard_name = ""time"" ;
time:units = ""day as %Y%m%d.%f"" ;
time:calendar = ""proleptic_gregorian"" ;
short Rg(time, y, x) ;
Rg:_FillValue = -1s ;
Rg:long_name = ""HWSD sub sum content"" ;
Rg:units = ""percent wt"" ;
Rg:valid_range = 97., 103. ;
double latitude(y, x) ;
latitude:_FillValue = -99999. ;
double longitude(y, x) ;
longitude:_FillValue = -99999. ;
// global attributes:
:Conventions = ""CF-1.0"" ;
:content = ""HARMONIZED WORLD SOIL DATABASE; first it was aggregated to one global file; then the missing areas were filled with interpolated data; then separate tiles were extracted"" ;
:scaling_factor = ""20"" ;
}
```
This is why `ds.time` is an array of floats when you load the file in. We could discuss how to address that, but depending on your broader needs here that might not be a major concern.
Regarding assigning a new value to the time coordinate, the following should work:
```python
ds['time'] = np.array([times[0]])
```","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,377947810