-
Notifications
You must be signed in to change notification settings - Fork 32
Coords opts #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Coords opts #7
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -208,25 +208,33 @@ def list_to_regions(reg): | |
raise Exception("All region names must be two letters (for US) or three letters (for world)") | ||
return reg | ||
|
||
def get_points_from_polygon(coords): | ||
|
||
def polygon_to_mask(coords, dims): | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove line break |
||
""" | ||
Given a list of pairs of points which define a polygon, return a list of points interior to the polygon | ||
Given a list of pairs of points which define a polygon, return a binary | ||
mask covering the interior of the polygon | ||
""" | ||
|
||
bounds = array(coords).astype('int') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace |
||
path = Path(bounds) | ||
|
||
bMax = bounds.max(0) | ||
bMin = bounds.min(0) | ||
grid = meshgrid(range(dims[1]), range(dims[0])) | ||
grid_flat = zip(grid[0].ravel(), grid[1].ravel()) | ||
|
||
path = Path(bounds) | ||
mask = path.contains_points(grid_flat).reshape(dims[0:2]).astype('int') | ||
|
||
grid = meshgrid(range(bMin[0],bMax[0]+1),range(bMin[1],bMax[1]+1)) | ||
return mask | ||
|
||
gridFlat = zip(grid[0].ravel(),grid[1].ravel()) | ||
|
||
inside = path.contains_points(gridFlat).reshape(grid[0].shape).astype('int') | ||
inside = where(inside) | ||
inside = vstack([inside[0],inside[1]]).T + bMin[-1::-1] | ||
inside.tolist() | ||
|
||
return inside | ||
def mask_to_points(mask): | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove line break |
||
""" | ||
Convert binary mask to a list of (y,x) points for each point where the mask is 1 | ||
""" | ||
|
||
points = where(mask) | ||
points = vstack([points[0], points[1]]).T | ||
points = points.tolist() | ||
|
||
return points |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Follow arg formatting of other functions, it should look like: