environmentaltools.spatial.confidence_interval_2d
- environmentaltools.spatial.confidence_interval_2d(data, loc0=None, angle=None, n_points=1000)[source]
Calculate 2D confidence intervals and statistics for profile data.
Computes mean, standard deviation, minimum, and maximum values across multiple 2D profiles by rotating, interpolating, and analyzing the data in a common coordinate system. Useful for analyzing variability in spatial transects or time series of profiles.
- Parameters:
data (dict of pd.DataFrame) – Dictionary where keys identify different profiles and values are DataFrames containing ‘x’ and ‘y’ columns representing profile coordinates. All profiles should span similar spatial extent.
loc0 (list of float, optional) – Origin point [x0, y0] for coordinate rotation. If None, uses the minimum x location from the first profile. Default is None.
angle (float, optional) – Rotation angle in radians to align profiles. If None, automatically calculated from data geometry. Default is None.
n_points (int, optional) – Number of points for the regular interpolation grid. Default is 1000. Higher values provide finer resolution but increase computation time.
- Returns:
Statistical summary with index representing x-coordinates and columns: - ‘mean’: Mean y-value across all profiles - ‘std’: Standard deviation of y-values - ‘min’: Minimum y-value across all profiles - ‘max’: Maximum y-value across all profiles - ‘x’: X coordinates (in original coordinate system) - ‘ini’: Y-values from first profile - ‘end’: Y-values from last profile
- Return type:
pd.DataFrame
Notes
The function performs the following steps: 1. Rotates all profiles to a common reference frame 2. Interpolates each profile onto a regular n_points-grid 3. Calculates statistics across all interpolated profiles 4. Rotates results back to original coordinate system
Requires all profiles to have comparable spatial extent for meaningful results.
Examples
>>> import pandas as pd >>> import numpy as np >>> # Create sample profile data >>> data = { ... 1: pd.DataFrame({'x': [0, 1, 2], 'y': [0, 1, 2]}), ... 2: pd.DataFrame({'x': [0, 1, 2], 'y': [0, 1.5, 3]}), ... 3: pd.DataFrame({'x': [0, 1, 2], 'y': [0, 0.5, 1]}) ... } >>> stats = confidence_interval_2d(data, n_points=500) >>> print(stats[['mean', 'std']].head())