Data
Data
¤
Bases: ABC
Base class for all data.
The time domain data are considered the primary entity; the Fourier domain data are derived from an FFT after applying a window. The structure is set up so that td and fd are always Fourier conjugates of each other: the one-sided Fourier series is complete up to the Nyquist frequency.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Name of the data instance. |
td |
Float[Array, n_time]
|
Time domain data array. |
fd |
Complex[Array, n_time // 2 + 1]
|
Frequency domain data array. |
start_time |
float
|
GPS start time of the data segment in seconds. |
delta_t |
FloatLike
|
Time step between samples. |
window |
Float[Array, n_time]
|
Window function applied to data. |
Methods:
| Name | Description |
|---|---|
__bool__ |
Check if the data is empty. |
__init__ |
Initialize the data class. |
__iter__ |
Iterator over the time-domain data. |
__len__ |
Returns the length of the time-domain data. |
fft |
Compute the Fourier transform of the data and store it |
frequency_slice |
Slice the data in the frequency domain. |
from_fd |
Create a Data object starting from (potentially incomplete) |
from_file |
Load data from a file. |
from_gwosc |
Pull data from GWOSC. |
set_tukey_window |
Create a Tukey window on the data; the window is stored in the |
to_file |
Save the data to a file. |
to_psd |
Compute a Welch estimate of the power spectral density of the data. |
duration: FloatLike
property
¤
Gets duration of the data in seconds.
Returns:
| Name | Type | Description |
|---|---|---|
float |
FloatLike
|
Duration in seconds. |
frequencies: Float[Array, n_time // 2 + 1]
property
¤
Gets frequencies of the data.
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Float[Array, n_time // 2 + 1]
|
Array of frequencies in Hz. |
has_fd: bool
property
¤
Checks if Fourier domain data exists.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if Fourier domain data exists, False otherwise. |
is_empty: bool
property
¤
Checks if the data is empty.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if data is empty, False otherwise. |
n_freq: int
property
¤
Gets number of frequency samples.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
Number of frequency domain samples. |
n_time: int
property
¤
Gets number of time samples.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
Number of time domain samples. |
sampling_frequency: FloatLike
property
¤
Gets sampling frequency of the data.
Returns:
| Name | Type | Description |
|---|---|---|
float |
FloatLike
|
Sampling frequency in Hz. |
times: Float[Array, n_time]
property
¤
Gets time points of the data.
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Float[Array, n_time]
|
Array of time points in seconds. |
__bool__() -> bool
¤
Check if the data is empty.
__init__(td: Float[Array, n_time] = jnp.array([]), delta_t: FloatLike = 0.0, start_time: float = 0.0, name: str = '', window: Optional[Float[Array, n_time]] = None) -> None
¤
Initialize the data class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
td
|
Float[Array, n_time]
|
Time domain data array. |
array([])
|
delta_t
|
FloatLike
|
Time step of the data in seconds. |
0.0
|
start_time
|
float
|
GPS start time of the segment in seconds (default: 0). |
0.0
|
name
|
str
|
Name of the data (default: ''). |
''
|
window
|
Optional[Float[Array, n_time]]
|
Window function to apply to the data before FFT (default: None). |
None
|
__iter__()
¤
Iterator over the time-domain data.
Returns:
| Name | Type | Description |
|---|---|---|
iterator |
Iterator over time domain data. |
__len__() -> int
¤
Returns the length of the time-domain data.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
Length of time domain data array. |
fft(window: Optional[Float[Array, n_time]] = None) -> Complex[Array, n_freq]
¤
Compute the Fourier transform of the data and store it in the fd attribute.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
window
|
Optional[Float[Array, n_time]]
|
Window function to apply to the data before FFT (default: None). |
None
|
frequency_slice(f_min: FloatLike, f_max: FloatLike, auto_fft: bool = True) -> tuple[Complex[Array, ' n_sample'], Float[Array, ' n_sample']]
¤
Slice the data in the frequency domain. This is the main function which interacts with the likelihood.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f_min
|
FloatLike
|
Minimum frequency of the slice in Hz. |
required |
f_max
|
FloatLike
|
Maximum frequency of the slice in Hz. |
required |
auto_fft
|
bool
|
Whether to automatically compute FFT if not already done. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
tuple[Complex[Array, ' n_sample'], Float[Array, ' n_sample']]
|
Sliced data in the frequency domain and corresponding frequencies. |
from_fd(fd_strain: Complex[Array, n_freq], frequencies: Float[Array, n_freq], start_time: float = 0.0, name: str = '') -> Self
classmethod
¤
Create a Data object starting from (potentially incomplete) Fourier domain data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fd_strain
|
Complex[Array, n_freq]
|
Fourier domain data array. |
required |
frequencies
|
Float[Array, n_freq]
|
Frequencies of the data in Hz. |
required |
start_time
|
float
|
GPS start time of the segment in seconds (default: 0). |
0.0
|
name
|
str
|
Name of the data (default: ''). |
''
|
Returns:
| Name | Type | Description |
|---|---|---|
Data |
Self
|
Data object with the Fourier and time domain data. |
from_file(path: str, channel: Optional[str] = None, start_time: Optional[float] = None, end_time: Optional[float] = None) -> Self
classmethod
¤
Load data from a file.
Supported formats:
.npz— NumPy archive containingtd(time-domain strain),dt(time step in seconds), andstart_time(GPS start time)..gwf/.gwf.gz— LIGO/Virgo Gravitational Wave Frame file. Requiresgwpy. Specify channel (e.g.'H1:GDS-CALIB_STRAIN'); if omitted, common preset channel names are tried automatically..hdf5/.h5/.hdf— HDF5 file readable by gwpy. channel is required when the file contains multiple channels..csv— Two-column CSV time-series file (gwpy format).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to the file. |
required |
channel
|
Optional[str]
|
Channel name for frame or HDF5 files
(e.g. |
None
|
start_time
|
Optional[float]
|
GPS start time to read (optional; for gwpy-backed formats). |
None
|
end_time
|
Optional[float]
|
GPS end time to read (optional; for gwpy-backed formats). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Data |
Self
|
Data object with the loaded time domain data. |
from_gwosc(ifo: str, gps_start_time: float, gps_end_time: float, cache: bool = True, **kws) -> Self
classmethod
¤
Pull data from GWOSC.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ifo
|
str
|
Interferometer name. |
required |
gps_start_time
|
float
|
GPS start time of the data. |
required |
gps_end_time
|
float
|
GPS end time of the data. |
required |
cache
|
bool
|
Whether to cache the data (default: True). |
True
|
**kws
|
Keyword arguments for |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Data |
Self
|
Data object with the fetched time domain data. |
set_tukey_window(alpha: float = 0.2) -> None
¤
Create a Tukey window on the data; the window is stored in the window attribute and only applied when FFTing the data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
alpha
|
float
|
Shape parameter of the Tukey window (default: 0.2); this is the fraction of the segment that is tapered on each side. |
0.2
|
to_file(path: str) -> None
¤
Save the data to a file.
Supported formats:
.npz— NumPy archive with keystd(time-domain strain),dt(time step in seconds),start_time(GPS), andname..txt/.dat— Three-column whitespace-separated text file containing[f, real(h(f)), imag(h(f))](frequency-domain strain)..csv— Same as.txtbut comma-separated..gwf— LIGO/Virgo Gravitational Wave Frame file (time-domain). Requiresgwpy..hdf5/.h5— HDF5 file (time-domain). Requiresgwpy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to the output file (extension determines format). |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the file extension is not supported. |
to_psd(**kws) -> PowerSpectrum
¤
Compute a Welch estimate of the power spectral density of the data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kws
|
Keyword arguments for |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
PowerSpectrum |
PowerSpectrum
|
Power spectral density of the data. |
PowerSpectrum
¤
Bases: ABC
Class representing a power spectral density.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Name of the power spectrum. |
values |
Float[Array, n_freq]
|
Array of PSD values. |
frequencies |
Float[Array, n_freq]
|
Array of frequencies corresponding to PSD values. |
Methods:
| Name | Description |
|---|---|
__bool__ |
Check if the power spectrum is empty. |
__init__ |
Initialize PowerSpectrum. |
frequency_slice |
Slice the power spectrum to a frequency range. |
from_file |
Load a power spectrum from a file. |
interpolate |
Interpolate the power spectrum to new frequencies. |
simulate_data |
Simulate noise data based on the power spectrum. |
to_file |
Save the power spectrum to a file in .npz format. |
delta_f: FloatScalar
property
¤
Gets frequency resolution.
Returns:
| Name | Type | Description |
|---|---|---|
float |
FloatScalar
|
Frequency resolution in Hz. |
delta_t: FloatScalar
property
¤
Gets time resolution.
Returns:
| Name | Type | Description |
|---|---|---|
float |
FloatScalar
|
Time resolution in seconds. |
duration: FloatScalar
property
¤
Gets duration of the data.
Returns:
| Name | Type | Description |
|---|---|---|
float |
FloatScalar
|
Duration in seconds. |
is_empty: bool
property
¤
Checks if the data is empty.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if data is empty, False otherwise. |
n_freq: int
property
¤
Gets number of frequency samples.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
Number of frequency samples. |
sampling_frequency: FloatScalar
property
¤
Gets sampling frequency.
Returns:
| Name | Type | Description |
|---|---|---|
float |
FloatScalar
|
Sampling frequency in Hz. |
__bool__() -> bool
¤
Check if the power spectrum is empty.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if power spectrum contains data, False otherwise. |
__init__(values: Float[Array, n_freq] = jnp.array([]), frequencies: Float[Array, n_freq] = jnp.array([]), name: Optional[str] = None) -> None
¤
Initialize PowerSpectrum.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
Float[Array, n_freq]
|
Array of PSD values. Defaults to empty array. |
array([])
|
frequencies
|
Float[Array, n_freq]
|
Array of frequencies in Hz. Defaults to empty array. |
array([])
|
name
|
Optional[str]
|
Name of the power spectrum. Defaults to None. |
None
|
frequency_slice(f_min: float, f_max: float) -> tuple[Float[Array, ' n_sample'], Float[Array, ' n_sample']]
¤
Slice the power spectrum to a frequency range.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f_min
|
float
|
Minimum frequency of the slice in Hz. |
required |
f_max
|
float
|
Maximum frequency of the slice in Hz. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
tuple[Float[Array, ' n_sample'], Float[Array, ' n_sample']]
|
Contains: - values: Sliced PSD values - frequencies: Frequencies corresponding to sliced values |
from_file(path: str, is_asd: bool = False) -> Self
classmethod
¤
Load a power spectrum from a file.
Supported formats:
.npz— NumPy archive containingvalues(PSD, Hz⁻¹) andfrequenciesarrays. is_asd is ignored..txt/.dat— two-column whitespace-separated text file(frequency, value). Set is_asd=True if the second column contains amplitude spectral density (Hz⁻¹/²); it will be squared internally to give the PSD..csv— same two-column format as.txt/.datbut comma-separated.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to the PSD file. |
required |
is_asd
|
bool
|
If |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
PowerSpectrum |
Self
|
Loaded power spectrum. |
interpolate(frequencies: Float[Array, ' n_sample'], kind: str = 'linear', **kws) -> PowerSpectrum
¤
Interpolate the power spectrum to new frequencies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Frequencies to interpolate to. |
required | |
kind
|
str
|
Interpolation method. Defaults to 'linear'. |
'linear'
|
**kws
|
Additional keyword arguments for scipy.interpolate.interp1d. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
PowerSpectrum |
PowerSpectrum
|
New power spectrum with interpolated values. |
simulate_data(key: Key) -> Complex[Array, ' n_sample']
¤
Simulate noise data based on the power spectrum.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
Key
|
JAX PRNG key for random number generation. |
required |
Returns:
| Type | Description |
|---|---|
Complex[Array, ' n_sample']
|
Complex frequency series of simulated noise data. |
to_file(path: str)
¤
Save the power spectrum to a file in .npz format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to save the .npz file. |
required |