signature
stringlengths
8
3.44k
body
stringlengths
0
1.41M
docstring
stringlengths
1
122k
id
stringlengths
5
17
def _postgenerate(self, res):
hp, hc = res<EOL>try:<EOL><INDENT>hp = taper_timeseries(hp, tapermethod=self.current_params['<STR_LIT>'])<EOL>hc = taper_timeseries(hc, tapermethod=self.current_params['<STR_LIT>'])<EOL><DEDENT>except KeyError:<EOL><INDENT>pass<EOL><DEDENT>return hp, hc<EOL>
Applies a taper if it is in current params.
f16080:c3:m1
def set_epoch(self, epoch):
self._epoch = float(epoch)<EOL>
Sets the epoch; epoch should be a float or a LIGOTimeGPS.
f16080:c8:m1
@property<EOL><INDENT>def static_args(self):<DEDENT>
return self._static_args<EOL>
Returns a dictionary of the static arguments.
f16080:c8:m2
def generate_from_args(self, *args):
return self.generate(**dict(zip(self.variable_args, args)))<EOL>
Generates a waveform, applies a time shift and the detector response function from the given args. The args are assumed to be in the same order as the variable args.
f16080:c8:m4
def generate(self, **kwargs):
self.current_params.update(kwargs)<EOL>rfparams = {param: self.current_params[param]<EOL>for param in kwargs if param not in self.location_args}<EOL>hp, hc = self.rframe_generator.generate(**rfparams)<EOL>if isinstance(hp, TimeSeries):<EOL><INDENT>df = self.current_params['<STR_LIT>']<EOL>hp = hp.to_frequencyseries(delta_f=df)<EOL>hc = hc.to_frequencyseries(delta_f=df)<EOL>tshift = <NUM_LIT:1.>/df - abs(hp._epoch)<EOL><DEDENT>else:<EOL><INDENT>tshift = <NUM_LIT:0.><EOL><DEDENT>hp._epoch = hc._epoch = self._epoch<EOL>h = {}<EOL>if self.detector_names != ['<STR_LIT>']:<EOL><INDENT>for detname, det in self.detectors.items():<EOL><INDENT>fp, fc = det.antenna_pattern(self.current_params['<STR_LIT>'],<EOL>self.current_params['<STR_LIT>'],<EOL>self.current_params['<STR_LIT>'],<EOL>self.current_params['<STR_LIT>'])<EOL>thish = fp*hp + fc*hc<EOL>tc = self.current_params['<STR_LIT>'] +det.time_delay_from_earth_center(self.current_params['<STR_LIT>'],<EOL>self.current_params['<STR_LIT>'], self.current_params['<STR_LIT>'])<EOL>h[detname] = apply_fd_time_shift(thish, tc+tshift, copy=False)<EOL>if self.recalib:<EOL><INDENT>h[detname] =self.recalib[detname].map_to_adjust(h[detname],<EOL>**self.current_params)<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>if '<STR_LIT>' in self.current_params:<EOL><INDENT>hp = apply_fd_time_shift(hp, self.current_params['<STR_LIT>']+tshift,<EOL>copy=False)<EOL><DEDENT>h['<STR_LIT>'] = hp<EOL><DEDENT>if self.gates is not None:<EOL><INDENT>for d in h.values():<EOL><INDENT>d.resize(ceilpow2(len(d)-<NUM_LIT:1>) + <NUM_LIT:1>)<EOL><DEDENT>h = strain.apply_gates_to_fd(h, self.gates)<EOL><DEDENT>return h<EOL>
Generates a waveform, applies a time shift and the detector response function from the given kwargs.
f16080:c8:m5
def ceilpow2(n):
signif,exponent = frexp(n)<EOL>if (signif < <NUM_LIT:0>):<EOL><INDENT>return <NUM_LIT:1>;<EOL><DEDENT>if (signif == <NUM_LIT:0.5>):<EOL><INDENT>exponent -= <NUM_LIT:1>;<EOL><DEDENT>return (<NUM_LIT:1>) << exponent<EOL>
convenience function to determine a power-of-2 upper frequency limit
f16081:m0
def coalign_waveforms(h1, h2, psd=None,<EOL>low_frequency_cutoff=None,<EOL>high_frequency_cutoff=None,<EOL>resize=True):
from pycbc.filter import matched_filter<EOL>mlen = ceilpow2(max(len(h1), len(h2)))<EOL>h1 = h1.copy()<EOL>h2 = h2.copy()<EOL>if resize:<EOL><INDENT>h1.resize(mlen)<EOL>h2.resize(mlen)<EOL><DEDENT>elif len(h1) != len(h2) or len(h2) % <NUM_LIT:2> != <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>snr = matched_filter(h1, h2, psd=psd,<EOL>low_frequency_cutoff=low_frequency_cutoff,<EOL>high_frequency_cutoff=high_frequency_cutoff)<EOL>_, l = snr.abs_max_loc()<EOL>rotation = snr[l] / abs(snr[l])<EOL>h1 = (h1.to_frequencyseries() * rotation).to_timeseries()<EOL>h1.roll(l)<EOL>h1 = TimeSeries(h1, delta_t=h2.delta_t, epoch=h2.start_time)<EOL>return h1, h2<EOL>
Return two time series which are aligned in time and phase. The alignment is only to the nearest sample point and all changes to the phase are made to the first input waveform. Waveforms should not be split accross the vector boundary. If it is, please use roll or cyclic time shift to ensure that the entire signal is contiguous in the time series. Parameters ---------- h1: pycbc.types.TimeSeries The first waveform to align. h2: pycbc.types.TimeSeries The second waveform to align. psd: {None, pycbc.types.FrequencySeries} A psd to weight the alignment low_frequency_cutoff: {None, float} The low frequency cutoff to weight the matching in Hz. high_frequency_cutoff: {None, float} The high frequency cutoff to weight the matching in Hz. resize: Optional, {True, boolean} If true, the vectors will be resized to match each other. If false, they must be the same length and even in length Returns ------- h1: pycbc.types.TimeSeries The shifted waveform to align with h2 h2: pycbc.type.TimeSeries The resized (if necessary) waveform to align with h1.
f16081:m1
def phase_from_frequencyseries(htilde, remove_start_phase=True):
p = numpy.unwrap(numpy.angle(htilde.data)).astype(<EOL>real_same_precision_as(htilde))<EOL>if remove_start_phase:<EOL><INDENT>p += -p[<NUM_LIT:0>]<EOL><DEDENT>return FrequencySeries(p, delta_f=htilde.delta_f, epoch=htilde.epoch,<EOL>copy=False)<EOL>
Returns the phase from the given frequency-domain waveform. This assumes that the waveform has been sampled finely enough that the phase cannot change by more than pi radians between each step. Parameters ---------- htilde : FrequencySeries The waveform to get the phase for; must be a complex frequency series. remove_start_phase : {True, bool} Subtract the initial phase before returning. Returns ------- FrequencySeries The phase of the waveform as a function of frequency.
f16081:m2
def amplitude_from_frequencyseries(htilde):
amp = abs(htilde.data).astype(real_same_precision_as(htilde))<EOL>return FrequencySeries(amp, delta_f=htilde.delta_f, epoch=htilde.epoch,<EOL>copy=False)<EOL>
Returns the amplitude of the given frequency-domain waveform as a FrequencySeries. Parameters ---------- htilde : FrequencySeries The waveform to get the amplitude of. Returns ------- FrequencySeries The amplitude of the waveform as a function of frequency.
f16081:m3
def time_from_frequencyseries(htilde, sample_frequencies=None,<EOL>discont_threshold=<NUM_LIT>*numpy.pi):
if sample_frequencies is None:<EOL><INDENT>sample_frequencies = htilde.sample_frequencies.numpy()<EOL><DEDENT>phase = phase_from_frequencyseries(htilde).data<EOL>dphi = numpy.diff(phase)<EOL>time = -dphi / (<NUM_LIT>*numpy.pi*numpy.diff(sample_frequencies))<EOL>nzidx = numpy.nonzero(abs(htilde.data))[<NUM_LIT:0>]<EOL>kmin, kmax = nzidx[<NUM_LIT:0>], nzidx[-<NUM_LIT:2>]<EOL>discont_idx = numpy.where(abs(dphi[kmin:]) >= discont_threshold)[<NUM_LIT:0>]<EOL>if discont_idx.size != <NUM_LIT:0>:<EOL><INDENT>kmax = min(kmax, kmin + discont_idx[<NUM_LIT:0>]-<NUM_LIT:1>)<EOL><DEDENT>time[:kmin] = time[kmin]<EOL>time[kmax:] = time[kmax]<EOL>return FrequencySeries(time.astype(real_same_precision_as(htilde)),<EOL>delta_f=htilde.delta_f, epoch=htilde.epoch,<EOL>copy=False)<EOL>
Computes time as a function of frequency from the given frequency-domain waveform. This assumes the stationary phase approximation. Any frequencies lower than the first non-zero value in htilde are assigned the time at the first non-zero value. Times for any frequencies above the next-to-last non-zero value in htilde will be assigned the time of the next-to-last non-zero value. .. note:: Some waveform models (e.g., `SEOBNRv2_ROM_DoubleSpin`) can have discontinuities in the phase towards the end of the waveform due to numerical error. We therefore exclude any points that occur after a discontinuity in the phase, as the time estimate becomes untrustworthy beyond that point. What determines a discontinuity in the phase is set by the `discont_threshold`. To turn this feature off, just set `discont_threshold` to a value larger than pi (due to the unwrapping of the phase, no two points can have a difference > pi). Parameters ---------- htilde : FrequencySeries The waveform to get the time evolution of; must be complex. sample_frequencies : {None, array} The frequencies at which the waveform is sampled. If None, will retrieve from ``htilde.sample_frequencies``. discont_threshold : {0.99*pi, float} If the difference in the phase changes by more than this threshold, it is considered to be a discontinuity. Default is 0.99*pi. Returns ------- FrequencySeries The time evolution of the waveform as a function of frequency.
f16081:m4
def phase_from_polarizations(h_plus, h_cross, remove_start_phase=True):
p = numpy.unwrap(numpy.arctan2(h_cross.data, h_plus.data)).astype(<EOL>real_same_precision_as(h_plus))<EOL>if remove_start_phase:<EOL><INDENT>p += -p[<NUM_LIT:0>]<EOL><DEDENT>return TimeSeries(p, delta_t=h_plus.delta_t, epoch=h_plus.start_time,<EOL>copy=False)<EOL>
Return gravitational wave phase Return the gravitation-wave phase from the h_plus and h_cross polarizations of the waveform. The returned phase is always positive and increasing with an initial phase of 0. Parameters ---------- h_plus : TimeSeries An PyCBC TmeSeries vector that contains the plus polarization of the gravitational waveform. h_cross : TimeSeries A PyCBC TmeSeries vector that contains the cross polarization of the gravitational waveform. Returns ------- GWPhase : TimeSeries A TimeSeries containing the gravitational wave phase. Examples --------s >>> from pycbc.waveform import get_td_waveform, phase_from_polarizations >>> hp, hc = get_td_waveform(approximant="TaylorT4", mass1=10, mass2=10, f_lower=30, delta_t=1.0/4096) >>> phase = phase_from_polarizations(hp, hc)
f16081:m5
def amplitude_from_polarizations(h_plus, h_cross):
amp = (h_plus.squared_norm() + h_cross.squared_norm()) ** (<NUM_LIT:0.5>)<EOL>return TimeSeries(amp, delta_t=h_plus.delta_t, epoch=h_plus.start_time)<EOL>
Return gravitational wave amplitude Return the gravitation-wave amplitude from the h_plus and h_cross polarizations of the waveform. Parameters ---------- h_plus : TimeSeries An PyCBC TmeSeries vector that contains the plus polarization of the gravitational waveform. h_cross : TimeSeries A PyCBC TmeSeries vector that contains the cross polarization of the gravitational waveform. Returns ------- GWAmplitude : TimeSeries A TimeSeries containing the gravitational wave amplitude. Examples -------- >>> from pycbc.waveform import get_td_waveform, phase_from_polarizations >>> hp, hc = get_td_waveform(approximant="TaylorT4", mass1=10, mass2=10, f_lower=30, delta_t=1.0/4096) >>> amp = amplitude_from_polarizations(hp, hc)
f16081:m6
def frequency_from_polarizations(h_plus, h_cross):
phase = phase_from_polarizations(h_plus, h_cross)<EOL>freq = numpy.diff(phase) / ( <NUM_LIT:2> * lal.PI * phase.delta_t )<EOL>start_time = phase.start_time + phase.delta_t / <NUM_LIT:2><EOL>return TimeSeries(freq.astype(real_same_precision_as(h_plus)),<EOL>delta_t=phase.delta_t, epoch=start_time)<EOL>
Return gravitational wave frequency Return the gravitation-wave frequency as a function of time from the h_plus and h_cross polarizations of the waveform. It is 1 bin shorter than the input vectors and the sample times are advanced half a bin. Parameters ---------- h_plus : TimeSeries A PyCBC TimeSeries vector that contains the plus polarization of the gravitational waveform. h_cross : TimeSeries A PyCBC TimeSeries vector that contains the cross polarization of the gravitational waveform. Returns ------- GWFrequency : TimeSeries A TimeSeries containing the gravitational wave frequency as a function of time. Examples -------- >>> from pycbc.waveform import get_td_waveform, phase_from_polarizations >>> hp, hc = get_td_waveform(approximant="TaylorT4", mass1=10, mass2=10, f_lower=30, delta_t=1.0/4096) >>> freq = frequency_from_polarizations(hp, hc)
f16081:m7
def taper_timeseries(tsdata, tapermethod=None, return_lal=False):
if tapermethod is None:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>if tapermethod not in taper_map.keys():<EOL><INDENT>raise ValueError("<STR_LIT>" %(tapermethod, "<STR_LIT:U+002CU+0020>".join(taper_map.keys())))<EOL><DEDENT>if tsdata.dtype not in (float32, float64):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>+ str(tsdata.dtype))<EOL><DEDENT>taper_func = taper_func_map[tsdata.dtype]<EOL>ts_lal = tsdata.astype(tsdata.dtype).lal()<EOL>if taper_map[tapermethod] is not None:<EOL><INDENT>taper_func(ts_lal.data, taper_map[tapermethod])<EOL><DEDENT>if return_lal:<EOL><INDENT>return ts_lal<EOL><DEDENT>else:<EOL><INDENT>return TimeSeries(ts_lal.data.data[:], delta_t=ts_lal.deltaT,<EOL>epoch=ts_lal.epoch)<EOL><DEDENT>
Taper either or both ends of a time series using wrapped LALSimulation functions Parameters ---------- tsdata : TimeSeries Series to be tapered, dtype must be either float32 or float64 tapermethod : string Should be one of ('TAPER_NONE', 'TAPER_START', 'TAPER_END', 'TAPER_STARTEND', 'start', 'end', 'startend') - NB 'TAPER_NONE' will not change the series! return_lal : Boolean If True, return a wrapped LAL time series object, else return a PyCBC time series.
f16081:m8
@schemed("<STR_LIT>")<EOL>def apply_fseries_time_shift(htilde, dt, kmin=<NUM_LIT:0>, copy=True):
Shifts a frequency domain waveform in time. The waveform is assumed to be sampled at equal frequency intervals.
f16081:m9
def apply_fd_time_shift(htilde, shifttime, kmin=<NUM_LIT:0>, fseries=None, copy=True):
dt = float(shifttime - htilde.epoch)<EOL>if dt == <NUM_LIT:0.>:<EOL><INDENT>if copy:<EOL><INDENT>htilde = <NUM_LIT:1.> * htilde<EOL><DEDENT><DEDENT>elif isinstance(htilde, FrequencySeries):<EOL><INDENT>htilde = apply_fseries_time_shift(htilde, dt, kmin=kmin, copy=copy)<EOL><DEDENT>else:<EOL><INDENT>if fseries is None:<EOL><INDENT>fseries = htilde.sample_frequencies.numpy()<EOL><DEDENT>shift = Array(numpy.exp(-<NUM_LIT>*numpy.pi*dt*fseries),<EOL>dtype=complex_same_precision_as(htilde))<EOL>if copy:<EOL><INDENT>htilde = <NUM_LIT:1.> * htilde<EOL><DEDENT>htilde *= shift<EOL><DEDENT>return htilde<EOL>
Shifts a frequency domain waveform in time. The shift applied is shiftime - htilde.epoch. Parameters ---------- htilde : FrequencySeries The waveform frequency series. shifttime : float The time to shift the frequency series to. kmin : {0, int} The starting index of htilde to apply the time shift. Default is 0. fseries : {None, numpy array} The frequencies of each element in htilde. This is only needed if htilde is not sampled at equal frequency steps. copy : {True, bool} Make a copy of htilde before applying the time shift. If False, the time shift will be applied to htilde's data. Returns ------- FrequencySeries A frequency series with the waveform shifted to the new time. If makecopy is True, will be a new frequency series; if makecopy is False, will be the same as htilde.
f16081:m10
def td_taper(out, start, end, beta=<NUM_LIT:8>, side='<STR_LIT:left>'):
out = out.copy()<EOL>width = end - start<EOL>winlen = <NUM_LIT:2> * int(width / out.delta_t)<EOL>window = Array(signal.get_window(('<STR_LIT>', beta), winlen))<EOL>xmin = int((start - out.start_time) / out.delta_t)<EOL>xmax = xmin + winlen//<NUM_LIT:2><EOL>if side == '<STR_LIT:left>':<EOL><INDENT>out[xmin:xmax] *= window[:winlen//<NUM_LIT:2>]<EOL>if xmin > <NUM_LIT:0>:<EOL><INDENT>out[:xmin].clear()<EOL><DEDENT><DEDENT>elif side == '<STR_LIT:right>':<EOL><INDENT>out[xmin:xmax] *= window[winlen//<NUM_LIT:2>:]<EOL>if xmax < len(out):<EOL><INDENT>out[xmax:].clear()<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>".format(side))<EOL><DEDENT>return out<EOL>
Applies a taper to the given TimeSeries. A half-kaiser window is used for the roll-off. Parameters ---------- out : TimeSeries The ``TimeSeries`` to taper. start : float The time (in s) to start the taper window. end : float The time (in s) to end the taper window. beta : int, optional The beta parameter to use for the Kaiser window. See ``scipy.signal.kaiser`` for details. Default is 8. side : {'left', 'right'} The side to apply the taper to. If ``'left'`` (``'right'``), the taper will roll up (down) between ``start`` and ``end``, with all values before ``start`` (after ``end``) set to zero. Default is ``'left'``. Returns ------- TimeSeries The tapered time series.
f16081:m11
def fd_taper(out, start, end, beta=<NUM_LIT:8>, side='<STR_LIT:left>'):
out = out.copy()<EOL>width = end - start<EOL>winlen = <NUM_LIT:2> * int(width / out.delta_f)<EOL>window = Array(signal.get_window(('<STR_LIT>', beta), winlen))<EOL>kmin = int(start / out.delta_f)<EOL>kmax = kmin + winlen//<NUM_LIT:2><EOL>if side == '<STR_LIT:left>':<EOL><INDENT>out[kmin:kmax] *= window[:winlen//<NUM_LIT:2>]<EOL>out[:kmin] *= <NUM_LIT:0.><EOL><DEDENT>elif side == '<STR_LIT:right>':<EOL><INDENT>out[kmin:kmax] *= window[winlen//<NUM_LIT:2>:]<EOL>out[kmax:] *= <NUM_LIT:0.><EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>".format(side))<EOL><DEDENT>return out<EOL>
Applies a taper to the given FrequencySeries. A half-kaiser window is used for the roll-off. Parameters ---------- out : FrequencySeries The ``FrequencySeries`` to taper. start : float The frequency (in Hz) to start the taper window. end : float The frequency (in Hz) to end the taper window. beta : int, optional The beta parameter to use for the Kaiser window. See ``scipy.signal.kaiser`` for details. Default is 8. side : {'left', 'right'} The side to apply the taper to. If ``'left'`` (``'right'``), the taper will roll up (down) between ``start`` and ``end``, with all values before ``start`` (after ``end``) set to zero. Default is ``'left'``. Returns ------- FrequencySeries The tapered frequency series.
f16081:m12
def fd_to_td(htilde, delta_t=None, left_window=None, right_window=None,<EOL>left_beta=<NUM_LIT:8>, right_beta=<NUM_LIT:8>):
if left_window is not None:<EOL><INDENT>start, end = left_window<EOL>htilde = fd_taper(htilde, start, end, side='<STR_LIT:left>', beta=left_beta)<EOL><DEDENT>if right_window is not None:<EOL><INDENT>start, end = right_window<EOL>htilde = fd_taper(htilde, start, end, side='<STR_LIT:right>', beta=right_beta)<EOL><DEDENT>return htilde.to_timeseries(delta_t=delta_t)<EOL>
Converts a FD waveform to TD. A window can optionally be applied using ``fd_taper`` to the left or right side of the waveform before being converted to the time domain. Parameters ---------- htilde : FrequencySeries The waveform to convert. delta_t : float, optional Make the returned time series have the given ``delta_t``. left_window : tuple of float, optional A tuple giving the start and end frequency of the FD taper to apply on the left side. If None, no taper will be applied on the left. right_window : tuple of float, optional A tuple giving the start and end frequency of the FD taper to apply on the right side. If None, no taper will be applied on the right. left_beta : int, optional The beta parameter to use for the left taper. See ``fd_taper`` for details. Default is 8. right_beta : int, optional The beta parameter to use for the right taper. Default is 8. Returns ------- TimeSeries The time-series representation of ``htilde``.
f16081:m13
def FinalSpin( Xi, eta ):
s4 = -<NUM_LIT><EOL>s5 = -<NUM_LIT><EOL>t0 = -<NUM_LIT><EOL>t2 = -<NUM_LIT><EOL>t3 = <NUM_LIT><EOL>etaXi = eta * Xi<EOL>eta2 = eta*eta<EOL>finspin = (Xi + s4*Xi*etaXi + s5*etaXi*eta + t0*etaXi + <NUM_LIT>*(<NUM_LIT>**<NUM_LIT:0.5>)*eta + t2*eta2 + t3*eta2*eta)<EOL>if finspin > <NUM_LIT:1.0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>return finspin<EOL><DEDENT>
Computes the spin of the final BH that gets formed after merger. This is done usingn Eq 5-6 of arXiv:0710.3345
f16082:m0
def fRD( a, M):
f = (lal.C_SI**<NUM_LIT> / (<NUM_LIT>*lal.PI*lal.G_SI*M*lal.MSUN_SI)) * (<NUM_LIT> - <NUM_LIT>*(<NUM_LIT:1.0>-a)**<NUM_LIT>)<EOL>return f<EOL>
Calculate the ring-down frequency for the final Kerr BH. Using Eq. 5.5 of Main paper
f16082:m1
def Qa( a ):
return (<NUM_LIT> + <NUM_LIT>*(<NUM_LIT:1.0>-a)**-<NUM_LIT>)<EOL>
Calculate the quality factor of ring-down, using Eq 5.6 of Main paper
f16082:m2
def imrphenomc_tmplt(**kwds):
<EOL>f_min = float128(kwds['<STR_LIT>'])<EOL>f_max = float128(kwds['<STR_LIT>'])<EOL>delta_f = float128(kwds['<STR_LIT>'])<EOL>distance = float128(kwds['<STR_LIT>'])<EOL>mass1 = float128(kwds['<STR_LIT>'])<EOL>mass2 = float128(kwds['<STR_LIT>'])<EOL>spin1z = float128(kwds['<STR_LIT>'])<EOL>spin2z = float128(kwds['<STR_LIT>'])<EOL>if '<STR_LIT>' in kwds:<EOL><INDENT>out = kwds['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>out = None<EOL><DEDENT>M = mass1 + mass2<EOL>eta = mass1 * mass2 / (M * M)<EOL>Xi = (mass1 * spin1z / M) + (mass2 * spin2z / M)<EOL>Xisum = <NUM_LIT>*Xi<EOL>Xiprod = Xi*Xi<EOL>Xi2 = Xi*Xi<EOL>m_sec = M * lal.MTSUN_SI;<EOL>piM = lal.PI * m_sec;<EOL>distance *= (<NUM_LIT> * lal.PC_SI / (<NUM_LIT> * sqrt(<NUM_LIT> / (<NUM_LIT>*lal.PI)) * M * lal.MRSUN_SI * M * lal.MTSUN_SI))<EOL>if not f_max:<EOL><INDENT>f_max = (<NUM_LIT> * eta * eta - <NUM_LIT> * eta + <NUM_LIT>) / piM<EOL><DEDENT>z101 = -<NUM_LIT><EOL>z102 = -<NUM_LIT><EOL>z111 = -<NUM_LIT><EOL>z110 = <NUM_LIT><EOL>z120 = -<NUM_LIT><EOL>z201 = <NUM_LIT><EOL>z202 = -<NUM_LIT><EOL>z211 = <NUM_LIT><EOL>z210 = -<NUM_LIT><EOL>z220 = <NUM_LIT><EOL>z301 = -<NUM_LIT><EOL>z302 = <NUM_LIT><EOL>z311 = <NUM_LIT><EOL>z310 = <NUM_LIT><EOL>z320 = -<NUM_LIT><EOL>z401 = <NUM_LIT><EOL>z402 = -<NUM_LIT><EOL>z411 = -<NUM_LIT><EOL>z410 = -<NUM_LIT><EOL>z420 = <NUM_LIT><EOL>z501 = -<NUM_LIT><EOL>z502 = <NUM_LIT><EOL>z511 = <NUM_LIT><EOL>z510 = <NUM_LIT><EOL>z520 = -<NUM_LIT><EOL>z601 = -<NUM_LIT><EOL>z602 = -<NUM_LIT><EOL>z611 = -<NUM_LIT><EOL>z610 = <NUM_LIT><EOL>z620 = <NUM_LIT><EOL>z701 = <NUM_LIT><EOL>z702 = -<NUM_LIT><EOL>z711 = -<NUM_LIT><EOL>z710 = -<NUM_LIT><EOL>z720 = <NUM_LIT><EOL>z801 = -<NUM_LIT><EOL>z802 = <NUM_LIT><EOL>z811 = <NUM_LIT><EOL>z810 = <NUM_LIT><EOL>z820 = <NUM_LIT><EOL>z901 = -<NUM_LIT><EOL>z902 = <NUM_LIT><EOL>z911 = <NUM_LIT><EOL>z910 = <NUM_LIT><EOL>z920 = -<NUM_LIT><EOL>eta2 = eta*eta<EOL>Xi2 = Xiprod<EOL>a1 = z101 * Xi + z102 * Xi2 + z111 * eta * Xi + z110 * eta + z120 * eta2<EOL>a2 = z201 * Xi + z202 * Xi2 + z211 * eta * Xi + z210 * eta + z220 * eta2<EOL>a3 = z301 * Xi + z302 * Xi2 + z311 * eta * Xi + z310 * eta + z320 * eta2<EOL>a4 = z401 * Xi + z402 * Xi2 + z411 * eta * Xi + z410 * eta + z420 * eta2<EOL>a5 = z501 * Xi + z502 * Xi2 + z511 * eta * Xi + z510 * eta + z520 * eta2<EOL>a6 = z601 * Xi + z602 * Xi2 + z611 * eta * Xi + z610 * eta + z620 * eta2<EOL>g1 = z701 * Xi + z702 * Xi2 + z711 * eta * Xi + z710 * eta + z720 * eta2<EOL>del1 = z801 * Xi + z802 * Xi2 + z811 * eta * Xi + z810 * eta + z820 * eta2<EOL>del2 = z901 * Xi + z902 * Xi2 + z911 * eta * Xi + z910 * eta + z920 * eta2<EOL>afin = FinalSpin( Xi, eta )<EOL>Q = Qa( abs(afin) )<EOL>frd = fRD( abs(afin), M)<EOL>Mfrd = frd * m_sec<EOL>f1 = <NUM_LIT:0.1> * frd<EOL>Mf1 = m_sec * f1<EOL>f2 = frd<EOL>Mf2 = m_sec * f2<EOL>d1 = <NUM_LIT><EOL>d2 = <NUM_LIT><EOL>f0 = <NUM_LIT> * frd<EOL>Mf0 = m_sec * f0<EOL>d0 = <NUM_LIT><EOL>b2 = ((-<NUM_LIT>/<NUM_LIT>)* a1 * pow(Mfrd,(-<NUM_LIT>/<NUM_LIT>)) - a2/(Mfrd*Mfrd) -(a3/<NUM_LIT>)*pow(Mfrd,(-<NUM_LIT>/<NUM_LIT>)) + (<NUM_LIT>/<NUM_LIT>)* a5 * pow(Mfrd,(-<NUM_LIT:1.>/<NUM_LIT>)) + a6)/eta<EOL>psiPMrd = (a1 * pow(Mfrd,(-<NUM_LIT>/<NUM_LIT>)) + a2/Mfrd + a3 * pow(Mfrd,(-<NUM_LIT:1.>/<NUM_LIT>)) +a4 + a5 * pow(Mfrd,(<NUM_LIT>/<NUM_LIT>)) + a6 * Mfrd)/eta<EOL>b1 = psiPMrd - (b2 * Mfrd)<EOL>pfaN = <NUM_LIT>/(<NUM_LIT> * eta)<EOL>pfa2 = (<NUM_LIT>/<NUM_LIT>) + (<NUM_LIT>*eta/<NUM_LIT>)<EOL>pfa3 = -<NUM_LIT>*lal.PI + (<NUM_LIT>/<NUM_LIT>)*Xi - <NUM_LIT>*eta*Xisum/<NUM_LIT><EOL>pfa4 = (<NUM_LIT>/<NUM_LIT>) - <NUM_LIT>*Xi2 + eta*(<NUM_LIT>/<NUM_LIT> + <NUM_LIT>*Xiprod) +<NUM_LIT>*eta2/<NUM_LIT><EOL>pfa5 = lal.PI*(<NUM_LIT>/<NUM_LIT> - <NUM_LIT>*eta/<NUM_LIT>) -Xi*(<NUM_LIT>/<NUM_LIT> + <NUM_LIT>*eta/<NUM_LIT>) + Xisum*(<NUM_LIT>*eta/<NUM_LIT> + <NUM_LIT>*eta2/<NUM_LIT>) -<NUM_LIT>*Xi2*Xi/<NUM_LIT> + <NUM_LIT>*eta*Xi*Xiprod<EOL>pfa6 = <NUM_LIT>/<NUM_LIT> - <NUM_LIT>*lal.PI*lal.PI/<NUM_LIT> -<NUM_LIT>*lal.GAMMA/<NUM_LIT> - <NUM_LIT>*log(<NUM_LIT>)/<NUM_LIT> +eta*(<NUM_LIT>*lal.PI*lal.PI/<NUM_LIT> - <NUM_LIT>/<NUM_LIT>) +<NUM_LIT>*eta2/<NUM_LIT> - (<NUM_LIT>*eta2*eta/<NUM_LIT>) +<NUM_LIT>*lal.PI*Xi/<NUM_LIT> - (<NUM_LIT> - <NUM_LIT>*eta)*Xi2/<NUM_LIT> -(<NUM_LIT>*lal.PI/<NUM_LIT> - <NUM_LIT>*Xi/<NUM_LIT>)*eta*Xisum +(<NUM_LIT>*eta/<NUM_LIT> - <NUM_LIT>*eta2/<NUM_LIT>)*Xiprod<EOL>pfa6log = -<NUM_LIT>/<NUM_LIT><EOL>pfa7 = lal.PI*(<NUM_LIT>/<NUM_LIT> + <NUM_LIT>*eta/<NUM_LIT> - <NUM_LIT>*eta2/<NUM_LIT>) -Xi*(<NUM_LIT>/<NUM_LIT> + <NUM_LIT>*eta/<NUM_LIT> - <NUM_LIT>*eta2/<NUM_LIT>) +Xisum*(<NUM_LIT>*eta/<NUM_LIT> + <NUM_LIT>*eta2/<NUM_LIT> - <NUM_LIT>*eta2*eta/<NUM_LIT> - <NUM_LIT>*eta*Xi2/<NUM_LIT> + <NUM_LIT>*eta2*Xiprod/<NUM_LIT>) -<NUM_LIT>*lal.PI*Xi2 + <NUM_LIT>*lal.PI*eta*Xiprod +Xi2*Xi*(<NUM_LIT>/<NUM_LIT> - <NUM_LIT>*eta) + Xi*Xiprod*(<NUM_LIT>*eta/<NUM_LIT> + <NUM_LIT>*eta2)<EOL>xdotaN = <NUM_LIT>*eta/<NUM_LIT><EOL>xdota2 = -<NUM_LIT>/<NUM_LIT> - <NUM_LIT>*eta/<NUM_LIT><EOL>xdota3 = <NUM_LIT>*lal.PI - <NUM_LIT>*Xi/<NUM_LIT> + <NUM_LIT>*eta*Xisum/<NUM_LIT><EOL>xdota4 = <NUM_LIT>/<NUM_LIT> + <NUM_LIT:5>*Xi2 + eta*(<NUM_LIT>/<NUM_LIT> - Xiprod/<NUM_LIT>) + <NUM_LIT>*eta2/<NUM_LIT><EOL>xdota5 = -lal.PI*(<NUM_LIT>/<NUM_LIT> + <NUM_LIT>*eta/<NUM_LIT>) - Xi*(<NUM_LIT>/<NUM_LIT> - <NUM_LIT>*eta/<NUM_LIT>) +Xisum*(<NUM_LIT>*eta/<NUM_LIT> - <NUM_LIT>*eta2/<NUM_LIT>) - <NUM_LIT:3>*Xi*Xi2/<NUM_LIT> +<NUM_LIT>*eta*Xi*Xiprod/<NUM_LIT><EOL>xdota6 = <NUM_LIT>/<NUM_LIT> - <NUM_LIT>*lal.GAMMA/<NUM_LIT> +<NUM_LIT>*lal.PI*lal.PI/<NUM_LIT:3> - <NUM_LIT>*log(<NUM_LIT>)/<NUM_LIT> +eta*(<NUM_LIT>*lal.PI*lal.PI/<NUM_LIT> - <NUM_LIT>/<NUM_LIT>) +<NUM_LIT>*eta2/<NUM_LIT> - <NUM_LIT>*eta*eta2/<NUM_LIT> - <NUM_LIT>*lal.PI*Xi/<NUM_LIT> +eta*Xisum*(<NUM_LIT>*lal.PI/<NUM_LIT> - <NUM_LIT>*Xi/<NUM_LIT>) +Xi2*(<NUM_LIT>/<NUM_LIT> - <NUM_LIT>*eta/<NUM_LIT>) -Xiprod*(<NUM_LIT>*eta/<NUM_LIT> - <NUM_LIT>*eta2/<NUM_LIT>)<EOL>xdota6log = -<NUM_LIT>/<NUM_LIT><EOL>xdota7 = -lal.PI*(<NUM_LIT>/<NUM_LIT> - <NUM_LIT>*eta/<NUM_LIT> - <NUM_LIT>*eta2/<NUM_LIT>) -Xi*(<NUM_LIT>/<NUM_LIT> - <NUM_LIT>*eta/<NUM_LIT> + <NUM_LIT>*eta2/<NUM_LIT>) +Xisum*(<NUM_LIT>*eta/<NUM_LIT> - <NUM_LIT>*eta2/<NUM_LIT> + <NUM_LIT>*eta2*eta/<NUM_LIT> + <NUM_LIT>*eta*Xi2/<NUM_LIT> - <NUM_LIT>*eta2*Xiprod/<NUM_LIT>) +<NUM_LIT>*lal.PI*Xi2 - Xi2*Xi*(<NUM_LIT>/<NUM_LIT> + eta/<NUM_LIT>) +Xi*Xiprod*(<NUM_LIT>*eta/<NUM_LIT> + <NUM_LIT>*eta2/<NUM_LIT>)<EOL>AN = <NUM_LIT>*eta*sqrt(lal.PI/<NUM_LIT>)<EOL>A2 = (-<NUM_LIT> + <NUM_LIT>*eta)/<NUM_LIT><EOL>A3 = <NUM_LIT>*lal.PI - <NUM_LIT>*Xi/<NUM_LIT> + <NUM_LIT>*eta*Xisum/<NUM_LIT><EOL>A4 = -<NUM_LIT>/<NUM_LIT> - eta*(<NUM_LIT>/<NUM_LIT> - <NUM_LIT>*Xiprod) + <NUM_LIT>*eta2/<NUM_LIT><EOL>A5 = -<NUM_LIT>*lal.PI/<NUM_LIT> + eta*(<NUM_LIT>*lal.PI/<NUM_LIT>)<EOL>A5imag = -<NUM_LIT>*eta<EOL>A6 = <NUM_LIT>/<NUM_LIT> - <NUM_LIT>*lal.GAMMA/<NUM_LIT> +<NUM_LIT>*lal.PI*lal.PI/<NUM_LIT> +eta*(<NUM_LIT>*lal.PI*lal.PI/<NUM_LIT> - <NUM_LIT>/<NUM_LIT>) -<NUM_LIT>*eta2/<NUM_LIT> + <NUM_LIT>*eta*eta2/<NUM_LIT> -<NUM_LIT>*log(<NUM_LIT>)/<NUM_LIT><EOL>A6log = -<NUM_LIT>/<NUM_LIT><EOL>A6imag = <NUM_LIT>*lal.PI/<NUM_LIT><EOL>kmin = int(f_min / delta_f)<EOL>kmax = int(f_max / delta_f)<EOL>n = kmax + <NUM_LIT:1>;<EOL>if not out:<EOL><INDENT>htilde = FrequencySeries(zeros(n,dtype=numpy.complex128), delta_f=delta_f, copy=False)<EOL><DEDENT>else:<EOL><INDENT>if type(out) is not Array:<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>if len(out) < kmax:<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>if out.dtype != complex64:<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>htilde = FrequencySeries(out, delta_f=delta_f, copy=False)<EOL><DEDENT>phenomC_kernel(htilde.data[kmin:kmax], kmin, delta_f, eta, Xi, distance,<EOL>m_sec, piM, Mfrd,<EOL>pfaN, pfa2, pfa3, pfa4, pfa5, pfa6, pfa6log, pfa7,<EOL>a1, a2, a3, a4, a5, a6, b1, b2,<EOL>Mf1, Mf2, Mf0, d1, d2, d0,<EOL>xdota2, xdota3, xdota4, xdota5, xdota6, xdota6log,<EOL>xdota7, xdotaN, AN, A2, A3, A4, A5,<EOL>A5imag, A6, A6log, A6imag,<EOL>g1, del1, del2, Q )<EOL>hp = htilde<EOL>hc = htilde * <NUM_LIT><EOL>return hp, hc<EOL>
Return an IMRPhenomC waveform using CUDA to generate the phase and amplitude Main Paper: arXiv:1005.3306
f16082:m3
def sigma_cached(self, psd):
if not hasattr(self, '<STR_LIT>'):<EOL><INDENT>from pycbc.opt import LimitedSizeDict<EOL>self._sigmasq = LimitedSizeDict(size_limit=<NUM_LIT:2>**<NUM_LIT:5>)<EOL><DEDENT>key = id(psd)<EOL>if not hasattr(psd, '<STR_LIT>'):<EOL><INDENT>psd._sigma_cached_key = {}<EOL><DEDENT>if key not in self._sigmasq or id(self) not in psd._sigma_cached_key:<EOL><INDENT>psd._sigma_cached_key[id(self)] = True<EOL>if pycbc.waveform.waveform_norm_exists(self.approximant):<EOL><INDENT>if not hasattr(psd, '<STR_LIT>'):<EOL><INDENT>psd.sigmasq_vec = {}<EOL><DEDENT>if self.approximant not in psd.sigmasq_vec:<EOL><INDENT>psd.sigmasq_vec[self.approximant] = pycbc.waveform.get_waveform_filter_norm(<EOL>self.approximant, psd, len(psd), psd.delta_f, self.f_lower)<EOL><DEDENT>if not hasattr(self, '<STR_LIT>'):<EOL><INDENT>amp_norm = pycbc.waveform.get_template_amplitude_norm(<EOL>self.params, approximant=self.approximant)<EOL>amp_norm = <NUM_LIT:1> if amp_norm is None else amp_norm<EOL>self.sigma_scale = (DYN_RANGE_FAC * amp_norm) ** <NUM_LIT><EOL><DEDENT>self._sigmasq[key] = self.sigma_scale *psd.sigmasq_vec[self.approximant][self.end_idx-<NUM_LIT:1>]<EOL><DEDENT>else:<EOL><INDENT>if not hasattr(self, '<STR_LIT>'):<EOL><INDENT>from pycbc.filter.matchedfilter import get_cutoff_indices<EOL>N = (len(self) -<NUM_LIT:1>) * <NUM_LIT:2><EOL>kmin, kmax = get_cutoff_indices(<EOL>self.min_f_lower or self.f_lower, self.end_frequency,<EOL>self.delta_f, N)<EOL>self.sslice = slice(kmin, kmax)<EOL>self.sigma_view = self[self.sslice].squared_norm() * <NUM_LIT> * self.delta_f<EOL><DEDENT>if not hasattr(psd, '<STR_LIT>'):<EOL><INDENT>psd.invsqrt = <NUM_LIT:1.0> / psd[self.sslice]<EOL><DEDENT>self._sigmasq[key] = self.sigma_view.inner(psd.invsqrt)<EOL><DEDENT><DEDENT>return self._sigmasq[key]<EOL>
Cache sigma calculate for use in tandem with the FilterBank class
f16083:m0
def boolargs_from_apprxstr(approximant_strs):
if not isinstance(approximant_strs, list):<EOL><INDENT>approximant_strs = [approximant_strs]<EOL><DEDENT>return [tuple(arg.split('<STR_LIT::>')) for arg in approximant_strs]<EOL>
Parses a list of strings specifying an approximant and where that approximant should be used into a list that can be understood by FieldArray.parse_boolargs. Parameters ---------- apprxstr : (list of) string(s) The strings to parse. Each string should be formatted `APPRX:COND`, where `APPRX` is the approximant and `COND` is a string specifying where it should be applied (see `FieldArgs.parse_boolargs` for examples of conditional strings). The last string in the list may exclude a conditional argument, which is the same as specifying ':else'. Returns ------- boolargs : list A list of tuples giving the approximant and where to apply them. This can be passed directly to `FieldArray.parse_boolargs`.
f16083:m1
def add_approximant_arg(parser, default=None, help=None):
if help is None:<EOL><INDENT>help=str("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>parser.add_argument("<STR_LIT>", nargs='<STR_LIT:+>', type=str, default=default,<EOL>metavar='<STR_LIT>',<EOL>help=help)<EOL>
Adds an approximant argument to the given parser. Parameters ---------- parser : ArgumentParser The argument parser to add the argument to. default : {None, str} Specify a default for the approximant argument. Defaults to None. help : {None, str} Provide a custom help message. If None, will use a descriptive message on how to specify the approximant.
f16083:m2
def parse_approximant_arg(approximant_arg, warray):
return warray.parse_boolargs(boolargs_from_apprxstr(approximant_arg))[<NUM_LIT:0>]<EOL>
Given an approximant arg (see add_approximant_arg) and a field array, figures out what approximant to use for each template in the array. Parameters ---------- approximant_arg : list The approximant argument to parse. Should be the thing returned by ArgumentParser when parsing the argument added by add_approximant_arg. warray : FieldArray The array to parse. Must be an instance of a FieldArray, or a class that inherits from FieldArray. Returns ------- array A numpy array listing the approximants to use for each element in the warray.
f16083:m3
def find_variable_start_frequency(approximant, parameters, f_start, max_length,<EOL>delta_f = <NUM_LIT:1>):
l = max_length + <NUM_LIT:1><EOL>f = f_start - delta_f<EOL>while l > max_length:<EOL><INDENT>f += delta_f<EOL>l = pycbc.waveform.get_waveform_filter_length_in_time(approximant,<EOL>parameters, f_lower=f)<EOL><DEDENT>return f<EOL>
Find a frequency value above the starting frequency that results in a waveform shorter than max_length.
f16083:m4
def ensure_hash(self):
fields = self.table.fieldnames<EOL>if '<STR_LIT>' in fields:<EOL><INDENT>return<EOL><DEDENT>hash_fields = ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>', '<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>', '<STR_LIT>', '<STR_LIT>',]<EOL>fields = [f for f in hash_fields if f in fields]<EOL>template_hash = np.array([hash(v) for v in zip(*[self.table[p]<EOL>for p in fields])])<EOL>self.table = self.table.add_fields(template_hash, '<STR_LIT>')<EOL>
Ensure that there is a correctly populated template_hash. Check for a correctly populated template_hash and create if it doesn't already exist.
f16083:c1:m2
def write_to_hdf(self, filename, start_index=None, stop_index=None,<EOL>force=False, skip_fields=None,<EOL>write_compressed_waveforms=True):
if not filename.endswith('<STR_LIT>'):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if os.path.exists(filename) and not force:<EOL><INDENT>raise IOError("<STR_LIT>" %(filename))<EOL><DEDENT>f = h5py.File(filename, '<STR_LIT:w>')<EOL>parameters = self.parameters<EOL>if skip_fields is not None:<EOL><INDENT>if not isinstance(skip_fields, list):<EOL><INDENT>skip_fields = [skip_fields]<EOL><DEDENT>parameters = [p for p in parameters if p not in skip_fields]<EOL><DEDENT>f.attrs['<STR_LIT>'] = parameters<EOL>write_tbl = self.table[start_index:stop_index]<EOL>for p in parameters:<EOL><INDENT>f[p] = write_tbl[p]<EOL><DEDENT>if write_compressed_waveforms and self.has_compressed_waveforms:<EOL><INDENT>for tmplt_hash in write_tbl.template_hash:<EOL><INDENT>compressed_waveform = pycbc.waveform.compress.CompressedWaveform.from_hdf(<EOL>self.filehandler, tmplt_hash,<EOL>load_now=True)<EOL>compressed_waveform.write_to_hdf(f, tmplt_hash)<EOL><DEDENT><DEDENT>return f<EOL>
Writes self to the given hdf file. Parameters ---------- filename : str The name of the file to write to. Must end in '.hdf'. start_index : If a specific slice of the template bank is to be written to the hdf file, this would specify the index of the first template in the slice stop_index : If a specific slice of the template bank is to be written to the hdf file, this would specify the index of the last template in the slice force : {False, bool} If the file already exists, it will be overwritten if True. Otherwise, an OSError is raised if the file exists. skip_fields : {None, (list of) strings} Do not write the given fields to the hdf file. Default is None, in which case all fields in self.table.fieldnames are written. write_compressed_waveforms : {True, bool} Write compressed waveforms to the output (hdf) file if this is True, which is the default setting. If False, do not write the compressed waveforms group, but only the template parameters to the output file. Returns ------- h5py.File The file handler to the output hdf file (left open).
f16083:c1:m3
def end_frequency(self, index):
from pycbc.waveform.waveform import props<EOL>return pycbc.waveform.get_waveform_end_frequency(<EOL>self.table[index],<EOL>approximant=self.approximant(index),<EOL>**self.extra_args)<EOL>
Return the end frequency of the waveform at the given index value
f16083:c1:m4
def parse_approximant(self, approximant):
return parse_approximant_arg(approximant, self.table)<EOL>
Parses the given approximant argument, returning the approximant to use for each template in self. This is done by calling `parse_approximant_arg` using self's table as the array; see that function for more details.
f16083:c1:m5
def approximant(self, index):
if '<STR_LIT>' not in self.table.fieldnames:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>return self.table["<STR_LIT>"][index]<EOL>
Return the name of the approximant ot use at the given index
f16083:c1:m6
def template_thinning(self, inj_filter_rejector):
if not inj_filter_rejector.enabled orinj_filter_rejector.chirp_time_window is None:<EOL><INDENT>return<EOL><DEDENT>injection_parameters = inj_filter_rejector.injection_params.table<EOL>fref = inj_filter_rejector.f_lower<EOL>threshold = inj_filter_rejector.chirp_time_window<EOL>m1= self.table['<STR_LIT>']<EOL>m2= self.table['<STR_LIT>']<EOL>tau0_temp, _ = pycbc.pnutils.mass1_mass2_to_tau0_tau3(m1, m2, fref)<EOL>indices = []<EOL>for inj in injection_parameters:<EOL><INDENT>tau0_inj, _ =pycbc.pnutils.mass1_mass2_to_tau0_tau3(inj.mass1, inj.mass2,<EOL>fref)<EOL>inj_indices = np.where(abs(tau0_temp - tau0_inj) <= threshold)[<NUM_LIT:0>]<EOL>indices.append(inj_indices)<EOL>indices_combined = np.concatenate(indices)<EOL><DEDENT>indices_unique= np.unique(indices_combined)<EOL>self.table = self.table[indices_unique]<EOL>
Remove templates from bank that are far from all injections.
f16083:c1:m8
def ensure_standard_filter_columns(self, low_frequency_cutoff=None):
<EOL>if not hasattr(self.table, '<STR_LIT>'):<EOL><INDENT>self.table = self.table.add_fields(np.zeros(len(self.table),<EOL>dtype=np.float32), '<STR_LIT>')<EOL><DEDENT>if low_frequency_cutoff is not None:<EOL><INDENT>if not hasattr(self.table, '<STR_LIT>'):<EOL><INDENT>vec = np.zeros(len(self.table), dtype=np.float32)<EOL>self.table = self.table.add_fields(vec, '<STR_LIT>')<EOL><DEDENT>self.table['<STR_LIT>'][:] = low_frequency_cutoff<EOL><DEDENT>self.min_f_lower = min(self.table['<STR_LIT>'])<EOL>if self.f_lower is None and self.min_f_lower == <NUM_LIT:0.>:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>
Initialize FilterBank common fields Parameters ---------- low_frequency_cutoff: {float, None}, Optional A low frequency cutoff which overrides any given within the template bank file.
f16083:c1:m9
def round_up(self, num):
inc = self.increment<EOL>size = np.ceil(num / self.sample_rate / inc) * self.sample_rate * inc<EOL>return size<EOL>
Determine the length to use for this waveform by rounding. Parameters ---------- num : int Proposed size of waveform in seconds Returns ------- size: int The rounded size to use for the waveform buffer in seconds. This is calculaed using an internal `increment` attribute, which determines the discreteness of the rounding.
f16083:c2:m1
def id_from_hash(self, hash_value):
return self.hash_lookup[hash_value]<EOL>
Get the index of this template based on its hash value Parameters ---------- hash : int Value of the template hash Returns -------- index : int The ordered index that this template has in the template bank.
f16083:c2:m3
def get_decompressed_waveform(self, tempout, index, f_lower=None,<EOL>approximant=None, df=None):
from pycbc.waveform.waveform import props<EOL>from pycbc.waveform import get_waveform_filter_length_in_time<EOL>tmplt_hash = self.table.template_hash[index]<EOL>compressed_waveform = pycbc.waveform.compress.CompressedWaveform.from_hdf(<EOL>self.filehandler, tmplt_hash,<EOL>load_now=True)<EOL>if self.waveform_decompression_method is not None :<EOL><INDENT>decompression_method = self.waveform_decompression_method<EOL><DEDENT>else :<EOL><INDENT>decompression_method = compressed_waveform.interpolation<EOL><DEDENT>logging.info("<STR_LIT>", decompression_method)<EOL>if df is not None :<EOL><INDENT>delta_f = df<EOL><DEDENT>else :<EOL><INDENT>delta_f = self.delta_f<EOL><DEDENT>decomp_scratch = FrequencySeries(tempout[<NUM_LIT:0>:self.filter_length], delta_f=delta_f, copy=False)<EOL>hdecomp = compressed_waveform.decompress(out=decomp_scratch, f_lower=f_lower, interpolation=decompression_method)<EOL>p = props(self.table[index])<EOL>p.pop('<STR_LIT>')<EOL>try:<EOL><INDENT>tmpltdur = self.table[index].template_duration<EOL><DEDENT>except AttributeError:<EOL><INDENT>tmpltdur = None<EOL><DEDENT>if tmpltdur is None or tmpltdur==<NUM_LIT:0.0> :<EOL><INDENT>tmpltdur = get_waveform_filter_length_in_time(approximant, **p)<EOL><DEDENT>hdecomp.chirp_length = tmpltdur<EOL>hdecomp.length_in_time = hdecomp.chirp_length<EOL>return hdecomp<EOL>
Returns a frequency domain decompressed waveform for the template in the bank corresponding to the index taken in as an argument. The decompressed waveform is obtained by interpolating in frequency space, the amplitude and phase points for the compressed template that are read in from the bank.
f16083:c3:m1
def generate_with_delta_f_and_max_freq(self, t_num, max_freq, delta_f,<EOL>low_frequency_cutoff=None,<EOL>cached_mem=None):
approximant = self.approximant(t_num)<EOL>if approximant.endswith('<STR_LIT>'):<EOL><INDENT>approximant = approximant.replace('<STR_LIT>', '<STR_LIT>')<EOL><DEDENT>if approximant == '<STR_LIT>':<EOL><INDENT>approximant = '<STR_LIT>'<EOL><DEDENT>if cached_mem is None:<EOL><INDENT>wav_len = int(max_freq / delta_f) + <NUM_LIT:1><EOL>cached_mem = zeros(wav_len, dtype=np.complex64)<EOL><DEDENT>if self.has_compressed_waveforms and self.enable_compressed_waveforms:<EOL><INDENT>htilde = self.get_decompressed_waveform(cached_mem, t_num,<EOL>f_lower=low_frequency_cutoff,<EOL>approximant=approximant,<EOL>df=delta_f)<EOL><DEDENT>else :<EOL><INDENT>htilde = pycbc.waveform.get_waveform_filter(<EOL>cached_mem, self.table[t_num], approximant=approximant,<EOL>f_lower=low_frequency_cutoff, f_final=max_freq, delta_f=delta_f,<EOL>distance=<NUM_LIT:1.>/DYN_RANGE_FAC, delta_t=<NUM_LIT:1.>/(<NUM_LIT>*max_freq))<EOL><DEDENT>return htilde<EOL>
Generate the template with index t_num using custom length.
f16083:c3:m2
def props(obj, required, **kwargs):
<EOL>pr = get_obj_attrs(obj)<EOL>input_params = default_qnm_args.copy()<EOL>input_params.update(pr)<EOL>input_params.update(kwargs)<EOL>for arg in required:<EOL><INDENT>if arg not in input_params:<EOL><INDENT>raise ValueError('<STR_LIT>' + str(arg))<EOL><DEDENT><DEDENT>return input_params<EOL>
Return a dictionary built from the combination of defaults, kwargs, and the attributes of the given object.
f16084:m0
def lm_amps_phases(**kwargs):
l, m = kwargs['<STR_LIT:l>'], kwargs['<STR_LIT:m>']<EOL>amps, phis = {}, {}<EOL>try:<EOL><INDENT>amps['<STR_LIT>'] = kwargs['<STR_LIT>']<EOL><DEDENT>except KeyError:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>for n in range(kwargs['<STR_LIT>']):<EOL><INDENT>if (l, m, n) != (<NUM_LIT:2>, <NUM_LIT:2>, <NUM_LIT:0>):<EOL><INDENT>try:<EOL><INDENT>amps['<STR_LIT>' %(l,m,n)] = kwargs['<STR_LIT>' %(l,m,n)] * amps['<STR_LIT>']<EOL><DEDENT>except KeyError:<EOL><INDENT>raise ValueError('<STR_LIT>' %(l,m,n))<EOL><DEDENT><DEDENT>try:<EOL><INDENT>phis['<STR_LIT>' %(l,m,n)] = kwargs['<STR_LIT>' %(l,m,n)]<EOL><DEDENT>except KeyError:<EOL><INDENT>raise ValueError('<STR_LIT>' %(l,m,n))<EOL><DEDENT><DEDENT>return amps, phis<EOL>
Take input_params and return dictionaries with amplitudes and phases of each overtone of a specific lm mode, checking that all of them are given.
f16084:m1
def lm_freqs_taus(**kwargs):
lmns = kwargs['<STR_LIT>']<EOL>freqs, taus = {}, {}<EOL>for lmn in lmns:<EOL><INDENT>l, m, nmodes = int(lmn[<NUM_LIT:0>]), int(lmn[<NUM_LIT:1>]), int(lmn[<NUM_LIT:2>])<EOL>for n in range(nmodes):<EOL><INDENT>try:<EOL><INDENT>freqs['<STR_LIT>' %(l,m,n)] = kwargs['<STR_LIT>' %(l,m,n)]<EOL><DEDENT>except KeyError:<EOL><INDENT>raise ValueError('<STR_LIT>' %(l,m,n))<EOL><DEDENT>try:<EOL><INDENT>taus['<STR_LIT>' %(l,m,n)] = kwargs['<STR_LIT>' %(l,m,n)]<EOL><DEDENT>except KeyError:<EOL><INDENT>raise ValueError('<STR_LIT>' %(l,m,n))<EOL><DEDENT><DEDENT><DEDENT>return freqs, taus<EOL>
Take input_params and return dictionaries with frequencies and damping times of each overtone of a specific lm mode, checking that all of them are given.
f16084:m2
def qnm_time_decay(tau, decay):
return - tau * numpy.log(decay)<EOL>
Return the time at which the amplitude of the ringdown falls to decay of the peak amplitude. Parameters ---------- tau : float The damping time of the sinusoid. decay: float The fraction of the peak amplitude. Returns ------- t_decay: float The time at which the amplitude of the time-domain ringdown falls to decay of the peak amplitude.
f16084:m3
def qnm_freq_decay(f_0, tau, decay):
q_0 = pi * f_0 * tau<EOL>alpha = <NUM_LIT:1.> / decay<EOL>alpha_sq = <NUM_LIT:1.> / decay / decay<EOL>q_sq = (alpha_sq + <NUM_LIT:4>*q_0*q_0 + alpha*numpy.sqrt(alpha_sq + <NUM_LIT:16>*q_0*q_0)) / <NUM_LIT><EOL>return numpy.sqrt(q_sq) / pi / tau<EOL>
Return the frequency at which the amplitude of the ringdown falls to decay of the peak amplitude. Parameters ---------- f_0 : float The ringdown-frequency, which gives the peak amplitude. tau : float The damping time of the sinusoid. decay: float The fraction of the peak amplitude. Returns ------- f_decay: float The frequency at which the amplitude of the frequency-domain ringdown falls to decay of the peak amplitude.
f16084:m4
def lm_tfinal(damping_times, modes):
t_max = {}<EOL>for lmn in modes:<EOL><INDENT>l, m, nmodes = int(lmn[<NUM_LIT:0>]), int(lmn[<NUM_LIT:1>]), int(lmn[<NUM_LIT:2>])<EOL>for n in range(nmodes):<EOL><INDENT>t_max['<STR_LIT>' %(l,m,n)] =qnm_time_decay(damping_times['<STR_LIT>' %(l,m,n)], <NUM_LIT:1.>/<NUM_LIT:1000>)<EOL><DEDENT><DEDENT>return max(t_max.values())<EOL>
Return the maximum t_final of the modes given, with t_final the time at which the amplitude falls to 1/1000 of the peak amplitude
f16084:m5
def lm_deltat(freqs, damping_times, modes):
dt = {}<EOL>for lmn in modes:<EOL><INDENT>l, m, nmodes = int(lmn[<NUM_LIT:0>]), int(lmn[<NUM_LIT:1>]), int(lmn[<NUM_LIT:2>])<EOL>for n in range(nmodes):<EOL><INDENT>dt['<STR_LIT>' %(l,m,n)] = <NUM_LIT:1.> / qnm_freq_decay(freqs['<STR_LIT>' %(l,m,n)],<EOL>damping_times['<STR_LIT>' %(l,m,n)], <NUM_LIT:1.>/<NUM_LIT:1000>)<EOL><DEDENT><DEDENT>delta_t = min(dt.values())<EOL>if delta_t < min_dt:<EOL><INDENT>delta_t = min_dt<EOL><DEDENT>return delta_t<EOL>
Return the minimum delta_t of all the modes given, with delta_t given by the inverse of the frequency at which the amplitude of the ringdown falls to 1/1000 of the peak amplitude.
f16084:m6
def lm_ffinal(freqs, damping_times, modes):
f_max = {}<EOL>for lmn in modes:<EOL><INDENT>l, m, nmodes = int(lmn[<NUM_LIT:0>]), int(lmn[<NUM_LIT:1>]), int(lmn[<NUM_LIT:2>])<EOL>for n in range(nmodes):<EOL><INDENT>f_max['<STR_LIT>' %(l,m,n)] = qnm_freq_decay(freqs['<STR_LIT>' %(l,m,n)],<EOL>damping_times['<STR_LIT>' %(l,m,n)], <NUM_LIT:1.>/<NUM_LIT:1000>)<EOL><DEDENT><DEDENT>f_final = max(f_max.values())<EOL>if f_final > max_freq:<EOL><INDENT>f_final = max_freq<EOL><DEDENT>return f_final<EOL>
Return the maximum f_final of the modes given, with f_final the frequency at which the amplitude falls to 1/1000 of the peak amplitude
f16084:m7
def lm_deltaf(damping_times, modes):
df = {}<EOL>for lmn in modes:<EOL><INDENT>l, m, nmodes = int(lmn[<NUM_LIT:0>]), int(lmn[<NUM_LIT:1>]), int(lmn[<NUM_LIT:2>])<EOL>for n in range(nmodes):<EOL><INDENT>df['<STR_LIT>' %(l,m,n)] =<NUM_LIT:1.> / qnm_time_decay(damping_times['<STR_LIT>' %(l,m,n)], <NUM_LIT:1.>/<NUM_LIT:1000>)<EOL><DEDENT><DEDENT>return min(df.values())<EOL>
Return the minimum delta_f of all the modes given, with delta_f given by the inverse of the time at which the amplitude of the ringdown falls to 1/1000 of the peak amplitude.
f16084:m8
def spher_harms(l, m, inclination):
<EOL>Y_lm = lal.SpinWeightedSphericalHarmonic(inclination, <NUM_LIT:0.>, -<NUM_LIT:2>, l, m).real<EOL>Y_lminusm = lal.SpinWeightedSphericalHarmonic(inclination, <NUM_LIT:0.>, -<NUM_LIT:2>, l, -m).real<EOL>Y_plus = Y_lm + (-<NUM_LIT:1>)**l * Y_lminusm<EOL>Y_cross = Y_lm - (-<NUM_LIT:1>)**l * Y_lminusm<EOL>return Y_plus, Y_cross<EOL>
Return spherical harmonic polarizations
f16084:m9
def Kerr_factor(final_mass, distance):
<EOL>mass = final_mass * lal.MSUN_SI * lal.G_SI / lal.C_SI**<NUM_LIT:2><EOL>dist = distance * <NUM_LIT> * lal.PC_SI<EOL>return mass / dist<EOL>
Return the factor final_mass/distance (in dimensionless units) for Kerr ringdowns
f16084:m10
def apply_taper(delta_t, taper, f_0, tau, amp, phi, l, m, inclination):
<EOL>taper_times = -numpy.arange(<NUM_LIT:1>, int(taper*tau/delta_t))[::-<NUM_LIT:1>] * delta_t<EOL>Y_plus, Y_cross = spher_harms(l, m, inclination)<EOL>taper_hp = amp * Y_plus * numpy.exp(<NUM_LIT:10>*taper_times/tau) *numpy.cos(two_pi*f_0*taper_times + phi)<EOL>taper_hc = amp * Y_cross * numpy.exp(<NUM_LIT:10>*taper_times/tau) *numpy.sin(two_pi*f_0*taper_times + phi)<EOL>return taper_hp, taper_hc<EOL>
Return tapering window.
f16084:m11
def taper_shift(waveform, output):
if len(waveform) == len(output):<EOL><INDENT>output.data += waveform.data<EOL><DEDENT>else:<EOL><INDENT>output.data[len(output)-len(waveform):] += waveform.data<EOL><DEDENT>return output<EOL>
Add waveform to output with waveform shifted accordingly (for tapering multi-mode ringdowns)
f16084:m12
def get_td_qnm(template=None, taper=None, **kwargs):
input_params = props(template, qnm_required_args, **kwargs)<EOL>f_0 = input_params.pop('<STR_LIT>')<EOL>tau = input_params.pop('<STR_LIT>')<EOL>amp = input_params.pop('<STR_LIT>')<EOL>phi = input_params.pop('<STR_LIT>')<EOL>inc = input_params.pop('<STR_LIT>', None)<EOL>l = input_params.pop('<STR_LIT:l>', <NUM_LIT:2>)<EOL>m = input_params.pop('<STR_LIT:m>', <NUM_LIT:2>)<EOL>delta_t = input_params.pop('<STR_LIT>', None)<EOL>t_final = input_params.pop('<STR_LIT>', None)<EOL>if not delta_t:<EOL><INDENT>delta_t = <NUM_LIT:1.> / qnm_freq_decay(f_0, tau, <NUM_LIT:1.>/<NUM_LIT:1000>)<EOL>if delta_t < min_dt:<EOL><INDENT>delta_t = min_dt<EOL><DEDENT><DEDENT>if not t_final:<EOL><INDENT>t_final = qnm_time_decay(tau, <NUM_LIT:1.>/<NUM_LIT:1000>)<EOL><DEDENT>kmax = int(t_final / delta_t) + <NUM_LIT:1><EOL>times = numpy.arange(kmax) * delta_t<EOL>if inc is not None:<EOL><INDENT>Y_plus, Y_cross = spher_harms(l, m, inc)<EOL><DEDENT>else:<EOL><INDENT>Y_plus, Y_cross = <NUM_LIT:1>, <NUM_LIT:1><EOL><DEDENT>hplus = amp * Y_plus * numpy.exp(-times/tau) *numpy.cos(two_pi*f_0*times + phi)<EOL>hcross = amp * Y_cross * numpy.exp(-times/tau) *numpy.sin(two_pi*f_0*times + phi)<EOL>if taper and delta_t < taper*tau:<EOL><INDENT>taper_window = int(taper*tau/delta_t)<EOL>kmax += taper_window<EOL><DEDENT>outplus = TimeSeries(zeros(kmax), delta_t=delta_t)<EOL>outcross = TimeSeries(zeros(kmax), delta_t=delta_t)<EOL>if not taper or delta_t > taper*tau:<EOL><INDENT>outplus.data[:kmax] = hplus<EOL>outcross.data[:kmax] = hcross<EOL>return outplus, outcross<EOL><DEDENT>else:<EOL><INDENT>taper_hp, taper_hc = apply_taper(delta_t, taper, f_0, tau, amp, phi,<EOL>l, m, inc)<EOL>start = - taper * tau<EOL>outplus.data[:taper_window] = taper_hp<EOL>outplus.data[taper_window:] = hplus<EOL>outcross.data[:taper_window] = taper_hc<EOL>outcross.data[taper_window:] = hcross<EOL>outplus._epoch, outcross._epoch = start, start<EOL>return outplus, outcross<EOL><DEDENT>
Return a time domain damped sinusoid. Parameters ---------- template: object An object that has attached properties. This can be used to substitute for keyword arguments. A common example would be a row in an xml table. taper: {None, float}, optional Tapering at the beginning of the waveform with duration taper * tau. This option is recommended with timescales taper=1./2 or 1. for time-domain ringdown-only injections. The abrupt turn on of the ringdown can cause issues on the waveform when doing the fourier transform to the frequency domain. Setting taper will add a rapid ringup with timescale tau/10. f_0 : float The ringdown-frequency. tau : float The damping time of the sinusoid. amp : float The amplitude of the ringdown (constant for now). phi : float The initial phase of the ringdown. Should also include the information from the azimuthal angle (phi_0 + m*Phi) inclination : {None, float}, optional Inclination of the system in radians for the spherical harmonics. l : {2, int}, optional l mode for the spherical harmonics. Default is l=2. m : {2, int}, optional m mode for the spherical harmonics. Default is m=2. delta_t : {None, float}, optional The time step used to generate the ringdown. If None, it will be set to the inverse of the frequency at which the amplitude is 1/1000 of the peak amplitude. t_final : {None, float}, optional The ending time of the output time series. If None, it will be set to the time at which the amplitude is 1/1000 of the peak amplitude. Returns ------- hplus: TimeSeries The plus phase of the ringdown in time domain. hcross: TimeSeries The cross phase of the ringdown in time domain.
f16084:m13
def get_fd_qnm(template=None, **kwargs):
input_params = props(template, qnm_required_args, **kwargs)<EOL>f_0 = input_params.pop('<STR_LIT>')<EOL>tau = input_params.pop('<STR_LIT>')<EOL>amp = input_params.pop('<STR_LIT>')<EOL>phi = input_params.pop('<STR_LIT>')<EOL>t_0 = input_params.pop('<STR_LIT>')<EOL>inc = input_params.pop('<STR_LIT>', None)<EOL>l = input_params.pop('<STR_LIT:l>', <NUM_LIT:2>)<EOL>m = input_params.pop('<STR_LIT:m>', <NUM_LIT:2>)<EOL>delta_f = input_params.pop('<STR_LIT>', None)<EOL>f_lower = input_params.pop('<STR_LIT>', None)<EOL>f_final = input_params.pop('<STR_LIT>', None)<EOL>if not delta_f:<EOL><INDENT>delta_f = <NUM_LIT:1.> / qnm_time_decay(tau, <NUM_LIT:1.>/<NUM_LIT:1000>)<EOL><DEDENT>if not f_lower:<EOL><INDENT>f_lower = delta_f<EOL>kmin = <NUM_LIT:0><EOL><DEDENT>else:<EOL><INDENT>kmin = int(f_lower / delta_f)<EOL><DEDENT>if not f_final:<EOL><INDENT>f_final = qnm_freq_decay(f_0, tau, <NUM_LIT:1.>/<NUM_LIT:1000>)<EOL><DEDENT>if f_final > max_freq:<EOL><INDENT>f_final = max_freq<EOL><DEDENT>kmax = int(f_final / delta_f) + <NUM_LIT:1><EOL>freqs = numpy.arange(kmin, kmax)*delta_f<EOL>if inc is not None:<EOL><INDENT>Y_plus, Y_cross = spher_harms(l, m, inc)<EOL><DEDENT>else:<EOL><INDENT>Y_plus, Y_cross = <NUM_LIT:1>, <NUM_LIT:1><EOL><DEDENT>denominator = <NUM_LIT:1> + (<NUM_LIT> * pi * freqs * tau) - (<NUM_LIT:4> * pi_sq * ( freqs*freqs - f_0*f_0) * tau*tau)<EOL>norm = amp * tau / denominator<EOL>if t_0 != <NUM_LIT:0>:<EOL><INDENT>time_shift = numpy.exp(-<NUM_LIT> * two_pi * freqs * t_0)<EOL>norm *= time_shift<EOL><DEDENT>hp_tilde = norm * Y_plus * ( (<NUM_LIT:1> + <NUM_LIT> * pi * freqs * tau) * numpy.cos(phi)<EOL>- two_pi * f_0 * tau * numpy.sin(phi) )<EOL>hc_tilde = norm * Y_cross * ( (<NUM_LIT:1> + <NUM_LIT> * pi * freqs * tau) * numpy.sin(phi)<EOL>+ two_pi * f_0 * tau * numpy.cos(phi) )<EOL>outplus = FrequencySeries(zeros(kmax, dtype=complex128), delta_f=delta_f)<EOL>outcross = FrequencySeries(zeros(kmax, dtype=complex128), delta_f=delta_f)<EOL>outplus.data[kmin:kmax] = hp_tilde<EOL>outcross.data[kmin:kmax] = hc_tilde<EOL>return outplus, outcross<EOL>
Return a frequency domain damped sinusoid. Parameters ---------- template: object An object that has attached properties. This can be used to substitute for keyword arguments. A common example would be a row in an xml table. f_0 : float The ringdown-frequency. tau : float The damping time of the sinusoid. amp : float The amplitude of the ringdown (constant for now). phi : float The initial phase of the ringdown. Should also include the information from the azimuthal angle (phi_0 + m*Phi). inclination : {None, float}, optional Inclination of the system in radians for the spherical harmonics. l : {2, int}, optional l mode for the spherical harmonics. Default is l=2. m : {2, int}, optional m mode for the spherical harmonics. Default is m=2. t_0 : {0, float}, optional The starting time of the ringdown. delta_f : {None, float}, optional The frequency step used to generate the ringdown. If None, it will be set to the inverse of the time at which the amplitude is 1/1000 of the peak amplitude. f_lower: {None, float}, optional The starting frequency of the output frequency series. If None, it will be set to delta_f. f_final : {None, float}, optional The ending frequency of the output frequency series. If None, it will be set to the frequency at which the amplitude is 1/1000 of the peak amplitude. Returns ------- hplustilde: FrequencySeries The plus phase of the ringdown in frequency domain. hcrosstilde: FrequencySeries The cross phase of the ringdown in frequency domain.
f16084:m14
def get_td_lm(template=None, taper=None, **kwargs):
input_params = props(template, lm_required_args, **kwargs)<EOL>amps, phis = lm_amps_phases(**input_params)<EOL>f_0 = input_params.pop('<STR_LIT>')<EOL>tau = input_params.pop('<STR_LIT>')<EOL>inc = input_params.pop('<STR_LIT>', None)<EOL>l, m = input_params.pop('<STR_LIT:l>'), input_params.pop('<STR_LIT:m>')<EOL>nmodes = input_params.pop('<STR_LIT>')<EOL>if int(nmodes) == <NUM_LIT:0>:<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>delta_t = input_params.pop('<STR_LIT>', None)<EOL>t_final = input_params.pop('<STR_LIT>', None)<EOL>if not delta_t:<EOL><INDENT>delta_t = lm_deltat(f_0, tau, ['<STR_LIT>' %(l,m,nmodes)])<EOL><DEDENT>if not t_final:<EOL><INDENT>t_final = lm_tfinal(tau, ['<STR_LIT>' %(l, m, nmodes)])<EOL><DEDENT>kmax = int(t_final / delta_t) + <NUM_LIT:1><EOL>if taper:<EOL><INDENT>taper_window = int(taper*max(tau.values())/delta_t)<EOL>kmax += taper_window<EOL><DEDENT>outplus = TimeSeries(zeros(kmax, dtype=float64), delta_t=delta_t)<EOL>outcross = TimeSeries(zeros(kmax, dtype=float64), delta_t=delta_t)<EOL>if taper:<EOL><INDENT>start = - taper * max(tau.values())<EOL>outplus._epoch, outcross._epoch = start, start<EOL><DEDENT>for n in range(nmodes):<EOL><INDENT>hplus, hcross = get_td_qnm(template=None, taper=taper,<EOL>f_0=f_0['<STR_LIT>' %(l,m,n)],<EOL>tau=tau['<STR_LIT>' %(l,m,n)],<EOL>phi=phis['<STR_LIT>' %(l,m,n)],<EOL>amp=amps['<STR_LIT>' %(l,m,n)],<EOL>inclination=inc, l=l, m=m,<EOL>delta_t=delta_t, t_final=t_final)<EOL>if not taper:<EOL><INDENT>outplus.data += hplus.data<EOL>outcross.data += hcross.data<EOL><DEDENT>else:<EOL><INDENT>outplus = taper_shift(hplus, outplus)<EOL>outcross = taper_shift(hcross, outcross)<EOL><DEDENT><DEDENT>return outplus, outcross<EOL>
Return time domain lm mode with the given number of overtones. Parameters ---------- template: object An object that has attached properties. This can be used to substitute for keyword arguments. A common example would be a row in an xml table. taper: {None, float}, optional Tapering at the beginning of the waveform with duration taper * tau. This option is recommended with timescales taper=1./2 or 1. for time-domain ringdown-only injections. The abrupt turn on of the ringdown can cause issues on the waveform when doing the fourier transform to the frequency domain. Setting taper will add a rapid ringup with timescale tau/10. Each overtone will have a different taper depending on its tau, the final taper being the superposition of all the tapers. freqs : dict {lmn:f_lmn} Dictionary of the central frequencies for each overtone, as many as number of modes. taus : dict {lmn:tau_lmn} Dictionary of the damping times for each overtone, as many as number of modes. l : int l mode (lm modes available: 22, 21, 33, 44, 55). m : int m mode (lm modes available: 22, 21, 33, 44, 55). nmodes: int Number of overtones desired (maximum n=8) amp220 : float Amplitude of the fundamental 220 mode, needed for any lm. amplmn : float Fraction of the amplitude of the lmn overtone relative to the fundamental mode, as many as the number of subdominant modes. philmn : float Phase of the lmn overtone, as many as the number of modes. Should also include the information from the azimuthal angle (phi + m*Phi). inclination : {None, float}, optional Inclination of the system in radians for the spherical harmonics. delta_t : {None, float}, optional The time step used to generate the ringdown. If None, it will be set to the inverse of the frequency at which the amplitude is 1/1000 of the peak amplitude (the minimum of all modes). t_final : {None, float}, optional The ending time of the output time series. If None, it will be set to the time at which the amplitude is 1/1000 of the peak amplitude (the maximum of all modes). Returns ------- hplus: TimeSeries The plus phase of a lm mode with overtones (n) in time domain. hcross: TimeSeries The cross phase of a lm mode with overtones (n) in time domain.
f16084:m15
def get_fd_lm(template=None, **kwargs):
input_params = props(template, lm_required_args, **kwargs)<EOL>amps, phis = lm_amps_phases(**input_params)<EOL>f_0 = input_params.pop('<STR_LIT>')<EOL>tau = input_params.pop('<STR_LIT>')<EOL>l, m = input_params.pop('<STR_LIT:l>'), input_params.pop('<STR_LIT:m>')<EOL>inc = input_params.pop('<STR_LIT>', None)<EOL>nmodes = input_params.pop('<STR_LIT>')<EOL>if int(nmodes) == <NUM_LIT:0>:<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>delta_f = input_params.pop('<STR_LIT>', None)<EOL>f_lower = input_params.pop('<STR_LIT>', None)<EOL>f_final = input_params.pop('<STR_LIT>', None)<EOL>if not delta_f:<EOL><INDENT>delta_f = lm_deltaf(tau, ['<STR_LIT>' %(l,m,nmodes)])<EOL><DEDENT>if not f_final:<EOL><INDENT>f_final = lm_ffinal(f_0, tau, ['<STR_LIT>' %(l, m, nmodes)])<EOL><DEDENT>kmax = int(f_final / delta_f) + <NUM_LIT:1><EOL>outplus = FrequencySeries(zeros(kmax, dtype=complex128), delta_f=delta_f)<EOL>outcross = FrequencySeries(zeros(kmax, dtype=complex128), delta_f=delta_f)<EOL>for n in range(nmodes):<EOL><INDENT>hplus, hcross = get_fd_qnm(template=None, f_0=f_0['<STR_LIT>' %(l,m,n)],<EOL>tau=tau['<STR_LIT>' %(l,m,n)],<EOL>amp=amps['<STR_LIT>' %(l,m,n)],<EOL>phi=phis['<STR_LIT>' %(l,m,n)],<EOL>inclination=inc, l=l, m=m, delta_f=delta_f,<EOL>f_lower=f_lower, f_final=f_final)<EOL>outplus.data += hplus.data<EOL>outcross.data += hcross.data<EOL><DEDENT>return outplus, outcross<EOL>
Return frequency domain lm mode with a given number of overtones. Parameters ---------- template: object An object that has attached properties. This can be used to substitute for keyword arguments. A common example would be a row in an xml table. freqs : dict {lmn:f_lmn} Dictionary of the central frequencies for each overtone, as many as number of modes. taus : dict {lmn:tau_lmn} Dictionary of the damping times for each overtone, as many as number of modes. l : int l mode (lm modes available: 22, 21, 33, 44, 55). m : int m mode (lm modes available: 22, 21, 33, 44, 55). nmodes: int Number of overtones desired (maximum n=8) amplmn : float Amplitude of the lmn overtone, as many as the number of nmodes. philmn : float Phase of the lmn overtone, as many as the number of modes. Should also include the information from the azimuthal angle (phi + m*Phi). inclination : {None, float}, optional Inclination of the system in radians for the spherical harmonics. delta_f : {None, float}, optional The frequency step used to generate the ringdown. If None, it will be set to the inverse of the time at which the amplitude is 1/1000 of the peak amplitude (the minimum of all modes). f_lower: {None, float}, optional The starting frequency of the output frequency series. If None, it will be set to delta_f. f_final : {None, float}, optional The ending frequency of the output frequency series. If None, it will be set to the frequency at which the amplitude is 1/1000 of the peak amplitude (the maximum of all modes). Returns ------- hplustilde: FrequencySeries The plus phase of a lm mode with n overtones in frequency domain. hcrosstilde: FrequencySeries The cross phase of a lm mode with n overtones in frequency domain.
f16084:m16
def get_td_from_final_mass_spin(template=None, taper=None,<EOL>distance=None, **kwargs):
input_params = props(template, mass_spin_required_args, **kwargs)<EOL>final_mass = input_params['<STR_LIT>']<EOL>final_spin = input_params['<STR_LIT>']<EOL>lmns = input_params['<STR_LIT>']<EOL>for lmn in lmns:<EOL><INDENT>if int(lmn[<NUM_LIT:2>]) == <NUM_LIT:0>:<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT><DEDENT>delta_t = input_params.pop('<STR_LIT>', None)<EOL>t_final = input_params.pop('<STR_LIT>', None)<EOL>f_0, tau = get_lm_f0tau_allmodes(final_mass, final_spin, lmns)<EOL>if not delta_t:<EOL><INDENT>delta_t = lm_deltat(f_0, tau, lmns)<EOL><DEDENT>if not t_final:<EOL><INDENT>t_final = lm_tfinal(tau, lmns)<EOL><DEDENT>kmax = int(t_final / delta_t) + <NUM_LIT:1><EOL>if taper:<EOL><INDENT>taper_window = int(taper*max(tau.values())/delta_t)<EOL>kmax += taper_window<EOL><DEDENT>outplus = TimeSeries(zeros(kmax, dtype=float64), delta_t=delta_t)<EOL>outcross = TimeSeries(zeros(kmax, dtype=float64), delta_t=delta_t)<EOL>if taper:<EOL><INDENT>start = - taper * max(tau.values())<EOL>outplus._epoch, outcross._epoch = start, start<EOL><DEDENT>for lmn in lmns:<EOL><INDENT>l, m, nmodes = int(lmn[<NUM_LIT:0>]), int(lmn[<NUM_LIT:1>]), int(lmn[<NUM_LIT:2>])<EOL>hplus, hcross = get_td_lm(taper=taper, freqs=f_0, taus=tau,<EOL>l=l, m=m, nmodes=nmodes,<EOL>delta_t=delta_t, t_final=t_final,<EOL>**input_params)<EOL>if not taper:<EOL><INDENT>outplus.data += hplus.data<EOL>outcross.data += hcross.data<EOL><DEDENT>else:<EOL><INDENT>outplus = taper_shift(hplus, outplus)<EOL>outcross = taper_shift(hcross, outcross)<EOL><DEDENT><DEDENT>norm = Kerr_factor(final_mass, distance) if distance else <NUM_LIT:1.><EOL>return norm*outplus, norm*outcross<EOL>
Return time domain ringdown with all the modes specified. Parameters ---------- template: object An object that has attached properties. This can be used to substitute for keyword arguments. A common example would be a row in an xml table. taper: {None, float}, optional Tapering at the beginning of the waveform with duration taper * tau. This option is recommended with timescales taper=1./2 or 1. for time-domain ringdown-only injections. The abrupt turn on of the ringdown can cause issues on the waveform when doing the fourier transform to the frequency domain. Setting taper will add a rapid ringup with timescale tau/10. Each mode and overtone will have a different taper depending on its tau, the final taper being the superposition of all the tapers. distance : {None, float}, optional Luminosity distance of the system. If specified, the returned ringdown will contain the factor (final_mass/distance). final_mass : float Mass of the final black hole. final_spin : float Spin of the final black hole. lmns : list Desired lmn modes as strings (lm modes available: 22, 21, 33, 44, 55). The n specifies the number of overtones desired for the corresponding lm pair (maximum n=8). Example: lmns = ['223','331'] are the modes 220, 221, 222, and 330 amp220 : float Amplitude of the fundamental 220 mode. Note that if distance is given, this parameter will have a completely different order of magnitude. See table II in https://arxiv.org/abs/1107.0854 for an estimate. amplmn : float Fraction of the amplitude of the lmn overtone relative to the fundamental mode, as many as the number of subdominant modes. philmn : float Phase of the lmn overtone, as many as the number of modes. Should also include the information from the azimuthal angle (phi + m*Phi). inclination : float Inclination of the system in radians. delta_t : {None, float}, optional The time step used to generate the ringdown. If None, it will be set to the inverse of the frequency at which the amplitude is 1/1000 of the peak amplitude (the minimum of all modes). t_final : {None, float}, optional The ending time of the output frequency series. If None, it will be set to the time at which the amplitude is 1/1000 of the peak amplitude (the maximum of all modes). Returns ------- hplus: TimeSeries The plus phase of a ringdown with the lm modes specified and n overtones in time domain. hcross: TimeSeries The cross phase of a ringdown with the lm modes specified and n overtones in time domain.
f16084:m17
def get_fd_from_final_mass_spin(template=None, distance=None, **kwargs):
input_params = props(template, mass_spin_required_args, **kwargs)<EOL>final_mass = input_params['<STR_LIT>']<EOL>final_spin = input_params['<STR_LIT>']<EOL>lmns = input_params['<STR_LIT>']<EOL>for lmn in lmns:<EOL><INDENT>if int(lmn[<NUM_LIT:2>]) == <NUM_LIT:0>:<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT><DEDENT>delta_f = input_params.pop('<STR_LIT>', None)<EOL>f_lower = input_params.pop('<STR_LIT>', None)<EOL>f_final = input_params.pop('<STR_LIT>', None)<EOL>f_0, tau = get_lm_f0tau_allmodes(final_mass, final_spin, lmns)<EOL>if not delta_f:<EOL><INDENT>delta_f = lm_deltaf(tau, lmns)<EOL><DEDENT>if not f_final:<EOL><INDENT>f_final = lm_ffinal(f_0, tau, lmns)<EOL><DEDENT>if not f_lower:<EOL><INDENT>f_lower = delta_f<EOL><DEDENT>kmax = int(f_final / delta_f) + <NUM_LIT:1><EOL>outplustilde = FrequencySeries(zeros(kmax, dtype=complex128), delta_f=delta_f)<EOL>outcrosstilde = FrequencySeries(zeros(kmax, dtype=complex128), delta_f=delta_f)<EOL>for lmn in lmns:<EOL><INDENT>l, m, nmodes = int(lmn[<NUM_LIT:0>]), int(lmn[<NUM_LIT:1>]), int(lmn[<NUM_LIT:2>])<EOL>hplustilde, hcrosstilde = get_fd_lm(freqs=f_0, taus=tau,<EOL>l=l, m=m, nmodes=nmodes,<EOL>delta_f=delta_f, f_lower=f_lower,<EOL>f_final=f_final, **input_params)<EOL>outplustilde.data += hplustilde.data<EOL>outcrosstilde.data += hcrosstilde.data<EOL><DEDENT>norm = Kerr_factor(final_mass, distance) if distance else <NUM_LIT:1.><EOL>return norm*outplustilde, norm*outcrosstilde<EOL>
Return frequency domain ringdown with all the modes specified. Parameters ---------- template: object An object that has attached properties. This can be used to substitute for keyword arguments. A common example would be a row in an xml table. distance : {None, float}, optional Luminosity distance of the system. If specified, the returned ringdown will contain the factor (final_mass/distance). final_mass : float Mass of the final black hole. final_spin : float Spin of the final black hole. lmns : list Desired lmn modes as strings (lm modes available: 22, 21, 33, 44, 55). The n specifies the number of overtones desired for the corresponding lm pair (maximum n=8). Example: lmns = ['223','331'] are the modes 220, 221, 222, and 330 amp220 : float Amplitude of the fundamental 220 mode. Note that if distance is given, this parameter will have a completely different order of magnitude. See table II in https://arxiv.org/abs/1107.0854 for an estimate. amplmn : float Fraction of the amplitude of the lmn overtone relative to the fundamental mode, as many as the number of subdominant modes. philmn : float Phase of the lmn overtone, as many as the number of modes. Should also include the information from the azimuthal angle (phi + m*Phi). inclination : float Inclination of the system in radians. delta_f : {None, float}, optional The frequency step used to generate the ringdown. If None, it will be set to the inverse of the time at which the amplitude is 1/1000 of the peak amplitude (the minimum of all modes). f_lower: {None, float}, optional The starting frequency of the output frequency series. If None, it will be set to delta_f. f_final : {None, float}, optional The ending frequency of the output frequency series. If None, it will be set to the frequency at which the amplitude is 1/1000 of the peak amplitude (the maximum of all modes). Returns ------- hplustilde: FrequencySeries The plus phase of a ringdown with the lm modes specified and n overtones in frequency domain. hcrosstilde: FrequencySeries The cross phase of a ringdown with the lm modes specified and n overtones in frequency domain.
f16084:m18
def get_td_from_freqtau(template=None, taper=None, **kwargs):
input_params = props(template, freqtau_required_args, **kwargs)<EOL>f_0, tau = lm_freqs_taus(**input_params)<EOL>lmns = input_params['<STR_LIT>']<EOL>for lmn in lmns:<EOL><INDENT>if int(lmn[<NUM_LIT:2>]) == <NUM_LIT:0>:<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT><DEDENT>inc = input_params.pop('<STR_LIT>', None)<EOL>delta_t = input_params.pop('<STR_LIT>', None)<EOL>t_final = input_params.pop('<STR_LIT>', None)<EOL>if not delta_t:<EOL><INDENT>delta_t = lm_deltat(f_0, tau, lmns)<EOL><DEDENT>if not t_final:<EOL><INDENT>t_final = lm_tfinal(tau, lmns)<EOL><DEDENT>kmax = int(t_final / delta_t) + <NUM_LIT:1><EOL>if taper:<EOL><INDENT>taper_window = int(taper*max(tau.values())/delta_t)<EOL>kmax += taper_window<EOL><DEDENT>outplus = TimeSeries(zeros(kmax, dtype=float64), delta_t=delta_t)<EOL>outcross = TimeSeries(zeros(kmax, dtype=float64), delta_t=delta_t)<EOL>if taper:<EOL><INDENT>start = - taper * max(tau.values())<EOL>outplus._epoch, outcross._epoch = start, start<EOL><DEDENT>for lmn in lmns:<EOL><INDENT>l, m, nmodes = int(lmn[<NUM_LIT:0>]), int(lmn[<NUM_LIT:1>]), int(lmn[<NUM_LIT:2>])<EOL>hplus, hcross = get_td_lm(freqs=f_0, taus=tau, l=l, m=m, nmodes=nmodes,<EOL>taper=taper, inclination=inc, delta_t=delta_t,<EOL>t_final=t_final, **input_params)<EOL>if not taper:<EOL><INDENT>outplus.data += hplus.data<EOL>outcross.data += hcross.data<EOL><DEDENT>else:<EOL><INDENT>outplus = taper_shift(hplus, outplus)<EOL>outcross = taper_shift(hcross, outcross)<EOL><DEDENT><DEDENT>return outplus, outcross<EOL>
Return time domain ringdown with all the modes specified. Parameters ---------- template: object An object that has attached properties. This can be used to substitute for keyword arguments. A common example would be a row in an xml table. taper: {None, float}, optional Tapering at the beginning of the waveform with duration taper * tau. This option is recommended with timescales taper=1./2 or 1. for time-domain ringdown-only injections. The abrupt turn on of the ringdown can cause issues on the waveform when doing the fourier transform to the frequency domain. Setting taper will add a rapid ringup with timescale tau/10. Each mode and overtone will have a different taper depending on its tau, the final taper being the superposition of all the tapers. lmns : list Desired lmn modes as strings (lm modes available: 22, 21, 33, 44, 55). The n specifies the number of overtones desired for the corresponding lm pair (maximum n=8). Example: lmns = ['223','331'] are the modes 220, 221, 222, and 330 f_lmn: float Central frequency of the lmn overtone, as many as number of modes. tau_lmn: float Damping time of the lmn overtone, as many as number of modes. amp220 : float Amplitude of the fundamental 220 mode. amplmn : float Fraction of the amplitude of the lmn overtone relative to the fundamental mode, as many as the number of subdominant modes. philmn : float Phase of the lmn overtone, as many as the number of modes. Should also include the information from the azimuthal angle (phi + m*Phi). inclination : {None, float}, optional Inclination of the system in radians. If None, the spherical harmonics will be set to 1. delta_t : {None, float}, optional The time step used to generate the ringdown. If None, it will be set to the inverse of the frequency at which the amplitude is 1/1000 of the peak amplitude (the minimum of all modes). t_final : {None, float}, optional The ending time of the output frequency series. If None, it will be set to the time at which the amplitude is 1/1000 of the peak amplitude (the maximum of all modes). Returns ------- hplustilde: FrequencySeries The plus phase of a ringdown with the lm modes specified and n overtones in frequency domain. hcrosstilde: FrequencySeries The cross phase of a ringdown with the lm modes specified and n overtones in frequency domain.
f16084:m19
def get_fd_from_freqtau(template=None, **kwargs):
input_params = props(template, freqtau_required_args, **kwargs)<EOL>f_0, tau = lm_freqs_taus(**input_params)<EOL>lmns = input_params['<STR_LIT>']<EOL>for lmn in lmns:<EOL><INDENT>if int(lmn[<NUM_LIT:2>]) == <NUM_LIT:0>:<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT><DEDENT>inc = input_params.pop('<STR_LIT>', None)<EOL>delta_f = input_params.pop('<STR_LIT>', None)<EOL>f_lower = input_params.pop('<STR_LIT>', None)<EOL>f_final = input_params.pop('<STR_LIT>', None)<EOL>if not delta_f:<EOL><INDENT>delta_f = lm_deltaf(tau, lmns)<EOL><DEDENT>if not f_final:<EOL><INDENT>f_final = lm_ffinal(f_0, tau, lmns)<EOL><DEDENT>if not f_lower:<EOL><INDENT>f_lower = delta_f<EOL><DEDENT>kmax = int(f_final / delta_f) + <NUM_LIT:1><EOL>outplustilde = FrequencySeries(zeros(kmax, dtype=complex128), delta_f=delta_f)<EOL>outcrosstilde = FrequencySeries(zeros(kmax, dtype=complex128), delta_f=delta_f)<EOL>for lmn in lmns:<EOL><INDENT>l, m, nmodes = int(lmn[<NUM_LIT:0>]), int(lmn[<NUM_LIT:1>]), int(lmn[<NUM_LIT:2>])<EOL>hplustilde, hcrosstilde = get_fd_lm(freqs=f_0, taus=tau,<EOL>l=l, m=m, nmodes=nmodes,<EOL>inclination=inc,<EOL>delta_f=delta_f, f_lower=f_lower,<EOL>f_final=f_final, **input_params)<EOL>outplustilde.data += hplustilde.data<EOL>outcrosstilde.data += hcrosstilde.data<EOL><DEDENT>return outplustilde, outcrosstilde<EOL>
Return frequency domain ringdown with all the modes specified. Parameters ---------- template: object An object that has attached properties. This can be used to substitute for keyword arguments. A common example would be a row in an xml table. lmns : list Desired lmn modes as strings (lm modes available: 22, 21, 33, 44, 55). The n specifies the number of overtones desired for the corresponding lm pair (maximum n=8). Example: lmns = ['223','331'] are the modes 220, 221, 222, and 330 f_lmn: float Central frequency of the lmn overtone, as many as number of modes. tau_lmn: float Damping time of the lmn overtone, as many as number of modes. amp220 : float Amplitude of the fundamental 220 mode. amplmn : float Fraction of the amplitude of the lmn overtone relative to the fundamental mode, as many as the number of subdominant modes. philmn : float Phase of the lmn overtone, as many as the number of modes. Should also include the information from the azimuthal angle (phi + m*Phi). inclination : {None, float}, optional Inclination of the system in radians. If None, the spherical harmonics will be set to 1. delta_f : {None, float}, optional The frequency step used to generate the ringdown. If None, it will be set to the inverse of the time at which the amplitude is 1/1000 of the peak amplitude (the minimum of all modes). f_lower: {None, float}, optional The starting frequency of the output frequency series. If None, it will be set to delta_f. f_final : {None, float}, optional The ending frequency of the output frequency series. If None, it will be set to the frequency at which the amplitude is 1/1000 of the peak amplitude (the maximum of all modes). Returns ------- hplustilde: FrequencySeries The plus phase of a ringdown with the lm modes specified and n overtones in frequency domain. hcrosstilde: FrequencySeries The cross phase of a ringdown with the lm modes specified and n overtones in frequency domain.
f16084:m20
def docstr(self, prefix='<STR_LIT>', include_label=True):
outstr = "<STR_LIT>" %(prefix, self.name, str(self.default),<EOL>str(self.dtype).replace("<STR_LIT>", '<STR_LIT>').replace("<STR_LIT>", '<STR_LIT>')) +"<STR_LIT>" %(prefix, self.description)<EOL>if include_label:<EOL><INDENT>outstr += "<STR_LIT>" %(self.label)<EOL><DEDENT>return outstr<EOL>
Returns a string summarizing the parameter. Format is: <prefix>``name`` : {``default``, ``dtype``} <prefix> ``description`` Label: ``label``.
f16085:c0:m1
@property<EOL><INDENT>def names(self):<DEDENT>
return [x.name for x in self]<EOL>
Returns a list of the names of each parameter.
f16085:c1:m0
@property<EOL><INDENT>def aslist(self):<DEDENT>
return list(self)<EOL>
Cast to basic list.
f16085:c1:m1
@property<EOL><INDENT>def asdict(self):<DEDENT>
return dict([[x, x] for x in self])<EOL>
Returns a dictionary of the parameters keyed by the parameters.
f16085:c1:m2
def defaults(self):
return [(x, x.default) for x in self]<EOL>
Returns a list of the name and default value of each parameter, as tuples.
f16085:c1:m3
def default_dict(self):
return OrderedDict(self.defaults())<EOL>
Returns a dictionary of the name and default value of each parameter.
f16085:c1:m4
@property<EOL><INDENT>def nodefaults(self):<DEDENT>
return ParameterList([x for x in self if x.default is None])<EOL>
Returns a ParameterList of the parameters that have None for defaults.
f16085:c1:m5
@property<EOL><INDENT>def dtypes(self):<DEDENT>
return [(x, x.dtype) for x in self]<EOL>
Returns a list of the name and dtype of each parameter, as tuples.
f16085:c1:m6
@property<EOL><INDENT>def dtype_dict(self):<DEDENT>
return OrderedDict(self.dtypes)<EOL>
Returns a dictionary of the name and dtype of each parameter.
f16085:c1:m7
@property<EOL><INDENT>def descriptions(self):<DEDENT>
return [(x, x.description) for x in self]<EOL>
Returns a list of the name and description of each parameter, as tuples.
f16085:c1:m8
@property<EOL><INDENT>def description_dict(self):<DEDENT>
return OrderedDict(self.descriptions)<EOL>
Return a dictionary of the name and description of each parameter.
f16085:c1:m9
@property<EOL><INDENT>def labels(self):<DEDENT>
return [(x, x.label) for x in self]<EOL>
Returns a list of each parameter and its label, as tuples.
f16085:c1:m10
@property<EOL><INDENT>def label_dict(self):<DEDENT>
return OrderedDict(self.labels)<EOL>
Return a dictionary of the name and label of each parameter.
f16085:c1:m11
def docstr(self, prefix='<STR_LIT>', include_label=True):
return '<STR_LIT:\n>'.join([x.docstr(prefix, include_label) for x in self])<EOL>
Returns the ``docstr`` of each parameter joined together.
f16085:c1:m12
def insert_injfilterrejector_option_group(parser):
injfilterrejector_group =parser.add_argument_group(_injfilterrejector_group_help)<EOL>curr_arg = "<STR_LIT>"<EOL>injfilterrejector_group.add_argument(curr_arg, type=float, default=None,<EOL>help=_injfilterer_cthresh_help)<EOL>curr_arg = "<STR_LIT>"<EOL>injfilterrejector_group.add_argument(curr_arg, type=float, default=None,<EOL>help=_injfilterer_mthresh_help)<EOL>curr_arg = "<STR_LIT>"<EOL>injfilterrejector_group.add_argument(curr_arg, type=float, default=<NUM_LIT:1.>,<EOL>help=_injfilterer_deltaf_help)<EOL>curr_arg = "<STR_LIT>"<EOL>injfilterrejector_group.add_argument(curr_arg, type=float, default=<NUM_LIT>,<EOL>help=_injfilterer_fmax_help)<EOL>curr_arg = "<STR_LIT>"<EOL>injfilterrejector_group.add_argument(curr_arg, type=int, default=<NUM_LIT:10>,<EOL>help=_injfilterer_buffer_help)<EOL>curr_arg = "<STR_LIT>"<EOL>injfilterrejector_group.add_argument(curr_arg, type=int, default=None,<EOL>help=_injfilterer_flower_help)<EOL>
Add options for injfilterrejector to executable.
f16086:m0
def __init__(self, injection_file, chirp_time_window,<EOL>match_threshold, f_lower, coarsematch_deltaf=<NUM_LIT:1.>,<EOL>coarsematch_fmax=<NUM_LIT>, seg_buffer=<NUM_LIT:10>):
<EOL>if injection_file is None or injection_file == '<STR_LIT:False>' or(chirp_time_window is None and match_threshold is None):<EOL><INDENT>self.enabled = False<EOL>return<EOL><DEDENT>else:<EOL><INDENT>self.enabled = True<EOL><DEDENT>self.chirp_time_window = chirp_time_window<EOL>self.match_threshold = match_threshold<EOL>self.coarsematch_deltaf = coarsematch_deltaf<EOL>self.coarsematch_fmax = coarsematch_fmax<EOL>self.seg_buffer = seg_buffer<EOL>self.f_lower = f_lower<EOL>assert(self.f_lower is not None)<EOL>self.short_injections = {}<EOL>self._short_template_mem = None<EOL>self._short_psd_storage = {}<EOL>self._short_template_id = None<EOL>
Initialise InjFilterRejector instance.
f16086:c0:m0
@classmethod<EOL><INDENT>def from_cli(cls, opt):<DEDENT>
injection_file = opt.injection_file<EOL>chirp_time_window =opt.injection_filter_rejector_chirp_time_window<EOL>match_threshold = opt.injection_filter_rejector_match_threshold<EOL>coarsematch_deltaf = opt.injection_filter_rejector_coarsematch_deltaf<EOL>coarsematch_fmax = opt.injection_filter_rejector_coarsematch_fmax<EOL>seg_buffer = opt.injection_filter_rejector_seg_buffer<EOL>if opt.injection_filter_rejector_f_lower is not None:<EOL><INDENT>f_lower = opt.injection_filter_rejector_f_lower<EOL><DEDENT>else:<EOL><INDENT>f_lower = opt.low_frequency_cutoff<EOL><DEDENT>return cls(injection_file, chirp_time_window, match_threshold,<EOL>f_lower, coarsematch_deltaf=coarsematch_deltaf,<EOL>coarsematch_fmax=coarsematch_fmax,<EOL>seg_buffer=seg_buffer)<EOL>
Create an InjFilterRejector instance from command-line options.
f16086:c0:m1
def generate_short_inj_from_inj(self, inj_waveform, simulation_id):
if not self.enabled:<EOL><INDENT>return<EOL><DEDENT>if simulation_id in self.short_injections:<EOL><INDENT>err_msg = "<STR_LIT>"<EOL>err_msg += str(simulation_id)<EOL>err_msg += "<STR_LIT>"<EOL>err_msg += "<STR_LIT>"<EOL>err_msg += "<STR_LIT>"<EOL>raise ValueError(err_msg)<EOL><DEDENT>curr_length = len(inj_waveform)<EOL>new_length = int(nearest_larger_binary_number(curr_length))<EOL>while new_length * inj_waveform.delta_t < <NUM_LIT:1.>/self.coarsematch_deltaf:<EOL><INDENT>new_length = new_length * <NUM_LIT:2><EOL><DEDENT>inj_waveform.resize(new_length)<EOL>inj_tilde = inj_waveform.to_frequencyseries()<EOL>inj_tilde_np = inj_tilde.numpy() * DYN_RANGE_FAC<EOL>delta_f = inj_tilde.get_delta_f()<EOL>new_freq_len = int(self.coarsematch_fmax / delta_f + <NUM_LIT:1>)<EOL>assert(new_freq_len <= len(inj_tilde))<EOL>df_ratio = int(self.coarsematch_deltaf/delta_f)<EOL>inj_tilde_np = inj_tilde_np[:new_freq_len:df_ratio]<EOL>new_inj = FrequencySeries(inj_tilde_np, dtype=np.complex64,<EOL>delta_f=self.coarsematch_deltaf)<EOL>self.short_injections[simulation_id] = new_inj<EOL>
Generate and a store a truncated representation of inj_waveform.
f16086:c0:m2
def template_segment_checker(self, bank, t_num, segment, start_time):
if not self.enabled:<EOL><INDENT>return True<EOL><DEDENT>sample_rate = <NUM_LIT> * (len(segment) - <NUM_LIT:1>) * segment.delta_f<EOL>cum_ind = segment.cumulative_index<EOL>diff = segment.analyze.stop - segment.analyze.start<EOL>seg_start_time = cum_ind / sample_rate + start_time<EOL>seg_end_time = (cum_ind + diff) / sample_rate + start_time<EOL>seg_start_time = seg_start_time - self.seg_buffer<EOL>seg_end_time = seg_end_time + self.seg_buffer<EOL>if self.chirp_time_window is not None:<EOL><INDENT>m1 = bank.table[t_num]['<STR_LIT>']<EOL>m2 = bank.table[t_num]['<STR_LIT>']<EOL>tau0_temp, _ = mass1_mass2_to_tau0_tau3(m1, m2, self.f_lower)<EOL>for inj in self.injection_params.table:<EOL><INDENT>end_time = inj.geocent_end_time +<NUM_LIT> * inj.geocent_end_time_ns<EOL>if not(seg_start_time <= end_time <= seg_end_time):<EOL><INDENT>continue<EOL><DEDENT>tau0_inj, _ =mass1_mass2_to_tau0_tau3(inj.mass1, inj.mass2,<EOL>self.f_lower)<EOL>tau_diff = abs(tau0_temp - tau0_inj)<EOL>if tau_diff <= self.chirp_time_window:<EOL><INDENT>break<EOL><DEDENT><DEDENT>else:<EOL><INDENT>return False<EOL><DEDENT><DEDENT>if self.match_threshold:<EOL><INDENT>if self._short_template_mem is None:<EOL><INDENT>wav_len = <NUM_LIT:1> + int(self.coarsematch_fmax /<EOL>self.coarsematch_deltaf)<EOL>self._short_template_mem = zeros(wav_len, dtype=np.complex64)<EOL><DEDENT>try:<EOL><INDENT>red_psd = self._short_psd_storage[id(segment.psd)]<EOL><DEDENT>except KeyError:<EOL><INDENT>curr_psd = segment.psd.numpy()<EOL>step_size = int(self.coarsematch_deltaf / segment.psd.delta_f)<EOL>max_idx = int(self.coarsematch_fmax / segment.psd.delta_f) + <NUM_LIT:1><EOL>red_psd_data = curr_psd[:max_idx:step_size]<EOL>red_psd = FrequencySeries(red_psd_data, <EOL>delta_f=self.coarsematch_deltaf)<EOL>self._short_psd_storage[id(curr_psd)] = red_psd<EOL><DEDENT>if not t_num == self._short_template_id:<EOL><INDENT>if self._short_template_mem is None:<EOL><INDENT>wav_len = <NUM_LIT:1> + int(self.coarsematch_fmax /<EOL>self.coarsematch_deltaf)<EOL>self._short_template_mem = zeros(wav_len,<EOL>dtype=np.complex64)<EOL><DEDENT>htilde = bank.generate_with_delta_f_and_max_freq(<EOL>t_num, self.coarsematch_fmax, self.coarsematch_deltaf,<EOL>low_frequency_cutoff=bank.table[t_num].f_lower,<EOL>cached_mem=self._short_template_mem)<EOL>self._short_template_id = t_num<EOL>self._short_template_wav = htilde<EOL><DEDENT>else:<EOL><INDENT>htilde = self._short_template_wav<EOL><DEDENT>for inj in self.injection_params.table:<EOL><INDENT>end_time = inj.geocent_end_time +<NUM_LIT> * inj.geocent_end_time_ns<EOL>if not(seg_start_time < end_time < seg_end_time):<EOL><INDENT>continue<EOL><DEDENT>curr_inj = self.short_injections[inj.simulation_id]<EOL>o, _ = match(htilde, curr_inj, psd=red_psd,<EOL>low_frequency_cutoff=self.f_lower)<EOL>if o > self.match_threshold:<EOL><INDENT>break<EOL><DEDENT><DEDENT>else:<EOL><INDENT>return False<EOL><DEDENT><DEDENT>return True<EOL>
Test if injections in segment are worth filtering with template. Using the current template, current segment, and injections within that segment. Test if the injections and sufficiently "similar" to any of the injections to justify actually performing a matched-filter call. Ther are two parts to this test: First we check if the chirp time of the template is within a provided window of any of the injections. If not then stop here, it is not worth filtering this template, segment combination for this injection set. If this check passes we compute a match between a coarse representation of the template and a coarse representation of each of the injections. If that match is above a user-provided value for any of the injections then filtering can proceed. This is currently only available if using frequency-domain templates. Parameters ----------- FIXME Returns -------- FIXME
f16086:c0:m3
def set_sim_data(inj, field, data):
try:<EOL><INDENT>sim_field = sim_inspiral_map[field]<EOL><DEDENT>except KeyError:<EOL><INDENT>sim_field = field<EOL><DEDENT>if sim_field == '<STR_LIT>':<EOL><INDENT>inj.geocent_end_time = int(data)<EOL>inj.geocent_end_time_ns = int(<NUM_LIT>*(data % <NUM_LIT:1>))<EOL><DEDENT>else:<EOL><INDENT>setattr(inj, sim_field, data)<EOL><DEDENT>
Sets data of a SimInspiral instance.
f16088:m0
def legacy_approximant_name(apx):
apx = str(apx)<EOL>try:<EOL><INDENT>order = sim.GetOrderFromString(apx)<EOL><DEDENT>except:<EOL><INDENT>print("<STR_LIT>")<EOL>order = -<NUM_LIT:1><EOL><DEDENT>name = sim.GetStringFromApproximant(sim.GetApproximantFromString(apx))<EOL>return name, order<EOL>
Convert the old style xml approximant name to a name and phase_order. Alex: I hate this function. Please delete this when we use Collin's new tables.
f16088:m1
def get_hdf_injtype(sim_file):
with h5py.File(sim_file, '<STR_LIT:r>') as fp:<EOL><INDENT>try:<EOL><INDENT>ftype = fp.attrs['<STR_LIT>']<EOL><DEDENT>except KeyError:<EOL><INDENT>ftype = CBCHDFInjectionSet.injtype<EOL><DEDENT><DEDENT>return hdfinjtypes[ftype]<EOL>
Gets the HDFInjectionSet class to use with the given file. This looks for the ``injtype`` in the given file's top level ``attrs``. If that attribute isn't set, will default to :py:class:`CBCHDFInjectionSet`. Parameters ---------- sim_file : str Name of the file. The file must already exist. Returns ------- HDFInjectionSet : The type of HDFInjectionSet to use.
f16088:m2
def hdf_injtype_from_approximant(approximant):
retcls = None<EOL>for cls in hdfinjtypes.values():<EOL><INDENT>if approximant in cls.supported_approximants():<EOL><INDENT>retcls = cls<EOL><DEDENT><DEDENT>if retcls is None:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>.format(approximant))<EOL><DEDENT>return retcls<EOL>
Gets the HDFInjectionSet class to use with the given approximant. Parameters ---------- approximant : str Name of the approximant. Returns ------- HDFInjectionSet : The type of HDFInjectionSet to use.
f16088:m3
def apply(self, strain, detector_name, f_lower=None, distance_scale=<NUM_LIT:1>,<EOL>simulation_ids=None, inj_filter_rejector=None):
if strain.dtype not in (float32, float64):<EOL><INDENT>raise TypeError("<STR_LIT>"+ str(strain.dtype))<EOL><DEDENT>lalstrain = strain.lal()<EOL>earth_travel_time = lal.REARTH_SI / lal.C_SI<EOL>t0 = float(strain.start_time) - earth_travel_time<EOL>t1 = float(strain.end_time) + earth_travel_time<EOL>add_injection = injection_func_map[strain.dtype]<EOL>injections = self.table<EOL>if simulation_ids:<EOL><INDENT>injections = [inj for inj in injectionsif inj.simulation_id in simulation_ids]<EOL><DEDENT>injection_parameters = []<EOL>for inj in injections:<EOL><INDENT>if f_lower is None:<EOL><INDENT>f_l = inj.f_lower<EOL><DEDENT>else:<EOL><INDENT>f_l = f_lower<EOL><DEDENT>end_time = inj.get_time_geocent() + <NUM_LIT:2><EOL>inj_length = sim.SimInspiralTaylorLength(<EOL>strain.delta_t, inj.mass1 * lal.MSUN_SI,<EOL>inj.mass2 * lal.MSUN_SI, f_l, <NUM_LIT:0>)<EOL>start_time = inj.get_time_geocent() - <NUM_LIT:2> * (inj_length+<NUM_LIT:1>)<EOL>if end_time < t0 or start_time > t1:<EOL><INDENT>continue<EOL><DEDENT>signal = self.make_strain_from_inj_object(inj, strain.delta_t,<EOL>detector_name, f_lower=f_l, distance_scale=distance_scale)<EOL>if float(signal.start_time) > t1:<EOL><INDENT>continue<EOL><DEDENT>signal = signal.astype(strain.dtype)<EOL>signal_lal = signal.lal()<EOL>add_injection(lalstrain, signal_lal, None)<EOL>injection_parameters.append(inj)<EOL>if inj_filter_rejector is not None:<EOL><INDENT>sid = inj.simulation_id<EOL>inj_filter_rejector.generate_short_inj_from_inj(signal, sid)<EOL><DEDENT><DEDENT>strain.data[:] = lalstrain.data.data[:]<EOL>injected = copy.copy(self)<EOL>injected.table = lsctables.SimInspiralTable()<EOL>injected.table += injection_parameters<EOL>if inj_filter_rejector is not None:<EOL><INDENT>inj_filter_rejector.injection_params = injected<EOL><DEDENT>return injected<EOL>
Add injections (as seen by a particular detector) to a time series. Parameters ---------- strain : TimeSeries Time series to inject signals into, of type float32 or float64. detector_name : string Name of the detector used for projecting injections. f_lower : {None, float}, optional Low-frequency cutoff for injected signals. If None, use value provided by each injection. distance_scale: {1, float}, optional Factor to scale the distance of an injection with. The default is no scaling. simulation_ids: iterable, optional If given, only inject signals with the given simulation IDs. inj_filter_rejector: InjFilterRejector instance; optional, default=None If given send each injected waveform to the InjFilterRejector instance so that it can store a reduced representation of that injection if necessary. Returns ------- None Raises ------ TypeError For invalid types of `strain`.
f16088:c1:m1
def make_strain_from_inj_object(self, inj, delta_t, detector_name,<EOL>f_lower=None, distance_scale=<NUM_LIT:1>):
detector = Detector(detector_name)<EOL>if f_lower is None:<EOL><INDENT>f_l = inj.f_lower<EOL><DEDENT>else:<EOL><INDENT>f_l = f_lower<EOL><DEDENT>name, phase_order = legacy_approximant_name(inj.waveform)<EOL>hp, hc = get_td_waveform(<EOL>inj, approximant=name, delta_t=delta_t,<EOL>phase_order=phase_order,<EOL>f_lower=f_l, distance=inj.distance,<EOL>**self.extra_args)<EOL>hp /= distance_scale<EOL>hc /= distance_scale<EOL>hp._epoch += inj.get_time_geocent()<EOL>hc._epoch += inj.get_time_geocent()<EOL>hp_tapered = wfutils.taper_timeseries(hp, inj.taper)<EOL>hc_tapered = wfutils.taper_timeseries(hc, inj.taper)<EOL>signal = detector.project_wave(hp_tapered, hc_tapered,<EOL>inj.longitude, inj.latitude, inj.polarization)<EOL>return signal<EOL>
Make a h(t) strain time-series from an injection object as read from a sim_inspiral table, for example. Parameters ----------- inj : injection object The injection object to turn into a strain h(t). delta_t : float Sample rate to make injection at. detector_name : string Name of the detector used for projecting injections. f_lower : {None, float}, optional Low-frequency cutoff for injected signals. If None, use value provided by each injection. distance_scale: {1, float}, optional Factor to scale the distance of an injection with. The default is no scaling. Returns -------- signal : float h(t) corresponding to the injection.
f16088:c1:m2
def end_times(self):
return [inj.get_time_geocent() for inj in self.table]<EOL>
Return the end times of all injections
f16088:c1:m3
@staticmethod<EOL><INDENT>def write(filename, samples, write_params=None, static_args=None):<DEDENT>
xmldoc = ligolw.Document()<EOL>xmldoc.appendChild(ligolw.LIGO_LW())<EOL>simtable = lsctables.New(lsctables.SimInspiralTable)<EOL>xmldoc.childNodes[<NUM_LIT:0>].appendChild(simtable)<EOL>if static_args is None:<EOL><INDENT>static_args = {}<EOL><DEDENT>if write_params is None:<EOL><INDENT>write_params = samples.fieldnames<EOL><DEDENT>for ii in range(samples.size):<EOL><INDENT>sim = lsctables.SimInspiral()<EOL>for col in sim.__slots__:<EOL><INDENT>setattr(sim, col, None)<EOL><DEDENT>for field in write_params:<EOL><INDENT>data = samples[ii][field]<EOL>set_sim_data(sim, field, data)<EOL><DEDENT>for (field, value) in static_args.items():<EOL><INDENT>set_sim_data(sim, field, value)<EOL><DEDENT>simtable.append(sim)<EOL><DEDENT>ligolw_utils.write_filename(xmldoc, filename,<EOL>gz=filename.endswith('<STR_LIT>'))<EOL>
Writes the injection samples to the given xml. Parameters ---------- filename : str The name of the file to write to. samples : io.FieldArray FieldArray of parameters. write_params : list, optional Only write the given parameter names. All given names must be keys in ``samples``. Default is to write all parameters in ``samples``. static_args : dict, optional Dictionary mapping static parameter names to values. These are written to the ``attrs``.
f16088:c1:m4
@abstractmethod<EOL><INDENT>def apply(self, strain, detector_name, distance_scale=<NUM_LIT:1>,<EOL>simulation_ids=None, inj_filter_rejector=None,<EOL>**kwargs):<DEDENT>
pass<EOL>
Adds injections to a detector's time series.
f16088:c2:m1
@abstractmethod<EOL><INDENT>def make_strain_from_inj_object(self, inj, delta_t, detector_name,<EOL>distance_scale=<NUM_LIT:1>, **kwargs):<DEDENT>
pass<EOL>
Make a h(t) strain time-series from an injection object.
f16088:c2:m2
@abstractmethod<EOL><INDENT>def end_times(self):<DEDENT>
pass<EOL>
Return the end times of all injections
f16088:c2:m3
@abstractmethod<EOL><INDENT>def supported_approximants(self):<DEDENT>
pass<EOL>
Return a list of the supported approximants.
f16088:c2:m4
@classmethod<EOL><INDENT>def write(cls, filename, samples, write_params=None, static_args=None,<EOL>**metadata):<DEDENT>
with h5py.File(filename, '<STR_LIT:w>') as fp:<EOL><INDENT>if static_args is None:<EOL><INDENT>static_args = {}<EOL><DEDENT>fp.attrs["<STR_LIT>"] = static_args.keys()<EOL>fp.attrs['<STR_LIT>'] = cls.injtype<EOL>for key, val in metadata.items():<EOL><INDENT>fp.attrs[key] = val<EOL><DEDENT>if write_params is None:<EOL><INDENT>write_params = samples.fieldnames<EOL><DEDENT>for arg, val in static_args.items():<EOL><INDENT>fp.attrs[arg] = val<EOL><DEDENT>for field in write_params:<EOL><INDENT>fp[field] = samples[field]<EOL><DEDENT><DEDENT>
Writes the injection samples to the given hdf file. Parameters ---------- filename : str The name of the file to write to. samples : io.FieldArray FieldArray of parameters. write_params : list, optional Only write the given parameter names. All given names must be keys in ``samples``. Default is to write all parameters in ``samples``. static_args : dict, optional Dictionary mapping static parameter names to values. These are written to the ``attrs``. \**metadata : All other keyword arguments will be written to the file's attrs.
f16088:c2:m5
def apply(self, strain, detector_name, f_lower=None, distance_scale=<NUM_LIT:1>,<EOL>simulation_ids=None, inj_filter_rejector=None):
if strain.dtype not in (float32, float64):<EOL><INDENT>raise TypeError("<STR_LIT>"+ str(strain.dtype))<EOL><DEDENT>lalstrain = strain.lal()<EOL>earth_travel_time = lal.REARTH_SI / lal.C_SI<EOL>t0 = float(strain.start_time) - earth_travel_time<EOL>t1 = float(strain.end_time) + earth_travel_time<EOL>add_injection = injection_func_map[strain.dtype]<EOL>injections = self.table<EOL>if simulation_ids:<EOL><INDENT>injections = injections[list(simulation_ids)]<EOL><DEDENT>for ii in range(injections.size):<EOL><INDENT>inj = injections[ii]<EOL>if f_lower is None:<EOL><INDENT>f_l = inj.f_lower<EOL><DEDENT>else:<EOL><INDENT>f_l = f_lower<EOL><DEDENT>end_time = inj.tc + <NUM_LIT:2><EOL>inj_length = sim.SimInspiralTaylorLength(<EOL>strain.delta_t, inj.mass1 * lal.MSUN_SI,<EOL>inj.mass2 * lal.MSUN_SI, f_l, <NUM_LIT:0>)<EOL>start_time = inj.tc - <NUM_LIT:2> * (inj_length+<NUM_LIT:1>)<EOL>if end_time < t0 or start_time > t1:<EOL><INDENT>continue<EOL><DEDENT>signal = self.make_strain_from_inj_object(inj, strain.delta_t,<EOL>detector_name, f_lower=f_l, distance_scale=distance_scale)<EOL>if float(signal.start_time) > t1:<EOL><INDENT>continue<EOL><DEDENT>signal = signal.astype(strain.dtype)<EOL>signal_lal = signal.lal()<EOL>add_injection(lalstrain, signal_lal, None)<EOL>if inj_filter_rejector is not None:<EOL><INDENT>inj_filter_rejector.generate_short_inj_from_inj(signal, ii)<EOL><DEDENT><DEDENT>strain.data[:] = lalstrain.data.data[:]<EOL>injected = copy.copy(self)<EOL>injected.table = injections<EOL>if inj_filter_rejector is not None:<EOL><INDENT>inj_filter_rejector.injection_params = injected<EOL><DEDENT>return injected<EOL>
Add injections (as seen by a particular detector) to a time series. Parameters ---------- strain : TimeSeries Time series to inject signals into, of type float32 or float64. detector_name : string Name of the detector used for projecting injections. f_lower : {None, float}, optional Low-frequency cutoff for injected signals. If None, use value provided by each injection. distance_scale: {1, float}, optional Factor to scale the distance of an injection with. The default is no scaling. simulation_ids: iterable, optional If given, only inject signals with the given simulation IDs. inj_filter_rejector: InjFilterRejector instance; optional, default=None If given send each injected waveform to the InjFilterRejector instance so that it can store a reduced representation of that injection if necessary. Returns ------- None Raises ------ TypeError For invalid types of `strain`.
f16088:c3:m0
def make_strain_from_inj_object(self, inj, delta_t, detector_name,<EOL>f_lower=None, distance_scale=<NUM_LIT:1>):
detector = Detector(detector_name)<EOL>if f_lower is None:<EOL><INDENT>f_l = inj.f_lower<EOL><DEDENT>else:<EOL><INDENT>f_l = f_lower<EOL><DEDENT>hp, hc = get_td_waveform(inj, delta_t=delta_t, f_lower=f_l,<EOL>**self.extra_args)<EOL>hp /= distance_scale<EOL>hc /= distance_scale<EOL>hp._epoch += inj.tc<EOL>hc._epoch += inj.tc<EOL>try:<EOL><INDENT>hp_tapered = wfutils.taper_timeseries(hp, inj.taper)<EOL>hc_tapered = wfutils.taper_timeseries(hc, inj.taper)<EOL><DEDENT>except AttributeError:<EOL><INDENT>hp_tapered = hp<EOL>hc_tapered = hc<EOL><DEDENT>signal = detector.project_wave(hp_tapered, hc_tapered,<EOL>inj.ra, inj.dec, inj.polarization)<EOL>return signal<EOL>
Make a h(t) strain time-series from an injection object. Parameters ----------- inj : injection object The injection object to turn into a strain h(t). Can be any object which has waveform parameters as attributes, such as an element in a ``WaveformArray``. delta_t : float Sample rate to make injection at. detector_name : string Name of the detector used for projecting injections. f_lower : {None, float}, optional Low-frequency cutoff for injected signals. If None, use value provided by each injection. distance_scale: {1, float}, optional Factor to scale the distance of an injection with. The default is no scaling. Returns -------- signal : float h(t) corresponding to the injection.
f16088:c3:m1
def end_times(self):
return self.table.tc<EOL>
Return the end times of all injections
f16088:c3:m2
def apply(self, strain, detector_name, distance_scale=<NUM_LIT:1>,<EOL>simulation_ids=None, inj_filter_rejector=None):
if inj_filter_rejector is not None:<EOL><INDENT>raise NotImplementedError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>if strain.dtype not in (float32, float64):<EOL><INDENT>raise TypeError("<STR_LIT>"+ str(strain.dtype))<EOL><DEDENT>lalstrain = strain.lal()<EOL>add_injection = injection_func_map[strain.dtype]<EOL>injections = self.table<EOL>if simulation_ids:<EOL><INDENT>injections = injections[list(simulation_ids)]<EOL><DEDENT>for ii in range(injections.size):<EOL><INDENT>injection = injections[ii]<EOL>signal = self.make_strain_from_inj_object(<EOL>injection, strain.delta_t, detector_name,<EOL>distance_scale=distance_scale)<EOL>signal = signal.astype(strain.dtype)<EOL>signal_lal = signal.lal()<EOL>add_injection(lalstrain, signal_lal, None)<EOL>strain.data[:] = lalstrain.data.data[:]<EOL><DEDENT>
Add injection (as seen by a particular detector) to a time series. Parameters ---------- strain : TimeSeries Time series to inject signals into, of type float32 or float64. detector_name : string Name of the detector used for projecting injections. distance_scale: float, optional Factor to scale the distance of an injection with. The default (=1) is no scaling. simulation_ids: iterable, optional If given, only inject signals with the given simulation IDs. inj_filter_rejector: InjFilterRejector instance, optional Not implemented. If not ``None``, a ``NotImplementedError`` will be raised. Returns ------- None Raises ------ NotImplementedError If an ``inj_filter_rejector`` is provided. TypeError For invalid types of `strain`.
f16088:c4:m0
def make_strain_from_inj_object(self, inj, delta_t, detector_name,<EOL>distance_scale=<NUM_LIT:1>):
detector = Detector(detector_name)<EOL>hp, hc = ringdown_td_approximants[inj['<STR_LIT>']](<EOL>inj, delta_t=delta_t, **self.extra_args)<EOL>hp._epoch += inj['<STR_LIT>']<EOL>hc._epoch += inj['<STR_LIT>']<EOL>if distance_scale != <NUM_LIT:1>:<EOL><INDENT>hp /= distance_scale<EOL>hc /= distance_scale<EOL><DEDENT>signal = detector.project_wave(hp, hc,<EOL>inj['<STR_LIT>'], inj['<STR_LIT>'], inj['<STR_LIT>'])<EOL>return signal<EOL>
Make a h(t) strain time-series from an injection object as read from an hdf file. Parameters ----------- inj : injection object The injection object to turn into a strain h(t). delta_t : float Sample rate to make injection at. detector_name : string Name of the detector used for projecting injections. distance_scale: float, optional Factor to scale the distance of an injection with. The default (=1) is no scaling. Returns -------- signal : float h(t) corresponding to the injection.
f16088:c4:m1
def end_times(self):
<EOL>tcs = self.table.tc<EOL>return tcs + <NUM_LIT:2><EOL>
Return the approximate end times of all injections. Currently, this just assumes all ringdowns are 2 seconds long.
f16088:c4:m2
@staticmethod<EOL><INDENT>def write(filename, samples, write_params=None, static_args=None,<EOL>injtype=None, **metadata):<DEDENT>
<EOL>ext = os.path.basename(filename)<EOL>if ext.endswith(('<STR_LIT>', '<STR_LIT>', '<STR_LIT>')):<EOL><INDENT>_XMLInjectionSet.write(filename, samples, write_params,<EOL>static_args)<EOL><DEDENT>else:<EOL><INDENT>if injtype is None:<EOL><INDENT>if static_args is not None and '<STR_LIT>' in static_args:<EOL><INDENT>injcls = hdf_injtype_from_approximant(<EOL>static_args['<STR_LIT>'])<EOL><DEDENT>elif '<STR_LIT>' in samples.fieldnames:<EOL><INDENT>apprxs = np.unique(samples['<STR_LIT>'])<EOL>injcls = [hdf_injtype_from_approximant(a) for a in apprxs]<EOL>if not all(c == injcls[<NUM_LIT:0>] for c in injcls):<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT:type>")<EOL><DEDENT>injcls = injcls[<NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT><DEDENT>else:<EOL><INDENT>injcls = hdfinjtypes[injtype]<EOL><DEDENT>injcls.write(filename, samples, write_params, static_args,<EOL>**metadata)<EOL><DEDENT>
Writes the injection samples to the given hdf file. Parameters ---------- filename : str The name of the file to write to. samples : io.FieldArray FieldArray of parameters. write_params : list, optional Only write the given parameter names. All given names must be keys in ``samples``. Default is to write all parameters in ``samples``. static_args : dict, optional Dictionary mapping static parameter names to values. These are written to the ``attrs``. injtype : str, optional Specify which `HDFInjectionSet` class to use for writing. If not provided, will try to determine it by looking for an approximant in the ``static_args``, followed by the ``samples``. \**metadata : All other keyword arguments will be written to the file's attrs.
f16088:c5:m1
def apply(self, strain, detector_name, f_lower=None, distance_scale=<NUM_LIT:1>):
if strain.dtype not in (float32, float64):<EOL><INDENT>raise TypeError("<STR_LIT>"+ str(strain.dtype))<EOL><DEDENT>lalstrain = strain.lal()<EOL>earth_travel_time = lal.REARTH_SI / lal.C_SI<EOL>t0 = float(strain.start_time) - earth_travel_time<EOL>t1 = float(strain.end_time) + earth_travel_time<EOL>add_injection = injection_func_map[strain.dtype]<EOL>for inj in self.table:<EOL><INDENT>end_time = inj.get_time_geocent()<EOL>inj_length = <NUM_LIT><EOL>eccentricity = <NUM_LIT:0.0><EOL>polarization = <NUM_LIT:0.0><EOL>start_time = end_time - <NUM_LIT:2> * inj_length<EOL>if end_time < t0 or start_time > t1:<EOL><INDENT>continue<EOL><DEDENT>hp, hc = sim.SimBurstSineGaussian(float(inj.q),<EOL>float(inj.frequency),float(inj.hrss),float(eccentricity),<EOL>float(polarization),float(strain.delta_t))<EOL>hp = TimeSeries(hp.data.data[:], delta_t=hp.deltaT, epoch=hp.epoch)<EOL>hc = TimeSeries(hc.data.data[:], delta_t=hc.deltaT, epoch=hc.epoch)<EOL>hp._epoch += float(end_time)<EOL>hc._epoch += float(end_time)<EOL>if float(hp.start_time) > t1:<EOL><INDENT>continue<EOL><DEDENT>strain = wfutils.taper_timeseries(strain, inj.taper)<EOL>signal_lal = hp.astype(strain.dtype).lal()<EOL>add_injection(lalstrain, signal_lal, None)<EOL><DEDENT>strain.data[:] = lalstrain.data.data[:]<EOL>
Add injections (as seen by a particular detector) to a time series. Parameters ---------- strain : TimeSeries Time series to inject signals into, of type float32 or float64. detector_name : string Name of the detector used for projecting injections. f_lower : {None, float}, optional Low-frequency cutoff for injected signals. If None, use value provided by each injection. distance_scale: {1, foat}, optional Factor to scale the distance of an injection with. The default is no scaling. Returns ------- None Raises ------ TypeError For invalid types of `strain`.
f16088:c6:m1