Debian Codegraph @

raster/r.resamp.interp/testsuite/test_r_resamp_interp.py

raw
1 from grass.gunittest.case import TestCase
2 from grass.gunittest.main import test
3
4
5 class TestResampInterp(TestCase):
6 """
7
8 Used dataset: nc_spm_08_grass7
9
10 Test cases:
11 test_finite_options: Test output with finite kernels only.
12 test_infinite_box_options: Test output with infinite kernels
13 in conjunction with the box kernel.
14 """
15
16 test_options = {
17 "nearest": {
18 "n": 5625000,
19 "null_cells": 0,
20 "cells": 5625000,
21 "min": 55.5787925720215,
22 "max": 156.329864501953,
23 "range": 100.751071929932,
24 "mean": 110.375436614522,
25 "mean_of_abs": 110.375436614522,
26 "stddev": 20.3153283525752,
27 "variance": 412.712566072944,
28 "coeff_var": 18.4056606938053,
29 "sum": 620861830.956688,
30 },
31 "bilinear": {
32 "n": 5615504,
33 "null_cells": 9496,
34 "cells": 5625000,
35 "min": 55.9232139587402,
36 "max": 156.316369018555,
37 "range": 100.393155059814,
38 "mean": 110.382539288015,
39 "mean_of_abs": 110.382539288015,
40 "stddev": 20.304736015932,
41 "variance": 412.282304676688,
42 "coeff_var": 18.3948803378694,
43 "sum": 619853590.902052,
44 },
45 "bicubic": {
46 "n": 5601275,
47 "null_cells": 23725,
48 "cells": 5625000,
49 "min": 55.8029828833008,
50 "max": 156.356721084961,
51 "range": 100.55373820166,
52 "mean": 110.404233965113,
53 "mean_of_abs": 110.404233965113,
54 "stddev": 20.2966878636654,
55 "variance": 411.955538235063,
56 "coeff_var": 18.3839759896156,
57 "sum": 618404475.602926,
58 },
59 "lanczos": {
60 "n": 5596536,
61 "null_cells": 28464,
62 "cells": 5625000,
63 "min": 55.7825176472632,
64 "max": 156.36299154775,
65 "range": 100.580473900487,
66 "mean": 110.396555800561,
67 "mean_of_abs": 110.396555800561,
68 "stddev": 20.2935834200418,
69 "variance": 411.829528026196,
70 "coeff_var": 18.3824425253842,
71 "sum": 617838298.813768,
72 },
73 }
74
75 # TODO: replace by unified handing of maps
76 to_remove = []
77
78 def check_univar(self, test_case):
79 """Checks multiple output against unviariate reference from dict"""
80 for method in self.test_options:
81 self.assertRasterFitsUnivar(
82 raster="{}_raster_{}".format(test_case, method),
83 reference=self.test_options[method],
84 precision=1e-5,
85 )
86 self.assertRasterFitsUnivar(
87 raster="{}_raster_threaded_{}".format(test_case, method),
88 reference=self.test_options[method],
89 precision=1e-5,
90 )
91
92 @classmethod
93 def setUpClass(cls):
94 cls.use_temp_region()
95 # run with resolution of 6
96 cls.runModule("g.region", raster="elevation", res=6)
97
98 @classmethod
99 def tearDownClass(cls):
100 cls.del_temp_region()
101 if cls.to_remove:
102 cls.runModule(
103 "g.remove", flags="f", type="raster", name=",".join(cls.to_remove)
104 )
105
106 def test_resamp_interp(self):
107 """Test for all methods of interpolation."""
108 test_case = "test_resamp_interp"
109 outputs = [
110 "{}_raster_{}".format(test_case, filter) for filter in self.test_options
111 ]
112 outputs_threaded = [
113 "{}_raster_threaded_{}".format(test_case, filter)
114 for filter in self.test_options
115 ]
116 self.to_remove.extend(outputs)
117 self.to_remove.extend(outputs_threaded)
118
119 for method in self.test_options:
120 self.assertModule(
121 "r.resamp.interp",
122 input="elevation",
123 output="{}_raster_{}".format(test_case, method),
124 method=method,
125 )
126 self.assertModule(
127 "r.resamp.interp",
128 input="elevation",
129 output="{}_raster_threaded_{}".format(test_case, method),
130 method=method,
131 nprocs=8,
132 )
133 self.check_univar(test_case)
134
135
136 if __name__ == "__main__":
137 test()