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

4
5
# AROSICS - Automated and Robust Open-Source Image Co-Registration Software
#
6
# Copyright (C) 2017-2020  Daniel Scheffler (GFZ Potsdam, daniel.scheffler@gfz-potsdam.de)
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#
# This software was developed within the context of the GeoMultiSens project funded
# by the German Federal Ministry of Education and Research
# (project grant code: 01 IS 14 010 A-C).
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License along
# with this program.  If not, see <http://www.gnu.org/licenses/>.

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

import unittest
28
29
import shutil
import os
30
31

# custom
32
from .cases import test_cases
33
34
35
36
37
38
39
40
41
42
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']
43
        self.coreg_kwargs = test_cases['INTER1']['kwargs_local']
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69

    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']
70
        self.coreg_kwargs = test_cases['INTER1']['kwargs_local']
71
72

    def tearDown(self):
73
74
75
76
        """Delete output."""
        dir_out = os.path.dirname(self.coreg_kwargs['path_out'])
        if os.path.isdir(dir_out):
            shutil.rmtree(dir_out)
77
78
79
80
81
82

    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
Daniel Scheffler's avatar
Daniel Scheffler committed
83
        # noinspection PyStatementEffect
84
        CRL.CoRegPoints_table
85
86

        # test tie point grid visualization
87
88
89
90
        CRL.view_CoRegPoints(hide_filtered=True)
        CRL.view_CoRegPoints(hide_filtered=False)
        CRL.view_CoRegPoints(shapes2plot='vectors')
        CRL.view_CoRegPoints_folium()
91

92
93
        # test shift correction and output writer
        CRL.correct_shifts()
94
95
96

        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
97

98
99
100
101
102
103
104
105
106
107
    def test_calculation_of_tie_point_grid_float_coords(self):
        # NOTE: This does not test against unequaly sized output of get_image_windows_to_match().

        # overwrite gt and prj
        ref = GeoArray(self.ref_path)
        ref.to_mem()
        ref.filePath = None
        tgt = GeoArray(self.tgt_path)
        tgt.to_mem()
        tgt.filePath = None
108
109
110
111
112

        ref.gt = [330000.19999996503, 10.00000001, 0.0, 5862000.7999997628, 0.0, -10.00000001]
        # ref.gt = [330000.1, 10.1, 0.0, 5862000.1, 0.0, -10.1]
        tgt.gt = [335440.19999996503, 10.00000001, 0.0, 5866490.7999997628, 0.0, -10.00000001]
        # tgt.gt = [330000.1, 10.1, 0.0, 5862000.1, 0.0, -10.1]
113
114

        # get instance of COREG_LOCAL object
115
116
        CRL = COREG_LOCAL(ref, tgt, **dict(CPUs=32,
                                           **self.coreg_kwargs))
117
118
119
120
121
122

        # use the getter of the CoRegPoints_table to calculate tie point grid
        # noinspection PyStatementEffect
        CRL.CoRegPoints_table


123
124
# if __name__ == '__main__':
#     unittest.main(argv=['first-arg-is-ignored'],exit=False, verbosity=2)
Daniel Scheffler's avatar
Daniel Scheffler committed
125
#
126
#      suite = unittest.TestLoader().loadTestsFromTestCase(eval("CompleteWorkflow_INTER1_S2A_S2A"))
Daniel Scheffler's avatar
Daniel Scheffler committed
127
128
#     alltests = unittest.TestSuite(suite)
#
129
130
#      # 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)