sampler Module¶
Road sampling functionality.
- class geo_sampling.sampler.RoadSampler(segments: List[RoadSegment])[source]¶
Bases:
objectClass for sampling road segments with various strategies.
- get_road_type_summary(road_types: str | List[str] | None = None) Dict[str, int][source]¶
Get count summary by road type.
- Parameters:
road_types – Road types to include
- Returns:
Dictionary mapping road type to count
- plot_sample(sample: List[RoadSegment], title: str | None = None, show_comparison: bool = True, figsize: tuple = (12, 10)) None[source]¶
Plot sampled segments.
- Parameters:
sample – Sampled road segments
title – Plot title
show_comparison – Whether to show comparison with full dataset
figsize – Figure size
- random_sample(n: int, road_types: str | List[str] | None = None, seed: int | None = None) List[RoadSegment][source]¶
Get random sample of road segments.
- Parameters:
n – Number of segments to sample
road_types – Road types to include (None = all types)
seed – Random seed for reproducibility
- Returns:
List of sampled RoadSegment objects
- Raises:
ValueError – If sample size exceeds available segments
- sample_by_length(target_length_km: float, road_types: str | List[str] | None = None, seed: int | None = None) List[RoadSegment][source]¶
Sample segments to approximate a target total length.
- Parameters:
target_length_km – Target total length in kilometers
road_types – Road types to include
seed – Random seed for reproducibility
- Returns:
List of sampled RoadSegment objects
- save_csv(segments: List[RoadSegment], path: str | Path) None[source]¶
Save segments to CSV file.
- Parameters:
segments – Road segments to save
path – Output file path
- stratified_sample(n: int, by: str = 'osm_type', road_types: str | List[str] | None = None, seed: int | None = None) List[RoadSegment][source]¶
Get stratified sample maintaining proportions across strata.
- Parameters:
n – Total number of segments to sample
by – Field to stratify by (default: “osm_type”)
road_types – Road types to include
seed – Random seed for reproducibility
- Returns:
List of sampled RoadSegment objects
- geo_sampling.sampler.load_segments_from_csv(path: str | Path) List[RoadSegment][source]¶
Load road segments from CSV file.
- Parameters:
path – Path to CSV file
- Returns:
List of RoadSegment objects
- geo_sampling.sampler.sample_roads(segments: List[RoadSegment], n: int, road_types: str | List[str] | None = None, strategy: str = 'random', seed: int | None = None) List[RoadSegment][source]¶
Convenience function to sample roads.
- Parameters:
segments – Road segments to sample from
n – Number of segments to sample
road_types – Road types to include
strategy – Sampling strategy (“random” or “stratified”)
seed – Random seed
- Returns:
List of sampled RoadSegment objects