Skip to content

Commit 6d6e44d

Browse files
committed
add cop test too
format
1 parent 882c229 commit 6d6e44d

File tree

1 file changed

+29
-35
lines changed

1 file changed

+29
-35
lines changed

sardem/tests/test_dem.py

Lines changed: 29 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
from sardem import dem, download, utils, loading
1414
from sardem.constants import DEFAULT_RES
15+
1516
HALF_PIXEL = 0.5 * DEFAULT_RES
1617

1718
DATAPATH = join(dirname(__file__), "data")
@@ -154,52 +155,45 @@ def test_bounding_box(self):
154155
) == ((-156.0, 18.7, -154.6, 20.3))
155156

156157

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-
184158
class TestMain:
185159
bbox = [-156.0, 19.0, -155.0, 20.0]
186160

187-
def test_main(self, tmp_path):
161+
def test_main_srtm(self, tmp_path):
188162
path = join(DATAPATH, "N19W156.hgt.zip")
189163
# tmpfile = tmp_path / "N19W156.hgt.zip"
190164
unzipfile = tmp_path / "N19W156.hgt"
191165
with zipfile.ZipFile(path, "r") as zip_ref:
192166
with open(unzipfile, "wb") as f:
193167
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
196170

197171
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+
)
199179
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)
202181

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())
203188

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

Comments
 (0)