Skip to content

Commit c5a3ea9

Browse files
authored
Merge pull request #54 from ColCarroll/square
Square is deprecated
2 parents 3e323f9 + 5008a50 commit c5a3ea9

File tree

2 files changed

+43
-27
lines changed

2 files changed

+43
-27
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
PKG-INFO
2+
SOURCES.txt
3+
dependency_links.txt
4+
requires.txt
5+
top_level.txt
6+
.coverage

ridge_map/ridge_map.py

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import matplotlib.pyplot as plt
99
import numpy as np
1010
from skimage.filters import rank
11-
from skimage.morphology import square
11+
from skimage.morphology import footprint_rectangle
1212
from skimage.util import img_as_ubyte
1313
from scipy.ndimage import rotate
1414

@@ -91,14 +91,15 @@ def longs(self):
9191
"""Bottom and top longitude of bounding box."""
9292
return (self.bbox[0], self.bbox[2])
9393

94+
# pylint: disable=too-many-arguments,too-many-positional-arguments
9495
def get_elevation_data(
95-
self,
96-
num_lines=80,
97-
elevation_pts=300,
98-
viewpoint_angle=0,
96+
self,
97+
num_lines=80,
98+
elevation_pts=300,
99+
viewpoint_angle=0,
99100
crop=False,
100-
interpolation=0,
101-
lock_resolution=False
101+
interpolation=0,
102+
lock_resolution=False,
102103
):
103104
"""Fetch elevation data and return a numpy array.
104105
@@ -114,25 +115,29 @@ def get_elevation_data(
114115
crop : bool
115116
If the corners are cropped when rotating
116117
interpolation : int in [0, 5]
117-
The level of interpolation. Can smooth out sharp edges, especially
118+
The level of interpolation. Can smooth out sharp edges, especially
118119
when rotating. Above 1 tends to lead to an all NaN graph.
119120
lock_resolution : bool
120-
Locks the resolution during rotation, ensuring consistent rotation
121-
deltas but producing potential scaling artifacts. These artifacts
121+
Locks the resolution during rotation, ensuring consistent rotation
122+
deltas but producing potential scaling artifacts. These artifacts
122123
can be reduced by setting num_lines = elevation_pts.
123124
124125
Returns
125126
-------
126127
np.ndarray
127128
"""
128-
if (45 < (viewpoint_angle % 360) < 135 or 225 < (viewpoint_angle % 360) < 315) and not lock_resolution:
129+
if (
130+
45 < (viewpoint_angle % 360) < 135 or 225 < (viewpoint_angle % 360) < 315
131+
) and not lock_resolution:
129132
num_lines, elevation_pts = elevation_pts, num_lines
130-
133+
131134
values = self._srtm_data.get_image(
132135
(elevation_pts, num_lines), self.lats, self.longs, 5280, mode="array"
133136
)
134-
values = rotate(values, angle=viewpoint_angle, reshape=not crop, order=interpolation)
135-
137+
values = rotate(
138+
values, angle=viewpoint_angle, reshape=not crop, order=interpolation
139+
)
140+
136141
return values
137142

138143
def preprocess(
@@ -173,7 +178,10 @@ def preprocess(
173178
values = (values - np.min(values)) / (np.max(values) - np.min(values))
174179

175180
is_water = values < np.percentile(values, water_ntile)
176-
is_lake = rank.gradient(img_as_ubyte(values), square(3)) < lake_flatness
181+
is_lake = (
182+
rank.gradient(img_as_ubyte(values), footprint_rectangle((3, 3)))
183+
< lake_flatness
184+
)
177185

178186
values[nan_vals] = np.nan
179187
values[np.logical_or(is_water, is_lake)] = np.nan
@@ -193,7 +201,7 @@ def plot_annotation(
193201
background=True,
194202
ax=None,
195203
):
196-
"""Plot an annotation to an existing map
204+
"""Plot an annotation to an existing map.
197205
198206
It is recommended to call this function only after calling map_plot()
199207
@@ -217,23 +225,26 @@ def plot_annotation(
217225
If there is a background or not
218226
ax : matplotlib Axes
219227
You can pass your own axes, but probably best not to
220-
228+
221229
Returns
222230
-------
223231
matplotlib.Axes
224-
"""
232+
"""
225233
if ax is None and self.ax is None:
226-
raise ValueError("No axes found: Either plot_map() beforehand or pass an matplotlib.Axes value through")
227-
elif ax is None:
234+
raise ValueError(
235+
"No axes found: Either plot_map() beforehand or pass an matplotlib.Axes value "
236+
"to the function."
237+
)
238+
if ax is None:
228239
ax = self.ax
229-
240+
230241
highest_zorder = max(text.zorder for text in ax.texts) if ax.texts else 1
231-
242+
232243
rel_coordinates = (
233244
(coordinates[0] - self.longs[0]) / (self.longs[1] - self.longs[0]),
234245
(coordinates[1] - self.lats[0]) / (self.lats[1] - self.lats[0]),
235246
)
236-
247+
237248
annotation_color = "black"
238249
if color:
239250
annotation_color = color
@@ -265,10 +276,10 @@ def plot_annotation(
265276
ms=annotation_size,
266277
zorder=highest_zorder,
267278
)
268-
279+
269280
self.ax = ax
270281
return ax
271-
282+
272283
# pylint: disable=too-many-arguments,too-many-locals
273284
def plot_map(
274285
self,
@@ -326,7 +337,6 @@ def plot_map(
326337
-------
327338
matplotlib.Axes
328339
"""
329-
330340
if kind not in {"gradient", "elevation"}:
331341
raise TypeError("Argument `kind` must be one of 'gradient' or 'elevation'")
332342
if values is None:
@@ -383,6 +393,6 @@ def plot_map(
383393
for spine in ax.spines.values():
384394
spine.set_visible(False)
385395
ax.set_facecolor(background_color)
386-
396+
387397
self.ax = ax
388398
return ax

0 commit comments

Comments
 (0)