Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions xcdat/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from typing import Literal

import cf_xarray as cfxr # noqa: F401
import numpy as np
import xarray as xr

Expand Down Expand Up @@ -122,6 +123,17 @@ def get_dim_coords(
# Example: ["lat", "lon", "time"]
index_keys = obj.indexes.keys()

# FIXME: Attempt -- If index_keys is None, attempt to retrieve keys using
# cf_xarray for the axis. This is a fallback for objects with
# multidimensional coordiantes.
if not index_keys:
try:
obj = obj.cf[axis]
except KeyError:
raise KeyError(
f"Could not find coordinate for dimension '{axis}'"
) from None

# Attempt to map the axis it all of its coordinate variable(s) using the
# axis and coordinate names in the object attributes (if they are set).
# Example: Returns ["time", "time_centered"] with `axis="T"`
Expand Down
13 changes: 6 additions & 7 deletions xcdat/regridder/accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ def horizontal(
f"Tool {e!s} does not exist, valid choices {list(HORIZONTAL_REGRID_TOOLS)}"
) from e

# FIXME: Line 170 -- Can't add bounds for multidimensional coordinates
input_grid = _get_input_grid(self._ds, data_var, ["X", "Y"])
regridder = regrid_tool(input_grid, output_grid, **options)
output_ds = regridder.horizontal(data_var, self._ds)
Expand Down Expand Up @@ -236,13 +237,8 @@ def vertical(
f"Tool {e!s} does not exist, valid choices "
f"{list(VERTICAL_REGRID_TOOLS)}"
) from e
input_grid = _get_input_grid(
self._ds,
data_var,
[
"Z",
],
)

input_grid = _get_input_grid(self._ds, data_var, ["Z"])
regridder = regrid_tool(input_grid, output_grid, **options)
output_ds = regridder.vertical(data_var, self._ds)

Expand Down Expand Up @@ -310,8 +306,10 @@ def _obj_to_grid_ds(obj: xr.Dataset | xr.DataArray) -> xr.Dataset:
# same axis (e.g., (nlat, lat) for X and (nlon, lon) for Y). We only
# need lat_bnds and lon_bnds for the X and Y axes, respectively, and not
# nlat_bnds and nlon_bnds.

for axis, has_bounds in axis_has_bounds.items():
if not has_bounds:
# FIXME: Line 313 --Can't add bounds for multidimensional coordinates
output_ds = output_ds.bounds.add_bounds(axis=axis)

return output_ds
Expand Down Expand Up @@ -387,6 +385,7 @@ def _get_input_grid(ds: xr.Dataset, data_var: str, dup_check_dims: list[CFAxisKe
input_grid = ds.drop_dims(to_drop)

# drops extra dimensions on input grid
# FIXME: Line 389 --Can't add bounds for multidimensional coordinates
grid = input_grid.regridder.grid

# preserve mask on grid
Expand Down
Loading