Commit 10ca3f53 authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

Added minimal version of geoarray.


Signed-off-by: Daniel Scheffler's avatarDaniel Scheffler <danschef@gfz-potsdam.de>
parent 27a16136
Pipeline #15218 passed with stages
in 5 minutes and 22 seconds
......@@ -12,6 +12,7 @@ test_spechomo:
script:
- source /root/miniconda3/bin/activate ci_env
- conda install -y -c conda-forge "scikit-learn=0.23.2" # FIXME remove as soon as docker container is rebuilt
- pip install 'geoarray>=0.10.4' # FIXME remove as soon as docker container is rebuilt
# run nosetests
- make nosetests # test are called here
......
......@@ -16,6 +16,7 @@ History
(causes faulty predictions).
* Bugfix for only choosing 25 spectra in classifier creation in case the maximum angle threshold is automatically
set to 0 because there are many well matching spectra.
* Added minimal version of geoarray.
0.8.2 (2020-10-12)
......
......@@ -41,7 +41,7 @@ with open("spechomo/version.py") as version_file:
req = [
'dill',
'geoarray',
'geoarray>=0.10.4',
'matplotlib',
'natsort',
'nested_dict',
......
......@@ -96,8 +96,11 @@ class SpectralHomogenizer(object):
np.max(outarr) <= np.iinfo(np.int16).max:
outarr = outarr.astype(np.int16)
elif np.min(outarr) >= np.iinfo(np.int32).min and np.max(outarr) <= np.iinfo(np.int32).max:
outarr = outarr.astype(np.int32)
else:
raise TypeError('The interpolated data cube cannot be cast into a 16- or 32-bit integer array.')
......@@ -405,7 +408,8 @@ class RSImage_ClusterPredictor(object):
if self.classif_alg == 'RF':
train_spectra = np.vstack([classifier.MLdict[clust].cluster_sample_spectra
for clust in range(classifier.n_clusters)])
train_labels = list(np.hstack([[i] * 100 for i in range(classifier.n_clusters)]))
train_labels = list(np.hstack([[i] * 100
for i in range(classifier.n_clusters)]))
else:
train_spectra = classifier.cluster_centers
train_labels = classifier.cluster_pixVals
......@@ -424,7 +428,10 @@ class RSImage_ClusterPredictor(object):
% time.strftime("%H:%M:%S", time.gmtime(time.time() - t0)))
else:
self.classif_map = GeoArray(np.full((image.rows, image.cols), classifier.cluster_pixVals[0], np.int16),
self.classif_map = GeoArray(np.full((image.rows,
image.cols),
classifier.cluster_pixVals[0],
np.int16),
nodata=cmap_nodataVal)
# overwrite all pixels where the input image contains nodata in ANY band
......@@ -432,7 +439,8 @@ class RSImage_ClusterPredictor(object):
if in_nodataVal is not None and cmap_nodataVal is not None:
self.classif_map[np.any(image[:] == image.nodata, axis=2)] = cmap_nodataVal
self.distance_metrics = np.zeros_like(self.classif_map, np.float32)
self.distance_metrics = np.zeros_like(self.classif_map,
np.float32)
####################
# apply prediction #
......@@ -446,9 +454,17 @@ class RSImage_ClusterPredictor(object):
# NOTE: prediction is applied in 1000 x 1000 tiles to save memory (because classifier.predict returns float32)
t0 = time.time()
out_nodataVal = out_nodataVal if out_nodataVal is not None else image.nodata
image_predicted = GeoArray(np.empty((image.rows, image.cols, classifier.tgt_n_bands), dtype=image.dtype),
geotransform=image.gt, projection=image.prj, nodata=out_nodataVal,
bandnames=['B%s' % i if len(i) == 2 else 'B0%s' % i for i in classifier.tgt_LBA])
image_predicted = GeoArray(np.empty((image.rows,
image.cols,
classifier.tgt_n_bands),
dtype=image.dtype),
geotransform=image.gt,
projection=image.prj,
nodata=out_nodataVal,
bandnames=['B%s' % i
if len(i) == 2
else 'B0%s' % i
for i in classifier.tgt_LBA])
if classifier.n_clusters > 1 and\
self.classif_map.ndim > 2:
......@@ -458,6 +474,7 @@ class RSImage_ClusterPredictor(object):
dist_norm = (self.distance_metrics - dist_min) /\
(dist_max - dist_min)
weights = 1 - dist_norm
else:
weights = None
......
......@@ -6,7 +6,7 @@ channels: &id1
dependencies:
- python>=3.7.*
- pip
- geoarray>=0.9.0
- geoarray>=0.10.4
- matplotlib
- numpy
- pandas
......
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