Skip to content

Commit 98f128c

Browse files
committed
Format docstrings
1 parent 428d66f commit 98f128c

File tree

2 files changed

+38
-25
lines changed

2 files changed

+38
-25
lines changed

src/snail/damages.py

+21-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Damage assessment"""
2+
23
from abc import ABC
34
import numpy
45
import pandas
@@ -72,16 +73,16 @@ def from_csv(
7273
7374
Parameters
7475
----------
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"
7778
Column name to read hazard intensity values
78-
damage_col: str, default "damage_ratio"
79+
damage_col : str, default "damage_ratio"
7980
Column name to read damage values
80-
comment: str, default "#"
81+
comment : str, default "#"
8182
Indicates remainder of the line in the CSV should not be parsed.
8283
If found at the beginning of a line, the line will be ignored
8384
altogether.
84-
kwargs:
85+
kwargs
8586
see pandas.read_csv documentation
8687
8788
Returns
@@ -115,19 +116,19 @@ def from_excel(
115116
116117
Parameters
117118
----------
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
120121
Strings are used for sheet names. Integers are used in zero-indexed sheet
121122
positions (chart sheets do not count as a sheet position).
122-
intensity_col: str, default "intensity"
123+
intensity_col : str, default "intensity"
123124
Column name to read hazard intensity values
124-
damage_col: str, default "damage_ratio"
125+
damage_col : str, default "damage_ratio"
125126
Column name to read damage values
126-
comment: str, default "#"
127+
comment : str, default "#"
127128
Indicates remainder of the line in the CSV should not be parsed.
128129
If found at the beginning of a line, the line will be ignored
129130
altogether.
130-
kwargs:
131+
kwargs
131132
see pandas.read_csv documentation
132133
133134
Returns
@@ -159,9 +160,9 @@ def interpolate(
159160
160161
Parameters
161162
----------
162-
a: PiecewiseLinearDamageCurve
163-
b: PiecewiseLinearDamageCurve
164-
factor: float
163+
a : PiecewiseLinearDamageCurve
164+
b : PiecewiseLinearDamageCurve
165+
factor : float
165166
Interpolation factor, used to calculate the new curve
166167
167168
Returns
@@ -189,6 +190,7 @@ def damage_fraction(self, exposure: numpy.array) -> numpy.array:
189190
return self._interpolate(exposure)
190191

191192
def translate_y(self, y: float):
193+
"""Translate damage by a factor, y"""
192194
damage = self.damage + y
193195

194196
return PiecewiseLinearDamageCurve(
@@ -201,6 +203,7 @@ def translate_y(self, y: float):
201203
)
202204

203205
def scale_y(self, y: float):
206+
"""Scale damage by a factor, y"""
204207
damage = self.damage * y
205208

206209
return PiecewiseLinearDamageCurve(
@@ -213,6 +216,7 @@ def scale_y(self, y: float):
213216
)
214217

215218
def translate_x(self, x: float):
219+
"""Translate intensity by a factor, x"""
216220
intensity = self.intensity + x
217221

218222
return PiecewiseLinearDamageCurve(
@@ -225,6 +229,7 @@ def translate_x(self, x: float):
225229
)
226230

227231
def scale_x(self, x: float):
232+
"""Scale intensity by a factor, x"""
228233
intensity = self.intensity * x
229234

230235
return PiecewiseLinearDamageCurve(
@@ -238,6 +243,7 @@ def scale_x(self, x: float):
238243

239244
@staticmethod
240245
def clip_curve_data(intensity, damage):
246+
"""Clip damage curve values to valid 0-1 damage range"""
241247
if (damage.max() > 1) or (damage.min() < 0):
242248
# WARNING clipping out-of-bounds damage fractions
243249
bounds = (
@@ -281,6 +287,7 @@ def clip_curve_data(intensity, damage):
281287
return intensity, damage
282288

283289
def plot(self, ax=None):
290+
"""Plot a line chart of the damage curve"""
284291
import matplotlib.pyplot as plt
285292

286293
if ax is None:

src/snail/intersection.py

+17-11
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,22 @@ class GridDefinition:
4545
output files. They effectively form the first two rows of a 3x3 matrix:
4646
4747
48-
```
49-
| x | | a b c | | i |
50-
| y | = | d e f | | j |
51-
| 1 | | 0 0 1 | | 1 |
52-
```
48+
.. code-block:: text
49+
50+
| x | | a b c | | i |
51+
| y | = | d e f | | j |
52+
| 1 | | 0 0 1 | | 1 |
53+
5354
5455
In cases without shear or rotation, `a` and `e` define scaling or grid cell
5556
size, while `c` and `f` define the offset or grid upper-left corner:
5657
57-
```
58-
| x_scale 0 x_offset |
59-
| 0 y_scale y_offset |
60-
| 0 0 1 |
61-
```
58+
.. code-block:: text
59+
60+
| x_scale 0 x_offset |
61+
| 0 y_scale y_offset |
62+
| 0 0 1 |
63+
6264
"""
6365

6466
crs: str
@@ -68,6 +70,7 @@ class GridDefinition:
6870

6971
@classmethod
7072
def from_rasterio_dataset(cls, dataset):
73+
"""GridDefinition for a rasterio dataset"""
7174
crs = dataset.crs
7275
width = dataset.width
7376
height = dataset.height
@@ -77,6 +80,7 @@ def from_rasterio_dataset(cls, dataset):
7780

7881
@classmethod
7982
def from_raster(cls, fname):
83+
"""GridDefinition for a raster file (readable by rasterio)"""
8084
with rasterio.open(fname) as dataset:
8185
grid = GridDefinition.from_rasterio_dataset(dataset)
8286
return grid
@@ -92,6 +96,7 @@ def from_extent(
9296
cell_height: float,
9397
crs,
9498
):
99+
"""GridDefinition for a given extent, cell size and CRS"""
95100
return GridDefinition(
96101
crs=crs,
97102
width=math.ceil((xmax - xmin) / cell_width),
@@ -205,7 +210,8 @@ def split_polygons(
205210
return splits
206211

207212

208-
def generate_grid_boxes(grid):
213+
def generate_grid_boxes(grid: GridDefinition):
214+
"""Generate all the box polygons for a grid"""
209215
a, b, c, d, e, f = grid.transform
210216
idx = numpy.arange(grid.width * grid.height)
211217
i, j = numpy.unravel_index(idx, (grid.width, grid.height))

0 commit comments

Comments
 (0)