|
28 | 28 |
|
29 | 29 | from climada import CONFIG
|
30 | 30 | from climada.entity.entity_def import Entity
|
31 |
| -from climada.entity import Exposures, ImpactFuncSet, ImpactFunc |
32 |
| -from climada.hazard.base import Hazard |
| 31 | +from climada.entity import Exposures, ImpactFuncSet, ImpactFunc, ImpfTropCyclone |
| 32 | +from climada.hazard.base import Hazard, Centroids |
33 | 33 | from climada.engine import ImpactCalc, Impact
|
34 | 34 | from climada.engine.impact_calc import LOGGER as ILOG
|
35 | 35 | from climada.util.constants import ENT_DEMO_TODAY, DEMO_DIR
|
@@ -471,6 +471,34 @@ def test_stitch_risk_metrics(self):
|
471 | 471 | np.testing.assert_array_equal(eai_exp, [2.25, 1.25, 4.5])
|
472 | 472 | self.assertEqual(aai_agg, 8.0) # Sum of eai_exp
|
473 | 473 |
|
| 474 | + def test_single_exp_zero_mdr(self): |
| 475 | + """Test for case where exposure has a single value and MDR or fraction contains zeros""" |
| 476 | + centroids = Centroids.from_lat_lon([-26.16], [28.20]) |
| 477 | + haz = Hazard( |
| 478 | + intensity=sparse.csr_matrix(np.array([[31.5], [19.0]])), |
| 479 | + event_id=np.arange(2), |
| 480 | + event_name=[0,1], |
| 481 | + frequency=np.ones(2) / 2, |
| 482 | + fraction=sparse.csr_matrix(np.zeros((2,1))), |
| 483 | + date=np.array([0, 1]), |
| 484 | + centroids=centroids, |
| 485 | + haz_type='TC' |
| 486 | + ) |
| 487 | + exp = Exposures({'value': [1.], |
| 488 | + 'longitude': 28.22, |
| 489 | + 'latitude': -26.17, |
| 490 | + 'impf_TC': 1}, |
| 491 | + crs="EPSG:4326") |
| 492 | + imp_evt = 0.00250988804927603 |
| 493 | + aai_agg = imp_evt/2 |
| 494 | + eai_exp = np.array([aai_agg]) |
| 495 | + at_event = np.array([imp_evt, 0]) |
| 496 | + exp.set_geometry_points() |
| 497 | + impf_tc = ImpfTropCyclone.from_emanuel_usa() |
| 498 | + impf_set = ImpactFuncSet([impf_tc]) |
| 499 | + impf_set.check() |
| 500 | + imp = ImpactCalc(exp, impf_set, haz).impact(save_mat=True) |
| 501 | + check_impact(self, imp, haz, exp, aai_agg, eai_exp, at_event, at_event) |
474 | 502 |
|
475 | 503 | class TestImpactMatrixCalc(unittest.TestCase):
|
476 | 504 | """Verify the computation of the impact matrix"""
|
|
0 commit comments