Skip to main content

Optimal routing for CRNS mobile sensor data collection

Project description

Sensor Routing

Python Version License

Optimal routing solution for mobile Cosmic Ray Neutron Sensing (CRNS) data collection. This package provides sophisticated algorithms for calculating efficient routes that maximize information value while minimizing travel distance and time.

Features

  • ๐Ÿ—บ๏ธ Geospatial Route Optimization: Calculate optimal routes using real-world road networks from OpenStreetMap
  • ๐Ÿ“Š Information Value Maximization: Balance between spatial coverage and information gain
  • ๐Ÿ”„ Multiple Routing Strategies: Support for both standard and economical routing approaches
  • ๐ŸŽฏ Point Mapping: Map sensor locations to road networks with advanced filtering
  • ๐Ÿ“ˆ Benefit Calculation: Evaluate information value of different route segments
  • ๐Ÿ›ฃ๏ธ Path Finding: Dijkstra-based algorithms with custom cost functions
  • ๐Ÿ” Hull Point Extraction: Optimize sensor placement using convex hull analysis
  • โœ… Input Validation (v0.2.3+): Automatic validation of CSV files with delimiter/header detection
  • ๐Ÿ”ง Flexible Format Support: Handle comma, tab, and whitespace-separated files seamlessly

Installation

From PyPI (recommended)

pip install sensor-routing

From source

git clone https://codebase.helmholtz.cloud/ufz/tb5-smm/met/wg7/sensor-routing.git
cd sensor-routing
pip install -e .

Development installation

pip install -e ".[dev]"

Quick Start

Command Line Interface

The package provides a command-line interface for the full pipeline:

sensor-routing --wd /path/to/work_directory

Python API

Simplified API (v0.2.3+)

from sensor_routing import sensor_routing_pipeline

# Run the complete pipeline with automatic validation
sensor_routing_pipeline(work_dir="/path/to/work_directory")

Modular API

from sensor_routing import point_mapping, benefit_calculation, path_finding, route_finding

# Map points to road network
pm_output = point_mapping.point_mapping(
    points_path="input/points.csv",
    osm_path="input/osm_data_transformed.geojson",
    output_path="output"
)

# Calculate benefits
bc_output = benefit_calculation.benefit_calculation(
    pm_output=pm_output,
    output_path="output"
)

# Find optimal path
pf_output = path_finding.path_finding(
    bc_output=bc_output,
    output_path="output"
)

# Generate final route
route = route_finding.route_finding(
    pf_output=pf_output,
    output_path="output"
)

Requirements

  • Python 3.12 or higher
  • See requirements.txt for full dependency list

Key Dependencies

  • NumPy & Pandas: Numerical and data processing
  • GeoPandas: Geospatial data handling
  • OSMnx: OpenStreetMap network analysis
  • NetworkX: Graph-based routing algorithms
  • Shapely: Geometric operations
  • SciPy & scikit-learn: Scientific computing and machine learning
  • h5py: MATLAB v7.3 HDF5 file support
  • Pydantic: Data validation

Project Structure

sensor_routing/
โ”œโ”€โ”€ constants.py              # Centralized filename constants
โ”œโ”€โ”€ point_mapping.py          # Map sensor points to road network
โ”œโ”€โ”€ benefit_calculation.py    # Calculate information value
โ”œโ”€โ”€ path_finding.py           # Find optimal paths
โ”œโ”€โ”€ route_finding.py          # Generate final routes
โ”œโ”€โ”€ hull_points_extraction.py # Extract convex hull points
โ”œโ”€โ”€ econ_mapping.py           # Economic point mapping variant
โ”œโ”€โ”€ econ_benefit.py           # Economic benefit calculation variant
โ”œโ”€โ”€ econ_paths.py             # Economic path finding variant
โ”œโ”€โ”€ econ_route.py             # Economic route finding variant
โ””โ”€โ”€ full_pipeline_cli.py      # Command-line interface

Usage

Working Directory Structure

The pipeline expects a working directory with the following structure:

work_dir/
โ”œโ”€โ”€ osm_data_transformed.geojson  # OpenStreetMap road network (required)
โ”œโ”€โ”€ predictors.csv                # Environmental predictors (required)
โ”œโ”€โ”€ memberships.csv               # Fuzzy cluster memberships (required)
โ”œโ”€โ”€ parameters.json               # Pipeline configuration (auto-created if missing)
โ”œโ”€โ”€ transient/                    # Intermediate pipeline outputs (auto-created)
โ””โ”€โ”€ debug/                        # Debug outputs (optional, if DEBUG=True)

Note: As of v0.2.5, input files are placed directly in the working directory root, not in an input/ subdirectory.

Input Data Format

Road Network

osm_data_transformed.geojson: GeoJSON file containing road network from OpenStreetMap

Environmental Predictors (Required)

predictors.csv: CSV file with environmental variables and coordinates

Format Requirements:

  • Delimiters: Automatically detected (comma, tab, or whitespace)
  • Headers: Optional (auto-detected based on content)
  • First row validation: Must contain numeric data (not text headers like "Longitude", "Latitude")
  • Column order: X, Y, Mask, Predictor1, Predictor2, ...
  • Coordinates: Must be in the same CRS as OSM data (e.g., EPSG:25832)
  • NaN values: Allowed in predictor columns, excluded from validation

Example (comma-separated with header):

X,Y,Mask,BulkDensity,Clay,DEM,SOC,SandFraction,Slope
619500.0,5786500.0,0.0,132.95830,222.12509,145.67,2.34,0.456,1.23
619500.0,5786250.0,0.0,131.80805,215.62871,143.21,2.11,0.432,1.45

Example (space-separated, no header):

6.1950000e+05   5.7865000e+06   0.0000000e+00   1.3295830e+02   2.2212509e+02   ...
6.1950000e+05   5.7862500e+06   0.0000000e+00   1.3180805e+02   2.1562871e+02   ...

Column Definitions:

  • Column 1 (X): Easting coordinate
  • Column 2 (Y): Northing coordinate
  • Column 3 (Mask): Urban mask (0=rural, 1=urban)
  • Columns 4+: Environmental predictor values (e.g., soil moisture, temperature, elevation)

Cluster Memberships (Required)

memberships.csv: CSV file with fuzzy cluster membership probabilities

Format Requirements:

  • Delimiters: Automatically detected (comma, tab, or whitespace)
  • Headers: Optional (auto-detected)
  • Column order: X, Y, Cluster1, Cluster2, ...
  • Coordinates: Must match coordinates in predictors.csv
  • Membership values: Probabilities between 0 and 1 (should sum to 1.0 per row)
  • NaN values: Not allowed (will raise validation error)

Example:

X,Y,Cluster1,Cluster2,Cluster3
619500.0,5786500.0,0.75,0.15,0.10
619500.0,5786250.0,0.20,0.65,0.15

Input Validation (v0.2.3+)

The pipeline automatically validates input files:

  • โœ… Delimiter detection: Comma, tab, or whitespace
  • โœ… Header detection: Distinguishes numeric data from text headers
  • โœ… Coordinate validation: Ensures membership coordinates exist in predictors
  • โœ… Membership validation: Checks probabilities sum to 1.0 (within tolerance)
  • โœ… NaN handling: Validates NaN counts and locations
  • โœ… Flexible matching: Allows predictors to have more rows than memberships

Validation Output Example:

โœ“ Parsed 16928 rows from predictors.csv (6866 contain NaN values)
โœ“ Parsed 10062 rows from memberships.csv
โœ“ Coordinate validation: All 10062 membership coordinates found in predictors

Requirements:

  • All files must have the same number of data points
  • NaN values in any predictor automatically mark that point as urban (mask=1)

Migration: Convert your .mat files to predictors.csv using standard tools like MATLAB's writetable() or Python's pandas.

Pipeline Parameters

The pipeline can be configured via full_pipeline_parameters.json:

{
    "CRS": "EPSG:25832",
    "EPSG": 25832,
    "information_weight": 0.5,
    "start_node": null,
    "end_node": null,
    "max_iterations": 100,
    "enable_module_debug": false
}

Debug Mode

Enable debug output by setting ENABLE_MODULE_DEBUG = True in full_pipeline_cli.py or via parameters file. This will:

  • Print detailed progress information
  • Save intermediate results to debug/ directory
  • Show progress bars for long-running operations

Development

Running Tests

pytest test/

Code Formatting

black sensor_routing/
flake8 sensor_routing/

Type Checking

mypy sensor_routing/

Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Merge Request

Documentation

For detailed documentation on specific modules:

  • Point Mapping: See HOW_TO_USE_FOR_ROUTING.md
  • Benefit Calculation: See IMPROVED_INFORMATION_VALUE_EXPLANATION.md
  • Debug Control: See DEBUG_CONTROL_GUIDE.md
  • Information Weights: See INFORMATION_WEIGHT_RANGES.md

Citation

If you use this software in your research, please cite:

@software{sensor_routing,
  author = {Topaclioglu, Can},
  title = {Sensor Routing: Optimal routing for CRNS mobile sensor data collection},
  year = {2024},
  url = {https://codebase.helmholtz.cloud/ufz/tb5-smm/met/wg7/sensor-routing}
}

License

This project is licensed under the European Union Public License 1.2 (EUPL-1.2). See the LICENSE file for details.

Authors

  • Can Topaclioglu - Initial work - UFZ

Acknowledgments

  • Helmholtz Centre for Environmental Research (UFZ)
  • Department of Monitoring and Exploration Technologies

Support

For questions, issues, or feature requests:

Changelog

Version 0.2.5 (Current)

  • โœจ NEW: Constants module (constants.py) for centralized filename management
  • โœจ NEW: ROUTE_FILENAME = "solution.json" constant added
  • ๐Ÿ”ง BREAKING: Simplified directory structure - input files now in working directory root (no input/ subdirectory)
  • ๐Ÿ”ง Harmonized project structure with external standards (cosmonaut)
  • ๐Ÿ”ง All modules now expect absolute working_directory paths
  • ๐Ÿ”ง Output file locations standardized (initial_route.json, solution.json)
  • ๐Ÿ”ง Test data reorganized from test_data/input/ to test_data/
  • ๐Ÿ› Debug output fixes in path_finding.py (abort time only prints when DEBUG=True)
  • ๐Ÿงน Removed unnecessary try-except wrapper in full_sensor_routing_pipeline()
  • ๐Ÿงน Cleaned up auto-generated metadata files from version control

Version 0.2.4

  • โœจ NEW: Exported input file constants (PREDICTOR_FILENAME, MEMBERSHIP_FILENAME, OSM_FILENAME, PARAMETERS_FILENAME)
  • โœจ NEW: Added OSM_FILENAME constant for standardized road network file naming
  • โœจ NEW: Added DESCRIPTION_OSM with format requirements
  • โœจ NEW: OSM file validation in sensor_routing_pipeline()
  • ๐Ÿ“ Updated documentation to use correct OSM filename (osm_data_transformed.geojson)
  • ๐Ÿ“ All filename constants now accessible via public API

Version 0.2.3

  • โœจ NEW: Simplified API with sensor_routing_pipeline(work_dir) function
  • โœจ NEW: Comprehensive input validation with automatic delimiter detection
  • โœจ NEW: CSV support with auto-detection for comma, tab, and whitespace delimiters
  • โœจ NEW: Automatic header detection (numeric vs text)
  • โœจ NEW: Coordinate validation between predictor and membership files
  • โœจ NEW: Flexible validation allowing predictors to have more rows than memberships
  • ๐Ÿ“ Standardized input filenames: predictors.csv, memberships.csv
  • ๐Ÿ”ง Updated hull_points_extraction.py to use pandas for CSV parsing
  • ๐Ÿ“ฆ Updated test data to use CSV format
  • ๐Ÿ“ Enhanced documentation with detailed file format requirements

Version 0.2.2

  • โœจ Automatic urban mask generation from NaN values in predictors
  • ๐Ÿ“ฆ Updated dependencies for PyPI distribution
  • ๐Ÿ› Fixed hull_points_extraction summary_kwargs bug

Version 0.2.1

  • โœจ Added comprehensive debug control system
  • โœจ Migrated to Pydantic V2
  • โœจ Added economic routing variants
  • ๐Ÿ› Fixed multiple debug output issues
  • ๐Ÿ“ฆ Prepared for PyPI distribution
  • ๐Ÿ“ Improved documentation

Version 0.1.15

  • Initial release with basic routing functionality

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sensor_routing-0.2.6.tar.gz (4.5 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sensor_routing-0.2.6-py3-none-any.whl (4.7 MB view details)

Uploaded Python 3

File details

Details for the file sensor_routing-0.2.6.tar.gz.

File metadata

  • Download URL: sensor_routing-0.2.6.tar.gz
  • Upload date:
  • Size: 4.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for sensor_routing-0.2.6.tar.gz
Algorithm Hash digest
SHA256 e84f03acc948101b370d47e76f5ceace615243dbbb370ded17356417d463f58e
MD5 61c11da298964ffbd1f87bf1b1735766
BLAKE2b-256 e288fafd866621c4f92e5b26247626f16b0eda9fa3b9aae2d4d12b172fde4819

See more details on using hashes here.

File details

Details for the file sensor_routing-0.2.6-py3-none-any.whl.

File metadata

  • Download URL: sensor_routing-0.2.6-py3-none-any.whl
  • Upload date:
  • Size: 4.7 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for sensor_routing-0.2.6-py3-none-any.whl
Algorithm Hash digest
SHA256 128fbd76b9c597bc72555c2003bf3c5b5b35114c51fec7e5a005616db1c3c7ea
MD5 1ef1e3f93b03b0a4bcffc6f20a114356
BLAKE2b-256 4d42998131a0e2c32fa3ffa562be7b4fc74a92a83cbc7cdd5305114efa61fe68

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page