def slice_and_taper(inj, ts): """Slices and tapers a timeseries based on the injection settings. This assumes that ``set_ref_time`` has been applied to the timeseries first. A copy of the time series will be returned even if no slicing or tapering is done. """ try: tstart = inj.slice_start except AttributeError: tstart = ts.start_time try: tend = inj.slice_end except AttributeError: tend = ts.end_time ts = ts.time_slice(tstart, tend).copy() # now taper try: twidth = inj.left_taper_width except AttributeError: twidth = 0 if twidth: ts = wfutils.td_taper(ts, ts.start_time, ts.start_time+twidth, side='left') try: twidth = inj.right_taper_width except AttributeError: twidth = 0 if twidth: ts = wfutils.td_taper(ts, ts.end_time-twidth, ts.end_time, side='right') return ts
def get_fd_waveform_from_td(**params): """ Return time domain version of fourier domain approximant. This returns a frequency domain version of a fourier domain approximant, with padding and tapering at the start of the waveform. Parameters ---------- params: dict The parameters defining the waveform to generator. See `get_td_waveform`. Returns ------- hp: pycbc.types.FrequencySeries Plus polarization time series hc: pycbc.types.FrequencySeries Cross polarization time series """ # determine the duration to use full_duration = duration = get_waveform_filter_length_in_time(**params) nparams = params.copy() while full_duration < duration * 1.5: full_duration = get_waveform_filter_length_in_time(**nparams) nparams['f_lower'] -= 1 if 'f_fref' not in nparams: nparams['f_ref'] = params['f_lower'] # We'll try to do the right thing and figure out what the frequency # end is. Otherwise, we'll just assume 2048 Hz. # (consider removing as we hopefully have better estimates for more # approximants try: f_end = get_waveform_end_frequency(**params) delta_t = (0.5 / pnutils.nearest_larger_binary_number(f_end)) except: delta_t = 1.0 / 2048 nparams['delta_t'] = delta_t hp, hc = get_td_waveform(**nparams) # Resize to the right duration tsamples = int(1.0 / params['delta_f'] / delta_t) if tsamples < len(hp): raise ValueError("The frequency spacing (df = {}) is too low to " "generate the {} approximant from the time " "domain".format(params['delta_f'], params['approximant'])) hp.resize(tsamples) hc.resize(tsamples) # apply the tapering, we will use a safety factor here to allow for # somewhat innacurate duration difference estimation. window = (full_duration - duration) * 0.8 hp = wfutils.td_taper(hp, hp.start_time, hp.start_time + window) hc = wfutils.td_taper(hc, hc.start_time, hc.start_time + window) # avoid wraparound hp = hp.to_frequencyseries().cyclic_time_shift(hp.start_time) hc = hc.to_frequencyseries().cyclic_time_shift(hc.start_time) return hp, hc