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
11 changes: 6 additions & 5 deletions src/nhflotools/pwnlayers/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,9 @@ def get_pwn_layer_model(
remove_nan_layers=True,
)

# Get idomain based on layer thickness
idomain = nlmod.dims.layers.get_idomain(layer_model_active)

# idomain is deliberately not stored: it is derived from layer thickness and goes stale on any
# later geometry edit (e.g. set_model_top). nlmod recomputes it at package-build time via
# nlmod.dims.layers.get_idomain (see nlmod PR #250 / NHFLO/models#120).
return xr.Dataset(
data_vars={
"kh": layer_model_active["kh"],
Expand All @@ -260,7 +260,6 @@ def get_pwn_layer_model(
"xv": ds_regis["xv"],
"yv": ds_regis["yv"],
"icvert": ds_regis["icvert"],
"idomain": idomain,
},
coords={
"x": layer_model_active.coords["x"],
Expand Down Expand Up @@ -307,7 +306,9 @@ def get_top_from_ahn(
top = ds["ahn"].copy()

if replace_surface_water_with_peil:
gdf_surface_water = nlmod.read.rws.get_gdf_surface_water(extent=ds.extent, cachename="surface_water", cachedir=cachedir)
gdf_surface_water = nlmod.read.rws.get_gdf_surface_water(
extent=ds.extent, cachename="surface_water", cachedir=cachedir
)
rws_ds = nlmod.read.rws.discretize_surface_water(
ds, gdf=gdf_surface_water, da_basename="rws_oppwater", cachedir=cachedir, cachename="rws_ds.nc"
)
Expand Down
14 changes: 8 additions & 6 deletions src/nhflotools/pwnlayers3/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def get_pwn_layer_model(
-------
xr.Dataset
Merged dataset with variables 'kh', 'kv', 'botm', 'top', 'area',
'xv', 'yv', 'icvert', and 'idomain'. When ``return_diagnostics``
'xv', 'yv', and 'icvert'. When ``return_diagnostics``
is True, also contains ``cat_botm``, ``cat_kh``, ``cat_kv``,
``botm_pwn``, ``botm_method``, ``kh_method``, and ``kv_method``.
"""
Expand Down Expand Up @@ -221,9 +221,9 @@ def get_pwn_layer_model(
remove_nan_layers=True,
)

# Get idomain based on layer thickness
idomain = nlmod.dims.layers.get_idomain(layer_model_active)

# idomain is deliberately not stored: it is derived from layer thickness and goes stale on any
# later geometry edit (e.g. set_model_top). nlmod recomputes it at package-build time via
# nlmod.dims.layers.get_idomain (see nlmod PR #250 / NHFLO/models#120).
data_vars = {
"kh": layer_model_active["kh"],
"kv": layer_model_active["kv"],
Expand All @@ -233,7 +233,6 @@ def get_pwn_layer_model(
"xv": ds_regis["xv"],
"yv": ds_regis["yv"],
"icvert": ds_regis["icvert"],
"idomain": idomain,
}
if return_diagnostics:
# Category arrays share the merged layer dim
Expand Down Expand Up @@ -437,6 +436,7 @@ def get_ds(
transition,
)


def get_top(
*,
ds,
Expand Down Expand Up @@ -470,7 +470,9 @@ def get_top(
top = ds["ahn"].copy().rename("top")
if isinstance(fill_northsea, str) and fill_northsea == "bathymetry":
da_bathymetry = nlmod.read.rws.download_bathymetry(ds.extent, cachedir=cachedir, cachename="rws_bathymetry")
da_bathymetry_unstr = nlmod.dims.resample.structured_da_to_ds(da_bathymetry, ds, method="average", nodata=np.nan)
da_bathymetry_unstr = nlmod.dims.resample.structured_da_to_ds(
da_bathymetry, ds, method="average", nodata=np.nan
)
fill_mask = np.logical_and(top.isnull(), da_bathymetry_unstr.notnull())
top.values = xr.where(fill_mask, da_bathymetry_unstr, top)

Expand Down
Loading