Skip to content

convert xarray dataset to local timezone #1036

@slharris

Description

@slharris

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:

  • latitude (latitude) float32 -39.2 -39.1495 -39.099 -39.0486 -38.9981 ...
  • longitude (longitude) float32 140.8 140.848 140.896 140.944 140.992 ...
  • time (time) datetime64[ns] 2009-01-01 2009-01-01T01:00:00 ...

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions