-
Notifications
You must be signed in to change notification settings - Fork 149
Closed
Description
#795 has an unexpected repercussion (for me): The inserted hazard data now has to provide an "event" dimension that can be interpreted as datetime. I think this is unnecessarily strict. Consider the following code:
import xarray as xr
import numpy as np
from climada.hazard.base import Hazard
intensity = np.array([[[0, 1, 2], [3, 4, 5]], [[6, 7, 8], [9, 10, 11]]])
number = np.array([1, 2])
latitude = np.array([0, 1])
longitude = np.array([0, 1, 2])
dset = xr.Dataset(
{
"intensity": (["number", "latitude", "longitude"], intensity),
},
dict(number=number, latitude=latitude, longitude=longitude),
)
Hazard.from_xarray_raster(
dset, "", "", intensity="intensity", coordinate_vars={"event": "number"}
)This results in
TypeError: '.dt' accessor only available for DataArray with datetime64 timedelta64 dtype or for arrays containing cftime datetime objects.
Providing event names explicitly does not help, because the default values are always evaluated in the current implementation.
dset["event_name"] = ["a", "b"]
Hazard.from_xarray_raster(
dset, "", "", intensity="intensity", coordinate_vars={"event": "number"}
) # Same errorNote that following line is always evaluated, even if the default value is not used:
climada_python/climada/hazard/base.py
Line 843 in 0b06f3f
| data[coords["event"]].dt.strftime("%Y-%m-%d").values.flatten().tolist(), |
So, could we maybe just drop this default value altogehter? The default event name could just be a list of empty strings.
Metadata
Metadata
Assignees
Labels
No labels