Skip to content

Commit

Permalink
edge case in getitem. spatial only feature caching / regridding
Browse files Browse the repository at this point in the history
  • Loading branch information
bnb32 committed Aug 7, 2024
1 parent d04e6e7 commit 3d4114e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
10 changes: 6 additions & 4 deletions sup3r/preprocessing/accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,17 @@ def __getitem__(self, keys) -> Union[T_Array, Self]:
if no_slices:
return out

if not just_coords and not is_fancy:
out = out.isel(**slices)

out = out.data if single_feat else out.as_array()
if just_coords:
return out.as_array()[tuple(slices.values())]
return out[tuple(slices.values())]

if is_fancy:
out = out.data if single_feat else out.as_array()
return out.vindex[tuple(slices.values())]

out = out.isel(**slices)
return out.data if single_feat else out.as_array()
return out

def __getattr__(self, attr):
"""Get attribute and cast to ``type(self)`` if a ``xr.Dataset`` is
Expand Down
11 changes: 6 additions & 5 deletions sup3r/preprocessing/rasterizers/dual.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ class DualRasterizer(Container):
(Usually ERA5 and WTK, respectively). This essentially just regrids the
low-res data to the coarsened high-res grid. This is useful for caching
prepping data which then can go directly to a
:class:`~sup3r.preprocessing.samplers.DualSampler` object for a
:class:`~sup3r.preprocessing.batch_queues.DualBatchQueue`.
:class:`~sup3r.preprocessing.samplers.dual.DualSampler`
:class:`~sup3r.preprocessing.batch_queues.dual.DualBatchQueue`.
Note
----
When first extracting the low_res data make sure to extract a region that
completely overlaps the high_res region. It is easiest to load the full
low_res domain and let :class:`DualRasterizer` select the appropriate
low_res domain and let :class:`.DualRasterizer` select the appropriate
region through regridding.
"""

Expand Down Expand Up @@ -154,8 +154,9 @@ def update_hr_data(self):

hr_data_new = {}
for f in self.hr_data.features:
hr_slices = [f, *[slice(sh) for sh in self.hr_required_shape]]
hr_data_new[f] = self.hr_data[tuple(hr_slices)]
hr_slices = [slice(sh) for sh in self.hr_required_shape]
hr = self.hr_data.to_dataarray().sel(variable=f).data
hr_data_new[f] = hr[tuple(hr_slices)]

hr_coords_new = {
Dimension.LATITUDE: self.hr_lat_lon[..., 0],
Expand Down

0 comments on commit 3d4114e

Please sign in to comment.