Skip to content

Commit 3f13c2e

Browse files
committed
impact func __eq__
1 parent 31ea96d commit 3f13c2e

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

climada/entity/impact_funcs/base.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,19 @@ def __init__(
9797
self.mdd = mdd if mdd is not None else np.array([])
9898
self.paa = paa if paa is not None else np.array([])
9999

100+
def __eq__(self, value: object, /) -> bool:
101+
if isinstance(value, ImpactFunc):
102+
return (
103+
self.haz_type == value.haz_type
104+
and self.id == value.id
105+
and self.name == value.name
106+
and self.intensity_unit == value.intensity_unit
107+
and np.array_equal(self.intensity, value.intensity)
108+
and np.array_equal(self.mdd, value.mdd)
109+
and np.array_equal(self.paa, value.paa)
110+
)
111+
return False
112+
100113
def calc_mdr(self, inten: Union[float, np.ndarray]) -> np.ndarray:
101114
"""Interpolate impact function to a given intensity.
102115
@@ -177,7 +190,7 @@ def from_step_impf(
177190
mdd: tuple[float, float] = (0, 1),
178191
paa: tuple[float, float] = (1, 1),
179192
impf_id: int = 1,
180-
**kwargs
193+
**kwargs,
181194
):
182195
"""Step function type impact function.
183196
@@ -218,7 +231,7 @@ def from_step_impf(
218231
intensity=intensity,
219232
mdd=mdd,
220233
paa=paa,
221-
**kwargs
234+
**kwargs,
222235
)
223236

224237
def set_step_impf(self, *args, **kwargs):
@@ -238,7 +251,7 @@ def from_sigmoid_impf(
238251
x0: float,
239252
haz_type: str,
240253
impf_id: int = 1,
241-
**kwargs
254+
**kwargs,
242255
):
243256
r"""Sigmoid type impact function hinging on three parameter.
244257
@@ -287,7 +300,7 @@ def from_sigmoid_impf(
287300
intensity=intensity,
288301
paa=paa,
289302
mdd=mdd,
290-
**kwargs
303+
**kwargs,
291304
)
292305

293306
def set_sigmoid_impf(self, *args, **kwargs):
@@ -308,7 +321,7 @@ def from_poly_s_shape(
308321
exponent: float,
309322
haz_type: str,
310323
impf_id: int = 1,
311-
**kwargs
324+
**kwargs,
312325
):
313326
r"""S-shape polynomial impact function hinging on four parameter.
314327

climada/entity/impact_funcs/impact_func_set.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ def __init__(self, impact_funcs: Optional[Iterable[ImpactFunc]] = None):
109109
for impf in impact_funcs:
110110
self.append(impf)
111111

112+
def __eq__(self, value: object, /) -> bool:
113+
if isinstance(value, ImpactFuncSet):
114+
return self._data == value._data
115+
116+
return False
117+
112118
def clear(self):
113119
"""Reinitialize attributes."""
114120
self._data = dict() # {hazard_type : {id:ImpactFunc}}

0 commit comments

Comments
 (0)