Skip to content

Commit

Permalink
Feature/coverage (#608)
Browse files Browse the repository at this point in the history
Add plotting to unit test for increased coverage

Adds coverage to the following plot functions:
* `Hazard.plot_rp_intensity`
* `DiscRates.plot`
* `Centroids.plot`

Co-authored-by: Lukas Riedel <[email protected]>
  • Loading branch information
NicolasColombi and peanutfun authored Jan 6, 2023
1 parent 39073f8 commit 5c7daea
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions climada/test/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@

from climada.entity.entity_def import Entity
from climada.hazard.base import Hazard
from climada.hazard import Centroids
from climada.entity.exposures.base import Exposures
from climada.entity import DiscRates
from climada.entity.impact_funcs.impact_func_set import ImpactFuncSet
from climada.engine import ImpactCalc, ImpactFreqCurve
from climada.util.constants import HAZ_DEMO_MAT, ENT_DEMO_TODAY
Expand Down Expand Up @@ -90,6 +92,18 @@ def test_hazard_fraction_pass(self):
myax = hazard.plot_fraction(centr=-1)
self.assertIn('1-largest Centroid. 79: (30.0, -77.0)', myax.get_title())

def test_hazard_rp_intensity(self):
""""Plot exceedance intensity maps for different return periods"""
hazard = Hazard.from_mat(HAZ_DEMO_MAT)
(axis1, axis2), _ = hazard.plot_rp_intensity([25, 50])
self.assertEqual('Return period: 25 years', axis1.get_title())
self.assertEqual('Return period: 50 years', axis2.get_title())

def test_hazard_centroids(self):
"""Plot centroids scatter points over earth."""
centroids = Centroids.from_base_grid()
centroids.plot()

def test_exposures_value_pass(self):
"""Plot exposures values."""
myexp = pd.read_excel(ENT_DEMO_TODAY)
Expand Down Expand Up @@ -147,6 +161,15 @@ def test_ctx_osm_pass(self):
except urllib.error.HTTPError:
self.assertEqual(1, 0)

def test_disc_rates(self):
"""Test plot function of discount rates."""
years = np.arange(1950, 2100)
rates = np.ones(years.size) * 0.014
rates[51:55] = 0.025
rates[95:120] = 0.035
disc = DiscRates(years=years, rates=rates)
disc.plot()

# Execute Tests
if __name__ == "__main__":
TESTS = unittest.TestLoader().loadTestsFromTestCase(TestPlotter)
Expand Down

0 comments on commit 5c7daea

Please sign in to comment.