This module provides the core filtering algorithms used for
static shift correction, mirroring the methods described in the
Zonge ASTATIC program manual.
This filter is designed to remove single-station static
offsets while preserving broader geological trends. It can
operate on a pandas Series, a NumPy array, or a column
within a pandas DataFrame.
The apparent resistivity data to be filtered. This can be:
- A pandas Series of resistivity values.
- A 1D NumPy array of resistivity values.
- The string name of the column to use if data is
provided.
data (pd.DataFrame, optional) – A DataFrame containing the resistivity data. Required if
rho_profile is provided as a string.
window_size (int, default 5) – The size of the moving window for the filter. Must be
an odd integer.
trim_proportion (float, default 0.2) – The proportion of observations to trim from each end of
the window before computing the mean. For a window of 5,
0.2 trims 1 value from each end (the min and max).
Returns:
The smoothed resistivity profile, returned in the same
format as the input (rho_profile). If a DataFrame was
passed to data, the function returns a new DataFrame
with an added column for the smoothed data.
Return type:
pd.Series, np.ndarray, or pd.DataFrame
Raises:
ValueError – If rho_profile is a string but data is not provided,
or if window_size is not an odd integer.
Apply a Fixed-Length Moving Average (FLMA) filter.
This filter smooths complex impedance data using a spatial
Hanning window whose width is a fixed multiple of the
receiver dipole length.
Parameters:
z_profile (pd.Series, np.ndarray, or str) – The complex impedance data (Z) to be filtered. Can be:
- A pandas Series of complex impedance values.
- A 1D NumPy array of complex impedance values.
- The string name of the column if data is provided.
stations (pd.Series, np.ndarray, or str) – The station locations (coordinates). Must correspond to
the z_profile data. Can be a Series, array, or column
name if data is provided.
dipole_length (float) – The length of the E-field receiver dipole in the same
units as the station locations.
data (pd.DataFrame, optional) – A DataFrame containing the impedance and station data.
Required if z_profile or stations are strings.
filter_width_dipoles (float, default 5.0) – The total width of the Hanning window, expressed in
multiples of the dipole_length.
Returns:
The smoothed complex impedance profile, returned in the
same format as the input. If a DataFrame was passed to
data, a new DataFrame with an added column for the
smoothed data is returned.
Interpolate AVG data onto a regular log-spaced grid.
This function resamples the apparent resistivity and phase
data for each station and component onto a new, logarithmically
spaced frequency axis. This is a common preprocessing step for
inversion and modeling.
Parameters:
df (pandas.DataFrame) – The input DataFrame containing the AVG data. Must include
‘station’, ‘freq’, ‘rho’, and ‘phase’ columns.
freq_min (float, optional) – The minimum frequency for the new grid. If None, it is
inferred from the minimum frequency in the data.
freq_max (float, optional) – The maximum frequency for the new grid. If None, it is
inferred from the maximum frequency in the data.
num_points (int, default 50) – The number of logarithmically spaced points to create
between freq_min and freq_max.
interp_kind (str, default 'cubic') – The kind of interpolation to perform, passed to
scipy.interpolate.interp1d. Common options are
‘slinear’, ‘quadratic’, and ‘cubic’.
Returns:
A new DataFrame with the data interpolated onto the
specified logarithmic frequency grid.
Smooth apparent resistivity using the Hilbert transform.
This function reconstructs a smoother apparent resistivity
curve from the impedance phase data, leveraging the causal
nature of magnetotelluric data.
Parameters:
df (pandas.DataFrame) – The input DataFrame. Must include ‘station’, ‘freq’,
‘rho’, and ‘phase’ columns.
smoothing_factor (float, default 0.1) – The smoothing factor for the UnivariateSpline applied
to the phase data before the Hilbert transform. A smaller
value results in less smoothing.
Returns:
A new DataFrame with a ‘rho_smoothed’ column containing
the reconstructed, smoother apparent resistivity values.
Determine a suitable reference frequency for static shift.
This utility automatically selects a reference frequency based
on the principle of using the “highest frequency with clean
data,” as recommended in the ASTATIC manual.
Parameters:
df (pandas.DataFrame) – The input DataFrame containing the AVG data. Must include
‘station’, ‘freq’, and a quality control column.
The method for determining the reference frequency.
- ‘auto’: Automatically select the frequency based on QC
metrics.
float: A specific frequency value to use, which will be
returned directly.
qc_column (str, default 'pc_rho') – The canonical name of the quality control column to use for
filtering “clean” data points.
qc_threshold (float, default 20.0) – The threshold for the qc_column. Data points where the
value in this column is below the threshold are
considered clean.
The ‘auto’ mode follows a robust, data-driven approach:
1. It filters the dataset to include only “clean” data points
(where qc_column < qc_threshold).
For each station, it finds the highest frequency that has
clean data.
It then returns the median of these highest frequencies.
The median is used to provide a stable estimate that is
robust against outlier stations.
If no data points meet the clean criteria, the function will
issue a warning and fall back to using the absolute maximum
frequency present in the entire dataset.
Skew is a dimensionless parameter that quantifies the
three-dimensionality of the subsurface conductivity structure.
It is a crucial diagnostic tool for determining whether a 1D
or 2D interpretation is appropriate for the data.
Parameters:
df (pandas.DataFrame) – A tidy DataFrame containing the impedance tensor components.
Must include ‘station’, ‘freq’, ‘comp’, and a complex ‘z’
column.
Returns:
A DataFrame with columns for ‘station’, ‘freq’, and the
calculated ‘skew’.
Generally, skew values are interpreted as follows:
- skew < 0.1: Data can be considered 1D.
- 0.1 <= skew <= 0.3: Data is likely 2D.
- skew > 0.3: Data is likely 3D or affected by significant
This function determines the principal axis direction of the
impedance tensor for each station and frequency. The strike is
the angle to which the coordinate system must be rotated to
minimize the diagonal components of the impedance tensor
(\(Z_{xx}\), \(Z_{yy}\)), which is a common assumption
for 2D geological structures.
Parameters:
df (pandas.DataFrame) – A tidy DataFrame containing the impedance tensor components.
Must include ‘station’, ‘freq’, ‘comp’, and a complex ‘z’
column from which the tensor elements can be pivoted.
Returns:
A DataFrame with columns for ‘station’, ‘freq’, and the
calculated ‘strike_angle’ in degrees clockwise from North.
The calculation is performed using a common tensor
decomposition method based on the real parts of the impedance
tensor components [1]_. The formula used is:
This angle represents the orientation of the primary 2D
geological structure.
Examples
>>> frompycsamt.zongeimportAMTAVG>>> frompycsamt.zonge.proc_utilsimportget_strike>>> avg=AMTAVG.from_file('data/avg/K2.avg')>>> # The Z component's frame already has the required columns>>> strike_df=get_strike(avg.z.frame)>>> print(strike_df.head())