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
I have weather data with (time, latitude, longitude) dimensions. We construct a DataTree from the data where each node contains the mask for a weather feature. So a node has dimensions (latitude, longitude) with a single value for the time coordinate for the timestep where the feature occurs.
<xarray.DataTree> Group: / │ Dimensions: (time: 8, latitude: 201, longitude: 561) │ Coordinates: │ * time (time) datetime64[ns] 64B 2025-01-01T06:00:00 ... 2025-01-03 │ level float64 8B 950.0 │ * latitude (latitude) float64 2kB -20.0 -20.25 -20.5 ... -69.75 -70.0 │ * longitude (longitude) float64 4kB -80.0 -79.75 -79.5 ... 59.5 59.75 60.0 │ Data variables: (12/21) │ div (time, latitude, longitude) float32 4MB ... │ zg (time, latitude, longitude) float32 4MB 579.5 579.4 ... 417.9 │ hus (time, latitude, longitude) float32 4MB ... │ ta (time, latitude, longitude) float32 4MB <Quantity([[[ 11.937... │ ua (time, latitude, longitude) float32 4MB <Quantity([[[ -6.453... │ va (time, latitude, longitude) float32 4MB <Quantity([[[ 1.910... │ ... ... │ nvo (time, latitude, longitude) float32 4MB -0.09545 ... -0.3291 └── Group: /feature ├── Group: /feature/0 │ Dimensions: (latitude: 201, longitude: 561) │ Coordinates: │ time datetime64[ns] 8B 2025-01-01T06:00:00 │ level float64 8B 950.0 │ * latitude (latitude) float64 2kB -20.0 -20.25 -20.5 ... -69.5 -69.75 -70.0 │ * longitude (longitude) float64 4kB -80.0 -79.75 -79.5 ... 59.5 59.75 60.0 │ Data variables: │ mask (latitude, longitude) float64 902kB nan nan nan ... nan nan nan ├── Group: /feature/1 │ Dimensions: (latitude: 201, longitude: 561) │ Coordinates: │ time datetime64[ns] 8B 2025-01-01T06:00:00 │ level float64 8B 950.0 │ * latitude (latitude) float64 2kB -20.0 -20.25 -20.5 ... -69.5 -69.75 -70.0 │ * longitude (longitude) float64 4kB -80.0 -79.75 -79.5 ... 59.5 59.75 60.0 │ Data variables: │ mask (latitude, longitude) float64 902kB nan nan nan ... nan nan nan ├── Group: /feature/2 │ Dimensions: (latitude: 201, longitude: 561) │ Coordinates: │ time datetime64[ns] 8B 2025-01-01T12:00:00 │ level float64 8B 950.0 │ * latitude (latitude) float64 2kB -20.0 -20.25 -20.5 ... -69.5 -69.75 -70.0 │ * longitude (longitude) float64 4kB -80.0 -79.75 -79.5 ... 59.5 59.75 60.0 │ Data variables: │ mask (latitude, longitude) float64 902kB nan nan nan ... nan nan nan ... ├── Group: /feature/9 │ Dimensions: (latitude: 201, longitude: 561) │ Coordinates: │ time datetime64[ns] 8B 2025-01-02T12:00:00 │ level float64 8B 950.0 │ * latitude (latitude) float64 2kB -20.0 -20.25 -20.5 ... -69.5 -69.75 -70.0 │ * longitude (longitude) float64 4kB -80.0 -79.75 -79.5 ... 59.5 59.75 60.0 │ Data variables: │ mask (latitude, longitude) float64 902kB nan nan nan ... nan nan nan ├── Group: /feature/10 │ Dimensions: (latitude: 201, longitude: 561) │ Coordinates: │ time datetime64[ns] 8B 2025-01-02T18:00:00 │ level float64 8B 950.0 │ * latitude (latitude) float64 2kB -20.0 -20.25 -20.5 ... -69.5 -69.75 -70.0 │ * longitude (longitude) float64 4kB -80.0 -79.75 -79.5 ... 59.5 59.75 60.0 │ Data variables: │ mask (latitude, longitude) float64 902kB nan nan nan ... nan nan nan └── Group: /feature/11 Dimensions: (latitude: 201, longitude: 561) Coordinates: time datetime64[ns] 8B 2025-01-02T18:00:00 level float64 8B 950.0 * latitude (latitude) float64 2kB -20.0 -20.25 -20.5 ... -69.5 -69.75 -70.0 * longitude (longitude) float64 4kB -80.0 -79.75 -79.5 ... 59.5 59.75 60.0 Data variables: mask (latitude, longitude) float64 902kB nan nan nan ... nan nan nan
I want to select all the features within a time range.
When I try dt.sel(time=np.datetime64('2025-01-01')) I get
KeyError: "not all values found in index 'time'. Try setting the `method` keyword argument (example: method='nearest')." Raised whilst mapping function over node with path '.'
Adding method='nearest' I get.
ValueError: Dimensions {'time'} do not exist. Expected one or more of FrozenMappingWarningOnValuesAccess({'latitude': 201, 'longitude': 561}) Raised whilst mapping function over node with path 'feature/0'
I tried using dt.filter(lambda x: x.is_leaf and x.ds.where(x.time==np.datetime64('2025-01-01'))) but I just get back all the nodes.
I tried putting dates in the path, but this only helps for the simplest cases, like a single day or month. This doesn't work if I want to get all the nodes for a three month period.
Is there any way I can achieve this with DataTrees?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I have weather data with (time, latitude, longitude) dimensions. We construct a DataTree from the data where each node contains the mask for a weather feature. So a node has dimensions (latitude, longitude) with a single value for the time coordinate for the timestep where the feature occurs.
I want to select all the features within a time range.
When I try
dt.sel(time=np.datetime64('2025-01-01'))
I getAdding
method='nearest'
I get.I tried using
dt.filter(lambda x: x.is_leaf and x.ds.where(x.time==np.datetime64('2025-01-01')))
but I just get back all the nodes.I tried putting dates in the path, but this only helps for the simplest cases, like a single day or month. This doesn't work if I want to get all the nodes for a three month period.
Is there any way I can achieve this with DataTrees?
Beta Was this translation helpful? Give feedback.
All reactions