Skip to content

Commit

Permalink
r.learn.ml2 trap error if training_points do not contain any geometries
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenpawley committed Dec 14, 2020
1 parent 8ab5ba0 commit d218561
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions grass7/raster/r.learn.ml2/rlearnlib/raster.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/usr/bin/env python
import os
import itertools
from subprocess import PIPE
from copy import deepcopy
import re

import grass.script as gs
import numpy as np
Expand Down Expand Up @@ -769,6 +768,9 @@ def extract_pixels(self, rast_name, use_cats=False, as_df=False):
stdout_=PIPE,
).outputs.stdout

if data == "":
gs.fatal("The training pixel locations do not spatially intersect any raster datasets")

data = data.strip().split(os.linesep)
data = [i.split("|") for i in data]
data = np.asarray(data).astype("float32")
Expand Down Expand Up @@ -880,6 +882,9 @@ def extract_points(self, vect_name, fields, na_rm=True, as_df=False):
nodata = np.nan
dtype = np.float32

if len(list(itertools.chain(*rast_data))) == 0:
gs.fatal("There are no training point geometries in the supplied vector dataset")

X = [k.split("|")[1] if k.split("|")[1] != "*" else nodata for k in rast_data]
X = np.asarray(X)
cat = np.asarray([int(k.split("|")[0]) for k in rast_data])
Expand Down

0 comments on commit d218561

Please sign in to comment.