I have a year-long data set (netCDF) with time, latitude and longitude as coordinates, and KBDI-AWAP as variable that's sampled every day.
The data is loaded to xarray's Dataset with Python and is printed as below:
print(mds_kbdi)
Output:
<xarray.Dataset>
Dimensions: (latitude: 106, longitude: 193, time: 365)
Coordinates:
* latitude (latitude) float32 -39.2 -39.149525 ... -33.950478 -33.9
* longitude (longitude) float32 140.8 140.84792 140.89584 ... 149.95209 150.0
* time (time) datetime64[ns] 2017-01-01 2017-01-02 ... 2017-12-31
Data variables:
KBDI-AWAP (time, latitude, longitude) float32 dask.array<shape=(365, 106, 193), chunksize=(31, 106, 193)>
Attributes:
creationTime: 1525760660
creationTimeString: Mon May 7 23:24:20 PDT 2018
Conventions: COARDS
Put it in details (for each latitude and longitude):
Date KBDI-AWAP
2017-01-01 10.5
2017-01-02 9.2
2017-01-03 9.8
... ...
2017-12-31 8.2
I would like to resample the KBDI-AWAP values into an interval of a hour. So the dimension of the resampled dataset will be (latitude: 106, longitude: 193, time: 8760). Each KBDI-AWAP value for an hour within the same date should have the same value as the date's value in the original dataset.
The resampled data will be (for each latitude and longitude):
Date KBDI-AWAP
2017-01-01T00:00:00 10.5
2017-01-01T01:00:00 10.5
2017-01-01T02:00:00 10.5
...
2017-01-02T00:00:00 9.2
2017-01-02T01:00:00 9.2
2017-01-02T02:00:00 9.2
...
2017-01-03T00:00:00 9.8
2017-01-03T01:00:00 9.8
2017-01-03T02:00:00 9.8
... ...
... ...
2017-12-31T21:00:00 8.2
2017-12-31T22:00:00 8.2
2017-12-31T23:00:00 8.2
Thinking that I should use the resample function on Dataset, I tried with mds_kbdi_hourly = mds_kbdi.resample(time='H') but this only output a DatasetResample object instead of a new Dataset.
I tried both pad() and ffill() with the DatasetResample object. The resampled data seems to have missed some data with either of them. The generated ['time'] coordindates are
['2017-01-01T00:00:00.000000000'
'2017-01-01T01:00:00.000000000'
'2017-01-01T02:00:00.000000000' ...
'2017-12-30T22:00:00.000000000'
'2017-12-30T23:00:00.000000000'
'2017-12-31T00:00:00.000000000'].
It is missing timestamps from 2017-12-31T01:00:00.000000000 to 2017-12-31T23:00:00.000000000. How to fix this problem?