Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Graeme Weatherill
shakyground2
Commits
00590cd7
Commit
00590cd7
authored
Apr 21, 2021
by
g-weatherill
Browse files
Extends shakemap to bytes testcase
parent
2fbd4782
Pipeline
#22124
passed with stage
in 8 minutes and 21 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
tests/shakemap_test.py
View file @
00590cd7
...
...
@@ -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
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment