pycsamt.emtools.spectra#
pycsamt.emtools.spectra#
Analysis and visualisation of MT cross-spectra stored in
Spectra objects.
All plotting functions read visual defaults from the package-wide
API singletons at call time, so a single
configure_style() or
use_style() call propagates here too.
Analysis#
|
Compute the inter-channel coherence matrix. |
|
Power spectral density per channel as a tidy DataFrame. |
|
Inter-channel squared coherence as a tidy DataFrame. |
|
Signal-to-noise ratio estimated from squared coherence. |
|
Return a new |
|
Boolean mask of frequencies with sufficient coherence. |
|
Compact per-frequency summary table. |
Visualisation#
|
Plot the power spectral density per channel. |
|
Plot squared coherence for selected channel pairs. |
|
Visualise the full cross-spectral density matrix at one frequency. |
|
Plot apparent resistivity and phase recovered from spectra. |
|
Plot the induction tipper magnitude and phase from spectra. |
|
Pseudo-section of PSD across stations (station × period). |
|
Pseudo-section of coherence across stations (station × period). |
Quick start#
from pycsamt.seg.spectra import Spectra
from pycsamt.emtools.spectra import (
plot_psd, plot_coherence, plot_z_from_spectra,
plot_tipper_from_spectra, coherence_table,
)
sp = Spectra.from_file("site.edi")
# power spectral density per channel
plot_psd(sp, title="HBH05-03 PSD")
# inter-channel coherence
plot_coherence(sp)
# apparent resistivity + phase recovered from spectra
plot_z_from_spectra(sp)
Functions
|
Return a new |
|
Compute the inter-channel coherence matrix. |
|
Inter-channel squared coherence as a tidy DataFrame. |
|
Boolean mask of frequencies with sufficient coherence. |
|
Plot squared coherence for selected channel pairs. |
|
Pseudo-section of coherence across stations (station × period). |
|
Plot the power spectral density per channel. |
|
Pseudo-section of PSD across stations (station × period). |
|
Visualise the full cross-spectral density matrix at one frequency. |
|
Plot the induction tipper magnitude and phase from spectra. |
|
Plot apparent resistivity and phase recovered from spectra. |
|
Power spectral density per channel as a tidy DataFrame. |
|
Signal-to-noise ratio estimated from squared coherence. |
|
Compact per-frequency summary table. |
- pycsamt.emtools.spectra.coherence_matrix(sp)[source]#
Compute the inter-channel coherence matrix.
The squared coherence between channels i and j is:
\[\gamma^2_{ij}(f) = \frac{|S_{ij}(f)|^2}{S_{ii}(f)\,S_{jj}(f)}\]- Parameters:
sp (Spectra) – Cross-spectra container.
- Returns:
coh – Real-valued coherence matrix per frequency, values in [0, 1].
- Return type:
ndarray, shape
(n_freq, n_chan, n_chan)
- pycsamt.emtools.spectra.psd_table(sp_input, *, normalize=False, api=None)[source]#
Power spectral density per channel as a tidy DataFrame.
- pycsamt.emtools.spectra.coherence_table(sp_input, *, pairs=None, api=None)[source]#
Inter-channel squared coherence as a tidy DataFrame.
- pycsamt.emtools.spectra.snr_table(sp_input, *, pairs=None, api=None)[source]#
Signal-to-noise ratio estimated from squared coherence.
Uses the coherence-based estimator:
\[\text{SNR} = \frac{\gamma^2}{1 - \gamma^2}\]with the dB version
SNR_dB = 10 log₁₀(SNR).
- pycsamt.emtools.spectra.band_select(sp, f_min, f_max)[source]#
Return a new
Spectrarestricted to the frequency band[f_min, f_max]Hz.
- pycsamt.emtools.spectra.mask_low_coherence(sp, *, pairs=None, threshold=0.5, require_all=False)[source]#
Boolean mask of frequencies with sufficient coherence.
- Parameters:
- Returns:
mask –
Truewhere coherence is acceptable.- Return type:
ndarray of bool, shape
(n_freq,)
- pycsamt.emtools.spectra.spectra_summary(sp, *, api=None)[source]#
Compact per-frequency summary table.
Columns:
freq,period,bw,avgt,rotspec, plus the diagonal PSD and mean off-diagonal coherence for each channel.
- pycsamt.emtools.spectra.plot_psd(sp, *, channels=None, log_psd=True, lw=<object object>, alpha=<object object>, title='', figsize=(9, 5), ax=None)[source]#
Plot the power spectral density per channel.
The x-axis follows
PYCSAMT_CONTROL(log₁₀ period by default). Colours come frommultiline.- Parameters:
sp (Spectra)
channels (sequence of int, optional) – Channel indices to plot. Default = all channels.
log_psd (bool) – Display log₁₀(PSD) when
True.lw (float) – Line width. Default:
PYCSAMT_STYLE.multiline.lw.alpha (float) – Line alpha. Default:
PYCSAMT_STYLE.multiline.alpha.title (str)
ax (Axes or None)
- Returns:
ax
- Return type:
Axes
- pycsamt.emtools.spectra.plot_coherence(sp, *, pairs=None, threshold=0.5, show_threshold=True, lw=<object object>, alpha=<object object>, title='', axes=None, figsize=None)[source]#
Plot squared coherence for selected channel pairs.
Each pair gets its own sub-axis arranged in a grid. A dashed horizontal line marks threshold.
- Parameters:
sp (Spectra)
pairs (list of (i, j), optional) – Default = all upper-triangle pairs.
threshold (float) – Quality threshold drawn as a dashed line. Default 0.5.
show_threshold (bool)
lw (float) – Style defaults from
PYCSAMT_STYLE.multiline.alpha (float) – Style defaults from
PYCSAMT_STYLE.multiline.title (str)
figsize ((float, float) or None) – Auto-computed from the number of pairs when
None.
- Returns:
axes
- Return type:
ndarray of Axes, shape
(n_pairs,)
- pycsamt.emtools.spectra.plot_spectra_matrix(sp, *, freq_idx=0, quantity='abs', cmap=<object object>, log_scale=True, title='', ax=None, figsize=(7, 6))[source]#
Visualise the full cross-spectral density matrix at one frequency.
The matrix is drawn as a colour image. The diagonal shows auto- spectra (PSD); the upper and lower triangles show the magnitude (or real/imaginary part) of the cross-spectra.
- Parameters:
sp (Spectra)
freq_idx (int) – Index into
sp.freqfor the frequency slice.quantity ({'abs', 'real', 'imag', 'phase'}) – Quantity to colour.
cmap (str or _UNSET) – Colour map. Defaults to
"viridis"(abs) or"RdBu_r"(real/imag/phase).log_scale (bool) – Apply log₁₀ to the absolute value when
quantity="abs".title (str)
- Returns:
fig
- Return type:
Figure
- pycsamt.emtools.spectra.plot_z_from_spectra(sp, *, e_labels=('EX', 'EY'), h_labels=('HX', 'HY'), ridge=None, estimate_error=False, show_error=True, title='', axes=None, figsize=(10, 5))[source]#
Plot apparent resistivity and phase recovered from spectra.
Calls
to_Z()internally and renders the result with the standard MT component styling fromPYCSAMT_STYLE.- Parameters:
sp (Spectra)
e_labels (tuple of str) – Channel type labels used for the E and H blocks in
to_Z().h_labels (tuple of str) – Channel type labels used for the E and H blocks in
to_Z().ridge (float or None) – Tikhonov regularization for S_HH inversion.
estimate_error (bool) – Estimate 1-σ errors in
to_Z(). DefaultFalse(avoids DoF warnings when metadata is incomplete).show_error (bool) – Shade error envelope when errors are available.
title (str)
- Returns:
fig
- Return type:
Figure
- pycsamt.emtools.spectra.plot_tipper_from_spectra(sp, *, h_labels=('HX', 'HY'), ridge=None, estimate_error=False, show_error=True, title='', axes=None, figsize=(10, 5))[source]#
Plot the induction tipper magnitude and phase from spectra.
Displays the real and imaginary parts of T_x and T_y as well as their magnitudes on a two-panel figure (amplitude | phase).
- pycsamt.emtools.spectra.plot_psd_section(sp_input, *, channel=0, log_psd=True, cmap='viridis', vmin=None, vmax=None, section='pseudosection', title='', figsize=None, ax=None)[source]#
Pseudo-section of PSD across stations (station × period).
Interpolates all Spectra objects to a common log-spaced frequency grid before assembling the 2-D colour map.
- pycsamt.emtools.spectra.plot_coherence_section(sp_input, *, pair=None, threshold=0.5, show_threshold=True, cmap='RdYlGn', section='pseudosection', title='', figsize=None, ax=None)[source]#
Pseudo-section of coherence across stations (station × period).
- Parameters:
pair ((int, int) or None) – Single channel pair
(i, j)to display. WhenNonethe mean over all upper-triangle pairs is shown.threshold (float) – Value shown by the shared colorbar. Default 0.5.
show_threshold (bool) – Add a contour at threshold when
True.cmap (str) – Default
"RdYlGn"— red=low, green=high coherence.section (str or SectionStyle)
title (str)
ax (Axes or None)
- Returns:
ax
- Return type:
Axes