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

FIX: Min Max computation for physiographic descriptor #156

Merged
merged 1 commit into from
Mar 28, 2024
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
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)