-
Notifications
You must be signed in to change notification settings - Fork 10
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 #43 from phobson/cleanup-masking
Cleanup polygon masking
- Loading branch information
Showing
11 changed files
with
626 additions
and
114 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -2,4 +2,5 @@ | |
from .core import * | ||
from . import iotools | ||
from . import viz | ||
from . import qa | ||
from . import testing |
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,44 @@ | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
|
||
|
||
def _check_ax(ax): | ||
if ax is None: | ||
fig, ax = plt.subplots() | ||
else: | ||
fig = ax.figure | ||
|
||
ax.set_aspect('equal') | ||
return fig, ax | ||
|
||
|
||
def _validate_polygon(polyverts, min_points=3): | ||
polyverts_array = np.asarray(polyverts) | ||
if polyverts_array.ndim != 2: | ||
raise ValueError('polyverts must be a 2D array, or ' | ||
'similar sequence') | ||
|
||
if polyverts_array.shape[1] != 2: | ||
raise ValueError('polyverts must be two columns of points') | ||
|
||
if polyverts_array.shape[0] < min_points: | ||
raise ValueError('polyverts must contain at least {} points'.format(min_points)) | ||
|
||
return polyverts_array | ||
|
||
|
||
def _validate_xy_array(x, y, as_pairs=True): | ||
x, y = np.asanyarray(x), np.asanyarray(y) | ||
if x.shape != y.shape: | ||
raise ValueError("x and y must have the same shape.") | ||
|
||
if hasattr(x, 'mask') != hasattr(y, 'mask'): | ||
raise ValueError("only 1 of x and y have masks. Must be both or neither.") | ||
|
||
if hasattr(x, 'mask') and not np.all(x.mask == y.mask): | ||
raise ValueError("x and y has different masks.") | ||
|
||
if as_pairs: | ||
return np.array(list(zip(x.flatten(), y.flatten()))) | ||
else: | ||
return x, y |
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
Oops, something went wrong.