cf-xarray icon indicating copy to clipboard operation
cf-xarray copied to clipboard

item assignment

Open raybellwaves opened this issue 2 years ago • 1 comments

Couldn't see an issue open for this. It may also not be in the roadmap.

import xarray as xr
ds = xr.open_zarr("s3://era5-pds/zarr/2021/01/data/air_temperature_at_2_metres.zarr").isel(lat=0, lon=0)
# coord named time0 with standard_name: time
# want to change time to be in a local timezone
# in xarray
ds["time0"] = ds["time0"].to_index().tz_localize("UTC").tz_convert("US/Eastern").tz_localize(None).to_numpy())
# feature request in cf xarray
ds.cf["time"] = ds.cf["time"].to_index().tz_localize("UTC").tz_convert("US/Eastern").tz_localize(None).to_numpy())
TypeError: 'CFDatasetAccessor' object does not support item assignment

raybellwaves avatar Sep 06 '21 03:09 raybellwaves

I think i'm just after the mapping here e.g. time_dim = ds.cf["time"].name

then would be ds[time_dim] = ds[time_dim].to_index().tz_localize("UTC").tz_convert("US/Eastern").tz_localize(None).to_numpy())

raybellwaves avatar Sep 06 '21 03:09 raybellwaves