File: test_r_import.py

package info (click to toggle)
grass 8.4.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 277,040 kB
  • sloc: ansic: 460,798; python: 227,732; cpp: 42,026; sh: 11,262; makefile: 7,007; xml: 3,637; sql: 968; lex: 520; javascript: 484; yacc: 450; asm: 387; perl: 157; sed: 25; objc: 6; ruby: 4
file content (132 lines) | stat: -rwxr-xr-x 4,185 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/env python3

from grass.gunittest.case import TestCase
from grass.gunittest.main import test

import grass.script as gs


class TestRImportRegion(TestCase):
    imported = "test_r_import_imported"

    @classmethod
    def setUpClass(cls):
        cls.runModule("g.region", raster="elevation")

    def tearDown(cls):
        """Remove imported map after each test method"""
        cls.runModule("g.remove", flags="f", type="raster", name=cls.imported)

    def test_import_estimate(self):
        """Test e flag"""
        self.assertModule(
            "r.import",
            input="data/data2.asc",
            output=self.imported,
            resample="nearest",
            flags="e",
        )
        self.assertRasterDoesNotExist(name=self.imported)

    def test_import_same_proj_tif(self):
        """Import tif in same proj, default params"""
        self.assertModule(
            "r.import",
            input="data/data1.tif",
            output=self.imported,
            resample="bilinear",
        )
        reference = dict(
            north=223490,
            south=223390,
            east=636820,
            west=636710,
            nsres=10,
            ewres=10,
            datatype="FCELL",
        )
        self.assertRasterFitsInfo(
            raster=self.imported, reference=reference, precision=1e-6
        )

    def test_import_asc_custom_res(self):
        """Import ASC in different projection, with specified resolution"""
        self.assertModule(
            "r.import",
            input="data/data2.asc",
            output=self.imported,
            resample="nearest",
            resolution="value",
            resolution_value=30,
        )
        reference = dict(rows=3, cols=4, nsres=30, ewres=30, datatype="CELL")
        self.assertRasterFitsInfo(
            raster=self.imported, reference=reference, precision=1.1
        )

    def test_import_asc_region_extent(self):
        """Import ASC in different projection in specified region"""
        self.runModule("g.region", raster="elevation", n=223655, s=223600)
        self.assertModule(
            "r.import",
            input="data/data2.asc",
            output=self.imported,
            resample="nearest",
            extent="region",
            resolution="region",
        )
        reference = dict(north=223655, south=223600)
        self.assertRasterFitsInfo(
            raster=self.imported, reference=reference, precision=1e-6
        )

    def test_import_use_temp_region(self):
        """Import in specified region with use_temp_region activated"""
        self.runModule("g.region", raster="elevation", n=223660, s=223600)
        gs.use_temp_region()
        self.runModule("g.region", raster="elevation", n=223630, s=223600)
        self.assertModule(
            "r.import",
            input="data/data2.asc",
            output=self.imported,
            resample="nearest",
            extent="region",
            resolution="region",
        )
        reference = dict(north=223630, south=223600, nsres=10, ewres=10)
        self.assertRasterFitsInfo(
            raster=self.imported, reference=reference, precision=1e-6
        )

        self.runModule("g.region", raster="elevation", s=223390, n=223450)
        self.assertModule(
            "r.import",
            input="data/data1.tif",
            output=self.imported,
            resample="bilinear",
            extent="region",
            overwrite=True,
        )
        reference = dict(south=223390, north=223450, nsres=10, ewres=10)
        self.assertRasterFitsInfo(
            raster=self.imported, reference=reference, precision=1e-6
        )

        gs.del_temp_region()
        self.assertModule(
            "r.import",
            input="data/data2.asc",
            output=self.imported,
            resample="nearest",
            extent="region",
            resolution="region",
            overwrite=True,
        )
        reference = dict(north=223660, south=223600, nsres=10, ewres=10)
        self.assertRasterFitsInfo(
            raster=self.imported, reference=reference, precision=1e-6
        )


if __name__ == "__main__":
    test()