Skip to content

Commit

Permalink
r.vif.py: add error message (#942)
Browse files Browse the repository at this point in the history
The error message given when one of the input layers has no values (within the computational region) does not help to understand the problem. Added an error message to suggest the possible cause of the error. Print error messages in color.
  • Loading branch information
ecodiv committed Sep 17, 2023
1 parent e79e599 commit 176bf29
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/raster/r.vif/r.vif.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@


# Functions
def prRed(skk):
print("\033[91m {}\033[00m".format(skk))


def prGreen(skk):
print("\033[92m {}\033[00m".format(skk))


CLEAN_RAST = []


Expand Down Expand Up @@ -348,7 +356,13 @@ def main(options, flags):
vifstat = compute_vif2(x, y)
else:
# Compute vif using sample
y = p[:, k]
try:
y = p[:, k]
except IndexError as e:
prRed(f"An error occurred: {str(e)}")
prGreen(
"Tip: check if all input rasters have values within the computation region."
)
x = np.delete(p, k, axis=1)
vifstat = compute_vif(x, y)

Expand Down

0 comments on commit 176bf29

Please sign in to comment.