Commit 5cc73c0e authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

Added class 'ClusterClassifier_Generator' for generating classifiers with...

Added class 'ClusterClassifier_Generator' for generating classifiers with separate transformation parameters for spectral cluster of an image.
Added 'Test_ClusterClassifier_Generator'.
parent 08cdcb1b
This diff is collapsed.
......@@ -22,6 +22,7 @@ from gms_preprocessing.algorithms.L2B_P import ReferenceCube_Generator # noqa E
from gms_preprocessing.algorithms.L2B_P import RefCube # noqa E402 module level import not at top of file
from gms_preprocessing.algorithms.L2B_P import SpectralHomogenizer # noqa E402 module level import not at top of file
from gms_preprocessing.algorithms.L2B_P import Classifier_Generator # noqa E402 module level import not at top of file
from gms_preprocessing.algorithms.L2B_P import ClusterClassifier_Generator # noqa E402 module level import not at top of file
from gms_preprocessing.model.gms_object import GMS_identifier # noqa E402 module level import not at top of file
from . import db_host
......@@ -199,6 +200,71 @@ class Test_Classifier_Generator(unittest.TestCase):
self.assertTrue(bool(undilled), msg='Generated classifier collection is empty.')
class Test_ClusterClassifier_Generator(unittest.TestCase):
"""Tests class for gms_preprocessing.algorithms.L2B_P.Classifier_Generator"""
@classmethod
def setUpClass(cls):
set_config(job_ID=26186196, db_host=db_host, reset_status=True, is_test=True)
cls.tmpOutdir = tempfile.TemporaryDirectory()
@classmethod
def tearDownClass(cls):
cls.tmpOutdir.cleanup()
def test_init_from_path_strings(self):
CCG = ClusterClassifier_Generator([refcube_l8, refcube_l5])
self.assertIsInstance(CCG, ClusterClassifier_Generator)
def test_init_from_RefCubes(self):
RC = RefCube(refcube_l8)
CCG = ClusterClassifier_Generator([RC, RC])
self.assertIsInstance(CCG, ClusterClassifier_Generator)
def test_cluster_refcube_spectra(self):
CCG = ClusterClassifier_Generator([refcube_l8, refcube_l5])
CCG.cluster_refcube_spectra(n_clusters=5)
def test_create_classifiers_LR(self):
"""Test creation of linear regression classifiers."""
CCG = ClusterClassifier_Generator([refcube_l8, refcube_l5])
CCG.create_classifiers(outDir=self.tmpOutdir.name, method='LR', n_clusters=5)
outpath_cls = os.path.join(self.tmpOutdir.name, 'LR__Landsat-8__OLI_TIRS__clust5.dill')
self.assertTrue(os.path.exists(outpath_cls))
with open(outpath_cls, 'rb') as inF:
undilled = dill.load(inF)
self.assertIsInstance(undilled, dict)
self.assertTrue(bool(undilled), msg='Generated classifier collection is empty.')
def test_create_classifiers_RR(self):
"""Test creation of ridge regression classifiers."""
CCG = ClusterClassifier_Generator([refcube_l8, refcube_l5])
CCG.create_classifiers(outDir=self.tmpOutdir.name, method='RR', n_clusters=5)
outpath_cls = os.path.join(self.tmpOutdir.name, 'RR_alpha1.0__Landsat-8__OLI_TIRS__clust5.dill')
self.assertTrue(os.path.exists(outpath_cls))
with open(outpath_cls, 'rb') as inF:
undilled = dill.load(inF)
self.assertIsInstance(undilled, dict)
self.assertTrue(bool(undilled), msg='Generated classifier collection is empty.')
def test_create_classifiers_QR(self):
"""Test creation of quadratic regression classifiers."""
CCG = ClusterClassifier_Generator([refcube_l8, refcube_l5])
CCG.create_classifiers(outDir=self.tmpOutdir.name, method='QR', n_clusters=5)
outpath_cls = os.path.join(self.tmpOutdir.name, 'QR__Landsat-8__OLI_TIRS__clust5.dill')
self.assertTrue(os.path.exists(outpath_cls))
with open(outpath_cls, 'rb') as inF:
undilled = dill.load(inF)
self.assertIsInstance(undilled, dict)
self.assertTrue(bool(undilled), msg='Generated classifier collection is empty.')
class Test_SpectralHomogenizer(unittest.TestCase):
"""Tests class for gms_preprocessing.algorithms.L2B_P.Test_SpectralHomogenizer"""
......
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