I am working with xarray to create a new Dataset based on the conditions of values from another Dataset.
The input Dataset object ds_season
is by seasons and has three dimensions as below.
<xarray.Dataset>
Dimensions: (latitude: 106, longitude: 193, season: 4)
Coordinates:
* latitude (latitude) float32 -39.2 -39.149525 ... -33.9
* longitude (longitude) float32 140.8 140.84792 ... 150.0
* season (season) object 'DJF' 'JJA' 'MAM' 'SON'
Data variables:
FFDI 95TH PERCENTILE (season, latitude, longitude) float64 dask.array<shape=(4, 106, 193), chunksize=(4, 106, 193)>
I need to create a new Dataset which has three dimensions latitude, longitude and time. The latitude and longitude should have the same coordinates as the input Dataset, and the time coordinates should be days over 10 years.
For example, the resulting Dataset is like:
<xarray.Dataset>
Dimensions: (latitude: 106, longitude: 193, time: 3653)
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] 1972-01-01T00:00:00 1972-01-02T00:00:00 1972-01-03T00:00:00 ... 1981-12-30T00:00:00 1981-12-31T00:00:00
Data variables:
FFDI 95TH PERCENTILE (time, latitude, longitude) float64 dask.array<shape=(3653, 106, 193), chunksize=(3653, 106, 193)>
The variable for a day should be the same as the variable for the season that the day falls in. This means, 1972-01-01, 1972-02-02 and 1972-02-28 should have the same value as the season DJF has; and 1972-04-01, 1972-05-02 and 1972-05-31 should have the same value as the season MAM has.
I am thinking of the Dataset's where() function but have no clue where to start with. http://xarray.pydata.org/en/stable/generated/xarray.Dataset.where.html?highlight=where#xarray.Dataset.where