Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create constant infiltration rates based on lulc and reclass_table #103

Merged
merged 5 commits into from
Jul 12, 2023
Merged
Changes from 1 commit
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
21 changes: 12 additions & 9 deletions hydromt_sfincs/sfincs.py
Original file line number Diff line number Diff line change
Expand Up @@ -972,31 +972,34 @@ def setup_constant_infiltration(
bbox=self.mask.raster.transform_bounds(4326),
buffer=10,
)
da_inf = da_inf.raster.mask_nodata() # set nodata to nan
elif lulc is not None:
# landuse/landcover should always be combined with mapping
if reclass_table is None and isinstance(lulc, str):
reclass_table = join(DATADIR, "qinf", f"{lulc}_mapping.csv")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this to point the the "data/lulc" folder. Should we also modify the tables in there to contain a qinf column?

if (
not os.path.isfile(reclass_table)
and reclass_table not in self.data_catalog
):
raise IOError(f"Infiltration mapping file not found: {reclass_table}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work if reclass_table is a pandas DataFrame

reclass_table = join(DATADIR, "lulc", f"{lulc}_mapping.csv")
if reclass_table is None:
raise IOError(
f"Infiltration mapping file should be provided for {lulc}"
)
da_lulc = self.data_catalog.get_rasterdataset(
lulc,
bbox=self.mask.raster.transform_bounds(4326),
buffer=10,
variables=["lulc"],
)
df_map = self.data_catalog.get_dataframe(reclass_table, index_col=0)
df_map = self.data_catalog.get_dataframe(
reclass_table,
variables=["qinf"],
index_col=0, # driver kwargs
)
# reclassify
da_inf = da_lulc.raster.reclassify(df_map[["qinf"]])["qinf"]
da_inf = da_lulc.raster.reclassify(df_map)["qinf"]
else:
raise ValueError(
"Either qinf or lulc must be provided when setting up constant infiltration."
)

# reproject infiltration data to model grid
da_inf = da_inf.raster.mask_nodata() # set nodata to nan
da_inf = da_inf.raster.reproject_like(self.mask, method=reproj_method)

# check on nan values
Expand Down
Loading