Skip to content

Commit

Permalink
load_dataset -> open_dataset
Browse files Browse the repository at this point in the history
  • Loading branch information
LuukBlom committed Jan 15, 2025
1 parent c85e88e commit 5c539d0
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion hydromt_sfincs/sfincs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3189,14 +3189,15 @@ def read_forcing(self, data_vars: List = None):
for name in dvars_2d:
fname, rename = self._FORCING_NET[name]
fn = self.get_config(f"{fname}file", abs_path=True)
ds = None
if fn is None or not isfile(fn):
if fn is not None:
self.logger.warning(f"{name}file not found at {fn}")
continue
elif name in ["netbndbzsbzi", "netsrcdis"]:
ds = GeoDataset.from_netcdf(fn, crs=self.crs, chunks="auto")
else:
ds = xr.load_dataset(fn, chunks="auto")
ds = xr.open_dataset(fn, chunks="auto")

rename = {k: v for k, v in rename.items() if k in ds}
if len(rename) > 0:
Expand All @@ -3205,6 +3206,9 @@ def read_forcing(self, data_vars: List = None):
else:
logger.warning(f"No forcing variables found in {fname}file")

if ds is not None:
ds.close()

def write_forcing(self, data_vars: Union[List, str] = None, fmt: str = "%7.2f"):
"""Write forcing to ascii or netcdf (netampr) files.
Filenames are based on the `config` attribute.
Expand Down

0 comments on commit 5c539d0

Please sign in to comment.