diff --git a/climada/hazard/base.py b/climada/hazard/base.py index eee424115a..6c3592c91b 100644 --- a/climada/hazard/base.py +++ b/climada/hazard/base.py @@ -159,10 +159,10 @@ class Hazard(): scalar, string, list, 1dim np.array of size num_events.""" def __init__(self, - haz_type: str, intensity: sparse.csr_matrix, centroids: Centroids, date: np.ndarray, + haz_type: str = "", units: str = "", frequency: Optional[np.ndarray] = None, frequency_unit: str = DEF_FREQ_UNIT, @@ -182,14 +182,15 @@ def __init__(self, Parameters ---------- - haz_type : str - String indicating the hazard type (e.g., ``TC`` for tropical cyclone) intensity : sparse.csr_matrix The intensity of the hazard for each event. Shape ``(n_event, n_centroids)`` centroids : Centroids The centroids on which this hazard is defined. date : np.array of int The ordinal representation of the date of each event. + haz_type : str (optional) + String indicating the hazard type (e.g., ``TC`` for tropical cyclone). This + parameter is passed to the hazard ``Tag``. units : str (optional) The physical units of the intensity (used for plotting) frequency : np.array of float (optional) diff --git a/climada/hazard/test/test_base.py b/climada/hazard/test/test_base.py index ee3a85c4f2..31a7cf6859 100644 --- a/climada/hazard/test/test_base.py +++ b/climada/hazard/test/test_base.py @@ -55,10 +55,10 @@ def dummy_hazard(): [4.3, 2.1, 1.0], [5.3, 0.2, 0.0]]) units = 'm/s' - return Hazard(haz_type, - intensity, + return Hazard(intensity, centroids, date, + haz_type, units, frequency, frequency_unit, @@ -86,10 +86,10 @@ def setUp(self): self.intensity = sparse.csr_matrix([[1, 2], [1, 2], [1, 2]]) self.fraction = sparse.csr_matrix([[1, 2], [1, 2], [1, 2]]) - self.hazard = Hazard(self.haz_type, - self.intensity, + self.hazard = Hazard(self.intensity, self.centroids, self.date, + self.haz_type, event_id=self.event_id, event_name=self.event_name, frequency=self.frequency, @@ -101,10 +101,10 @@ def good_hazard(self): def test_minimal_hazard(self): """Check if stating only the required parameters works""" - Hazard(self.haz_type, - self.intensity, + Hazard(self.intensity, self.centroids, self.date, + self.haz_type, fast=False) def test_fast_init_fail(self): @@ -112,21 +112,21 @@ def test_fast_init_fail(self): frequency = np.array([1, 2]) # Not fast: Should raise exception with self.assertRaises(ValueError) as cm: - Hazard(self.haz_type, - self.intensity, - self.centroids, - self.date, - event_id=self.event_id, - event_name=self.event_name, - frequency=frequency, - fraction=self.fraction) + Hazard(self.intensity, + self.centroids, + self.date, + self.haz_type, + event_id=self.event_id, + event_name=self.event_name, + frequency=frequency, + fraction=self.fraction) self.assertIn("Invalid Hazard.frequency", str(cm.exception)) # Fast: Skip check - Hazard(self.haz_type, - self.intensity, + Hazard(self.intensity, self.centroids, self.date, + self.haz_type, event_id=self.event_id, event_name=self.event_name, frequency=frequency,