-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
35 additions
and
16 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,61 @@ | ||
import os | ||
import pytest | ||
import logging | ||
|
||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
from hazardmaps import hazardmap as hazmap | ||
|
||
from hazardmaps import hazardmap as hazmap | ||
from hazardmaps.config import volcfile, volcnames, exposure_file, exposure_breakdown_file, floodratio, floodtypes, eearthquake_file | ||
|
||
logging.basicConfig(format='%(asctime)s - %(message)s', level=logging.INFO) | ||
|
||
|
||
@pytest.mark.mpl_image_compare | ||
def test_succeeds(): | ||
""" | ||
Very simple test to check that the matplotlib | ||
image compare hook is set up correctly. | ||
""" | ||
fig = plt.figure() | ||
ax = fig.add_subplot(1,1,1) | ||
ax.plot([1,2,3], linestyle='-') | ||
return fig | ||
|
||
# This is a long-running test as it essential runs the whole script against | ||
# the full Tanzania dataset. | ||
# Should rewrite or skip if nepal data because the logic is slightly different | ||
|
||
@pytest.mark.skipif(os.getenv("GITLAB_CI") is not None, reason="cannot run this test on CI server due to data requirement") | ||
@pytest.mark.mpl_image_compare | ||
def test_hazard_map_regression(): | ||
# Call the main function here to get the image gpd | ||
print("Generating regression test data...this may take a while") | ||
"""Regression test to check that running a full hazard map analysis to completion | ||
produces the same map by the way of an image comparison check. | ||
You must run this test locally. If the test case data is changed, you will need | ||
to regenerate the test images, the "baseline" images. and replace | ||
the ones in the baseline folder in the test directory. | ||
pytest --mpl-generate-path="test/baseline" test/test.py | ||
Then run the tests with the --mpl flag | ||
pytest --mpl test/test.py | ||
""" | ||
logging.info("Generating regression test data...this may take a while") | ||
# The steps below are similar to the ones found in the main() function in the hazardmaps.py file | ||
volcano_lahar, volcano_pyro = hazmap.read_volcano_data(volcfile, volcnames) | ||
tz, tz_withgeometry = hazmap.buildings(exposure_file, exposure_breakdown_file) # tz needs a rename... | ||
tz_withgeometry_withflood = hazmap.flood_data(floodratio, floodtypes, tz, tz_withgeometry) # returns tz_withgeometry again! | ||
tz_withgeometry_withflood_withvolcano = hazmap.combine_volcano_buildings(tz_withgeometry_withflood, volcano_lahar, volcano_pyro) # as above - flood_data is the tz_geometry | ||
tz_earthquakes = hazmap.earthquake_data(eearthquake_file) # as above - but this one only generates earthquake data | ||
tz, tz_withgeometry = hazmap.buildings(exposure_file, exposure_breakdown_file) | ||
tz_withgeometry_withflood = hazmap.flood_data(floodratio, floodtypes, tz, tz_withgeometry) | ||
tz_withgeometry_withflood_withvolcano = hazmap.combine_volcano_buildings(tz_withgeometry_withflood, volcano_lahar, volcano_pyro) | ||
tz_earthquakes = hazmap.earthquake_data(eearthquake_file) | ||
combined_data = hazmap.hazards_combined(tz_earthquakes, tz_withgeometry_withflood_withvolcano) | ||
|
||
np.sum(np.isnan(combined_data.volc)) | ||
|
||
print("Printing single hmap plot:") | ||
logging.info("Printing single hmap plot:") | ||
|
||
# Now plot the test figures | ||
fig = plt.figure() | ||
ax = fig.add_subplot(1,1,1) | ||
ax = combined_data.plot(ax=ax, column="hmap", markersize=0.01, legend=True) # Problemm calling from pandas? | ||
plt.savefig("regression_test_hmap_step1.png") | ||
ax = combined_data.plot(ax=ax, column="hmap", markersize=0.01, legend=True) | ||
|
||
lims = plt.axis('equal') | ||
plt.savefig("regression_test_hmap_step2.png") | ||
return fig # Test function must return the figure to work wth decorator | ||
# Test function must return the figure to work with the mpl image compare decorator | ||
return fig |