Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions _DENA/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ Please note that the Precision-Recall plot that is shown at the end of a run is
| `-l`, `--altitude` | Use this flag to generate the active spaces at a particular altitude (in meters). *Ex*: `-l 1524` generates active spaces at 1524 meters or 5000 feet.<br/>If not passed, the average altitude of the valid, audible ground-truthed tracks will be calculated and used. |
| `-b`, `--beta` | ***default 1.0***<br/>the beta value to use when calculating the f-beta for each active space.<br/>https://en.wikipedia.org/wiki/F-score#F%CE%B2_score) |
| `--cleanup` | If this flag is added, all intermediary control and batch files will be deleted upon script completion. |
| `--annotation-file` | If provided, basename of GEOJSON annotations file to use instead of the default. File should be in the site directory. |


Example executions:

Expand Down
2 changes: 1 addition & 1 deletion _DENA/resource/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,4 +521,4 @@ def plot_activespace_fit(project_dir, unit, site, year, gain, ax=None, dem=None,
zorder=2
)

mic.plot(ax=ax, color='r', markersize=10, marker='*', zorder=10)
mic.plot(ax=ax, color="black", markersize=15, marker='o', zorder=10)
46 changes: 28 additions & 18 deletions _DENA/scripts/run_audible_transits.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from abc import ABC, abstractmethod
from argparse import ArgumentParser
import shapely
from shapely.geometry import Point, MultiPoint, LineString, Polygon, box, GeometryCollection
from shapely.geometry import Point, MultiPoint, LineString, Polygon, box, GeometryCollection, MultiLineString, MultiPolygon
import rasterio.plot
import rasterio
import geopy as geopy
Expand Down Expand Up @@ -114,28 +114,38 @@ def coords_equal(a, b, tol=1e-4):

def complex_split(geom: LineString, splitter):
"""
Function to split linestrings without self intersection issues.
Solution comes from here: https://github.com/shapely/shapely/issues/1068#issuecomment-770296614
Function to split linestrings along a polygon boundary without self intersection issues.
Solution based on this: https://github.com/shapely/shapely/issues/1068#issuecomment-770296614
Note that this will fail to fully split the geom if the splitter intersects the geometry at a self-intersection point.
This can likely be fixed by calling this function again on the split results, but not sure.
"""
if geom.is_simple:
return shapely.ops.split(geom, splitter)
# convert splitter to a linestring, so that the intersection is only computed
# along the boundary of the polygon / multipolygon
if type(splitter) in [Polygon, MultiPolygon]:
splitter = splitter.boundary
assert type(splitter) in [LineString, MultiLineString]

# find intersection of splitter and geom, if empty just return geom
intersection = geom.intersection(splitter)
if intersection.is_empty:
return GeometryCollection((geom,))

if isinstance(splitter, Polygon):
splitter = splitter.exterior
# Get intersection points to use for splitting.
# It's possible that the intersection contains linestrings, in that case
# just take the first point of each linestring as the split point
intersection_pts = []
# get an iterable of the intersection geometries - the intersection may have multiple or a single geometry
intersect_geoms = intersection.geoms if hasattr(intersection, "geoms") else [intersection]
for g in intersect_geoms:
if isinstance(g, LineString):
g = Point(g.coords[0])
assert isinstance(g, Point)
intersection_pts.append(g)
intersection_pts = MultiPoint(intersection_pts)

# Ensure that intersection exists and is zero dimensional.
relate_str = geom.relate(splitter)
if relate_str[0] == '1':
raise ValueError('Cannot split LineString by a geometry which intersects a '
'continuous portion of the LineString.')
if not (relate_str[0] == '0' or relate_str[1] == '0'):
return GeometryCollection((geom,))

intersection_points = geom.intersection(splitter)
snapped_geom = shapely.snap(geom, intersection_points, tolerance=1.0e-4)
return shapely.ops.split(snapped_geom, intersection_points)
# snap geom to the intersection points so that we can split w/o floating point issues
snapped_geom = shapely.snap(geom, intersection_pts, tolerance=1.0e-4)
return shapely.ops.split(snapped_geom, intersection_pts)


class AudibleTransits(ABC):
Expand Down
2 changes: 1 addition & 1 deletion nps_active_space/utils/computation.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
'ambience_from_nvspl',
'ambience_from_raster',
'audible_time_delay',
'barometric_pressure'
'barometric_pressure',
'build_src_point_mesh',
'calculate_duration_summary',
'climb_angle',
Expand Down