1
1
"""Damage assessment"""
2
+
2
3
from abc import ABC
3
4
import numpy
4
5
import pandas
@@ -72,16 +73,16 @@ def from_csv(
72
73
73
74
Parameters
74
75
----------
75
- fname: str, path object or file-like object
76
- intensity_col: str, default "intensity"
76
+ fname : str, path object or file-like object
77
+ intensity_col : str, default "intensity"
77
78
Column name to read hazard intensity values
78
- damage_col: str, default "damage_ratio"
79
+ damage_col : str, default "damage_ratio"
79
80
Column name to read damage values
80
- comment: str, default "#"
81
+ comment : str, default "#"
81
82
Indicates remainder of the line in the CSV should not be parsed.
82
83
If found at the beginning of a line, the line will be ignored
83
84
altogether.
84
- kwargs:
85
+ kwargs
85
86
see pandas.read_csv documentation
86
87
87
88
Returns
@@ -115,19 +116,19 @@ def from_excel(
115
116
116
117
Parameters
117
118
----------
118
- fname: str, path object or file-like object
119
- sheet_name: str, int
119
+ fname : str, path object or file-like object
120
+ sheet_name : str or int
120
121
Strings are used for sheet names. Integers are used in zero-indexed sheet
121
122
positions (chart sheets do not count as a sheet position).
122
- intensity_col: str, default "intensity"
123
+ intensity_col : str, default "intensity"
123
124
Column name to read hazard intensity values
124
- damage_col: str, default "damage_ratio"
125
+ damage_col : str, default "damage_ratio"
125
126
Column name to read damage values
126
- comment: str, default "#"
127
+ comment : str, default "#"
127
128
Indicates remainder of the line in the CSV should not be parsed.
128
129
If found at the beginning of a line, the line will be ignored
129
130
altogether.
130
- kwargs:
131
+ kwargs
131
132
see pandas.read_csv documentation
132
133
133
134
Returns
@@ -159,9 +160,9 @@ def interpolate(
159
160
160
161
Parameters
161
162
----------
162
- a: PiecewiseLinearDamageCurve
163
- b: PiecewiseLinearDamageCurve
164
- factor: float
163
+ a : PiecewiseLinearDamageCurve
164
+ b : PiecewiseLinearDamageCurve
165
+ factor : float
165
166
Interpolation factor, used to calculate the new curve
166
167
167
168
Returns
@@ -189,6 +190,7 @@ def damage_fraction(self, exposure: numpy.array) -> numpy.array:
189
190
return self ._interpolate (exposure )
190
191
191
192
def translate_y (self , y : float ):
193
+ """Translate damage by a factor, y"""
192
194
damage = self .damage + y
193
195
194
196
return PiecewiseLinearDamageCurve (
@@ -201,6 +203,7 @@ def translate_y(self, y: float):
201
203
)
202
204
203
205
def scale_y (self , y : float ):
206
+ """Scale damage by a factor, y"""
204
207
damage = self .damage * y
205
208
206
209
return PiecewiseLinearDamageCurve (
@@ -213,6 +216,7 @@ def scale_y(self, y: float):
213
216
)
214
217
215
218
def translate_x (self , x : float ):
219
+ """Translate intensity by a factor, x"""
216
220
intensity = self .intensity + x
217
221
218
222
return PiecewiseLinearDamageCurve (
@@ -225,6 +229,7 @@ def translate_x(self, x: float):
225
229
)
226
230
227
231
def scale_x (self , x : float ):
232
+ """Scale intensity by a factor, x"""
228
233
intensity = self .intensity * x
229
234
230
235
return PiecewiseLinearDamageCurve (
@@ -238,6 +243,7 @@ def scale_x(self, x: float):
238
243
239
244
@staticmethod
240
245
def clip_curve_data (intensity , damage ):
246
+ """Clip damage curve values to valid 0-1 damage range"""
241
247
if (damage .max () > 1 ) or (damage .min () < 0 ):
242
248
# WARNING clipping out-of-bounds damage fractions
243
249
bounds = (
@@ -281,6 +287,7 @@ def clip_curve_data(intensity, damage):
281
287
return intensity , damage
282
288
283
289
def plot (self , ax = None ):
290
+ """Plot a line chart of the damage curve"""
284
291
import matplotlib .pyplot as plt
285
292
286
293
if ax is None :
0 commit comments