Skip to content

Data

jimgw.core.single_event.data ¤

asd_file_dict = {'H1': 'https://dcc.ligo.org/public/0169/P2000251/001/O3-H1-C01_CLEAN_SUB60HZ-1251752040.0_sensitivity_strain_asd.txt', 'L1': 'https://dcc.ligo.org/public/0169/P2000251/001/O3-L1-C01_CLEAN_SUB60HZ-1240573680.0_sensitivity_strain_asd.txt', 'V1': 'https://dcc.ligo.org/public/0169/P2000251/001/O3-V1_sensitivity_strain_asd.txt'} module-attribute ¤

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 Float

Time step between samples.

window Float[Array, n_time]

Window function applied to data.

window: Float[Array, n_time] instance-attribute ¤
n_time: int property ¤

Gets number of time samples.

Returns:

Name Type Description
int int

Number of time domain samples.

n_freq: int property ¤

Gets number of frequency samples.

Returns:

Name Type Description
int int

Number of frequency domain samples.

is_empty: bool property ¤

Checks if the data is empty.

Returns:

Name Type Description
bool bool

True if data is empty, False otherwise.

duration: float property ¤

Gets duration of the data in seconds.

Returns:

Name Type Description
float float

Duration in seconds.

sampling_frequency: float property ¤

Gets sampling frequency of the data.

Returns:

Name Type Description
float float

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.

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.

name: str = name or '' instance-attribute ¤
td: Float[Array, n_time] = td instance-attribute ¤
fd: Complex[Array, n_time // 2 + 1] = jnp.zeros(self.n_freq, dtype='complex128') instance-attribute ¤
delta_t: Float = delta_t instance-attribute ¤
start_time: Float = start_time instance-attribute ¤
__len__() -> int ¤

Returns the length of the time-domain data.

Returns:

Name Type Description
int int

Length of time domain data array.

__iter__() ¤

Iterator over the time-domain data.

Returns:

Name Type Description
iterator

Iterator over time domain data.

__init__(td: Float[Array, n_time] = jnp.array([]), delta_t: Float = 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 Float

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
__repr__() ¤
__bool__() -> bool ¤

Check if the data is empty.

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
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: Float, f_max: Float, 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 Float

Minimum frequency of the slice in Hz.

required
f_max Float

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.

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 scipy.signal.welch.

{}

Returns:

Name Type Description
PowerSpectrum PowerSpectrum

Power spectral density of the 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 gwpy.timeseries.TimeSeries.fetch_open_data.

{}

Returns:

Name Type Description
Data Self

Data object with the fetched time domain data.

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) -> Self classmethod ¤

Load data from a file. This assumes the data to be in .npz format. It should at least contain the keys 'td', 'dt', and 'start_time' (GPS start time).

Parameters:

Name Type Description Default
path str

Path to the .npz file containing the data.

required
to_file(path: str) ¤

Save the data to a file in .npz format.

Parameters:

Name Type Description Default
path str

Path to save the .npz file.

required

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.

n_freq: int property ¤

Gets number of frequency samples.

Returns:

Name Type Description
int int

Number of frequency samples.

is_empty: bool property ¤

Checks if the data is empty.

Returns:

Name Type Description
bool bool

True if data is empty, False otherwise.

delta_f: Float property ¤

Gets frequency resolution.

Returns:

Name Type Description
float Float

Frequency resolution in Hz.

delta_t: Float property ¤

Gets time resolution.

Returns:

Name Type Description
float Float

Time resolution in seconds.

duration: Float property ¤

Gets duration of the data.

Returns:

Name Type Description
float Float

Duration in seconds.

sampling_frequency: Float property ¤

Gets sampling frequency.

Returns:

Name Type Description
float Float

Sampling frequency in Hz.

values: Float[Array, n_freq] = values instance-attribute ¤
frequencies: Float[Array, n_freq] = frequencies instance-attribute ¤
name: str = name or '' instance-attribute ¤
__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
__repr__() -> str ¤
__bool__() -> bool ¤

Check if the power spectrum is empty.

Returns:

Name Type Description
bool bool

True if power spectrum contains data, False otherwise.

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

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.

from_file(path: str) -> Self classmethod ¤

Load power spectrum from a file. This assumes the data to be in .npz format. It should at least contains the keys 'values', 'frequencies', and 'name'. values is the PSD values, frequencies is the frequencies of the PSD.

Parameters:

Name Type Description Default
path str

Path to the .npz file containing the data.

required
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