Skip to content
Merged
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
7 changes: 2 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ description = "uxarray extension for SCHISM."
readme = "README.rst"
requires-python = ">=3.8,<3.13"
authors = [
{ name = "California Department of Water Resources", email = "knam@water.ca.gov" }
{ name = "California Department of Water Resources", email = "knam@water.ca.gov" },
]
license = { file = "LICENSE" }
keywords = ["suxarray"]
Expand All @@ -35,10 +35,7 @@ dependencies = [
[project.optional-dependencies]
vtk = ["vtk"]

test = [
"pytest>=3",
"vtk"
]
test = ["pytest>=3", "vtk"]

[project.urls]
Homepage = "https://github.com/cadwrdeltamodeling/suxarray"
Expand Down
20 changes: 18 additions & 2 deletions suxarray/core/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ def open_ts_dataset(

return ds

def _choose_netcdf_engine() -> str:
"""Pick an available NetCDF backend for xarray.

Prefer h5netcdf when available to avoid netCDF4 binary issues on
some environments. Fallback to netcdf4 for compatibility.
"""
try:
import h5netcdf # noqa: F401

return "h5netcdf"
except ImportError:
return "netcdf4"


def read_schism_nc(grid: Grid, ds_data: xr.Dataset) -> SxDataset:
ds_data = ux.core.utils._map_dims_to_ugrid(ds_data, grid._source_dims_dict, grid)
if "nSCHISM_vgrid_layers" in ds_data.dims:
Expand Down Expand Up @@ -94,13 +108,15 @@ def open_grid(
`suxarray.Grid`
"""

engine = _choose_netcdf_engine()

# if chunks is None:
# chunks = {
# "time": 12,
# }
ds_out2d = xr.open_mfdataset(
files_out2d,
engine="netcdf4",
engine=engine,
mask_and_scale=False,
chunks=chunks,
preprocess=lambda ds: ds[
Expand Down Expand Up @@ -130,7 +146,7 @@ def open_grid(
if files_zcoords is not None:
ds_zcoords = xr.open_mfdataset(
files_zcoords,
engine="netcdf4",
engine=engine,
chunks=chunks,
join="override",
coords="minimal",
Expand Down
Loading