reclaim.static_features.utils package

reclaim.static_features.utils.aec_shape module

reclaim.static_features.utils.aec_shape.concavity_index(df: DataFrame) float[source]

Computes the concavity index from a reservoir’s area-elevation curve.

Parameters:

df (pd.DataFrame) – Must contain columns ‘area’ (km²) and ‘elevation’ (m).

Returns:

Concavity index (ratio of actual curve to straight line). Returns np.nan if invalid.

Return type:

float

reclaim.static_features.utils.aec_shape.mean_curvature(df: DataFrame) float[source]

Computes the mean curvature (d²A/dz²) of reservoir bathymetry from area–elevation data.

reclaim.static_features.utils.aec_shape.mean_slope(df: DataFrame) float[source]

Computes the mean slope (dA/dz) of reservoir bathymetry from area–elevation data.

reclaim.static_features.utils.area_perimeter module

reclaim.static_features.utils.area_perimeter.calculate_length_area_meters(geometry, area=True)[source]

Calculate the length and area of a geometry in meters and square meters using approximate conversion factors based on the geometry’s centroid latitude.

Parameters: geometry (shapely.geometry): Geometry in WGS84 (EPSG:4326) to calculate length and area.

Returns: tuple: (length in meters, area in square meters)

reclaim.static_features.utils.catchment_agreggate module

reclaim.static_features.utils.flow_length module

reclaim.static_features.utils.flow_length.clean_narrow_necks(geometry, buffer_fraction=0.002)[source]

Buffer in and out to remove narrow slivers or necks without overly changing geometry.

Parameters: - geometry: Polygon or MultiPolygon - buffer_fraction: Fraction of geometry diagonal to use as buffer width.

Returns: - cleaned geometry

reclaim.static_features.utils.flow_length.compute_adaptive_buffer_dist(polygon, fraction=0.004)[source]

Compute an adaptive buffer distance based on polygon scale.

Parameters: - polygon: shapely Polygon or MultiPolygon - fraction: proportion of diagonal length (e.g. 0.004 = 0.4%)

Returns: - buffer distance (float)

reclaim.static_features.utils.flow_length.compute_initial_tolerance(geometry, fraction=0.005)[source]

Compute a tolerance based on the size of the geometry. Smaller fraction = higher fidelity.

reclaim.static_features.utils.flow_length.create_continuous_linestring(a, b, geometry, resolution=0.01)[source]

Create a continuous LineString between two points that lies entirely within a given geometry.

Parameters:
  • a (tuple) – The coordinates of the first point (x, y).

  • b (tuple) – The coordinates of the second point (x, y).

  • geometry (shapely.geometry.Polygon or shapely.geometry.MultiPolygon) – The geometry within which the LineString should be created.

  • resolution (float, optional) – The resolution of the grid used for pathfinding. Default is 0.5.

Returns:

A continuous LineString between points a and b that does not cross the exterior boundary of the geometry. If it is not possible to create such a LineString, None is returned.

Return type:

shapely.geometry.LineString or None

reclaim.static_features.utils.flow_length.extract_valid_lines(geometry)[source]

Ensure that only valid LineString segments are returned, regardless of input geometry type.

reclaim.static_features.utils.flow_length.filter_narrow_removed_parts(removed, min_area=1e-06, min_aspect_ratio=2)[source]

Filter out noisy edge slivers by area and shape.

Parameters: - removed: a Polygon or MultiPolygon - min_area: minimum area to be considered significant - min_aspect_ratio: minimum elongation to count as a narrow feature

Returns: - MultiPolygon of retained significant narrow parts

reclaim.static_features.utils.flow_length.find_actual_flow_path(dam_point, reservoir_polygon, inlet_point=None, resolution=None)[source]

This function finds the actual flow path between a dam point and the inlet of the reservoir boundary within the polygon.

Parameters:
  • dam_point (Point) – The point representing the dam location.

  • reservoir_polygon (Polygon) – The polygon representing the reservoir boundary.

  • inlet_point (Point, optional) – The point representing the inlet of the reservoir. If not provided, the farthest point on the simplified reservoir boundary is used.

  • resolution (float, optional) – The resolution to use for simplifying the reservoir boundary. If not provided, the optimal resolution is found.

Returns:

The simplified reservoir boundary. far_end_point (Point): The farthest point on the simplified reservoir boundary. path (LineString): The shortest path between the dam point and the far end point. graph (Graph): The graph used for pathfinding.

Return type:

simplified_reservoir (Polygon)

reclaim.static_features.utils.flow_length.find_optimal_resolution(geometry, min_resolution=0.0001, max_resolution=0.1, complexity_weight=0.38)[source]

Estimate an optimal grid resolution for pathfinding within a given geometry.

Parameters: - geometry (Polygon or MultiPolygon): The geometry to analyze. - min_resolution (float): Minimum allowable resolution. - max_resolution (float): Maximum allowable resolution. - complexity_weight (float): Weight that determines how much the resolution adapts to complexity.

Returns: - float: Suggested resolution.

reclaim.static_features.utils.flow_length.get_largest_polygon(geometry)[source]

Return the largest polygon from a Polygon or MultiPolygon

reclaim.static_features.utils.flow_length.plot_flow_length_with_reservoir(dam, reservoir, farthest_point, actual_flow_path, simplified_reservoir, save_path)[source]
reclaim.static_features.utils.flow_length.shape_index(polygon)[source]
reclaim.static_features.utils.flow_length.simplify_geometry(polygon, shape_index_threshold=800, max_tolerance_fraction=0.05, narrow_portion='widen')[source]

Simplify polygon while preserving topology and ensuring shape index is under control.

Parameters: - polygon: shapely.geometry.Polygon or MultiPolygon - shape_index_threshold: Target upper bound for shape index (lower = simpler) - max_tolerance_fraction: Max allowed simplification (as % of bounding box diagonal) - narrow_portion: ‘clean’ to remove narrow connections before simplification or ‘widen’ to widen the narrow connections. Default is ‘widen’.

Returns: - simplified polygon

reclaim.static_features.utils.flow_length.simplify_path(points, geometry)[source]
reclaim.static_features.utils.flow_length.widen_narrow_parts(polygon, fraction=0.0043, min_area_fraction=1e-08, min_aspect_ratio=None)[source]

Widen narrow regions removed during negative buffering using adaptive buffer distance.

Parameters: - polygon: shapely Polygon or MultiPolygon - fraction: % of bbox diagonal to use for buffer distance - min_area_fraction: threshold to remove small slivers (as % of polygon area) - min_aspect_ratio: minimum elongation to classify as narrow feature. If None, it is ignored. Default is None.

Returns: - widened polygon