Commit 3a3c74a2 authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

Reference cubes are now clustered separately; cluster map is not copied from Sentinel-2 anymore.

parent 81193c8d
Pipeline #3052 failed with stage
in 20 minutes and 16 seconds
......@@ -1300,19 +1300,15 @@ class ClusterClassifier_Generator(object):
return ML
def cluster_refcube_spectra(self, n_clusters=50, CPUs=24):
# type: (int, int) -> np.ndarray
"""Generate cluster labels for the reference cubes passed to __init__().
NOTE: The labels are computed based on the reference cube with the most spectral bands.
These computed labels apply to all input refcubes because the refcubes are spatially equal and
differ only in their spectral information.
@staticmethod
def cluster_refcube_spectra(cube2cluster, n_clusters=50, CPUs=24):
# type: (RefCube, int, int) -> np.ndarray
"""Generate cluster labels for the given reference cube.
:param n_clusters: number of clusters to be used for KMeans clustering
:param CPUs: number of CPUs to be used for KMeans clustering
:param cube2cluster: reference cube to be clustered
:param n_clusters: number of clusters to be used for KMeans clustering
:param CPUs: number of CPUs to be used for KMeans clustering
"""
# get the refcube with the most spectral bands
cube2cluster = self.refcubes[int(np.argmax([inRC.data.bands for inRC in self.refcubes]))]
# use this refcube for KMeans clustering
km = KMeansRSImage(cube2cluster.data, n_clusters=n_clusters, CPUs=CPUs)
......@@ -1334,16 +1330,17 @@ class ClusterClassifier_Generator(object):
:param CPUs: number of CPUs to be used for KMeans clustering
:param kwargs: keyword arguments to be passed to machine learner
"""
# get cluster labels once (for refcube with the most spectral bands)
print('Clustering reference cubes (%s clusters)...' % n_clusters)
labels1D = self.cluster_refcube_spectra(n_clusters=n_clusters, CPUs=CPUs)
# build the classifier collections with separate classfifiers for each cluster
for src_cube in self.refcubes:
# build the classifier collections with separate classifiers for each cluster
for src_cube in self.refcubes: # type: RefCube
cls_collection = nested_dict()
fName_cls = get_filename_classifier_collection(method, src_cube.satellite, src_cube.sensor,
n_clusters=n_clusters)
# get cluster labels for for source cube
print('Clustering %s %s reference cube (%s clusters)...'
% (src_cube.satellite, src_cube.sensor, n_clusters))
labels1D = self.cluster_refcube_spectra(src_cube, n_clusters=n_clusters, CPUs=CPUs)
for tgt_cube in self.refcubes:
if (src_cube.satellite, src_cube.sensor) == (tgt_cube.satellite, tgt_cube.sensor):
continue
......
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