test_COREG_LOCAL.py 2.79 KB
Newer Older
1
2
3
4
5
6
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""Tests for the local co-registration module of AROSICS."""

import unittest
7
8
import shutil
import os
9
10

# custom
11
from .cases import test_cases
12
13
14
15
16
17
18
19
20
21
from arosics import COREG_LOCAL
from geoarray import GeoArray


class COREG_LOCAL_init(unittest.TestCase):
    """Test case on object initialization of COREG_LOCAL."""

    def setUp(self):
        self.ref_path = test_cases['INTER1']['ref_path']
        self.tgt_path = test_cases['INTER1']['tgt_path']
22
        self.coreg_kwargs = test_cases['INTER1']['kwargs_local']
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

    def test_coreg_init_from_disk(self):
        self.CRL = COREG_LOCAL(self.ref_path, self.tgt_path, **self.coreg_kwargs)

    def test_coreg_init_from_inMem_GeoArray(self):
        # get GeoArray instances
        self.ref_gA = GeoArray(self.ref_path)
        self.tgt_gA = GeoArray(self.tgt_path)

        # assure the raster data are in-memory
        self.ref_gA.to_mem()
        self.tgt_gA.to_mem()

        # get instance of COREG_LOCAL object
        self.CRL = COREG_LOCAL(self.ref_gA, self.tgt_gA, **self.coreg_kwargs)


class CompleteWorkflow_INTER1_S2A_S2A(unittest.TestCase):
    """Test case for the complete workflow of local co-registration based on two Sentinel-2 datasets, one with
    ~25% cloud cover, the other one without any clouds. The subsets cover the S2A tiles only partly (nodata areas
    are present).
    """

    def setUp(self):
        self.ref_path = test_cases['INTER1']['ref_path']
        self.tgt_path = test_cases['INTER1']['tgt_path']
49
        self.coreg_kwargs = test_cases['INTER1']['kwargs_local']
50
51

    def tearDown(self):
52
53
54
55
        """Delete output."""
        dir_out = os.path.dirname(self.coreg_kwargs['path_out'])
        if os.path.isdir(dir_out):
            shutil.rmtree(dir_out)
56
57
58
59
60
61
62
63
64

    def test_calculation_of_tie_point_grid(self):
        # get instance of COREG_LOCAL object
        CRL = COREG_LOCAL(self.ref_path, self.tgt_path, **self.coreg_kwargs)

        # use the getter of the CoRegPoints_table to calculate tie point grid
        TPG = CRL.CoRegPoints_table

        # test tie point grid visualization
65
        # CRL.view_CoRegPoints() # only works if basemap is installed
66
67
68

        # test shift correction and output writer
        CRL.correct_shifts()
69
70
71

        self.assertTrue(os.path.exists(self.coreg_kwargs['path_out']),
                        'Output of local co-registration has not been written.')
Daniel Scheffler's avatar
Daniel Scheffler committed
72

73
74
# if __name__ == '__main__':
#     unittest.main(argv=['first-arg-is-ignored'],exit=False, verbosity=2)
Daniel Scheffler's avatar
Daniel Scheffler committed
75
#
76
#      suite = unittest.TestLoader().loadTestsFromTestCase(eval("CompleteWorkflow_INTER1_S2A_S2A"))
Daniel Scheffler's avatar
Daniel Scheffler committed
77
78
#     alltests = unittest.TestSuite(suite)
#
79
80
#      # Part 2: Saving the results of each testsuite and the query for the job.status in individual variables.
#      testResult = unittest.TextTestRunner(verbosity=2).run(alltests)