Skip to content

Commit ba95b66

Browse files
authored
Merge pull request #49 from Freeman-Trader/more_viewing_angles
More Viewing Angles
2 parents 53785cf + d8d44fd commit ba95b66

File tree

4 files changed

+52
-8
lines changed

4 files changed

+52
-8
lines changed

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,33 @@ rm.plot_map(values=rm.preprocess(values=values, lake_flatness=4, water_ntile=30,
164164

165165
![png](https://github.com/ColCarroll/ridge_map/blob/main/examples/boston.png?raw=true)
166166

167+
### Can I change the angle?
168+
169+
Yes, you can change the angle at which you look at the map. South to North is 0 degrees, East to West is 90 degrees and so forth with the rest of the compass. I really recommend playing around with this setting because of the really cool maps it can generate.
170+
171+
Play around with `interpolation`, `lock_rotation`, and `crop` to polish out the map.
172+
173+
```python
174+
rm = RidgeMap((-124.848974,46.292035,-116.463262,49.345786))
175+
values = rm.get_elevation_data(elevation_pts=300, num_lines=300, viewpoint_angle=11)
176+
values=rm.preprocess(
177+
values=values,
178+
lake_flatness=2,
179+
water_ntile=10,
180+
vertical_ratio=240
181+
)
182+
rm.plot_map(values=values,
183+
label='Washington',
184+
label_y=0.8,
185+
label_x=0.05,
186+
label_size=40,
187+
linewidth=2
188+
)
189+
```
190+
191+
![png](/examples/washington.png?raw=true)
192+
![gif](/examples/washington.gif?raw=true)
193+
167194
### What about Walden Pond?
168195

169196
It is that pleasant kettle pond in the bottom right of this map, looking entirely comfortable with its place in Western writing and thought.

examples/washington.gif

13.4 MB
Loading

examples/washington.png

1.26 MB
Loading

ridge_map/ridge_map.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from skimage.filters import rank
1111
from skimage.morphology import square
1212
from skimage.util import img_as_ubyte
13+
from scipy.ndimage import rotate
1314

1415
import srtm
1516

@@ -90,7 +91,15 @@ def longs(self):
9091
"""Bottom and top longitude of bounding box."""
9192
return (self.bbox[0], self.bbox[2])
9293

93-
def get_elevation_data(self, num_lines=80, elevation_pts=300, viewpoint="south"):
94+
def get_elevation_data(
95+
self,
96+
num_lines=80,
97+
elevation_pts=300,
98+
viewpoint_angle=0,
99+
crop=False,
100+
interpolation=0,
101+
lock_resolution=False
102+
):
94103
"""Fetch elevation data and return a numpy array.
95104
96105
Parameters
@@ -100,22 +109,30 @@ def get_elevation_data(self, num_lines=80, elevation_pts=300, viewpoint="south")
100109
elevation_pts : int
101110
Number of points on each line to request. There's some limit to
102111
this that srtm enforces, but feel free to go for it!
103-
viewpoint : str in ["south", "west", "north", "east"] (default "south")
104-
The compass direction from which the map will be visualised.
112+
viewpoint_angle : int (default 0)
113+
The angle in degrees from which the map will be visualised.
114+
crop : bool
115+
If the corners are cropped when rotating
116+
interpolation : int in [0, 5]
117+
The level of interpolation. Can smooth out sharp edges, especially
118+
when rotating. Above 1 tends to lead to an all NaN graph.
119+
lock_resolution : bool
120+
Locks the resolution during rotation, ensuring consistent rotation
121+
deltas but producing potential scaling artifacts. These artifacts
122+
can be reduced by setting num_lines = elevation_pts.
105123
106124
Returns
107125
-------
108126
np.ndarray
109127
"""
110-
if viewpoint in ["east", "west"]:
128+
if (45 < (viewpoint_angle % 360) < 135 or 225 < (viewpoint_angle % 360) < 315) and not lock_resolution:
111129
num_lines, elevation_pts = elevation_pts, num_lines
130+
112131
values = self._srtm_data.get_image(
113132
(elevation_pts, num_lines), self.lats, self.longs, 5280, mode="array"
114133
)
115-
116-
switch = {"south": 0, "west": 3, "north": 2, "east": 1}
117-
rotations = switch[viewpoint]
118-
values = np.rot90(m=values, k=rotations)
134+
values = rotate(values, angle=viewpoint_angle, reshape=not crop, order=interpolation)
135+
119136
return values
120137

121138
def preprocess(

0 commit comments

Comments
 (0)