spectrochempy.PSD
- class PSD(*, log_level='WARNING', warm_start=False, harmonic=1, input_mode='auto', integration_method='trapezoid', method='matrix', n_spectra_per_cycle=None, phase_unit='degrees', phi=None, subtract_mean=False)[source]
PSD (Phase-Sensitive Detection) for demodulating spectroscopic data.
Supports two computation methods: 1. Matrix transform method: demodulated = np.dot(T, A) 2. Explicit integration method: PSD(phi, nu) = 2/T * ∫ D(t,nu) * sin(k*ω*t + phi) dt
- Parameters:
Computation method. “matrix” is faster using linear algebra.
Number of spectra per cycle. If None, inferred from data shape.
Input data format
- “raw” (2D (N_cycles*n_spectra_per_cycle, n_wavenumbers))
- “grouped” (3D (N_cycles, n_spectra_per_cycle, n_wavenumbers))
- “averaged” (2D (n_spectra_per_cycle, n_wavenumbers))
- “auto” (infer from shape)
Demodulation harmonic index (k in sin(k*ω*t + phi)).
Phase angles for demodulation (in degrees).
Quadrature method for numerical integration weights.
If True, subtract mean from data before demodulation.
Unit for phase output.
- harmonic
int, optional, default:1 Demodulation harmonic index.
input_mode : any value of [
'auto','raw','grouped','averaged'], optional, default:'auto'integration_method : any value of [
'rectangle','riemann','trapezoid','simpson'], optional, default:'trapezoid'method : any value of [
'matrix','integration'], optional, default:'matrix'phase_unit : any value of [
'degrees','radians'], optional, default:'degrees'- phia list or a numpy array, optional, default:
None Phase angles for demodulation (in degrees).
- subtract_mean
bool, optional, default:False If True, subtract mean from data before demodulation.
Notes
Requires phi to contain 0° and 90° for in_phase/quadrature extraction.
Matrix method is default and faster.
Integration method uses explicit numerical integration with configurable quadrature.
Math notation:
T = transform matrix (shape: n_phi × n_spectra_per_cycle)
period = modulation period (from time coordinate)
ω = 2π / period (angular frequency)
harmonic = k (demodulation harmonic index)
PSD equation (matrix method):
A = T · D_averaged
where D_averaged has shape (n_spectra_per_cycle, n_wavenumbers), averaged across all cycles.
PSD equation (integration method):
PSD(φ, λ) = (2/period) ∫ D_averaged(t, λ) · sin(k·ω·t + φ) dt
where φ is the demodulation phase angle, λ is wavenumber, and t is normalized time within one modulation period.
Examples
>>> import spectrochempy as scp >>> import numpy as np >>> # Raw 2D input (120 spectra, 1000 wavenumbers) >>> X = scp.NDDataset(np.random.rand(120, 1000)) >>> psd = scp.PSD(n_spectra_per_cycle=60, method='matrix') >>> psd.fit(X) >>> in_phase = psd.in_phase >>> quadrature = psd.quadrature >>> amplitude = psd.amplitude >>> phase = psd.phase
- T
Transform matrix (NOT the period). Shape: (n_phi, n_spectra_per_cycle). Dims: [“y”, “x”] where y=phi angles, x=time/spectra.
- Type:
- prs
Phase-resolved spectra (PRS) with shape (n_phi, n_wavenumbers) and dims [“y”, “x”].
- Type:
Initialize the BaseConfigurable class.
- Parameters:
log_level (int, optional) – The log level at startup. Default is logging.WARNING.
**kwargs (dict) – Additional keyword arguments for configuration.
Attributes Summary
Return the transform matrix T.
Return the X input dataset (eventually modified by the model).
Return the amplitude (sqrt(in_phase² + quadrature²)).
traitlets.config.Configobject.Demodulation harmonic index.
Return the in-phase component (phi=0°).
An enum whose value must be in a given sequence.
An enum whose value must be in a given sequence.
Return
logoutput.An enum whose value must be in a given sequence.
Number of spectra per cycle.
Object name
Return the phase (atan2(quadrature, in_phase)).
An enum whose value must be in a given sequence.
Phase angles for demodulation (in degrees).
Return the phase-resolved spectra (PRS).
Return the quadrature component (phi=90°).
If True, subtract mean from data before demodulation.
Methods Summary
fit(X[, Y])Fit the PSD model on X.
fit_transform(X, **kwargs)Fit the PSD model on X and return the PSD.
inverse_transform([X_transform])Inverse transform is not supported for PSD.
parameters([replace, removed, default])Alias for
paramsmethod.params([default])Return current or default configuration values.
reset()Reset configuration parameters to their default values.
to_dict()Return config value in a dict form.
transform(X)Transform data X using the fitted PSD model.
Attributes Documentation
- T
Return the transform matrix T.
- X
Return the X input dataset (eventually modified by the model).
- amplitude
Return the amplitude (sqrt(in_phase² + quadrature²)).
- config
traitlets.config.Configobject.
- harmonic
Demodulation harmonic index.
- in_phase
Return the in-phase component (phi=0°).
- input_mode
An enum whose value must be in a given sequence.
- integration_method
An enum whose value must be in a given sequence.
- log
Return
logoutput.
- method
An enum whose value must be in a given sequence.
- n_spectra_per_cycle
Number of spectra per cycle.
- name
Object name
- phase
Return the phase (atan2(quadrature, in_phase)).
- phase_unit
An enum whose value must be in a given sequence.
- phi
Phase angles for demodulation (in degrees).
- prs
Return the phase-resolved spectra (PRS).
- quadrature
Return the quadrature component (phi=90°).
- subtract_mean
If True, subtract mean from data before demodulation.
Methods Documentation
- fit(X, Y=None)[source]
Fit the PSD model on X.
- Parameters:
X (NDDataset or array-like) – Input data for PRS.
Y (None) – Ignored, present for API compatibility.
- Returns:
self (PSD) – The fitted PSD instance.
- fit_transform(X, **kwargs)[source]
Fit the PSD model on X and return the PSD.
- Parameters:
X (NDDataset or array-like) – Input data for PSD.
**kwargs – Additional keyword arguments (ignored).
- Returns:
NDDataset – Phase-resolved spectra (PRS).
- inverse_transform(X_transform=None, **kwargs)[source]
Inverse transform is not supported for PSD.
- Raises:
NotImplementedError – Always raised as PRS is not invertible.
- parameters(replace="params", removed="0.8.0") def parameters(self, default=False)[source]
Alias for
paramsmethod.Deprecated since version 0.8.0: Use
paramsinstead.
Examples using spectrochempy.PSD