Commit b1755e6e authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

Fixed wrong nodata value detection in case nodata is np.nan.

parent 0fd7b716
......@@ -633,19 +633,21 @@ class GeoArray(object):
:param bandIdx:
:param sz: window size in which corner pixels are analysed
"""
def get_mean_std(corner_subset): return {'mean': np.mean(corner_subset), 'std': np.std(corner_subset)}
wins = [self[0:sz, 0:sz, bandIdx], self[0:sz, -sz:, bandIdx],
self[-sz:, -sz:, bandIdx], self[-sz:, 0:sz, bandIdx]] # UL, UR, LR, LL
means_stds = [get_mean_std(win) for win in wins]
possVals = [i['mean'] for i in means_stds if i['std'] == 0]
means, stds = [np.mean(win) for win in wins], [np.std(win) for win in wins]
possVals = [mean for mean, std in zip(means, stds) if std == 0 or np.isnan(std)]
# possVals==[]: all corners are filled with data; np.std(possVals)==0: noDataVal clearly identified
if possVals:
if np.std(possVals) != 0:
if np.isnan(np.std(possVals)):
# at least one of the possible values is np.nan
nodata = np.nan
else:
# different possible nodata values have been found in the image corner
return 'ambiguous'
nodata = 'ambiguous'
else:
if len(possVals) <= 2:
# each window in each corner
......@@ -654,9 +656,11 @@ class GeoArray(object):
"the correct nodata value."
% (possVals[0], self.basename, ('2 image corners' if len(possVals) == 2 else
'1 image corner')))
return possVals[0]
nodata = possVals[0]
else:
return None
nodata = None
return nodata
def set_gdalDataset_meta(self):
"""Retrieves GDAL metadata from file. This function is only executed once to avoid overwriting of user defined
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment