-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from magnusuMET/deprecated_collections
Replace use of deprecated collections with get_paths
- Loading branch information
Showing
6 changed files
with
139 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from collections.abc import Generator | ||
|
||
import numpy as np | ||
import numpy.typing as npt | ||
from matplotlib.path import Path | ||
|
||
def get_vertices_from_path(path: Path) -> Generator[npt.NDArray[float], None, None]: | ||
"""Splits the vertices from path into continous lines, | ||
by taking into account path.codes | ||
See https://matplotlib.org/stable/api/path_api.html for a | ||
description of path.vertices/path.codes | ||
""" | ||
# path = path.cleaned(curves=False, simplify=False) | ||
vertices = path.vertices | ||
codes = path.codes | ||
if codes is None: | ||
codes = [Path.MOVETO] + [Path.LINETO]*(len(vertices)-1) | ||
current_vertice = [] | ||
for (v, c) in zip(vertices, codes): | ||
if c == Path.STOP: | ||
if len(current_vertice) != 0: | ||
yield np.array(current_vertice) | ||
current_vertice = [] | ||
elif c == Path.MOVETO: | ||
if len(current_vertice) != 0: | ||
yield np.array(current_vertice) | ||
current_vertice = [v] | ||
elif c == Path.LINETO: | ||
current_vertice.append(v) | ||
elif c == Path.CLOSEPOLY: | ||
if len(current_vertice) != 0: | ||
current_vertice.append(current_vertice[0]) | ||
yield np.array(current_vertice) | ||
current_vertice = [] | ||
else: | ||
raise Exception(f"Unknown code {c} encountered") | ||
if len(current_vertice) != 0: | ||
yield np.array(current_vertice) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ | |
install_requires=[ | ||
'geojson', | ||
'numpy', | ||
'matplotlib', | ||
'matplotlib>=3.8', | ||
'xarray' | ||
], | ||
zip_safe=False, | ||
|
Oops, something went wrong.