Spatiotemporal module
Spatiotemporal Analysis Module
This module provides tools for analyzing spatiotemporal environmental data, with a focus on Bayesian Maximum Entropy (BME) methods for optimal estimation and uncertainty quantification.
Main Components
- BME Estimation
Optimal spatiotemporal prediction combining prior knowledge with data
Integration of hard (exact) and soft (probabilistic) observations
Local neighborhood-based estimation with adaptive data selection
Cross-validation for model performance assessment
- Spatiotemporal Covariance
Empirical covariance calculation from spatiotemporal data
Theoretical covariance models (exponential, non-separable)
Directional (anisotropic) covariance analysis
Automated covariance model parameter fitting
- Threshold-Based Indicators
Fractional area exceeding threshold (raeh)
Mean exceedance values (mew, wmew)
Mean difference exceedance (medw, wmdw)
Area-weighted indicators (aean)
Single-point moment extraction (one_point)
- Multi-Criteria Decision Analysis
TOPSIS method for spatial prioritization
Multiple weighting schemes
Visualization and mapping tools
- Raster Analysis
Spatiotemporal binary matrix generation
Input validation and preprocessing
NetCDF output generation
Examples
- BME estimation workflow:
>>> import numpy as np >>> from environmentaltools.spatiotemporal import ( ... compute_spatiotemporal_covariance, ... fit_covariance_model, ... compute_bme_moments ... ) >>> >>> # Compute empirical covariance >>> empcov, pairs, dists, distt = compute_spatiotemporal_covariance( ... dfh, dfs, slag=np.linspace(0, 100, 20), tlag=np.linspace(0, 30, 10) ... ) >>> >>> # Fit theoretical model >>> import scipy.optimize as opt >>> result = opt.minimize( ... fit_covariance_model, ... x0=[1.0, 20.0, 5.0, 0.1], ... args=(empcov, [dists, distt], 'exponentialST') ... ) >>> >>> # Compute BME moments >>> moments = compute_bme_moments( ... dfk, dfh, dfs, 'exponentialST', result.x, ... nmax=[50, 100], dmax=[100, 30, 3], order=[1, 1], ... options=[100, 3, 0.95], path='./cache', name='bme_run' ... )
This module provides comprehensive tools for spatiotemporal analysis of environmental data, with specialized functions for:
Bayesian Maximum Entropy (BME) estimation and uncertainty quantification
Spatiotemporal covariance modeling and fitting
Threshold-based indicators for risk and impact assessment
Multi-criteria decision analysis for spatial prioritization
Raster analysis for binary matrix generation and preprocessing
Bayesian Maximum Entropy
The BME framework provides optimal spatiotemporal estimation by combining prior knowledge with observational data (both exact and probabilistic). It’s particularly useful for environmental applications where data uncertainty must be quantified.
BME Estimation Functions
Core functions for performing BME spatiotemporal estimation.
|
Compute Bayesian Maximum Entropy moments for spatiotemporal estimation. |
|
Estimate local mean for Bayesian Maximum Entropy. |
|
Perform k-fold cross-validation for BME model evaluation. |
Support Functions
|
Calculate moments of the BME posterior probability density function. |
|
Compute moment integrals using the trapezoidal rule. |
|
Apply spatial smoothing to hard and soft data. |
Spatiotemporal Covariance
Functions for computing empirical covariances and fitting theoretical spatiotemporal covariance models (exponential, non-separable, directional).
|
Compute empirical spatiotemporal covariance. |
|
Compute sum of squared errors between theoretical and empirical covariance. |
Advanced Covariance Functions
|
Compute spatiotemporal covariance for multiple directional bins. |
|
Compute theoretical spatiotemporal covariance from parametric models. |
Utility Functions
Helper functions for data preparation, neighborhood selection, and coordinate transformations.
|
Select neighboring data points for local BME estimation. |
|
Compute parameter estimates for linear regression with covariance weighting. |
|
Create design matrix for polynomial regression. |
|
Apply spatial smoothing to data using exponential distance weighting. |
|
Create spatiotemporal data matrix. |
|
Compute distances between coordinate points. |
Compute distances and angles between spatial coordinate points. |
|
|
Find pairs of points separated by specified distance intervals. |
Threshold-Based Indicators
Functions for computing spatial indicators based on threshold exceedances. These indicators are useful for flood risk assessment, pollution exposure analysis, and environmental impact studies.
Key Indicators:
RAEH - Ratio of Area Exceeding thresHold: Fraction of spatial domain exceeding threshold
MEW - Mean Exceedance over Whole domain: Mean exceedance normalized by total area
MEDW - Mean Excess Difference over Whole domain: Mean excess above threshold over total area
WMEW - Weighted Mean Exceedance over exceedance area: Conditional mean given exceedance
WMDW - Weighted Mean excess Difference: Conditional mean excess given exceedance
AEAN - Area Exceeding to Area Non-exceeding: Ratio of exceedance to non-exceedance areas
Basic Indicators
|
Compute fractional area exceeding threshold values. |
|
Compute mean value of exceedances normalized by total area. |
|
Compute mean excess (difference from threshold) normalized by total area. |
|
Compute mean value of exceedances normalized by exceedance area only. |
|
Compute mean excess (difference from threshold) over exceedance area only. |
|
Compute ratio of exceedance area to non-exceedance area. |
Spatiotemporal Extent Indicators
|
Calculate spatial boundary where temporal mean exceeds a presence threshold. |
|
Calculate maximum spatial extent under extreme conditions. |
|
Calculate frequency of threshold exceedance for each spatial cell. |
|
Calculate permanently affected zones based on threshold exceedance persistence. |
|
Calculate representative mean value for each spatial cell. |
Extreme Value and Risk Indicators
|
Fit Generalized Extreme Value distribution and calculate return period value. |
|
Calculate environmental risk as frequency of extreme values combined with polarization. |
|
Calculate functional area loss between two time points. |
|
Calculate critical boundary retreat between two time points. |
Spatial Dynamics Indicators
|
Calculate mean spatial change rate for each cell over time. |
|
Calculate mean direction of spatial gradient for each cell. |
|
Calculate environmental convergence as reduction of neighborhood differences over time. |
Neighborhood Analysis
|
Calculate neighborhood mean value for each cell. |
|
Calculate gradient magnitude between each cell and its neighborhood. |
|
Calculate polarization as local standard deviation. |
|
Calculate local persistence as proportion of time cell exceeds its neighborhood. |
Multivariate Analysis
|
Calculate neighborhood synergy between multiple variables. |
|
Calculate spatiotemporal coupling between two variables. |
|
Calculate frequency of simultaneous threshold exceedance for multiple variables. |
|
Calculate directional coevolution between two variables. |
|
Calculate multivariate persistence as proportion of time with simultaneous conditions. |
Multi-Criteria Decision Analysis
TOPSIS (Technique for Order of Preference by Similarity to Ideal Solution) method for spatial prioritization. Useful for site selection, restoration planning, and resource allocation based on multiple environmental criteria.
Features:
Multiple weighting schemes (equal, entropy, analytical hierarchy process)
Comprehensive visualization (ranking maps, isolines, bar charts)
Sensitivity analysis across weighting methods
Statistical summaries and publication-ready outputs
|
Execute TOPSIS multi-criteria decision analysis on the combined suitability scores. |
|
Create visualization comparing different weighting schemes. |
|
Create spatial maps of TOPSIS scores for different weighting methods. |
Raster Analysis
Functions for processing spatiotemporal raster data, including configuration management, binary matrix generation for threshold exceedances, input validation, and NetCDF output creation.
Capabilities:
Configuration file validation and loading
Temporal difference analysis for change detection
Input validation and preprocessing
Post-treatment data preparation and refinement
Binary matrix generation for threshold analysis
Temporal aggregation (annual, seasonal)
NetCDF format output with metadata
|
Selects the largest region from a continuous field and returns its contour. |
|
Expand the dataset by adding a 'simulation' dimension using the 'simulation' attribute. |
|
Validate and prepare input configuration for marine spatial analysis processing. |
|
Compute the largest connected contour for each time slice in a 3D raster stack. |
|
Execute the complete spatiotemporal raster analysis workflow. |
|
Convert a contour represented by pixel indices to a real-world geometry. |
|
Save a set of geometry records as a spatial layer (GeoPackage or Shapefile). |
|
Save extracted contour geometries to disk as a spatial layer (GeoPackage or Shapefile). |
|
Save a list of arrays (per percentile) to a NetCDF file with spatial coordinates and metadata. |
|
Load indicator analysis results from a results directory (JSON + NPZ format). |