test_COREG_LOCAL.py 3.14 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
from importlib import util
10
11

# custom
12
from .cases import test_cases
13
14
15
16
17
18
19
20
21
22
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']
23
        self.coreg_kwargs = test_cases['INTER1']['kwargs_local']
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
49

    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']
50
        self.coreg_kwargs = test_cases['INTER1']['kwargs_local']
51
52

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

    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
63
        # noinspection PyStatementEffect
64
        CRL.CoRegPoints_table
65
66

        # test tie point grid visualization
67
        if util.find_spec('mpl_toolkits.basemap'):  # only works if basemap is installed
68
69
70
            CRL.view_CoRegPoints(hide_filtered=True)
            CRL.view_CoRegPoints(hide_filtered=False)
            CRL.view_CoRegPoints(shapes2plot='vectors')
71

72
73
74
        if util.find_spec('folium') and util.find_spec('geojson'):
            CRL.view_CoRegPoints_folium()

75
76
        # test shift correction and output writer
        CRL.correct_shifts()
77
78
79

        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
80

81
82
# if __name__ == '__main__':
#     unittest.main(argv=['first-arg-is-ignored'],exit=False, verbosity=2)
Daniel Scheffler's avatar
Daniel Scheffler committed
83
#
84
#      suite = unittest.TestLoader().loadTestsFromTestCase(eval("CompleteWorkflow_INTER1_S2A_S2A"))
Daniel Scheffler's avatar
Daniel Scheffler committed
85
86
#     alltests = unittest.TestSuite(suite)
#
87
88
#      # 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)