gwexpy.interop.multitaper_
Interoperate with multitaper spectral estimation packages.
Interoperability with multitaper spectral estimation packages.
Two packages are supported:
multitaper (Prieto) — object-oriented API via
MTSpec/MTSine. Install withpip install multitaper.mtspec (Krischer) — function-based API returning
(spectrum, freq). Install withpip install mtspec.
Both are converted to FrequencySeries (or FrequencySeriesDict when
confidence intervals are requested).
References
Prieto, G. A. (2022). The multitaper spectrum analysis package in Python. Seismological Research Letters.
Krischer, L. et al. — https://github.com/krischer/mtspec
Functions
|
Convert a Prieto |
|
Convert Krischer |
- gwexpy.interop.multitaper_.from_mtspec(cls: type, mt: Any, *, quantity: Literal['psd', 'asd'] = 'psd', include_ci: bool = True) Any[source]
Convert a Prieto
MTSpec/MTSineobject to a GWexpy type.- Parameters:
cls (type) – Target type. Pass
FrequencySeriesto always receive a plain spectrum (CI is discarded even when available). PassFrequencySeriesDictto receive a dict that includes CI series when CI is available.mt (multitaper.mtspec.MTSpec or multitaper.mtsine.MTSine) –
Computed multitaper object. Expected attributes:
freq: ndarray (nf,) — frequency axis [Hz]spec: ndarray (nf,) — adaptive-weighted PSDspec_ci: ndarray (nf, 2) — 95 % jackknife CI[lower, upper](optional; not present onMTSine)se: ndarray (nf,) — degrees of freedom per bin (optional)
quantity ({"psd", "asd"}, default "psd") – Whether to return power or amplitude spectral density.
"asd"appliesnp.sqrtto the PSD.include_ci (bool, default True) – If True and the object carries
spec_ci, return aFrequencySeriesDictwith keys"psd"/"asd","ci_lower", and"ci_upper". Ignored when the CI attribute is absent.
- Returns:
FrequencySeries – When CI is unavailable or
include_ci=False.FrequencySeriesDict – When CI is available and
include_ci=True.
- Raises:
ValueError – If
quantityis not"psd"or"asd", or if the frequency axis is empty.
- gwexpy.interop.multitaper_.from_mtspec_array(cls: type, spectrum: ndarray, freq: ndarray, *, quantity: Literal['psd', 'asd'] = 'psd', ci_lower: ndarray | None = None, ci_upper: ndarray | None = None, unit: Any | None = None) Any[source]
Convert Krischer
mtspecfunction output to a GWexpy type.- Parameters:
cls (type) – Target type. Pass
FrequencySeriesto always receive a plain spectrum (CI is discarded even when available). PassFrequencySeriesDictto receive a dict that includes CI series when CI is available.spectrum (array-like, shape (nf,)) – PSD (or ASD, depending on
quantity) array returned bymtspec.mtspec().freq (array-like, shape (nf,)) – Frequency axis [Hz] returned by
mtspec.mtspec().quantity ({"psd", "asd"}, default "psd") – Whether spectrum is a PSD or ASD. Set to
"asd"to interpret the input as amplitude spectral density.ci_lower (array-like, shape (nf,), optional) – Lower confidence-interval bound (same units as spectrum).
ci_upper (array-like, shape (nf,), optional) – Upper confidence-interval bound (same units as spectrum).
unit (str or astropy.units.Unit, optional) – Physical unit of the spectral density values.
- Returns:
FrequencySeries – When ci_lower and ci_upper are both None.
FrequencySeriesDict – When either CI array is provided. Keys:
"psd"/"asd","ci_lower","ci_upper".
- Raises:
ValueError – If
quantityis not"psd"or"asd", if freq is not equally spaced, or if shapes are inconsistent.