Utilities
Alignment
- gwModels.utils.alignment.get_peak(t, func)[source]
Find the peak of a function via quadratic fit over 5 points closest to argmax.
- Parameters:
t (np.ndarray) – An array of times.
func (np.ndarray) – An array of function values.
- Returns:
(tpeak, fpeak)
- Return type:
- gwModels.utils.alignment.check_pi_rotation(h_dict)[source]
Checks whether a pi rotation is required in waveform mode data.
This function determines the phase factor required for each mode based on the phase of the h_l2m1 mode, applying a pi rotation for odd m modes if necessary.
Parameters: h_dict (dict): Dictionary of gravitational wave modes. Keys should be “h_l2m2”, “h_l2m1”, etc.
Returns: dict: Updated dictionary of gravitational wave modes after potential rotation.
- gwModels.utils.alignment.phase_align_dict(hdict)[source]
Aligns a waveform dictionary to ensure proper phases.
This function modifies the phases of the waveform modes to ensure that the initial phase of the (2,2) mode is zero and that the relative phases of higher modes are consistent.
Parameters: hdict (dict): Dictionary of gravitational wave modes. Keys should include
‘h_l2m2’, ‘h_l3m3’, etc.
Returns: dict: A new dictionary with aligned phases for each mode.
- class gwModels.utils.alignment.AlignWFData(t_input, h_input, t_common=None)[source]
Bases:
objectClass to align a waveform such that the peak is at t=0 and the initial phase is zero.
This class also casts the waveform onto a different time grid if specified.
Attributes: t_input (np.ndarray): Input time array. h_input (dict): Input waveform dictionary with keys as spherical harmonics modes. t_common (np.ndarray or None): Target time grid on which waveform data should be cast.
Methods: _find_peak_time(): Finds the time of the peak for the (2,2) mode. _align_time(): Aligns the waveform to ensure the peak is at t=0. _find_offset_orb_phase(): Finds the phase rotation to set the initial (2,2) mode phase to zero. _align_phase(): Aligns the phases of the waveform modes. _cast_waveform_on_timegrid(): Casts the waveform onto the specified time grid.
Peak finding
- class gwModels.utils.compute_local_peaks.PeakFinderCrude(time, signal, dmin=1, dmax=1)[source]
Bases:
objectClass to find the peaks of a signal using a crude way
- __init__(time, signal, dmin=1, dmax=1)[source]
Input : time: 1d-array, time signal: 1d-array, data signal from which to extract high and low envelopes dmin, dmax: int, optional, size of chunks, use this if the size of the input signal is too big
Output : lmin,lmax : high/low envelope idx of input signal s
- class gwModels.utils.compute_local_peaks.PeakFinderScipy(time, signal, distance_btw_peaks=100)[source]
Bases:
objectClass to find the peaks of a signal using scipy
- __init__(time, signal, distance_btw_peaks=100)[source]
Input : time: 1d-array, time signal: 1d-array, data signal from which to extract high and low envelopes distance_btw_peaks : rough distance between peaks in time series g(t)
default: 100
Output : lmin,lmax : high/low envelope idx of input signal s
Waveform features
- gwModels.utils.features.get_amplitude(h)[source]
Computes amplitude of a given gravitational wave time-series.
- Parameters:
h (np.ndarray) – Waveform mode array.
- Returns:
Amplitude A = abs(h).
- Return type:
np.ndarray
- gwModels.utils.features.get_phase(h)[source]
Computes phase of a given gravitational wave time-series.
- Parameters:
h (np.ndarray) – Waveform mode array.
- Returns:
Phase phi = arg(h).
- Return type:
np.ndarray
Metrics
- gwModels.utils.metrics.mathcalE_error(h1, h2)[source]
Computes the time-domain error between two waveforms.
Calculates the error according to Equation 21 of https://arxiv.org/pdf/1701.00550.pdf by normalizing the difference between the two waveforms.
- Parameters:
h1 (np.ndarray) – Reference waveform in the time domain.
h2 (np.ndarray) – Comparison waveform in the time domain.
- Returns:
Normalized error for each time sample.
- Return type:
np.ndarray
- gwModels.utils.metrics.simple_mismatch(h1, h2)[source]
Computes a simple mismatch between two waveforms.
- The mismatch is defined as 1 minus the normalized inner product:
MM = 1 - Re(<h1, h2>) / (||h1|| * ||h2||)
- Parameters:
h1 (np.ndarray) – First waveform in the time domain.
h2 (np.ndarray) – Second waveform in the time domain.
- Returns:
Mismatch value. Returns NaN if either waveform has zero norm.
- Return type: