def generate_signal(param_set): hp, hc = get_td_waveform( approximant= 'SEOBNRv4', #This approximant is only appropriate for BBH mergers mass1=param_set['m1'], mass2=param_set['m2'], spin1z=param_set['x1'], spin2z=param_set['x2'], inclination_range=param_set['inc'], coa_phase=param_set['coa'], distance=param_set['dist'], delta_t=1.0 / param_set['f'], f_lower=30) time = 100000000 det_h1 = Detector('H1') det_l1 = Detector('L1') det_v1 = Detector('V1') hp = fade_on(hp, 0.25) hc = fade_on(hc, 0.25) sig_h1 = det_h1.project_wave(hp, hc, param_set['ra'], param_set['dec'], param_set['pol']) sig_l1 = det_l1.project_wave(hp, hc, param_set['ra'], param_set['dec'], param_set['pol']) sig_v1 = det_v1.project_wave(hp, hc, param_set['ra'], param_set['dec'], param_set['pol']) return {'H1': sig_h1, 'L1': sig_l1, 'V1': sig_v1}
def make_strain_from_inj_object(self, inj, delta_t, detector_name): """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. Returns -------- signal : float h(t) corresponding to the injection. """ detector = Detector(detector_name) # compute the waveform time series hp, hc = ringdown_td_approximants[inj['approximant']]( delta_t=delta_t, **inj) hp._epoch += inj['tc'] hc._epoch += inj['tc'] # compute the detector response and add it to the strain signal = detector.project_wave(hp, hc, inj['ra'], inj['dec'], inj['polarization']) return signal
def make_strain_from_inj_object(self, inj, delta_t, detector_name, f_lower=None, distance_scale=1): """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. """ detector = Detector(detector_name) if f_lower is None: f_l = inj.f_lower else: f_l = f_lower name, phase_order = legacy_approximant_name(inj.waveform) # compute the waveform time series hp, hc = get_td_waveform(inj, approximant=name, delta_t=delta_t, phase_order=phase_order, f_lower=f_l, distance=inj.distance, **self.extra_args) hp /= distance_scale hc /= distance_scale hp._epoch += inj.get_time_geocent() hc._epoch += inj.get_time_geocent() # taper the polarizations hp_tapered = wfutils.taper_timeseries(hp, inj.taper) hc_tapered = wfutils.taper_timeseries(hc, inj.taper) # compute the detector response and add it to the strain signal = detector.project_wave(hp_tapered, hc_tapered, inj.longitude, inj.latitude, inj.polarization) return signal
def make_strain_from_inj_object(self, inj, delta_t, detector_name): """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. Returns -------- signal : float h(t) corresponding to the injection. """ detector = Detector(detector_name) # compute the waveform time series hp, hc = ringdown_td_approximants[inj['approximant']](delta_t=delta_t, **inj) hp._epoch += inj['tc'] hc._epoch += inj['tc'] # compute the detector response and add it to the strain signal = detector.project_wave(hp, hc, inj['ra'], inj['dec'], inj['polarization']) return signal
def make_strain_from_inj_object(self, inj, delta_t, detector_name, f_lower=None, distance_scale=1): """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. """ detector = Detector(detector_name) if f_lower is None: f_l = inj.f_lower else: f_l = f_lower name, phase_order = legacy_approximant_name(inj.waveform) # compute the waveform time series hp, hc = get_td_waveform( inj, approximant=name, delta_t=delta_t, phase_order=phase_order, f_lower=f_l, distance=inj.distance, **self.extra_args ) hp /= distance_scale hc /= distance_scale hp._epoch += inj.get_time_geocent() hc._epoch += inj.get_time_geocent() # taper the polarizations hp_tapered = wfutils.taper_timeseries(hp, inj.taper) hc_tapered = wfutils.taper_timeseries(hc, inj.taper) # compute the detector response and add it to the strain signal = detector.project_wave(hp_tapered, hc_tapered, inj.longitude, inj.latitude, inj.polarization) return signal
def make_strain_from_inj_object(self, inj, delta_t, detector_name, f_lower=None, distance_scale=1): """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. """ detector = Detector(detector_name) if f_lower is None: f_l = inj.f_lower else: f_l = f_lower # compute the waveform time series hp, hc = get_td_waveform(inj, delta_t=delta_t, f_lower=f_l, **self.extra_args) hp /= distance_scale hc /= distance_scale hp._epoch += inj.tc hc._epoch += inj.tc # taper the polarizations try: hp_tapered = wfutils.taper_timeseries(hp, inj.taper) hc_tapered = wfutils.taper_timeseries(hc, inj.taper) except AttributeError: hp_tapered = hp hc_tapered = hc # compute the detector response and add it to the strain signal = detector.project_wave(hp_tapered, hc_tapered, inj.ra, inj.dec, inj.polarization) return signal
def project_waveform(hp, hc, skyloc=(0.0, 0.0), polarization=0.0, detector_name="H1"): """ Project the hp,c polarisations onto detector detname for sky location skyloc and polarisation pol """ detector = Detector(detector_name) signal = detector.project_wave(hp, hc, skyloc[0], skyloc[1], polarization) return signal
def projector(detector_name, inj, hp, hc, distance_scale=1): """ Use the injection row to project the polarizations into the detector frame """ detector = Detector(detector_name) hp /= distance_scale hc /= distance_scale try: tc = inj.tc ra = inj.ra dec = inj.dec except: tc = inj.get_time_geocent() ra = inj.longitude dec = inj.latitude hp.start_time += tc hc.start_time += tc # taper the polarizations try: hp_tapered = wfutils.taper_timeseries(hp, inj.taper) hc_tapered = wfutils.taper_timeseries(hc, inj.taper) except AttributeError: hp_tapered = hp hc_tapered = hc projection_method = 'lal' if hasattr(inj, 'detector_projection_method'): projection_method = inj.detector_projection_method logging.info('Injecting at %s, method is %s', tc, projection_method) # compute the detector response and add it to the strain signal = detector.project_wave( hp_tapered, hc_tapered, ra, dec, inj.polarization, method=projection_method, reference_time=tc, ) return signal
def make_strain_from_inj_object(self, inj, delta_t, detector_name, distance_scale=1): """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. """ detector = Detector(detector_name) # compute the waveform time series hp, hc = ringdown_td_approximants[inj['approximant']]( inj, delta_t=delta_t, **self.extra_args) hp._epoch += inj['tc'] hc._epoch += inj['tc'] if distance_scale != 1: hp /= distance_scale hc /= distance_scale # compute the detector response and add it to the strain signal = detector.project_wave(hp, hc, inj['ra'], inj['dec'], inj['polarization']) return signal
now = timeit.time.time() print "took %f sec to extract pols"%(now-then) # Generate the signal in the detector detector = Detector(detector_name) #longitude=float(sys.argv[1]) #latitude=float(sys.argv[2]) polarization=float(sys.argv[3]) # MAP from LALINF latitude=0.0#-1.26907692672 * 180 / np.pi longitude=0.0#0.80486732096 * 180 / np.pi signal = detector.project_wave(hp_tapered, hc_tapered, longitude, latitude, polarization) signal.data[:] /= pycbc.filter.sigma(signal) tlen = max(len(hp_tapered), len(signal)) hp_tapered.resize(tlen+1) hc_tapered.resize(tlen+1) signal.resize(tlen+1) freq_axis = signal.to_frequencyseries().sample_frequencies.data[:] asd_data = \ np.loadtxt('/home/jclark/Projects/GW150914_data/bw_reconstructions/GW150914/IFO0_asd.dat') asd = np.interp(freq_axis, asd_data[:,0], asd_data[:,1]) psd=pycbc.types.FrequencySeries(asd**2, delta_f=np.diff(freq_axis)[0])
def apply(self, strain, detector_name, f_lower=None, distance_scale=1, simulation_ids=None): """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. Returns ------- None Raises ------ TypeError For invalid types of `strain`. """ if not strain.dtype in (float32, float64): raise TypeError("Strain dtype must be float32 or float64, not " \ + str(strain.dtype)) lalstrain = strain.lal() detector = Detector(detector_name) earth_travel_time = lal.REARTH_SI / lal.C_SI t0 = float(strain.start_time) - earth_travel_time t1 = float(strain.end_time) + earth_travel_time # pick lalsimulation injection function add_injection = injection_func_map[strain.dtype] injections = self.table if simulation_ids: injections = [inj for inj in injections \ if inj.simulation_id in simulation_ids] for inj in injections: if f_lower is None: f_l = inj.f_lower else: f_l = f_lower if inj.numrel_data != None and inj.numrel_data != "": # performing NR waveform injection # reading Hp and Hc from the frame files swigrow = self.getswigrow(inj) import lalinspiral Hp, Hc = lalinspiral.NRInjectionFromSimInspiral(swigrow, strain.delta_t) # converting to pycbc timeseries hp = TimeSeries(Hp.data.data[:], delta_t=Hp.deltaT, epoch=Hp.epoch) hc = TimeSeries(Hc.data.data[:], delta_t=Hc.deltaT, epoch=Hc.epoch) hp /= distance_scale hc /= distance_scale end_time = float(hp.get_end_time()) start_time = float(hp.get_start_time()) if end_time < t0 or start_time > t1: continue else: # roughly estimate if the injection may overlap with the segment end_time = inj.get_time_geocent() inj_length = sim.SimInspiralTaylorLength( strain.delta_t, inj.mass1 * lal.MSUN_SI, inj.mass2 * lal.MSUN_SI, f_l, 0) start_time = end_time - 2 * inj_length if end_time < t0 or start_time > t1: continue name, phase_order = legacy_approximant_name(inj.waveform) # compute the waveform time series hp, hc = get_td_waveform( inj, approximant=name, delta_t=strain.delta_t, phase_order=phase_order, f_lower=f_l, distance=inj.distance * distance_scale, **self.extra_args) hp._epoch += float(end_time) hc._epoch += float(end_time) if float(hp.start_time) > t1: continue # taper the polarizations hp_tapered = wfutils.taper_timeseries(hp, inj.taper) hc_tapered = wfutils.taper_timeseries(hc, inj.taper) # compute the detector response and add it to the strain signal = detector.project_wave(hp_tapered, hc_tapered, inj.longitude, inj.latitude, inj.polarization) signal = signal.astype(strain.dtype) signal_lal = signal.lal() add_injection(lalstrain, signal_lal, None) strain.data[:] = lalstrain.data.data[:]
def make_strain_from_inj_object(self, inj, delta_t, detector_name, f_lower=None, distance_scale=1): """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. """ detector = Detector(detector_name) if f_lower is None: f_l = inj.f_lower else: f_l = f_lower # FIXME: Old NR interface will soon be removed. Do not use! if inj.numrel_data != None and inj.numrel_data != "": # performing NR waveform injection # reading Hp and Hc from the frame files swigrow = self.getswigrow(inj) import lalinspiral Hp, Hc = lalinspiral.NRInjectionFromSimInspiral(swigrow, delta_t) # converting to pycbc timeseries hp = TimeSeries(Hp.data.data[:], delta_t=Hp.deltaT, epoch=Hp.epoch) hc = TimeSeries(Hc.data.data[:], delta_t=Hc.deltaT, epoch=Hc.epoch) hp /= distance_scale hc /= distance_scale else: name, phase_order = legacy_approximant_name(inj.waveform) # compute the waveform time series hp, hc = get_td_waveform( inj, approximant=name, delta_t=delta_t, phase_order=phase_order, f_lower=f_l, distance=inj.distance, **self.extra_args) hp /= distance_scale hc /= distance_scale hp._epoch += inj.get_time_geocent() hc._epoch += inj.get_time_geocent() # taper the polarizations hp_tapered = wfutils.taper_timeseries(hp, inj.taper) hc_tapered = wfutils.taper_timeseries(hc, inj.taper) # compute the detector response and add it to the strain signal = detector.project_wave(hp_tapered, hc_tapered, inj.longitude, inj.latitude, inj.polarization) return signal
def apply(self, strain, detector_name, f_lower=None, distance_scale=1, simulation_ids=None): """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. Returns ------- None Raises ------ TypeError For invalid types of `strain`. """ if not strain.dtype in (float32, float64): raise TypeError("Strain dtype must be float32 or float64, not " \ + str(strain.dtype)) lalstrain = strain.lal() detector = Detector(detector_name) earth_travel_time = lal.REARTH_SI / lal.C_SI t0 = float(strain.start_time) - earth_travel_time t1 = float(strain.end_time) + earth_travel_time # pick lalsimulation injection function add_injection = injection_func_map[strain.dtype] injections = self.table if simulation_ids: injections = [inj for inj in injections \ if inj.simulation_id in simulation_ids] for inj in injections: if f_lower is None: f_l = inj.f_lower else: f_l = f_lower if inj.numrel_data != None and inj.numrel_data != "": # performing NR waveform injection # reading Hp and Hc from the frame files swigrow = self.getswigrow(inj) import lalinspiral Hp, Hc = lalinspiral.NRInjectionFromSimInspiral(swigrow, strain.delta_t) # converting to pycbc timeseries hp = TimeSeries(Hp.data.data[:], delta_t=Hp.deltaT, epoch=Hp.epoch) hc = TimeSeries(Hc.data.data[:], delta_t=Hc.deltaT, epoch=Hc.epoch) hp /= distance_scale hc /= distance_scale end_time = float(hp.get_end_time()) start_time = float(hp.get_start_time()) if end_time < t0 or start_time > t1: continue else: # roughly estimate if the injection may overlap with the segment end_time = inj.get_time_geocent() inj_length = sim.SimInspiralTaylorLength( strain.delta_t, inj.mass1 * lal.MSUN_SI, inj.mass2 * lal.MSUN_SI, f_l, 0) start_time = end_time - 2 * inj_length if end_time < t0 or start_time > t1: continue name, phase_order = legacy_approximant_name(inj.waveform) # compute the waveform time series hp, hc = get_td_waveform( inj, approximant=name, delta_t=strain.delta_t, phase_order=phase_order, f_lower=f_l, distance=inj.distance * distance_scale, **self.extra_args) hp._epoch += float(end_time) hc._epoch += float(end_time) if float(hp.start_time) > t1: continue # compute the detector response, taper it if requested # and add it to the strain signal = detector.project_wave( hp, hc, inj.longitude, inj.latitude, inj.polarization) # the taper_timeseries function converts to a LAL TimeSeries signal = signal.astype(strain.dtype) signal_lal = wfutils.taper_timeseries(signal, inj.taper, return_lal=True) add_injection(lalstrain, signal_lal, None) strain.data[:] = lalstrain.data.data[:]
det_h1 = Detector('H1') det_l1 = Detector('L1') det_v1 = Detector('V1') # Choose a GPS end time, sky location, and polarization phase for the merger # NOTE: Right ascension and polarization phase runs from 0 to 2pi # Declination runs from pi/2. to -pi/2 with the poles at pi/2. and -pi/2. end_time = 1192529720 declination = 0.65 right_ascension = 4.67 polarization = 2.34 hp.start_time += end_time hc.start_time += end_time signal_h1 = det_h1.project_wave(hp, hc, right_ascension, declination, polarization) signal_l1 = det_l1.project_wave(hp, hc, right_ascension, declination, polarization) signal_v1 = det_v1.project_wave(hp, hc, right_ascension, declination, polarization) pylab.plot(signal_h1.sample_times, signal_h1, label='H1') pylab.plot(signal_l1.sample_times, signal_l1, label='L1') pylab.plot(signal_v1.sample_times, signal_v1, label='V1') pylab.ylabel('Strain') pylab.xlabel('Time (s)') pylab.legend() pylab.show()
ra = 1.7 dec = 1.7 pol = 0.2 inc = 0 time = 1000000000 # We can calcualate the antenna pattern for Hanford at # the specific sky location d = Detector("H1") # We get back the fp and fc antenna pattern weights. fp, fc = d.antenna_pattern(ra, dec, pol, time) print("fp={}, fc={}".format(fp, fc)) # These factors allow us to project a signal into what the detector would # observe ## Generate a waveform hp, hc = get_td_waveform(approximant="IMRPhenomD", mass1=10, mass2=10, f_lower=30, delta_t=1.0/4096, inclination=inc, distance=400) ## Apply the factors to get the detector frame strain ht = fp * hp + fc * hc # The projection process can also take into account the rotation of the # earth using the project wave function. hp.start_time = hc.start_time = time ht = d.project_wave(hp, hc, ra, dec, pol)
coa_phase=2.45, delta_t=1.0/4096, f_lower=40) det_h1 = Detector('H1') det_l1 = Detector('L1') det_v1 = Detector('V1') # Choose a GPS end time, sky location, and polarization phase for the merger # NOTE: Right ascension and polarization phase runs from 0 to 2pi # Declination runs from pi/2. to -pi/2 with the poles at pi/2. and -pi/2. end_time = 1192529720 declination = 0.65 right_ascension = 4.67 polarization = 2.34 hp.start_time += end_time hc.start_time += end_time signal_h1 = det_h1.project_wave(hp, hc, right_ascension, declination, polarization) signal_l1 = det_l1.project_wave(hp, hc, right_ascension, declination, polarization) signal_v1 = det_v1.project_wave(hp, hc, right_ascension, declination, polarization) pylab.plot(signal_h1.sample_times, signal_h1, label='H1') pylab.plot(signal_l1.sample_times, signal_l1, label='L1') pylab.plot(signal_v1.sample_times, signal_v1, label='V1') pylab.ylabel('Strain') pylab.xlabel('Time (s)') pylab.legend() pylab.show()
def make_strain_from_inj_object(self, inj, delta_t, detector_name, f_lower=None, distance_scale=1): """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. """ detector = Detector(detector_name) if f_lower is None: f_l = inj.f_lower else: f_l = f_lower # FIXME: Old NR interface will soon be removed. Do not use! if inj.numrel_data != None and inj.numrel_data != "": # performing NR waveform injection # reading Hp and Hc from the frame files swigrow = self.getswigrow(inj) import lalinspiral Hp, Hc = lalinspiral.NRInjectionFromSimInspiral(swigrow, delta_t) # converting to pycbc timeseries hp = TimeSeries(Hp.data.data[:], delta_t=Hp.deltaT, epoch=Hp.epoch) hc = TimeSeries(Hc.data.data[:], delta_t=Hc.deltaT, epoch=Hc.epoch) hp /= distance_scale hc /= distance_scale else: name, phase_order = legacy_approximant_name(inj.waveform) # compute the waveform time series hp, hc = get_td_waveform(inj, approximant=name, delta_t=delta_t, phase_order=phase_order, f_lower=f_l, distance=inj.distance, **self.extra_args) hp /= distance_scale hc /= distance_scale hp._epoch += inj.get_time_geocent() hc._epoch += inj.get_time_geocent() # taper the polarizations hp_tapered = wfutils.taper_timeseries(hp, inj.taper) hc_tapered = wfutils.taper_timeseries(hc, inj.taper) # compute the detector response and add it to the strain signal = detector.project_wave(hp_tapered, hc_tapered, inj.longitude, inj.latitude, inj.polarization) return signal