Commit 0bf1b8ce authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

Fixed SRF class.


Former-commit-id: a8c36936
parent c11bf1d9
...@@ -714,6 +714,7 @@ class ReferenceCube_Generator(object): ...@@ -714,6 +714,7 @@ class ReferenceCube_Generator(object):
self.logger.info('Computing %s KMeans clusters from the input image %s...' self.logger.info('Computing %s KMeans clusters from the input image %s...'
% (self.n_clusters, im2clust.basename)) % (self.n_clusters, im2clust.basename))
kmeans = KMeansRSImage(im2clust, n_clusters=self.n_clusters, CPUs=self.CPUs, v=self.v) kmeans = KMeansRSImage(im2clust, n_clusters=self.n_clusters, CPUs=self.CPUs, v=self.v)
kmeans.compute_clusters()
if self.v: if self.v:
kmeans.plot_cluster_centers() kmeans.plot_cluster_centers()
...@@ -831,7 +832,7 @@ class RefCube(object): ...@@ -831,7 +832,7 @@ class RefCube(object):
def add_spectra(self, spectra, src_imname): def add_spectra(self, spectra, src_imname):
# type: (np.ndarray, str) -> None # type: (np.ndarray, str) -> None
""" """Add a set of spectral signatures to the reference cube.
:param spectra: 2D numpy array with rows: spectral samples / columns: spectral information (bands) :param spectra: 2D numpy array with rows: spectral samples / columns: spectral information (bands)
:param src_imname: image basename of the source hyperspectral image :param src_imname: image basename of the source hyperspectral image
......
...@@ -236,6 +236,7 @@ class SRF(object): ...@@ -236,6 +236,7 @@ class SRF(object):
return self.from_dict(srf_dict) return self.from_dict(srf_dict)
def from_dict(self, srf_dict): def from_dict(self, srf_dict):
# type: (collections.OrderedDict) -> SRF
"""Create an instance of SRF from a dictionary. """Create an instance of SRF from a dictionary.
:param srf_dict: {'key_LayerBandsAssignment': <2D array: cols=[wvl,resp],rows=samples>} :param srf_dict: {'key_LayerBandsAssignment': <2D array: cols=[wvl,resp],rows=samples>}
...@@ -249,8 +250,11 @@ class SRF(object): ...@@ -249,8 +250,11 @@ class SRF(object):
wvl = np.arange(all_wvls.min(), all_wvls.max() + self.specres_nm, self.specres_nm).astype(np.int16) wvl = np.arange(all_wvls.min(), all_wvls.max() + self.specres_nm, self.specres_nm).astype(np.int16)
df = DataFrame(index=wvl) df = DataFrame(index=wvl)
for band in srf_dict: bandnames = []
for band in srf_dict: # = OrderedDict -> order follows LayerBandsAssignment
bandname = band if not self.format_bandnames else ('B%s' % band if len(band) == 2 else 'B0%s' % band) bandname = band if not self.format_bandnames else ('B%s' % band if len(band) == 2 else 'B0%s' % band)
bandnames.append(bandname)
srfs = srf_dict[band][:, 1] srfs = srf_dict[band][:, 1]
wvls = np.array(srf_dict[band][:, 0] * scale_factor) wvls = np.array(srf_dict[band][:, 0] * scale_factor)
...@@ -275,7 +279,7 @@ class SRF(object): ...@@ -275,7 +279,7 @@ class SRF(object):
self.srfs[bN] = srf / np.trapz(x=wvl, y=srf) # TODO seems like we NEED nanometers here; BUT WHY?? self.srfs[bN] = srf / np.trapz(x=wvl, y=srf) # TODO seems like we NEED nanometers here; BUT WHY??
self.srfs_wvl = np.array(wvl) self.srfs_wvl = np.array(wvl)
self.bands = list(srf_dict.keys()) # = OrderedDict -> order follows LayerBandsAssignment self.bands = bandnames
# FIXME this is not the GMS algorithm to calculate center wavelengths # FIXME this is not the GMS algorithm to calculate center wavelengths
# calculate center wavelengths # calculate center wavelengths
......
Supports Markdown
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