Commit 942f268f authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

Added first working algorithm for cluster homogenization (must improved (slow,...

Added first working algorithm for cluster homogenization (must improved (slow, complex code). Added tests.
parent 5cc73c0e
This diff is collapsed.
......@@ -274,8 +274,12 @@ class Test_SpectralHomogenizer(unittest.TestCase):
cfg = set_config(job_ID=26186196, db_host=db_host, reset_status=True, is_test=True)
cls.SpH = SpectralHomogenizer(classifier_rootDir=cfg.path_spechomo_classif)
cls.testArr_L8 = GeoArray(np.random.randint(1, 10000, (50, 50, 7), dtype=np.int16)) # no band 9, no pan
cls.cwl_L8 = [442.98, 482.59, 561.33, 654.61, 864.57, 1609.09, 2201.25]
# cls.testArr_L8 = GeoArray(np.random.randint(1, 10000, (50, 50, 7), dtype=np.int16)) # no band 9, no pan
# cls.testArr_L8 = GeoArray('/home/gfz-fe/scheffler/temp/Landsat-8__OLI_TIRS__LC81940242014072LGN00_L2B__250x250.bsq') # no pan
cls.testArr_L8 = GeoArray('/home/gfz-fe/scheffler/temp/Landsat-8__OLI_TIRS__LC81940242014072LGN00_L2B.bsq') # no pan
# cls.cwl_L8 = [442.98, 482.59, 561.33, 654.61, 864.57, 1609.09, 2201.25]
cls.cwl_L8 = [442.98, 482.59, 561.33, 654.61, 864.57, 1373.48, 1609.09, 2201.25]
def test_interpolate_cube_linear(self):
outarr = self.SpH.interpolate_cube(self.testArr_L8, self.cwl_L8, [500., 700., 1300.], kind='linear')
......@@ -343,3 +347,42 @@ class Test_SpectralHomogenizer(unittest.TestCase):
self.assertIsInstance(errors, np.ndarray)
self.assertEqual(errors.shape, (50, 50, 13))
self.assertEqual(errors.dtype, np.int16)
def test_predict_by_machine_learner__QR_cluster_L8_S2(self):
"""Test quadratic regression in spectral clusters from Landsat-8 to Sentinel-2A."""
predarr, errors = self.SpH.predict_by_machine_learner(
self.testArr_L8, method='QRclust',
src_satellite='Landsat-8', src_sensor='OLI_TIRS',
# src_LBA=['1', '2', '3', '4', '5', '6', '7'],
src_LBA=['1', '2', '3', '4', '5', '9', '6', '7'],
tgt_satellite='Sentinel-2A', tgt_sensor='MSI',
tgt_LBA=['1', '2', '3', '4', '5', '6', '7', '8', '8A', '9', '10', '11', '12'],
compute_errors=True,
# compute_errors=False,
nodataVal=-9999)
self.assertIsInstance(predarr, GeoArray)
self.assertEqual(predarr.shape, (50, 50, 13))
self.assertEqual(predarr.dtype, np.int16)
self.assertIsInstance(errors, np.ndarray)
self.assertEqual(errors.shape, (50, 50, 13))
self.assertEqual(errors.dtype, np.int16)
class Test_SAM_Classifier(unittest.TestCase):
def test_classify(self):
from gms_preprocessing.algorithms.L2B_P import SAM_Classifier
gA = GeoArray('/home/gfz-fe/scheffler/temp/Landsat-7__ETM+__LE71920242016104NSG00_image_data_L1A.bsq')
with open('/home/gfz-fe/scheffler/temp/SPECHOM_py/QR__Landsat-7__ETM+__clust50.dill', 'rb') as inF:
undilled = dill.load(inF)
cluster_centers = \
np.array([cc.cluster_center
for cc in undilled['1__2__3__4__5__7'][('Landsat-5', 'TM')]['1__2__3__4__5__7'].values()])
SC = SAM_Classifier()
sub = gA[4465:4470, 4495:4500].astype(np.int16)
# sub[sub==-9999] = 10000
cmap = SC.classify(sub, cluster_centers, nodataVal=-9999)
cmap
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