Commit 00590cd7 authored by g-weatherill's avatar g-weatherill
Browse files

Extends shakemap to bytes testcase

parent 2fbd4782
Pipeline #22124 passed with stage
in 8 minutes and 21 seconds
......@@ -202,11 +202,34 @@ class ShakemapExportersTestCase(unittest.TestCase):
os.remove(geotiff_fname)
def test_export_to_raster_geotiff_bytes(self):
# Test raster export to geotiff as an in memory file - currently just verifies that
# the function runs - but without verification of correctness
# Test raster export to geotiff as an in memory file - compares this against the
# case that the raster is exported directly to file and verifies that the relevant
# content is the same
results = np.zeros(self.site_model.shape, dtype=np.dtype([("PGA", np.float64)]))
results["PGA"] = np.copy(self.dummy)
self.shakemap.to_geotiff(results, "PGA")
data_bytes = self.shakemap.to_geotiff(results, "PGA")
byte_shakemap_file = os.path.join(DATA_PATH, "dummy_shakemap_from_bytes.tif")
with open(byte_shakemap_file, "wb") as f:
f.write(data_bytes)
# Verify that this produces the same shakemap as direct export
shakemap_file = os.path.join(DATA_PATH, "dummy_shakemap.tif")
self.shakemap.to_geotiff(results, "PGA", shakemap_file)
# Compare the two files
raster_1 = rasterio.open(byte_shakemap_file)
raster_2 = rasterio.open(shakemap_file)
# Compare bounding boxes
for pos in ["left", "right", "top", "bottom"]:
self.assertAlmostEqual(getattr(raster_1.bounds, pos), getattr(raster_2.bounds, pos))
# Compare dimensions
self.assertEqual(raster_1.width, raster_2.width)
self.assertEqual(raster_1.height, raster_2.height)
for i in range(2):
self.assertAlmostEqual(raster_1.res[i], raster_2.res[i])
# Check data are equal
np.testing.assert_array_almost_equal(raster_1.read(1), raster_2.read(1))
# Remove testing diles
os.remove(byte_shakemap_file)
os.remove(shakemap_file)
def test_export_to_esri_ascii(self):
# Test raster export to ESRI ascii as a round trip
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment