pycsamt.ai.processing.denoise#
EMDenoiser — convolutional autoencoder for MT impedance tensor denoising.
Trains a 1-D convolutional autoencoder (CAE) on clean (or simulated) MT data. At inference time the trained network suppresses broadband Gaussian noise and narrowband artefacts (powerline harmonics, dead-band contamination) while preserving the smooth spectral shape of the true signal.
Architecture#
The network is a symmetric encoder-decoder:
where \(\boldsymbol{\varepsilon}\) is synthetic training noise and the network minimises \(\|\mathbf{x} - \hat{\mathbf{x}}\|_2^2\).
Input tensor shape#
(n_samples, n_components, n_freqs)
n_components = 4(default) →[log|Zxy|, \phi_{xy}, log|Zyx|, \phi_{yx}]n_components = 8→ all four impedance tensor components
Functions
|
Extract an impedance feature array from a site collection. |
Classes
|
Convolutional autoencoder for MT impedance tensor denoising. |
- class pycsamt.ai.processing.denoise.EMDenoiser(n_freqs=None, n_components=4, *, channels=(64, 128, 64), dropout=0.1, device=None)[source]#
Bases:
BaseEMProcessorConvolutional autoencoder for MT impedance tensor denoising.
The network is trained on clean (or synthetic) impedance data by adding controlled noise and learning to reconstruct the original signal. Supports both PyTorch and TensorFlow backends via
pycsamt.backends.- Parameters:
n_freqs (int or None, default None) – Number of frequency channels in the input. When
None, inferred fromX.shape[2]on the first call tofit().n_components ({4, 8}, default 4) – Feature channels per frequency: 4 = off-diagonal \(Z_{xy}\), \(Z_{yx}\) amplitudes and phases; 8 = all four tensor components.
channels (tuple of int, default (64, 128, 64)) – Channel widths for the encoder/decoder stages.
dropout (float, default 0.1) – Dropout probability in the encoder bottleneck.
device (str or None) –
"cpu","cuda","mps","/GPU:0", orNonefor auto-detect via the active backend.
Notes
When neither PyTorch nor TensorFlow is available the denoiser falls back to a per-channel Gaussian smoothing filter (requires scipy).
Call
prepare_z_features()to convert a site collection to the(n_samples, n_components, n_freqs)array expected here.Examples
>>> import numpy as np >>> X_clean = np.random.randn(200, 4, 32).astype("float32") >>> den = EMDenoiser() >>> den.fit(X_clean, epochs=5, verbose=False) EMDenoiser(n_freqs=32, n_components=4) >>> X_denoised = den.transform(X_clean)
- fit(X, *, noise_level=0.05, epochs=50, batch_size=64, lr=0.001, val_frac=0.1, seed=None, verbose=True)[source]#
Train the denoiser on clean impedance data.
- Parameters:
X (ndarray, shape (n_samples, n_components, n_freqs)) – Clean training data.
noise_level (float) – Standard deviation of additive Gaussian noise relative to the per-channel standard deviation of
X.epochs (int) – Maximum number of training epochs.
batch_size (int)
lr (float) – Initial Adam learning rate.
val_frac (float) – Fraction of training samples held out for validation.
seed (int or None)
verbose (bool)
- Return type:
self
- pycsamt.ai.processing.denoise.prepare_z_features(sites, *, n_components=4, log_amp=True, freq_ref=None)[source]#
Extract an impedance feature array from a site collection.
- Parameters:
sites (SiteCollection, dict, or list of Z objects) – MT impedance data in any format accepted by
ensure_sites().n_components ({4, 8}) – 4 uses off-diagonal components only; 8 includes diagonal.
log_amp (bool) – If
True, amplitudes are transformed as \(\log_{10}(|Z| + \varepsilon)\) before packing.freq_ref (ndarray or None) – Common frequency grid to interpolate onto. When
None, the grid of the first site is used.
- Returns:
X – Feature array ready for
EMDenoiser.- Return type:
ndarray, shape
(n_sites, n_components, n_freqs)