def spa_compression(htilde, fmin, fmax, min_seglen=0.02, sample_frequencies=None): """Returns the frequencies needed to compress the given frequency domain waveform. This is done by estimating t(f) of the waveform using the stationary phase approximation. Parameters ---------- htilde : FrequencySeries The waveform to compress. fmin : float The starting frequency of the compressed waveform. fmax : float The ending frequency of the compressed waveform. min_seglen : float The inverse of this gives the maximum frequency step that is used. sample_frequencies : {None, array} The frequencies that the waveform is evaluated at. If None, will retrieve the frequencies from the waveform's sample_frequencies attribute. Returns ------- array The frequencies at which to evaluate the compressed waveform. """ if sample_frequencies is None: sample_frequencies = htilde.sample_frequencies.numpy() kmin = int(fmin / htilde.delta_f) kmax = int(fmax / htilde.delta_f) tf = abs( utils.time_from_frequencyseries( htilde, sample_frequencies=sample_frequencies).data[kmin:kmax]) sample_frequencies = sample_frequencies[kmin:kmax] sample_points = [] f = fmin while f < fmax: f = int(f / htilde.delta_f) * htilde.delta_f sample_points.append(f) jj = numpy.searchsorted(sample_frequencies, f) f += 1. / (tf[jj:].max() + min_seglen) # add the last point if sample_points[-1] < fmax: sample_points.append(fmax) return numpy.array(sample_points)
def spa_compression(htilde, fmin, fmax, min_seglen=0.02, sample_frequencies=None): """Returns the frequencies needed to compress the given frequency domain waveform. This is done by estimating t(f) of the waveform using the stationary phase approximation. Parameters ---------- htilde : FrequencySeries The waveform to compress. fmin : float The starting frequency of the compressed waveform. fmax : float The ending frequency of the compressed waveform. min_seglen : float The inverse of this gives the maximum frequency step that is used. sample_frequencies : {None, array} The frequencies that the waveform is evaluated at. If None, will retrieve the frequencies from the waveform's sample_frequencies attribute. Returns ------- array The frequencies at which to evaluate the compressed waveform. """ if sample_frequencies is None: sample_frequencies = htilde.sample_frequencies.numpy() kmin = int(fmin/htilde.delta_f) kmax = int(fmax/htilde.delta_f) tf = abs(utils.time_from_frequencyseries(htilde, sample_frequencies=sample_frequencies).data[kmin:kmax]) sample_frequencies = sample_frequencies[kmin:kmax] sample_points = [] f = fmin while f < fmax: f = int(f/htilde.delta_f)*htilde.delta_f sample_points.append(f) jj = numpy.searchsorted(sample_frequencies, f) f += 1./(tf[jj:].max()+min_seglen) # add the last point if sample_points[-1] < fmax: sample_points.append(fmax) return numpy.array(sample_points)
def get_gate_times_hmeco(self): """Gets the time to apply a gate based on the current sky position. Returns ------- dict : Dictionary of detector names -> (gate start, gate width) """ # generate the template waveform try: wfs = self.get_waveforms() except NoWaveformError: return self._nowaveform_logl() except FailedWaveformError as e: if self.ignore_failed_waveforms: return self._nowaveform_logl() raise e # get waveform parameters params = self.current_params spin1 = params['spin1z'] spin2 = params['spin2z'] # gate input for ringdown analysis which consideres a start time # and an end time dgate = params['gate_window'] meco_f = hybrid_meco_frequency(params['mass1'], params['mass2'], spin1, spin2) # figure out the gate times gatetimes = {} for det, h in wfs.items(): invpsd = self._invpsds[det] h.resize(len(invpsd)) ht = h.to_timeseries() f_low = int((self._f_lower[det] + 1) / h.delta_f) sample_freqs = h.sample_frequencies[f_low:].numpy() f_idx = numpy.where(sample_freqs <= meco_f)[0][-1] # find time corresponding to meco frequency t_from_freq = time_from_frequencyseries( h[f_low:], sample_frequencies=sample_freqs) if t_from_freq[f_idx] > 0: gatestartdelay = t_from_freq[f_idx] + float(t_from_freq.epoch) else: gatestartdelay = t_from_freq[f_idx] + ht.sample_times[-1] gatestartdelay = min(gatestartdelay, params['t_gate_start']) gatetimes[det] = (gatestartdelay, dgate) return gatetimes