scrollstats.transecting package¶
- class scrollstats.transecting.MultiTransect(coord_list, centerline, ridges, shoot_distance, search_distance, dev_from_90, user_direction=None, verbose=1)¶
Bases:
objectCreates multiple instances of H74Transect from a given centerline, ridge dataset, and other parameters.
The create_transects method is used to generate a GeoDataframe of transects. The return_all_geometries method returns the transects from create_transects as well as other intermediate geometries used in the creation of the transects. Useful for deubgging and plotting.
This class is used in the create_transects convenience function in the public API.
- Parameters:
coord_list (
list[Point]) – List of starting coordinates for each transect.centerline (
GeoDataFrame) – GeoDataFrame containing the centerline geometry.ridges (
GeoDataFrame) – GeoDataFrame containing the ridge geometries.shoot_distance (
float) – Distance for each shot.search_distance (
float) – Buffer distance for the search area on r2.dev_from_90 (
float) – Allowed deviation from 90 degrees for p2 shots.user_direction (
int|None) – User-specified initial shot direction from centerline.verbose (
int) – Verbosity level for user feedback
- centerline¶
GeoDataFrame containing the centerline geometry.
- Type:
GeoDataFrame
- ridges¶
GeoDataFrame containing the ridge geometries.
- Type:
GeoDataFrame
- crs¶
Coordinate reference system for all geometries. Read from centerline
- Type:
CRS
- transect_list¶
List of generated transects.
- Type:
list of H74Transect
- transect_df¶
GeoDataFrame containing transect geometries.
- Type:
GeoDataFrame
- point_df¶
GeoDataFrame containing point geometries used in transect creation.
- Type:
GeoDataFrame
- search_area_df¶
GeoDataFrame containing search area polygons for p2 points.
- Type:
GeoDataFrame
- ridge_clip_df¶
GeoDataFrame containing ridge geometries clipped with search area polygons.
- Type:
GeoDataFrame
- create_point_df()¶
Creates a GeoDataFrame of all points used to create transects.
- Parameters:
None
- Returns:
GeoDataFrame containing points from all transects.
- Return type:
- create_ridge_clip_df()¶
Creates a GeoDataFrame of all ridge sections searched to create transects.
- Parameters:
None
- Returns:
GeoDataFrame containing ridge sections.
- Return type:
- create_search_area_df()¶
Creates a GeoDataFrame of all search areas used to create transects.
- Parameters:
None
- Returns:
GeoDataFrame containing search areas from all transects.
- Return type:
- create_transect_df()¶
Creates a GeoDataFrame of transects from all transects which successfully left the centerline.
- Parameters:
None
- Returns:
GeoDataFrame containing all successful transects.
- Return type:
- create_transect_list()¶
Creates a set of transects and aux geometries for a bend.
- Parameters:
None
- Returns:
List of generated transects.
- Return type:
- return_all_geometries()¶
Return all geometries created for a set of transects
- Parameters:
None
- Returns:
Tuple containing the transect, point, search area, and ridge clip GeoDataFrames.
- Return type:
tuple[GeoDataFrame,GeoDataFrame,GeoDataFrame,GeoDataFrame]
- scrollstats.transecting.create_transects(centerline, ridges, step, shoot_distance, search_distance, dev_from_90)¶
Convenience function to create a series of transects from a given centerline, set of ridges, and the necessary parameters.
Transects are created at the step provided by the user (ex. every nth vertex along the centerline). Centerline is assumed to have a vertex spacing of ~1m.
- Parameters:
centerline (
GeoDataFrame) – GeoDataFrame containing the centerline geometry.ridges (
GeoDataFrame) – GeoDataFrame containing the ridge geometries.step (
int) – Number of centerline vertices between each transect.shoot_distance (
float) – How far each point will shoot from the origin in a given direction.search_distance (
float) – Buffer distance for the search area on r2.dev_from_90 (
float) – Allowed deviation from 90 degrees for p2 shots.
- Returns:
GeoDataFrame containing the transects generated.
- Return type:
Submodules¶
scrollstats.transecting.transect module¶
- class scrollstats.transecting.transect.H74Transect(origin, point_id=None)¶
Bases:
objectStores information about a transect created using Hickin 1974 geometric methods.
- Parameters:
- linestring¶
LineString representing the transect.
- Type:
- ridge_clip_list¶
List of clipped ridge lines.
- Type:
list of LineString
- termination_point¶
Point where transect terminated.
- Type:
None
- class scrollstats.transecting.transect.H74TransectConstructor(origin, transect_id, centerline, ridges, shoot_distance, search_distance, dev_from_90, user_direction=None, verbose=1)¶
Bases:
objectTakes an H74Transect instance and builds the transect out with a given set of ridges and geometric parameters.
Each hickin function in the class will return a shapely object and avoid changing state variables within the class
- Parameters:
origin (
Point) – Starting point of the transect.transect_id (
str) – Identifier for the transect.centerline (
LineString) – Centerline geometry.ridges (
MultiLineString) – Ridge geometries.shoot_distance (
float) – Distance for each shot.search_distance (
float) – Search buffer distance.dev_from_90 (
float) – Allowed deviation from 90 degrees.user_direction (
int|None) – User-specified shot direction.verbose (
int) – Verbosity level.
- transect¶
Transect instance being constructed.
- Type:
- centerline¶
Centerline geometry.
- Type:
- ridges¶
Ridge geometries.
- Type:
- r1¶
Current ridge.
- Type:
- r2¶
Next ridge.
- Type:
- calc_dist_along_cl()¶
Calculates the distance along the centerline at the transect origin.
- Return type:
- calc_initial_direction(origin, alpha, ridges)¶
Determines the direction of the initial shot from the centerline.
This is done by evaluating which shot direction (+ or - 90°) intersects the ridges.
- Parameters:
origin (
Point) – Starting point.alpha (
float) – Alpha value at origin.ridges (
MultiLineString) – Ridge geometries.
- Returns:
Initial shot direction (+1, -1, or 0).
- Return type:
- dest90(p1, r2, dev_from_90)¶
Calculates a point on r2 from which a line that is perpendicular to r2 AND intersects p1 may be drawn.
This is done by creating an angle between 3 points: (p1, ridge point, a point along the line tangent to the ridge at the ridge point) These angles are collected for a series of ridge points within a certain distance to the src90 point The ridge point with the angle closest to 90° is returned as point p2
- Parameters:
p1 (
Point) – Current point.r2 (
LineString) – The ridge line on which to find the perpendicular point.dev_from_90 (
float) – Allowed deviation from 90 degrees.
- Returns:
The point on r2 from which a perpendicular line intersects p1.
- Return type:
- eval_user_direction()¶
Overrides the calculated shot direction value if direction is specified by the user.
- Return type:
- find_closest_ridge(line, ridges)¶
Takes a line and ridges as input and returns a snippet of a single ridge that the line intersects. Depending on the size of the search radius, line may still intersect ridge snippet at more than one point Initial intersection can have many geometry types. This function accounts for: empty geometry, Point, MultiPoint, GeometryCollection
- Parameters:
line (
LineString) – The transect line to intersect with ridges.ridges (
MultiLineString) – Ridge geometries.
- Returns:
Snippet of the closest intersected ridge.
- Return type:
- result_coord(p1, src90, dest90, r2)¶
Takes the coordinates of two points and their shared p1 to calculate the resultant vector.
- Parameters:
p1 (
Point) – Current point.src90 (
Point) – The point on r2 that lies on a line perpendicular from r1 at point p1.dest90 (
Point) – The point on r2 from which a perpendicular line intersects p1.r2 (
LineString) – The ridge line on which src90 and dest90 lie.
- Returns:
The intersection point between the vertical resultant and r2.
- Return type:
- shoot_point(p1, r1, dist)¶
Calculates the point perpendicular to r1 at point p1, dist away from p1. Used for the first shot from the centerline into the ridge field.
- Parameters:
p1 (
Point) – Starting point.r1 (
LineString) – The line from which to shoot.dist (
float) – Shoot distance from p1.
- Returns:
The point perpendicular to r1 at point p1.
- Return type:
- shoot_point_rg(p0, p1, r1, dist)¶
Calculates the point perpendicular to r1 at point p1, dist away from p1. Used when transect is moving from ridge to ridge. add_sub_90() is used to determine whether to add or subtract 90° from heading (alpha) value.
- Parameters:
p0 (
Point) – Previous point. Needed to calculate direction of shot (+/-90°).p1 (
Point) – Current point.r1 (
LineString) – The line from which to shoot.dist (
float) – Shoot distance from p1.
- Returns:
The point perpendicular to r1 at point p1.
- Return type:
- src90(shot, ridge)¶
Calculates the intersection between p1->shot_point and ridge r1 to define point p1.
- Parameters:
shot (
LineString) – The line from p1 to the shot point.ridge (
LineString) – The ridge line to intersect with the shot.
- Returns:
The intersection point between shot and ridge.
- Return type:
- walk_transect()¶
Iteratively walk the transect up the ridge field. Objects self.r1 and self.p1 are set in __init__ as the centerline and point on the centerline, respectively.
- Parameters:
None
- Returns:
The transect object containing all generated coordinates and geometries.
- Return type:
- class scrollstats.transecting.transect.MultiTransect(coord_list, centerline, ridges, shoot_distance, search_distance, dev_from_90, user_direction=None, verbose=1)¶
Bases:
objectCreates multiple instances of H74Transect from a given centerline, ridge dataset, and other parameters.
The create_transects method is used to generate a GeoDataframe of transects. The return_all_geometries method returns the transects from create_transects as well as other intermediate geometries used in the creation of the transects. Useful for deubgging and plotting.
This class is used in the create_transects convenience function in the public API.
- Parameters:
coord_list (
list[Point]) – List of starting coordinates for each transect.centerline (
GeoDataFrame) – GeoDataFrame containing the centerline geometry.ridges (
GeoDataFrame) – GeoDataFrame containing the ridge geometries.shoot_distance (
float) – Distance for each shot.search_distance (
float) – Buffer distance for the search area on r2.dev_from_90 (
float) – Allowed deviation from 90 degrees for p2 shots.user_direction (
int|None) – User-specified initial shot direction from centerline.verbose (
int) – Verbosity level for user feedback
- centerline¶
GeoDataFrame containing the centerline geometry.
- Type:
GeoDataFrame
- ridges¶
GeoDataFrame containing the ridge geometries.
- Type:
GeoDataFrame
- crs¶
Coordinate reference system for all geometries. Read from centerline
- Type:
CRS
- transect_list¶
List of generated transects.
- Type:
list of H74Transect
- transect_df¶
GeoDataFrame containing transect geometries.
- Type:
GeoDataFrame
- point_df¶
GeoDataFrame containing point geometries used in transect creation.
- Type:
GeoDataFrame
- search_area_df¶
GeoDataFrame containing search area polygons for p2 points.
- Type:
GeoDataFrame
- ridge_clip_df¶
GeoDataFrame containing ridge geometries clipped with search area polygons.
- Type:
GeoDataFrame
- create_point_df()¶
Creates a GeoDataFrame of all points used to create transects.
- Parameters:
None
- Returns:
GeoDataFrame containing points from all transects.
- Return type:
- create_ridge_clip_df()¶
Creates a GeoDataFrame of all ridge sections searched to create transects.
- Parameters:
None
- Returns:
GeoDataFrame containing ridge sections.
- Return type:
- create_search_area_df()¶
Creates a GeoDataFrame of all search areas used to create transects.
- Parameters:
None
- Returns:
GeoDataFrame containing search areas from all transects.
- Return type:
- create_transect_df()¶
Creates a GeoDataFrame of transects from all transects which successfully left the centerline.
- Parameters:
None
- Returns:
GeoDataFrame containing all successful transects.
- Return type:
- create_transect_list()¶
Creates a set of transects and aux geometries for a bend.
- Parameters:
None
- Returns:
List of generated transects.
- Return type:
- return_all_geometries()¶
Return all geometries created for a set of transects
- Parameters:
None
- Returns:
Tuple containing the transect, point, search area, and ridge clip GeoDataFrames.
- Return type:
tuple[GeoDataFrame,GeoDataFrame,GeoDataFrame,GeoDataFrame]
- scrollstats.transecting.transect.add_sub_90(a, b, alpha, length=100)¶
This function determines which direction to shoot a new transect (+ or - 90°) The proper line should have the largest of the interior angles formed by the incoming transect and new shoot being formed This function returns the coordinate representing the end point of the proper line
- Parameters:
- Returns:
The coordinates the point in the correct direction (largest interior angle).
- Return type:
- scrollstats.transecting.transect.calc_dist(p1, p2)¶
Calculates the distance element-wise between two arrays of points
- scrollstats.transecting.transect.calc_dist_along_line(line)¶
Calculate an array of distance along a given line
- Parameters:
line (
LineString) – The line for which to calculate distance along.- Returns:
Array of distance values for each vertex.
- Return type:
- scrollstats.transecting.transect.calc_dxdy(angle, length=100)¶
Calculates the delta x and y given an angle and a length
- scrollstats.transecting.transect.create_transects(centerline, ridges, step, shoot_distance, search_distance, dev_from_90)¶
Convenience function to create a series of transects from a given centerline, set of ridges, and the necessary parameters.
Transects are created at the step provided by the user (ex. every nth vertex along the centerline). Centerline is assumed to have a vertex spacing of ~1m.
- Parameters:
centerline (
GeoDataFrame) – GeoDataFrame containing the centerline geometry.ridges (
GeoDataFrame) – GeoDataFrame containing the ridge geometries.step (
int) – Number of centerline vertices between each transect.shoot_distance (
float) – How far each point will shoot from the origin in a given direction.search_distance (
float) – Buffer distance for the search area on r2.dev_from_90 (
float) – Allowed deviation from 90 degrees for p2 shots.
- Returns:
GeoDataFrame containing the transects generated.
- Return type:
- scrollstats.transecting.transect.curvature(line)¶
Calculates curvature and angle (alpha) along a given line.
- scrollstats.transecting.transect.direction_alpha_at_point(point, line)¶
Calculates both the shot direction and alpha value at the coordinate of line closest to point
- Parameters:
point (
Point) – The point at which to evaluate direction and alpha.line (
LineString) – The line from which to evaluate direction and alpha.
- Returns:
A tuple of the shot direction (+1, -1, or 0) and the angle (in radians) at the closest point on the line.
- Return type:
- scrollstats.transecting.transect.find_closest_idx(point, line)¶
Loops through the coordinates of line and returns the idx of the coord closest to point
- Parameters:
point (
Point)line (
LineString)
- Returns:
The index of the coordinate in line that is closest to point.
- Return type:
- scrollstats.transecting.transect.law_of_cos(a, b, c)¶
This function uses law of cosines to calculate the interior angle formed by two connected lines Traveling down the line, vertices are a, b, c (a=beg, b=mid, c=end) Distances between vertices are represented with ‘_’ ex. a_b is the distance between a and b
- scrollstats.transecting.transect.vert_res(p0, p1, p2)¶
Calculates the vertical resultant of the two vectors (LineStrings) p0->p1 and p0->p2