You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Can I convert an xarray dataset to a different timezone?
I have tried using similar steps that I would use in pandas to convert from UTC to 'Australia/Sydney'. I have pasted below some of these steps, along with a small section of the dataset I am working with.
Any feedback will be greatly appreciated.
Thank you - ds['time'].to_index() seems to work but I am having trouble replacing the UTC time in the ds with the converted local time in my new ds. I am using .update() because I want to override the original time. However, the time does not seem to have been changed following this step.
#convert pandas datetimeindex to a series and then series to xarray dataarray and then to xray dataset
local_series=time_local.to_series()
local_da=xray.DataArray.from_series(local_series)
local_ds=xray.DataArray.to_dataset(local_da)
#create a new dataset that replaces/updates the UTC time in the original dataset with the local time from the newly created dataset (in pandas)
new_ds=ds.update(local_ds)
Can I convert an xarray dataset to a different timezone?
I have tried using similar steps that I would use in pandas to convert from UTC to 'Australia/Sydney'. I have pasted below some of these steps, along with a small section of the dataset I am working with.
Any feedback will be greatly appreciated.
ds = xray.open_mfdataset('/DATA/WRF///*T_SFC.nc')
import pytz
ds_utc = ds['time'].tz_localize(pytz.UTC)
au_tz = pytz.timezone('Australia/Sydney')
ds_local = ds_utc.astimezone(au_tz)
<xray.Dataset>
Dimensions: (latitude: 106, longitude: 193, time: 17520)
Coordinates:
Data variables:
T_SFC (time, latitude, longitude) float64 13.83 13.86 13.89 13.92 ...
Attributes:
creationTime: 1431922712
creationTimeString: Sun May 17 21:18:32 PDT 2015
Conventions: COARDS
The text was updated successfully, but these errors were encountered: