|
3 | 3 | """ |
4 | 4 | import unittest |
5 | 5 | import numpy as np |
6 | | -from scipy import sparse |
7 | 6 |
|
8 | 7 | from climada.entity.exposures import nightlight |
9 | 8 | from climada.util.constants import SYSTEM_DIR |
@@ -74,133 +73,6 @@ def test_download_nightlight_files(self): |
74 | 73 | # The same length but not the correct length |
75 | 74 | self.assertRaises(ValueError, nightlight.download_nl_files, (1, 0, 1), (1, 1, 1)) |
76 | 75 |
|
77 | | - def test_cut_nl_nasa_1_pass(self): |
78 | | - """Test cut_nl_nasa situation 2->3->4->5.""" |
79 | | - nl_mat = sparse.lil.lil_matrix([]) |
80 | | - in_lat = (21599, 21600) |
81 | | - in_lon = (43199, 43200) |
82 | | - # 0 2 4 6 (lat: Upper=0) (lon: 0, 1, 2, 3) |
83 | | - # 1 3 5 7 (lat: Lower=1) (lon: 0, 1, 2, 3) |
84 | | - in_lat_nb = (1, 0) |
85 | | - in_lon_nb = (1, 2) |
86 | | - |
87 | | - idx_info = [2, -1, False] |
88 | | - try: |
89 | | - aux_nl = np.zeros((21600, 21600)) |
90 | | - aux_nl[21599, 21599] = 100 |
91 | | - nightlight.cut_nl_nasa(aux_nl, idx_info, nl_mat, in_lat, |
92 | | - in_lon, in_lat_nb, in_lon_nb) |
93 | | - |
94 | | - self.assertEqual(nl_mat.shape, (1, 1)) |
95 | | - self.assertEqual(nl_mat.tocsr()[0, 0], 100.0) |
96 | | - |
97 | | - idx_info[0] = 3 |
98 | | - idx_info[1] = 2 |
99 | | - aux_nl[21599, 21599] = 0 |
100 | | - aux_nl[0, 21599] = 101 |
101 | | - nightlight.cut_nl_nasa(aux_nl, idx_info, nl_mat, in_lat, |
102 | | - in_lon, in_lat_nb, in_lon_nb) |
103 | | - |
104 | | - self.assertEqual(nl_mat.shape, (2, 1)) |
105 | | - self.assertEqual(nl_mat.tocsr()[0, 0], 100.0) |
106 | | - self.assertEqual(nl_mat.tocsr()[1, 0], 101.0) |
107 | | - |
108 | | - idx_info[0] = 4 |
109 | | - idx_info[1] = 3 |
110 | | - aux_nl[0, 21599] = 0 |
111 | | - aux_nl[21599, 0] = 102 |
112 | | - nightlight.cut_nl_nasa(aux_nl, idx_info, nl_mat, in_lat, |
113 | | - in_lon, in_lat_nb, in_lon_nb) |
114 | | - |
115 | | - self.assertEqual(nl_mat.shape, (2, 2)) |
116 | | - self.assertEqual(nl_mat.tocsr()[0, 0], 100.0) |
117 | | - self.assertEqual(nl_mat.tocsr()[1, 0], 101.0) |
118 | | - self.assertEqual(nl_mat.tocsr()[0, 1], 102.0) |
119 | | - |
120 | | - idx_info[0] = 5 |
121 | | - idx_info[1] = 4 |
122 | | - aux_nl[21599, 0] = 0 |
123 | | - aux_nl[0, 0] = 103 |
124 | | - nightlight.cut_nl_nasa(aux_nl, idx_info, nl_mat, in_lat, |
125 | | - in_lon, in_lat_nb, in_lon_nb) |
126 | | - |
127 | | - self.assertEqual(nl_mat.shape, (2, 2)) |
128 | | - self.assertEqual(nl_mat.tocsr()[0, 0], 100.0) |
129 | | - self.assertEqual(nl_mat.tocsr()[1, 0], 101.0) |
130 | | - self.assertEqual(nl_mat.tocsr()[0, 1], 102.0) |
131 | | - self.assertEqual(nl_mat.tocsr()[1, 1], 103.0) |
132 | | - except MemoryError: |
133 | | - print('caught MemoryError') |
134 | | - pass |
135 | | - |
136 | | - def test_cut_nl_nasa_2_pass(self): |
137 | | - """Test cut_nl_nasa situation 3->5.""" |
138 | | - nl_mat = sparse.lil.lil_matrix([]) |
139 | | - in_lat = (21599, 21599) |
140 | | - in_lon = (43199, 43200) |
141 | | - # 0 2 4 6 (lat: Upper=0) (lon: 0, 1, 2, 3) |
142 | | - # 1 3 5 7 (lat: Lower=1) (lon: 0, 1, 2, 3) |
143 | | - in_lat_nb = (1, 1) |
144 | | - in_lon_nb = (1, 2) |
145 | | - |
146 | | - idx_info = [3, -1, False] |
147 | | - try: |
148 | | - aux_nl = np.zeros((21600, 21600)) |
149 | | - aux_nl[0, 21599] = 100 |
150 | | - nightlight.cut_nl_nasa(aux_nl, idx_info, nl_mat, in_lat, |
151 | | - in_lon, in_lat_nb, in_lon_nb) |
152 | | - |
153 | | - self.assertEqual(nl_mat.shape, (1, 1)) |
154 | | - self.assertEqual(nl_mat.tocsr()[0, 0], 100.0) |
155 | | - |
156 | | - idx_info[0] = 5 |
157 | | - idx_info[1] = 3 |
158 | | - aux_nl[0, 21599] = 0 |
159 | | - aux_nl[0, 0] = 101 |
160 | | - nightlight.cut_nl_nasa(aux_nl, idx_info, nl_mat, in_lat, |
161 | | - in_lon, in_lat_nb, in_lon_nb) |
162 | | - |
163 | | - self.assertEqual(nl_mat.shape, (1, 2)) |
164 | | - self.assertEqual(nl_mat.tocsr()[0, 0], 100.0) |
165 | | - self.assertEqual(nl_mat.tocsr()[0, 1], 101.0) |
166 | | - except MemoryError: |
167 | | - print('caught MemoryError') |
168 | | - pass |
169 | | - |
170 | | - def test_cut_nl_nasa_3_pass(self): |
171 | | - """Test cut_nl_nasa situation 2->4.""" |
172 | | - nl_mat = sparse.lil.lil_matrix([]) |
173 | | - in_lat = (21600, 21600) |
174 | | - in_lon = (43199, 43200) |
175 | | - # 0 2 4 6 (lat: Upper=0) (lon: 0, 1, 2, 3) |
176 | | - # 1 3 5 7 (lat: Lower=1) (lon: 0, 1, 2, 3) |
177 | | - in_lat_nb = (0, 0) |
178 | | - in_lon_nb = (1, 2) |
179 | | - |
180 | | - idx_info = [2, -1, False] |
181 | | - try: |
182 | | - aux_nl = np.zeros((21600, 21600)) |
183 | | - aux_nl[21599, 21599] = 100 |
184 | | - nightlight.cut_nl_nasa(aux_nl, idx_info, nl_mat, in_lat, |
185 | | - in_lon, in_lat_nb, in_lon_nb) |
186 | | - |
187 | | - self.assertEqual(nl_mat.shape, (1, 1)) |
188 | | - self.assertEqual(nl_mat.tocsr()[0, 0], 100.0) |
189 | | - |
190 | | - idx_info[0] = 4 |
191 | | - idx_info[1] = 2 |
192 | | - aux_nl[21599, 21599] = 0 |
193 | | - aux_nl[21599, 0] = 101 |
194 | | - nightlight.cut_nl_nasa(aux_nl, idx_info, nl_mat, in_lat, |
195 | | - in_lon, in_lat_nb, in_lon_nb) |
196 | | - |
197 | | - self.assertEqual(nl_mat.shape, (1, 2)) |
198 | | - self.assertEqual(nl_mat.tocsr()[0, 0], 100.0) |
199 | | - self.assertEqual(nl_mat.tocsr()[0, 1], 101.0) |
200 | | - except MemoryError: |
201 | | - print('caught MemoryError') |
202 | | - pass |
203 | | - |
204 | 76 | # Execute Tests |
205 | 77 | TESTS = unittest.TestLoader().loadTestsFromTestCase(TestNightLight) |
206 | 78 | unittest.TextTestRunner(verbosity=2).run(TESTS) |
0 commit comments