A Python-based toolkit for smoothing time series raster data and performing trend analysis on geospatial datasets.
This project provides a framework for processing and analyzing time series raster data. The toolkit implements a novel approach for detecting and adjusting changes in raster time series based on a magnitude-dependent error threshold, alongside functionality for trend analysis.
Key features include:
- Time series smoothing with adaptive thresholding
- Change detection and magnitude quantification
- Trend analysis using OLS
The transform_rasters_error_func()
is the heart of this toolkit. It processes a series of raster files to detect and adjust significant changes over time. Here's a detailed breakdown of its functionality:
-
Input: The function takes a list of file paths to raster images, along with user defined
slope
andintercept
parameters for threshold calculation. -
Initialization:
- Two lists are initialized:
transformed_rasters
andchange_magnitude_rasters
. - The first raster in the series is added to
transformed_rasters
without modification.
- Two lists are initialized:
-
Iterative Processing: For each subsequent raster in the series:
- A threshold is calculated for each pixel using the formula:
threshold = slope * previous_raster + intercept
. - The absolute difference between the current and previous raster is compared to this threshold.
- A threshold is calculated for each pixel using the formula:
-
Change Detection:
- If the difference exceeds the threshold, it's considered a significant change.
- A mask is created to identify pixels where significant changes occurred.
-
Output Generation:
- Smoothed Raster:
- Where significant changes are detected (mask is True), the new raster value is used.
- Where changes are below the threshold (mask is False), the previous raster value is retained.
- This smoothed raster is appended to
transformed_rasters
.
- Change Magnitude Raster:
- For pixels with significant changes, the magnitude of change (difference between current and previous value) is recorded.
- For pixels below the threshold, the change magnitude is set to 0.
- This change magnitude raster is appended to
change_magnitude_rasters
.
- Smoothed Raster:
-
Return: The function returns two lists:
transformed_rasters
: A time series of smoothed rasters where significant changes are preserved and noise is reduced.change_magnitude_rasters
: A time series of rasters showing the magnitude of detected changes at each time step.
This approach allows for adaptive smoothing that preserves significant changes while reducing noise in the time series, providing valuable insights into the temporal dynamics of the raster data.
graph TD
A[Input Raster Series] --> B[Calculate Threshold]
B --> C{Exceed Threshold?}
C -->|Yes| D[Record Change Magnitude]
C -->|No| E[Keep Original Value]
D --> F[Adjust Raster Value]
E --> G[Retain Original Value]
F --> H[Output Smoothed Raster]
G --> H
D --> I[Output Change Magnitude Raster]
- Python 3.7+
- numpy
- rasterio
- scikit-learn
- geowombat
- xarray
- Clone the repository:
git clone https://github.com/yourusername/raster-time-series-toolkit.git
- Install the required packages:
pip install -r requirements.txt
- Configure input and output paths in the
execute_timeseries_pipeline.py
:input_path = 'path/to/your/input/rasters' result_path = 'path/to/your/output/directory'
- Set the slope and intercept parameters for the threshold function:
slope = 0.15 intercept = 0.1
- Run the main() function of the script:
python execute_timeseries_pipeline.py
For common issues:
- Ensure all dependencies are correctly installed.
- Check that input raster files are in a supported format (e.g., GeoTIFF).
- Verify that input and output paths are correctly specified.
- GitHub: Sebastian Lehmler
TBD