fractopo.analysis.random_sampling module

Utilities for randomly Network sampling traces.

class fractopo.analysis.random_sampling.NetworkRandomSampler(trace_gdf: GeoDataFrame, area_gdf: GeoDataFrame, min_radius: float, snap_threshold: float, random_choice: RandomChoice | str, name: str)

Bases: object

Randomly sample traces inside given target area.

area_gdf: GeoDataFrame
static area_gdf_should_contain_polygon(area_gdf: GeoDataFrame) GeoDataFrame

Check that area_gdf contains one Polygon.

property max_area: float

Calculate maximum area from max_radius.

property max_radius: float

Calculate max radius from given area_gdf.

property min_area: float

Calculate minimum area from min_radius.

min_radius: float
name: str
random_area() float

Calculate random area in area range.

Range is calculated from [min_radius, max_radius[.

random_choice: RandomChoice | str
static random_choice_should_be_enum(random_choice: RandomChoice | str) RandomChoice

Check that random_choice is valid.

random_network_sample(determine_branches_nodes: bool = True) RandomSample

Get random Network sample with a random target area.

Returns the network, the sample circle centroid and circle radius.

classmethod random_network_sampler(network: Network, min_radius: float, random_choice: RandomChoice = RandomChoice.radius)

Initialize NetworkRandomSampler for random sampling.

Assumes that Network target area is a single Polygon circle.

random_radius() float

Calculate random radius in range [min_radius, max_radius[.

random_target_circle() tuple[Polygon, Point, float]

Get random target area and its centroid and radius.

The target area is always within the original target area.

snap_threshold: float
property target_area_centroid: Point

Get target area centroid.

property target_circle: Polygon

Target circle Polygon from area_gdf.

trace_gdf: GeoDataFrame
static trace_gdf_should_contain_traces(trace_gdf: GeoDataFrame) GeoDataFrame

Check that trace_gdf contains LineString traces.

static value_should_be_positive(min_radius: float | int | Real) float | int | Real

Check that value is positive.

class fractopo.analysis.random_sampling.RandomChoice(*values)

Bases: Enum

Choose between random area or radius.

The choice is relevant because area is polynomially correlated with radius.

area = 'area'
radius = 'radius'
class fractopo.analysis.random_sampling.RandomSample(network_maybe: Network | None, target_centroid: Point, radius: float, name: str)

Bases: object

Dataclass for sampling results.

name: str
network_maybe: Network | None
radius: float
target_centroid: Point