Skip to content

Commit

Permalink
FIX: Min Max computation for physiographic descriptor
Browse files Browse the repository at this point in the history
This commits resolves an issue when computing min and max value
of a physiographic descriptor when there are missing values that
are converted to -99
  • Loading branch information
inoelloc committed Mar 28, 2024
1 parent 18c911e commit 14128e9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
6 changes: 6 additions & 0 deletions doc/source/release/1.0.0-notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -705,3 +705,9 @@ Error in projected gradient value with ANN mapping

There was an error in the values of the projected gradient when using ANN mapping. The current iteration was
printing the projected gradient of the next iteration.

Error when computing min and max of physiograhic descriptor
***********************************************************

There was an error when computing the min and max of a physiograhic descriptor if there is no data (i.e.,
sea in the domain). No data from tif file are converted to -99 which leads to a wrong minimal value.
28 changes: 20 additions & 8 deletions smash/core/model/_read_input_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ def _read_qobs(setup: SetupDT, mesh: MeshDT, input_data: Input_DataDT):
stacklevel=2,
)
else:

ind_start_dat = max(0, start_diff)
ind_end_dat = min(dat.index.max(), end_diff)
ind_start_arr = max(0, -start_diff)
Expand Down Expand Up @@ -461,15 +460,28 @@ def _read_descriptor(setup: SetupDT, mesh: MeshDT, input_data: Input_DataDT):
miss.append(name)

else:
input_data.physio_data.descriptor[..., i] = _read_windowed_raster(path[0], mesh)
input_data.physio_data.l_descriptor[i] = np.min(input_data.physio_data.descriptor[..., i])
input_data.physio_data.u_descriptor[i] = np.max(input_data.physio_data.descriptor[..., i])
# % Check if descriptors are uniform
if input_data.physio_data.l_descriptor[i] == input_data.physio_data.u_descriptor[i]:
desc = _read_windowed_raster(path[0], mesh)
mask = desc != -99.0

# % Check if descriptor contains only no data
if not np.any(mask):
raise ValueError(
f"Invalid descriptor '{name}'. It contains only missing values on the selected domain"
)

low = np.min(desc, where=mask, initial=np.inf)
upp = np.max(desc, where=mask, initial=-np.inf)

# % Check if descriptor is uniform
if low == upp:
raise ValueError(
f"Reading spatially uniform descriptor '{name}'. It must be removed to perform "
f"optimization"
f"Invalid descriptor '{name}'. Spatially uniform values on the selected domain. It must "
"be removed to perform optimization"
)
# % Assign values
input_data.physio_data.descriptor[..., i] = desc
input_data.physio_data.l_descriptor[i] = low
input_data.physio_data.u_descriptor[i] = upp

if miss:
warnings.warn(f"Missing {len(miss)} descriptor file(s): {miss}", stacklevel=2)

0 comments on commit 14128e9

Please sign in to comment.