From 10c4728aa900b27d8a8de55974940c0d8b10813d Mon Sep 17 00:00:00 2001 From: colcarroll Date: Sun, 20 Apr 2025 07:29:47 -0400 Subject: [PATCH 1/2] Square is deprecated. --- .gitignore | 6 +++++ ridge_map/ridge_map.py | 61 +++++++++++++++++++++++++----------------- 2 files changed, 42 insertions(+), 25 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4701741 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +PKG-INFO +SOURCES.txt +dependency_links.txt +requires.txt +top_level.txt + diff --git a/ridge_map/ridge_map.py b/ridge_map/ridge_map.py index 87a9c05..a67b792 100644 --- a/ridge_map/ridge_map.py +++ b/ridge_map/ridge_map.py @@ -91,14 +91,15 @@ def longs(self): """Bottom and top longitude of bounding box.""" return (self.bbox[0], self.bbox[2]) + # pylint: disable=too-many-arguments,too-many-positional-arguments def get_elevation_data( - self, - num_lines=80, - elevation_pts=300, - viewpoint_angle=0, + self, + num_lines=80, + elevation_pts=300, + viewpoint_angle=0, crop=False, - interpolation=0, - lock_resolution=False + interpolation=0, + lock_resolution=False, ): """Fetch elevation data and return a numpy array. @@ -114,25 +115,29 @@ def get_elevation_data( crop : bool If the corners are cropped when rotating interpolation : int in [0, 5] - The level of interpolation. Can smooth out sharp edges, especially + The level of interpolation. Can smooth out sharp edges, especially when rotating. Above 1 tends to lead to an all NaN graph. lock_resolution : bool - Locks the resolution during rotation, ensuring consistent rotation - deltas but producing potential scaling artifacts. These artifacts + Locks the resolution during rotation, ensuring consistent rotation + deltas but producing potential scaling artifacts. These artifacts can be reduced by setting num_lines = elevation_pts. Returns ------- np.ndarray """ - if (45 < (viewpoint_angle % 360) < 135 or 225 < (viewpoint_angle % 360) < 315) and not lock_resolution: + if ( + 45 < (viewpoint_angle % 360) < 135 or 225 < (viewpoint_angle % 360) < 315 + ) and not lock_resolution: num_lines, elevation_pts = elevation_pts, num_lines - + values = self._srtm_data.get_image( (elevation_pts, num_lines), self.lats, self.longs, 5280, mode="array" ) - values = rotate(values, angle=viewpoint_angle, reshape=not crop, order=interpolation) - + values = rotate( + values, angle=viewpoint_angle, reshape=not crop, order=interpolation + ) + return values def preprocess( @@ -173,7 +178,10 @@ def preprocess( values = (values - np.min(values)) / (np.max(values) - np.min(values)) is_water = values < np.percentile(values, water_ntile) - is_lake = rank.gradient(img_as_ubyte(values), square(3)) < lake_flatness + is_lake = ( + rank.gradient(img_as_ubyte(values), footprint_rectangle((3, 3))) + < lake_flatness + ) values[nan_vals] = np.nan values[np.logical_or(is_water, is_lake)] = np.nan @@ -193,7 +201,7 @@ def plot_annotation( background=True, ax=None, ): - """Plot an annotation to an existing map + """Plot an annotation to an existing map. It is recommended to call this function only after calling map_plot() @@ -217,23 +225,26 @@ def plot_annotation( If there is a background or not ax : matplotlib Axes You can pass your own axes, but probably best not to - + Returns ------- matplotlib.Axes - """ + """ if ax is None and self.ax is None: - raise ValueError("No axes found: Either plot_map() beforehand or pass an matplotlib.Axes value through") - elif ax is None: + raise ValueError( + "No axes found: Either plot_map() beforehand or pass an matplotlib.Axes value " + "to the function." + ) + if ax is None: ax = self.ax - + highest_zorder = max(text.zorder for text in ax.texts) if ax.texts else 1 - + rel_coordinates = ( (coordinates[0] - self.longs[0]) / (self.longs[1] - self.longs[0]), (coordinates[1] - self.lats[0]) / (self.lats[1] - self.lats[0]), ) - + annotation_color = "black" if color: annotation_color = color @@ -265,10 +276,10 @@ def plot_annotation( ms=annotation_size, zorder=highest_zorder, ) - + self.ax = ax return ax - + # pylint: disable=too-many-arguments,too-many-locals def plot_map( self, @@ -383,6 +394,6 @@ def plot_map( for spine in ax.spines.values(): spine.set_visible(False) ax.set_facecolor(background_color) - + self.ax = ax return ax From 5008a5049ffb3d571e2fa8394c11d929764f4125 Mon Sep 17 00:00:00 2001 From: colcarroll Date: Sun, 20 Apr 2025 07:29:47 -0400 Subject: [PATCH 2/2] Square is deprecated. --- .gitignore | 2 +- ridge_map/ridge_map.py | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 4701741..669a895 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,4 @@ SOURCES.txt dependency_links.txt requires.txt top_level.txt - +.coverage diff --git a/ridge_map/ridge_map.py b/ridge_map/ridge_map.py index a67b792..4e7f68b 100644 --- a/ridge_map/ridge_map.py +++ b/ridge_map/ridge_map.py @@ -8,7 +8,7 @@ import matplotlib.pyplot as plt import numpy as np from skimage.filters import rank -from skimage.morphology import square +from skimage.morphology import footprint_rectangle from skimage.util import img_as_ubyte from scipy.ndimage import rotate @@ -337,7 +337,6 @@ def plot_map( ------- matplotlib.Axes """ - if kind not in {"gradient", "elevation"}: raise TypeError("Argument `kind` must be one of 'gradient' or 'elevation'") if values is None: