|
12 | 12 |
|
13 | 13 | from sardem import dem, download, utils, loading |
14 | 14 | from sardem.constants import DEFAULT_RES |
| 15 | + |
15 | 16 | HALF_PIXEL = 0.5 * DEFAULT_RES |
16 | 17 |
|
17 | 18 | DATAPATH = join(dirname(__file__), "data") |
@@ -154,52 +155,45 @@ def test_bounding_box(self): |
154 | 155 | ) == ((-156.0, 18.7, -154.6, 20.3)) |
155 | 156 |
|
156 | 157 |
|
157 | | -""" |
158 | | -TODO: |
159 | | - finish cropped, upsampled dem, show this: |
160 | | - expected_dem = np.array( |
161 | | - [[2071, 2072, 2074, 2076, 2078, 2078, 2079, 2080, 2082], [ |
162 | | - 2071, 2072, 2073, 2075, 2076, 2077, 2078, 2079, 2081 |
163 | | - ], [2071, 2072, 2073, 2074, 2075, 2076, 2078, 2079, 2080], [ |
164 | | - 2071, 2071, 2072, 2073, 2074, 2075, 2077, 2078, 2080 |
165 | | - ], [2071, 2071, 2072, 2073, 2074, 2075, 2076, 2078, 2080], [ |
166 | | - 2071, 2071, 2072, 2072, 2073, 2074, 2076, 2077, 2079 |
167 | | - ], [2071, 2071, 2072, 2072, 2073, 2074, 2076, 2077, 2078]], |
168 | | - dtype='<i2') |
169 | | -
|
170 | | - output_dem = sario.load_file('elevation.dem') |
171 | | - # assert_array_almost_equal(expected_dem) |
172 | | - """ |
173 | | - |
174 | | -def sample_cop_tile(tmp_path): |
175 | | - path = join(DATAPATH, "cop_tile_hawaii.dem.gz") |
176 | | - tmpfile = tmp_path / "cop_tile_hawaii.dem" |
177 | | - with gzip.open(path, "rb") as f_in: |
178 | | - with open(tmpfile, "wb") as f_out: |
179 | | - f_out.write(f_in.read()) |
180 | | - return tmpfile |
181 | | - # return np.fromfile(tmpfile, dtype=np.int16).reshape(3600, 3600) |
182 | | - |
183 | | - |
184 | 158 | class TestMain: |
185 | 159 | bbox = [-156.0, 19.0, -155.0, 20.0] |
186 | 160 |
|
187 | | - def test_main(self, tmp_path): |
| 161 | + def test_main_srtm(self, tmp_path): |
188 | 162 | path = join(DATAPATH, "N19W156.hgt.zip") |
189 | 163 | # tmpfile = tmp_path / "N19W156.hgt.zip" |
190 | 164 | unzipfile = tmp_path / "N19W156.hgt" |
191 | 165 | with zipfile.ZipFile(path, "r") as zip_ref: |
192 | 166 | with open(unzipfile, "wb") as f: |
193 | 167 | f.write(zip_ref.read("N19W156.hgt")) |
194 | | - sample_hgt = loading.load_elevation(unzipfile) |
195 | | - sample_hgt[sample_hgt < -1000] = 0 |
| 168 | + expected = loading.load_elevation(unzipfile) |
| 169 | + expected[expected < -1000] = 0 |
196 | 170 |
|
197 | 171 | tmp_output = tmp_path / "output.dem" |
198 | | - dem.main(output_name=str(tmp_output), bbox=self.bbox, keep_egm=True, data_source="NASA", cache_dir=str(tmp_path)) |
| 172 | + dem.main( |
| 173 | + output_name=str(tmp_output), |
| 174 | + bbox=self.bbox, |
| 175 | + keep_egm=True, |
| 176 | + data_source="NASA", |
| 177 | + cache_dir=str(tmp_path), |
| 178 | + ) |
199 | 179 | output = np.fromfile(tmp_output, dtype=np.int16).reshape(3600, 3600) |
200 | | - np.testing.assert_allclose(sample_hgt[:-1, :-1], output) |
201 | | - |
| 180 | + np.testing.assert_allclose(expected[:-1, :-1], output) |
202 | 181 |
|
| 182 | + def test_main_cop(self, tmp_path): |
| 183 | + path = join(DATAPATH, "cop_tile_hawaii.dem.gz") |
| 184 | + unzipfile = tmp_path / "cop_tile_hawaii.dem" |
| 185 | + with gzip.open(path, "rb") as f_in: |
| 186 | + with open(unzipfile, "wb") as f_out: |
| 187 | + f_out.write(f_in.read()) |
203 | 188 |
|
204 | | -# TODO: tests with the hawaii COP tile |
205 | | -# https://copernicus-dem-30m.s3.amazonaws.com/Copernicus_DSM_COG_10_N19_00_W156_00_DEM/Copernicus_DSM_COG_10_N19_00_W156_00_DEM.tif |
| 189 | + expected = np.fromfile(unzipfile, dtype=np.int16).reshape(3600, 3600) |
| 190 | + tmp_output = tmp_path / "output.dem" |
| 191 | + dem.main( |
| 192 | + output_name=str(tmp_output), |
| 193 | + bbox=self.bbox, |
| 194 | + keep_egm=True, |
| 195 | + data_source="COP", |
| 196 | + cache_dir=str(tmp_path), |
| 197 | + ) |
| 198 | + output = np.fromfile(tmp_output, dtype=np.int16).reshape(3600, 3600) |
| 199 | + np.testing.assert_allclose(expected, output, atol=1.0) |
0 commit comments