A Python tool for calibrating raster data against survey points.
- Processes calibration points against raster data
- Generates calibration plots and WSE comparison plots
- Creates shapefiles of outlier points
- Tracks calibration runs with statistics
- Supports test mode for validation
PyCalRas/
├── Inputs/
│ ├── Sample_Points/ # CSV files with calibration points
│ ├── Rasters/ # TIF files for processing
│ └── Alignment/ # Shapefiles for centerline
├── Outputs/
│ ├── calibration_runs.csv # Log of all calibration runs
│ └── run_name/ # Individual run outputs
│ ├── description.txt
│ ├── raster_name.png
│ ├── raster_name_wse.png
│ ├── raster_name.csv
│ └── outliers/
│ └── raster_name_outliers.shp
└── src/
├── main.py
├── reading.py
├── calculations.py
├── output.py
└── logger_config.py
- Required columns: P, N, E, Z, D
- Coordinates in feet
- First CSV file in Sample_Points directory will be used
- GeoTIFF format
- First TIF file in Rasters directory will be used
- Shapefile format
- First SHP file in Alignment directory will be used
- Place input files in their respective directories under
Inputs/ - Run the script:
python main.py
- Enter a name and description for the calibration run when prompted
- View results in the
Outputs/run_name/directory
To run in test mode with output validation:
python main.py --test- Shows high and low points relative to the centerline
- Points are colored blue (low) or red (high)
- Includes threshold information
- Compares measured vs. model WSE
- Includes RMSE and average difference statistics
- Contains all point data with calculated differences
- Includes stationing and sampled values
- Contains only high and low points
- Stored in the outliers subdirectory
- Can be used for further analysis in GIS software
- Tracks all calibration runs
- Includes:
- Run name and description
- RMSE (3 significant figures)
- Average difference (3 significant figures)
- Timestamp
- Sorted by most recent first
- Duplicate run names overwrite previous entries
- The script will automatically use the first file of each type found in the input directories
- Run names must be valid for directory names (no special characters)
- Existing run directories will prompt for overwrite confirmation
- Test mode validates output against reference files in
Outputs/test/
- Python 3.9 or higher
- Conda (recommended) or pip
- GDAL and other geospatial libraries (required)
git clone https://github.com/yourusername/pycalras.git
cd pycalras- Create and activate the Conda environment:
conda env create -f environment.yml
conda activate pyCal- Clone the repository:
git clone https://github.com/yourusername/pycalras.git
cd pycalras- Create a virtual environment (recommended):
python -m venv venv
source venv/bin/activate # On Linux/Mac
# or
.\venv\Scripts\activate # On Windows- Install the package:
pip install -e .Note: Installing GDAL and other geospatial dependencies through pip can be challenging. We strongly recommend using Conda instead.
main.py: Main execution script orchestrating the workflowreading.py: Handles file input and data loadingcalculations.py: Performs computational analysisoutput.py: Generates visualizations and resultsGeoDataPro.py: Provides geospatial utilities
- Data Loading: CSV points, TIF rasters, SHP centerlines
- Spatial Analysis: Raster sampling, stationing calculation
- Visualization: Calibration plots, WSE comparisons
- Load input files (reading.py)
- Process spatial data (GeoDataPro.py)
- Perform calculations (calculations.py)
- Generate visualizations (output.py)
The package includes a testing framework to validate output consistency. This is particularly useful when making code changes to ensure results remain consistent.
- Test files are stored in the
Outputs/test/directory - Each test file should correspond to an output file with the same name
- Test files contain reference values for validation
To run the script with output validation:
python Main.py --testWithout the --test flag, validation is skipped:
python Main.py- The validation compares the
Sampled_Valuecolumn in the output CSV with the reference test file - Results must match within 1% tolerance
- Validation results are logged to the console
- Create the test directory:
mkdir -p Outputs/test- Copy a known good output CSV to use as a reference:
cp Outputs/your_output.csv Outputs/test/your_output.csvThe package requires several geospatial libraries that are best installed through Conda:
- GDAL
- GeoPandas
- PyOGRIO
- Fiona
These dependencies are automatically installed when using the Conda environment.
This project is licensed under the MIT License - see the LICENSE file for details.