Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into fix-pr-hybrid-models
Browse files Browse the repository at this point in the history
  • Loading branch information
nghi-truyen committed Sep 9, 2024
2 parents 9351388 + 9699c96 commit cab0233
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion smash/core/simulation/_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
- `Model.rr_parameters`
- `Model.rr_initial_states`
- `Model.nn_parameters`, if using a hybrid structure model (depending on **hydrological_module**)
- `Model.nn_parameters`, if using a hybrid model structure (depending on **hydrological_module**)
%(parameters_serr_mu_parameters)s
%(parameters_serr_sigma_parameters)s
Expand Down
3 changes: 1 addition & 2 deletions smash/core/simulation/optimize/optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -954,8 +954,7 @@ def _sbs_optimize(
ret["iter_cost"] = np.array([gx])

for iter in range(1, wrap_options.optimize.maxiter * n + 1):
if dxn > ddx:
dxn = ddx
dxn = min(dxn, ddx)
if ddx > 2:
ddx = dxn

Expand Down
26 changes: 16 additions & 10 deletions smash/factory/mesh/mesh.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import warnings
from typing import TYPE_CHECKING

import numpy as np
Expand Down Expand Up @@ -99,10 +100,10 @@ def generate_mesh(
(i.e. in ``ASCII`` file). The **epsg** argument must be filled in.
check_well: `bool`, default True
If True, check the consistency of the flow directions. If some well(s) are detected,
the function will print an error and return a dictionnary with all necessary informations
to identify the well(s). If False, this check is disabled. Notice that the presence of well(s)
could lead to unexpected behaviours such as crashs and inconsistent hydrological results.
Whether to check the consistency of the flow directions. If any wells are detected, the function
will raise a warning and return a dictionary with all necessary information to identify the well(s).
If False, this check is disabled. Note that the presence of wells could lead to unexpected behaviors,
such as crashes or inconsistent hydrological results.
Returns
-------
Expand Down Expand Up @@ -429,13 +430,13 @@ def _generate_mesh_from_bbox(flwdir_dataset: rasterio.DatasetReader, bbox: np.nd
return mesh


def _check_well_in_flowdir(
def _check_well_in_flwdir(
flwdir_dataset: rasterio.DatasetReader,
):
(xmin, _, xres, _, ymax, yres) = _get_transform(flwdir_dataset)
flwdir = _get_array(flwdir_dataset)

well = mw_mesh.check_well_in_flowdir(flwdir)
well = mw_mesh.check_well_in_flwdir(flwdir)

well_coord_x = xmin + np.where(well > 0)[0] * xres
well_coord_y = ymax - np.where(well > 0)[1] * yres
Expand Down Expand Up @@ -463,15 +464,20 @@ def _generate_mesh(
check_well: bool,
) -> dict:
if check_well:
print(r"<\> Checking the consistency of the flow directions ...")
well = _check_well_in_flowdir(flwdir_dataset)
print("</> Checking the consistency of the flow directions")
well = _check_well_in_flwdir(flwdir_dataset)

if np.sum(well["well"]) != 0:
print(r"<\> Error: Well(s) detected in the flow directions.")
warnings.warn(
"Well(s) detected in the flow directions may lead to unexpected hydrological behaviors",
stacklevel=2,
)

flwdir_dataset.close()

return well

print(r"<\> Generate the mesh ...")
print("</> Generating mesh")

if bbox is not None:
return _generate_mesh_from_bbox(flwdir_dataset, bbox, epsg)
Expand Down
4 changes: 2 additions & 2 deletions smash/factory/mesh/mw_mesh.f90
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ subroutine flow_partition_variable(nrow, ncol, npar, flwpar, ncpar, cscpar, cpar

end subroutine flow_partition_variable

subroutine check_well_in_flowdir(nrow, ncol, flwdir, well)
subroutine check_well_in_flwdir(nrow, ncol, flwdir, well)

implicit none

Expand Down Expand Up @@ -507,6 +507,6 @@ subroutine check_well_in_flowdir(nrow, ncol, flwdir, well)

end do

end subroutine check_well_in_flowdir
end subroutine check_well_in_flwdir

end module mw_mesh
3 changes: 1 addition & 2 deletions smash/tests/generate_baseline.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ def compare_baseline(f: h5py.File, new_f: h5py.File):
status = []

for key in all_keys:
if len(key) > max_len_name:
max_len_name = len(key)
max_len_name = max(len(key), max_len_name)

test_name.append(key)

Expand Down

0 comments on commit cab0233

Please sign in to comment.