scrollstats package¶
Copyright (c) 2025 Andrew Vanderheiden. All rights reserved.
scrollstats: An open-source python library to calculate and extract morphometrics from scroll bar floodplains
- class scrollstats.BendDataExtractor(transects, bin_raster=None, dem=None, ridges=None, packets=None)¶
Bases:
objectResponsible for extraction of ridge metrics across an entire bend.
- Parameters:
transects (
GeoDataFrame)bin_raster (
DatasetReader|None)dem (
DatasetReader|None)ridges (
GeoDataFrame|None)packets (
GeoDataFrame|None)
- calc_itx_metrics()¶
For each transect found in transects, calculate the itx metrics.
- Return type:
- calc_transect_metrics()¶
- Return type:
- count_ridges(signal)¶
Counts ridges in binary waves.
- dense_sample(line, raster)¶
Sample an underlying in_bin_raster along a given LineString at a frequency of ~1m
- Parameters:
line (
LineString)raster (
DatasetReader)
- Return type:
- disqualify_coords(coord_array, raster)¶
Some coordinates may be out of the in_bin_raster. This function disqualifies these coordinates and returns a boolean array showing the location of all disqualified coordinates.
Coordinates are checked to see if they are 1) negative, 2) too large in x, or 3) too large in y
- Parameters:
raster (
DatasetReader)
- Return type:
- dominant_wavelength(ridge_count, signal)¶
Identifies the dominant wavelength from an input binary signal
- sample_array(coord_array, raster)¶
Takes in an array of image coordinates, samples the image, and returns the sampled values. Assumes that the coord array and in_bin_raster dataset share the same crs.
- Parameters:
raster (
DatasetReader)
- Return type:
- trans_fft(signal)¶
Calculates the fast fourier transform for a 1D signal.
If you wish to see the power spectra, plot the sampled frequencies (x) vs their measured amplitude (y) The dominant wavelength within a given signal can be found with the function dominant_wavelength() below
- class scrollstats.LineSmoother(lines, spacing, window)¶
Bases:
objectSmooth and densify rough, manually drawn LineStrings.
Smoothing is accomplished with the use of a mean filter and densifying is accomplished with the use of a piecewise cubic spline. The GeoDataFrame provided must only contain LineStrings. MuliLineStrings or other geometries are not supported. The vertex count of any ridge cannot be lower than the window size for the mean filter
- Values used for the Lower Brazos Ridges were:
window = 5 (vertices) spacing = 1 (meters)
- Parameters:
lines (
GeoDataFrame)spacing (
int)window (
int)
- calc_cubic_spline(line, spacing)¶
Fit a cubic spline function to a LineString then sample that function at the given spacing
- Parameters:
line (
LineString)spacing (
int)
- Return type:
- calc_dist(x, y)¶
Calc distance along the line
- check_vertex_count()¶
Check that all ridges have at least as many vertices as the smoothing window is long
- Return type:
- execute()¶
Apply the mean filter and cubic spline to each line in the geodataframe. Return a new geodataframe with the smooth lines
- Return type:
- meanfilt(line, w)¶
Use a mean filter to smooth the xy points of the line. This is done by passing a moving window with size w over the x and y coordinates separately and replacing the central value of the window with the mean value of the window. This particular method appends the first and last coord to the new line to account for erosion via convolution
- Parameters:
line (
LineString)w (
int)
- Return type:
- class scrollstats.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]
- class scrollstats.RidgeDataExtractor(geometry, position, ridges, dem_signal=None, bin_signal=None)¶
Bases:
objectResponsible for calculating ridge metrics at each intersection of a ridge and transect. The geometry for this class is a 3-vertex LineString
- Parameters:
geometry (
LineString)position (
int)ridges (
GeoDataFrame)
- add_point_geometries(gdf, line)¶
Add the vertices from the 3vertex line as point geometries
- Parameters:
gdf (
GeoDataFrame)line (
LineString)
- Return type:
- boolify_mask()¶
Simplifies the bin_sig (which may contain nans) to a pure boolean array
- calc_every_ridge_amp()¶
Calculates the average amplitude of each observed ridges in the units of the DEM.
- calc_relative_vertex_distance(gdf, line)¶
Calculate the relative distance of each vertex along the transect.
- Parameters:
gdf (
GeoDataFrame)line (
LineString)
- Return type:
- calc_ridge_coms()¶
Find the center of mass for each ridge in the input binary signal.
- calc_values_from_ridge_info(gdf)¶
Calculates the migration time, distance, and rate both before and after the center ridge. If the ridge does not have values for the deposit year, then mig_rate will be NaN.
- Parameters:
gdf (
GeoDataFrame)- Return type:
- calc_vertex_indices(gdf, signal_length)¶
Calculate the array index of all vertices. If self.signal_length is nan, then return array of nans
- Parameters:
gdf (
GeoDataFrame)signal_length (
float)
- Return type:
- coerce_dtypes(gdf)¶
Coerce the the ‘object’ dtypes into their proper numeric types
- Parameters:
gdf (
GeoDataFrame)- Return type:
- create_point_gdf()¶
Create a 3 point GeoDataFrame to contain all relevant info for other methods.
- Return type:
- determine_metric_confidence()¶
Assign a metric confidence score based on the boolean mask.
- Return type:
- determine_ridge_amp()¶
Select the correct ridge amplitude calculated by calc_every_ridge_amp() based on the number of ridges present
- dq_first_swale()¶
If the ridge position of the signal is 0, then remove the first chunk of false values
- find_closest_ridge()¶
The bin_signal may have more than two ridges present. This method identifies which ridge is closest to the transect-ridge intersection point.
- join_ridge_info(gdf, ridges)¶
Get ridge ids, time, distance, and migration rates via spatial join from the ridge features
- Parameters:
gdf (
GeoDataFrame)ridges (
GeoDataFrame)
- Return type:
- class scrollstats.TransectDataExtractor(transect_id, geometry, dem_signal=None, bin_signal=None, ridges=None)¶
Bases:
objectResponsible for extracting ridge metrics along a transect.
TransectDataExtractor will ultimately return a GeoDataFrame where each row is an eligible intersection between the transect and the ridge An eligible intersection is one that has a vertex before and after it so that the raster underneath can be sampled along the full width of the ridge. If a transect contains no eligible intersections, the gdf will be empty.
- Parameters:
transect_id (
str)geometry (
LineString)ridges (
GeoDataFrame|None)
- add_point_geometry(gdf)¶
Add the intersection (middle) point of the 3 vertex substring as its own point
- Parameters:
gdf (
GeoDataFrame)- Return type:
- add_relative_vertex_distances(gdf)¶
Calculate the distance between the substring coordinates relative to the length of the whole line.
- Parameters:
gdf (
GeoDataFrame)- Return type:
- add_substring_geometry(gdf)¶
Adds the 3 vertex substring that corresponds to each itx.
- Parameters:
gdf (
GeoDataFrame)- Return type:
- add_transect_id(gdf)¶
Add the transect id as a column
- Parameters:
gdf (
GeoDataFrame)- Return type:
- calc_cumulative_dist(coords)¶
Calculate the cumulative distances along a coordinate series
- calc_relative_vertex_distances(ls, start_dist)¶
Calculate the relative distance of each vertex along the transect.
- Parameters:
ls (
LineString)start_dist (
float)
- Return type:
- calc_ridge_metrics()¶
Calculate ridge width and amplitude at every transect-ridge intersection. Return a GeoDataFrame with Point geometries.
- Return type:
- calc_vertex_indices(gdf)¶
Calculates the corresponding signal index of each of the substring vertices
- Parameters:
gdf (
GeoDataFrame)- Return type:
- create_itx_gdf()¶
Create the gdf that will contain all the ridge data for each intersection.
- Return type:
- create_substrings(ls)¶
Create substrings starting from the eligible coordinates of the given linestring
- Parameters:
ls (
LineString)- Return type:
- determine_eligible_coords(ls)¶
Determine coordinates in the transect linestring that are eligible to be a start of a substring. Because the substrings are all 3 vertices long, the last two are not eligible. These eligible coords are defined because multiple functions need to use these coordinates.
- Parameters:
ls (
LineString)- Return type:
- determine_substring_starts(gdf)¶
Determine the along-transect distance of the points of each substring
- Parameters:
gdf (
GeoDataFrame)- Return type:
- slice_bin_signal(gdf)¶
Slice the binary signal between the two end vertices of the substrings
- Parameters:
gdf (
GeoDataFrame)- Return type:
- slice_dem_signal(gdf)¶
Slice the DEM between the two end vertices of the substrings
- Parameters:
gdf (
GeoDataFrame)- Return type:
- scrollstats.calc_ridge_amps(dem_sig, bin_sig)¶
Calculate the ridge amplitudes from a DEM profile using the boolean mask signal.
Different strategies are used to calculate the ridge amplitude based on the ridge and swale count found within the boolean mask signal.
- scrollstats.calculate_ridge_metrics(in_transects, in_ridges, in_bin_raster=None, in_dem=None, in_packets=None)¶
Main function to calculate scroll metrics.
If in_packets is specified, then all metrics for the rich_transects will be calculated for the transect fragment within each packet.
All arguments can be provided as a file path or in-memory object (vector: GeoDataFrame, raster: rasterio dataset)
- Parameters:
in_transects (
GeoDataFrame|Path)in_ridges (
GeoDataFrame|Path)in_bin_raster (
DatasetReader|Path|None)in_dem (
DatasetReader|Path|None)in_packets (
GeoDataFrame|Path|None)
- Return type:
- scrollstats.create_ridge_area_raster(dem_ds, geometry, classifier_funcs=(<function profile_curvature_classifier>, <function residual_topography_classifier>), denoiser_funcs=(<function binary_closing>, <function binary_opening>, <function remove_small_feats_w_flip>), no_data_value=None, **kwargs)¶
Main processing function to create the ridge area raster.
This function uses the provided classifier_funcs and denoiser_funcs to classify the ridge and swale areas within the input DEM.
Ridge Area Classification:¶
By default, scrollstats uses profile curvature (a measure of ridge convexity) and residual topography (a measure of ridge prominence) to classify ridge areas. Each classifier function is applied to the DEM, then the union of all the resulting binary arrays will be used for denoising. This means that the more classifier functions you use, the more conservative, but ideally more accurate, your ridge areas will be.
If the user desires, they can provide their own classifier functions so long as the functions follow the pattern below
classifier_func(ElevationArray2D, **kwargs) -> BinaryArray2D
See scrollstats/delineation/raster_classifiers.py for the DEFAULT_CLASSIFIERS list of functions and their definitions.
Clip Ridge and Swale Topography:¶
In order to avoid edge-effects from the classifier functions, the area corresponding to the ridge and swale topography will be clipped from a larger DEM. The nodata value for the input DEM will be used unless no_data_value is specified.
Image Denoising:¶
Once the ridge areas are classified within the DEM as a binary array (1=ridge, 0=swale), scrollstats uses a series of denoising algorithms to clean up the result. By default, scrollstats uses binary closing and binary opening operations to efficiently remove small objects from the binary image, then it uses another filter to remove of any remaining image object smaller than a certain size (measured in px). Each classifier function is applied to the binary array in sequence, meaning that the output of the first classifier function is the input of the second, and so on. Therefore, a different ordering of the same list of denoiser functions may yield a different result.
If the user desires, they can provide their own denoiser functions so long as the functions follow the pattern below
denoiser_func(BinarryArray2D, **kwargs) -> BinaryArray2D
See scrollstats/delineation/raster_denoisers.py for the DEFAULT_DENOISERS list of functions their definitions.
Keyword Arguments for Image Processing Functions:¶
Any additional arguments required by the classifier_funcs or denoier_funcs can be provided to this function as keyword arguments Any keyword arguments provided to this function will be passed to a given classifier or denoiser function if the provided keyword matches a keyword in the function’s signature.
- type dem_ds:
- param dem_ds:
- type geometry:
- param geometry:
- type classifier_funcs:
- param classifier_funcs:
- type denoiser_funcs:
- param denoiser_funcs:
- type no_data_value:
- param no_data_value:
- type kwargs:
- param kwargs:
- scrollstats.create_ridge_area_raster_fs(dem_path, geometry_path, out_dir, bend_id_dict=None, **kwargs)¶
File system interface for create_ridge_area_raster
- scrollstats.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.map_amp_values(amp_series, width_series)¶
Map the ridge amplidute values to their assumed location along the transect. Assumed location is the approximate midpoint of the ridge.
Subpackages¶
- scrollstats.delineation package
LineSmoothercreate_ridge_area_raster()create_ridge_area_raster_fs()quadratic_profile_curvature()residual_topography()- Submodules
- scrollstats.delineation.array_types module
- scrollstats.delineation.line_smoother module
- scrollstats.delineation.raster_classifiers module
- scrollstats.delineation.raster_denoisers module
- scrollstats.delineation.ridge_area_raster module
- scrollstats.ridge_metrics package
BendDataExtractorRidgeDataExtractorRidgeDataExtractor.add_point_geometries()RidgeDataExtractor.boolify_mask()RidgeDataExtractor.calc_every_ridge_amp()RidgeDataExtractor.calc_relative_vertex_distance()RidgeDataExtractor.calc_ridge_coms()RidgeDataExtractor.calc_ridge_width_px()RidgeDataExtractor.calc_values_from_ridge_info()RidgeDataExtractor.calc_vertex_indices()RidgeDataExtractor.coerce_dtypes()RidgeDataExtractor.create_point_gdf()RidgeDataExtractor.determine_metric_confidence()RidgeDataExtractor.determine_ridge_amp()RidgeDataExtractor.determine_signal_length()RidgeDataExtractor.dq_first_swale()RidgeDataExtractor.dump_data()RidgeDataExtractor.find_closest_ridge()RidgeDataExtractor.join_ridge_info()
TransectDataExtractorTransectDataExtractor.add_point_geometry()TransectDataExtractor.add_relative_vertex_distances()TransectDataExtractor.add_substring_geometry()TransectDataExtractor.add_transect_id()TransectDataExtractor.calc_cumulative_dist()TransectDataExtractor.calc_relative_vertex_distances()TransectDataExtractor.calc_ridge_metrics()TransectDataExtractor.calc_vertex_indices()TransectDataExtractor.create_itx_gdf()TransectDataExtractor.create_substrings()TransectDataExtractor.determine_eligible_coords()TransectDataExtractor.determine_substring_starts()TransectDataExtractor.slice_bin_signal()TransectDataExtractor.slice_dem_signal()
calc_ridge_amps()calculate_ridge_metrics()map_amp_values()- Submodules
- scrollstats.ridge_metrics.calc_ridge_metrics module
- scrollstats.ridge_metrics.data_extractors module
BendDataExtractorRidgeDataExtractorRidgeDataExtractor.add_point_geometries()RidgeDataExtractor.boolify_mask()RidgeDataExtractor.calc_every_ridge_amp()RidgeDataExtractor.calc_relative_vertex_distance()RidgeDataExtractor.calc_ridge_coms()RidgeDataExtractor.calc_ridge_width_px()RidgeDataExtractor.calc_values_from_ridge_info()RidgeDataExtractor.calc_vertex_indices()RidgeDataExtractor.coerce_dtypes()RidgeDataExtractor.create_point_gdf()RidgeDataExtractor.determine_metric_confidence()RidgeDataExtractor.determine_ridge_amp()RidgeDataExtractor.determine_signal_length()RidgeDataExtractor.dq_first_swale()RidgeDataExtractor.dump_data()RidgeDataExtractor.find_closest_ridge()RidgeDataExtractor.join_ridge_info()
TransectDataExtractorTransectDataExtractor.add_point_geometry()TransectDataExtractor.add_relative_vertex_distances()TransectDataExtractor.add_substring_geometry()TransectDataExtractor.add_transect_id()TransectDataExtractor.calc_cumulative_dist()TransectDataExtractor.calc_relative_vertex_distances()TransectDataExtractor.calc_ridge_metrics()TransectDataExtractor.calc_vertex_indices()TransectDataExtractor.create_itx_gdf()TransectDataExtractor.create_substrings()TransectDataExtractor.determine_eligible_coords()TransectDataExtractor.determine_substring_starts()TransectDataExtractor.slice_bin_signal()TransectDataExtractor.slice_dem_signal()
calc_dist()densify_line()densify_segment()explode()remove_coincident_points()transform_coords()
- scrollstats.ridge_metrics.ridge_amplitude module
- scrollstats.transecting package
MultiTransectMultiTransect.coord_listMultiTransect.centerlineMultiTransect.ridgesMultiTransect.shoot_distanceMultiTransect.search_distanceMultiTransect.dev_from_90MultiTransect.user_directionMultiTransect.verboseMultiTransect.crsMultiTransect.transect_listMultiTransect.transect_dfMultiTransect.point_dfMultiTransect.search_area_dfMultiTransect.ridge_clip_dfMultiTransect.create_point_df()MultiTransect.create_ridge_clip_df()MultiTransect.create_search_area_df()MultiTransect.create_transect_df()MultiTransect.create_transect_list()MultiTransect.return_all_geometries()
create_transects()- Submodules
- scrollstats.transecting.transect module
H74TransectH74Transect.originH74Transect.point_idH74Transect.coord_listH74Transect.n1_shoot_listH74Transect.n1_coord_listH74Transect.n2_coord_listH74Transect.vr_shoot_listH74Transect.p2_coord_listH74Transect.linestringH74Transect.search_area_listH74Transect.ridge_clip_listH74Transect.termination_pointH74Transect.termination_reasonH74Transect.distance_along_cl
H74TransectConstructorH74TransectConstructor.transectH74TransectConstructor.originH74TransectConstructor.centerlineH74TransectConstructor.user_directionH74TransectConstructor.initial_directionH74TransectConstructor.initial_alphaH74TransectConstructor.ridgesH74TransectConstructor.ridges_centroidH74TransectConstructor.p1H74TransectConstructor.p2H74TransectConstructor.r1H74TransectConstructor.r2H74TransectConstructor.n1H74TransectConstructor.n2H74TransectConstructor.walk_stateH74TransectConstructor.iterationH74TransectConstructor.verboseH74TransectConstructor.shoot_distanceH74TransectConstructor.search_distanceH74TransectConstructor.dev_from_90H74TransectConstructor.max_iterationsH74TransectConstructor.calc_dist_along_cl()H74TransectConstructor.calc_initial_direction()H74TransectConstructor.dest90()H74TransectConstructor.eval_user_direction()H74TransectConstructor.find_closest_ridge()H74TransectConstructor.result_coord()H74TransectConstructor.shoot_point()H74TransectConstructor.shoot_point_rg()H74TransectConstructor.src90()H74TransectConstructor.walk_transect()
MultiTransectMultiTransect.coord_listMultiTransect.centerlineMultiTransect.ridgesMultiTransect.shoot_distanceMultiTransect.search_distanceMultiTransect.dev_from_90MultiTransect.user_directionMultiTransect.verboseMultiTransect.crsMultiTransect.transect_listMultiTransect.transect_dfMultiTransect.point_dfMultiTransect.search_area_dfMultiTransect.ridge_clip_dfMultiTransect.create_point_df()MultiTransect.create_ridge_clip_df()MultiTransect.create_search_area_df()MultiTransect.create_transect_df()MultiTransect.create_transect_list()MultiTransect.return_all_geometries()
add_sub_90()calc_dist()calc_dist_along_line()calc_dxdy()create_transects()curvature()direction_alpha_at_point()find_closest_idx()law_of_cos()vert_res()