def blendTimeSeries(hp0, hc0, mm, sample, time, t_opt): """ [DEPRECATED - use "blend"] Only dealing with real part, don't do hc calculations t_opt is length-5 array describing multiples of mm Returns length-5 array of TimeSeries (1 per blending) """ #{{{ from UseNRinDA import nr_waveform nrtool = nr_waveform() amp = TimeSeries(np.sqrt(hp0**2 + hc0**2), copy=True, delta_t=hp0.delta_t) max_a, max_a_index = amp.abs_max_loc() print("Waveform max = %e, located at %d" % (max_a, max_a_index)) amp_after_peak = amp amp_after_peak[:max_a_index] = 0 mtsun = lal.MTSUN_SI iA, vA = min(enumerate(amp_after_peak), key=lambda x: abs(x[1] - 0.01 * max_a)) iB, vB = min(enumerate(amp_after_peak), key=lambda x: abs(x[1] - 0.1 * max_a)) print(iA, iB) t = [ [ t_opt[0] * mm, 500 * mm, hp0.sample_times.data[iA] / mtsun, hp0.sample_times.data[iA] / mtsun + t_opt[3] * mm ], # Prayush's E [ t_opt[0] * mm, t_opt[1] * mm, hp0.sample_times.data[iA] / mtsun, hp0.sample_times.data[iA] / mtsun + t_opt[3] * mm ], [ t_opt[0] * mm, t_opt[1] * mm, hp0.sample_times.data[iB] / mtsun, hp0.sample_times.data[iB] / mtsun + t_opt[4] * mm ], [ t_opt[0] * mm, t_opt[2] * mm, hp0.sample_times.data[iA] / mtsun, hp0.sample_times.data[iA] / mtsun + t_opt[3] * mm ], [ t_opt[0] * mm, t_opt[2] * mm, hp0.sample_times.data[iB] / mtsun, hp0.sample_times.data[iB] / mtsun + t_opt[4] * mm ] ] hphc = [] #hphc.append(hp0) for i in range(len(t)): print(t[i]) hphc.append(nrtool.blending_function_Tukey(hp0=hp0,t=t[i],\ sample_rate=sample,time_length=time)) print("No of blending windows being tested = %d" % len(hphc)) return hphc
def test_injection_presence(self): """Verify presence of signals at expected times""" injections = InjectionSet(self.inj_file.name) for det in self.detectors: for inj in self.injections: ts = TimeSeries(numpy.zeros(int(10 * self.sample_rate)), delta_t=1 / self.sample_rate, epoch=lal.LIGOTimeGPS(inj.end_time - 5), dtype=numpy.float64) injections.apply(ts, det.name) max_amp, max_loc = ts.abs_max_loc() # FIXME could test amplitude and time more precisely self.assertTrue(max_amp > 0 and max_amp < 1e-10) time_error = ts.sample_times.numpy()[max_loc] - inj.end_time self.assertTrue(abs(time_error) < 2 * self.earth_time)
def test_injection_presence(self): """Verify presence of signals at expected times""" injections = InjectionSet(self.inj_file.name) for det in self.detectors: for inj in self.injections: ts = TimeSeries(numpy.zeros(10 * self.sample_rate), delta_t=1/self.sample_rate, epoch=lal.LIGOTimeGPS(inj.end_time - 5), dtype=numpy.float64) injections.apply(ts, det.name) max_amp, max_loc = ts.abs_max_loc() # FIXME could test amplitude and time more precisely self.assertTrue(max_amp > 0 and max_amp < 1e-10) time_error = ts.sample_times.numpy()[max_loc] - inj.end_time self.assertTrue(abs(time_error) < 1.5 * self.earth_time)
def test_injection_absence(self): """Verify absence of signals outside known injection times""" clear_times = [ self.injections[0].end_time - 86400, self.injections[-1].end_time + 86400 ] injections = InjectionSet(self.inj_file.name) for det in self.detectors: for epoch in clear_times: ts = TimeSeries(numpy.zeros(int(10 * self.sample_rate)), delta_t=1 / self.sample_rate, epoch=lal.LIGOTimeGPS(epoch), dtype=numpy.float64) injections.apply(ts, det.name) max_amp, max_loc = ts.abs_max_loc() self.assertEqual(max_amp, 0)
def test_injection_absence(self): """Verify absence of signals outside known injection times""" clear_times = [ self.injections[0].end_time - 86400, self.injections[-1].end_time + 86400 ] injections = InjectionSet(self.inj_file.name) for det in self.detectors: for epoch in clear_times: ts = TimeSeries(numpy.zeros(10 * self.sample_rate), delta_t=1/self.sample_rate, epoch=lal.LIGOTimeGPS(epoch), dtype=numpy.float64) injections.apply(ts, det.name) max_amp, max_loc = ts.abs_max_loc() self.assertEqual(max_amp, 0)
def blend(hin, mm, sample, time, t_opt, WinID=-1): # Only dealing with real part, don't do hc calculations # t_opt is length-5 array describing multiples of mm # Returns length-5 array of TimeSeries (1 per blending) #{{{ hp0, hc0 = hin.rescale_to_totalmass(mm) hp0._epoch = hc0._epoch = 0 amp = TimeSeries(np.sqrt(hp0**2 + hc0**2), copy=True, delta_t=hp0.delta_t) max_a, max_a_index = amp.abs_max_loc() print("\n\n In blend:\nTotal Mass = %f, len(hp0,hc0) = %d, %d = %f s" %\ (mm, len(hp0), len(hc0), hp0.sample_times[-1]-hp0.sample_times[0])) print("Waveform max = %e, located at %d" % (max_a, max_a_index)) #amp_after_peak = amp #amp_after_peak[:max_a_index] = 0 mtsun = lal.MTSUN_SI amp_after_peak = amp[max_a_index:] iA, vA = min(enumerate(amp_after_peak), key=lambda x: abs(x[1] - 0.01 * max_a)) iA += max_a_index #iA, vA = min(enumerate(amp_after_peak),key=lambda x:abs(x[1]-0.01*max_a)) iB, vB = min(enumerate(amp_after_peak), key=lambda x: abs(x[1] - 0.1 * max_a)) iB += max_a_index if iA <= max_a_index: print("iA = %d, iB = %d, vA = %e, vB = %e" % (iA, iB, vA, vB), file=sys.stdout) sys.stdout.flush() raise RuntimeError("Couldnt find amplitude threshold time iA") # do something #fout = open('hpdump.dat','w+') #for i in range( len(amp) ): # if i > max_a_index and amp[i] == 0: break # fout.write('%e\t%e\n' % (amp.sample_times[i],amp[i])) #fout.close() # Find the point the hard way target_amp = max_a * 0.01 tmp_data = amp.data for idx in range(max_a_index, len(amp)): if tmp_data[idx] < target_amp: break iA = idx print("Newfound iA = %d" % iA) # Yet another way amp_after_peak = amp[max_a_index:] iA, vA = min(enumerate(amp_after_peak), key=lambda x: abs(x[1] - 0.01 * max_a)) iA += max_a_index print("Newfound iA another way = %d" % iA) raise RuntimeError("Had to find amplitude threshold the hard way") if iB <= max_a_index: raise RuntimeError("Couldnt find amplitude threshold time iB") # this doesn't happen yet pass print("NEW: iA = %d, iB = %d, vA = %e, vB = %e" % (iA, iB, vA, vB)) t = [ [ t_opt[0] * mm, 500 * mm, hp0.sample_times.data[iA] / mtsun, hp0.sample_times.data[iA] / mtsun + t_opt[3] * mm ], # Prayush's E [ t_opt[0] * mm, t_opt[1] * mm, hp0.sample_times.data[iA] / mtsun, hp0.sample_times.data[iA] / mtsun + t_opt[3] * mm ], [ t_opt[0] * mm, t_opt[1] * mm, hp0.sample_times.data[iB] / mtsun, hp0.sample_times.data[iB] / mtsun + t_opt[4] * mm ], [ t_opt[0] * mm, t_opt[2] * mm, hp0.sample_times.data[iA] / mtsun, hp0.sample_times.data[iA] / mtsun + t_opt[3] * mm ], [ t_opt[0] * mm, t_opt[2] * mm, hp0.sample_times.data[iB] / mtsun, hp0.sample_times.data[iB] / mtsun + t_opt[4] * mm ] ] hphc = [] hphc.append(hp0) for i in range(len(t)): if (WinID >= 0 and WinID < len(t)) and i != WinID: continue print("Testing window with t = ", t[i]) hphc.append( hin.blending_function(hp0=hp0, t=t[i], sample_rate=sample, time_length=time)) print("No of blending windows being tested = %d" % (len(hphc) - 1)) return hphc
row.amp_order = 0 row.coa_phase = 0 row.bandpass = 0 row.taper = inj.taper row.numrel_mode_min = 0 row.numrel_mode_max = 0 row.numrel_data = None row.source = 'ANTANI' row.process_id = 'process:process_id:0' row.simulation_id = 'sim_inspiral:simulation_id:0' sim_table.append(row) inj_file = open("injection.xml","w+") ligolw_utils.write_fileobj(xmldoc, inj_file) injection_set = InjectionSet("injection.xml") sample_rate = 4096 # Hz for det in [Detector(d) for d in ['H1', 'L1', 'V1']]: ts = TimeSeries(numpy.zeros(int(10 * sample_rate)), delta_t=1/sample_rate, epoch=lal.LIGOTimeGPS(end_time - 5), dtype=numpy.float64) injection_set.apply(ts, det.name) max_amp, max_loc = ts.abs_max_loc() pylab.plot(ts,label=det.name) pylab.legend()
ts1 = TimeSeries(np.real(wf_h), delta_t=wf_dt) ts2 = TimeSeries(np.real(mk1.h), delta_t=mk1_dt) tlen = max(len(ts1), len(ts2)) ts1.resize(tlen) ts2.resize(tlen) #ma, _ = pycbc.filter.match(ts1, ts2, low_frequency_cutoff=f_lower_int) ma, _ = pycbc.filter.match(ts1, ts2) print("\t {}".format(ma)) print('plotting aligned waveform') #ts1, ts2 = pycbc.waveform.utils.coalign_waveforms(ts1, ts2, low_frequency_cutoff=f_lower_int) ts1, ts2 = pycbc.waveform.utils.coalign_waveforms(ts1, ts2) _, mk1_idx = ts2.abs_max_loc() mk1_shift = ts2.sample_times[mk1_idx] figname = outdir + '/' + "{}-vs-mk1".format(sys['name']) + '.png' fig, axes = plt.subplots(1, 2, figsize=(14, 4)) axes[0].plot(ts1.sample_times - mk1_shift, ts1, label='{}'.format(approximant)) axes[0].plot(ts2.sample_times - mk1_shift, ts2, ls='--', label='Mk1') axes[0].legend(loc='upper left') axes[0].set_title('match = {:.4f}'.format(ma)) axes[0].set_xlim(start_time, 100) axes[1].plot(ts1.sample_times - mk1_shift, ts1, label='{}'.format(approximant)) axes[1].plot(ts2.sample_times - mk1_shift, ts2, ls='--', label='Mk1') axes[1].set_xlim(-500,100)