def _det_tc(detector_name, ra, dec, tc, ref_frame='geocentric'): """Returns the coalescence time of a signal in the given detector. Parameters ---------- detector_name : string The name of the detector, e.g., 'H1'. ra : float The right ascension of the signal, in radians. dec : float The declination of the signal, in radians. tc : float The GPS time of the coalescence of the signal in the `ref_frame`. ref_frame : {'geocentric', string} The reference frame that the given coalescence time is defined in. May specify 'geocentric', or a detector name; default is 'geocentric'. Returns ------- float : The GPS time of the coalescence in detector `detector_name`. """ if ref_frame == detector_name: return tc detector = Detector(detector_name) if ref_frame == 'geocentric': return tc + detector.time_delay_from_earth_center(ra, dec, tc) else: other = Detector(ref_frame) return tc + detector.time_delay_from_detector(other, ra, dec, tc)
from pycbc.detector import Detector from astropy.utils import iers # Make sure the documentation can be built without an internet connection iers.conf.auto_download = False # The source of the gravitational waves right_ascension = 0.7 declination = -0.5 # Reference location will be the Hanford detector # see the `time_delay_from_earth_center` method to use use geocentric time # as the reference dref = Detector("H1") # Time in GPS seconds that the GW passes time = 100000000 # Time that the GW will (or has) passed through the given detector for ifo in ["H1", "L1", "V1"]: d = Detector(ifo) dt = d.time_delay_from_detector(dref, right_ascension, declination, time) st = "GW passed through {} {} seconds relative to passing by Hanford" print(st.format(ifo, dt))
def load_inject_condition_ccsn(t_i, t_f, t_inj, ra, dec, pol, hp, hc, local=False, Tc=16, To=2, fw=2048, window='tukey', detector='H', qtrans=False, qsplit=False, dT=2.0, save=False, data_path=None): """Fucntion to load a chunk, inject a waveform and condition, created to enable parallelizing. """ vmem = psutil.virtual_memory() free_mem = vmem.free >> 20 avail_mem = vmem.available >> 20 # if free_mem < 3e5: if avail_mem < 3e5: return if local: files = get_files(detector) try: data = TimeSeries.read(files, start=t_i, end=t_f, format='hdf5.losc') # load data locally except: return else: # load data from losc try: data = TimeSeries.fetch_open_data(detector + '1', *(t_i, t_f), sample_rate=fw, verbose=False, cache=True) except: return if np.isnan(data.value).any(): return det_obj = Detector(detector + '1') delay = det_obj.time_delay_from_detector(Detector('H1'), ra, dec, t_inj) t_inj += delay fp, fc = det_obj.antenna_pattern(ra, dec, pol, t_inj) # wfs_path = Path(git_path + '/shared/ccsn_wfs/' + ccsn_paper) # sim_data = [i.strip().split() for i in open(join(wfs_path, ccsn_file)).readlines()] # if ccsn_paper == 'radice': # line_s = 1 # else: # line_s = 0 # D = D_kpc * 3.086e+21 # cm # sim_times = np.asarray([float(dat[0]) for dat in sim_data[line_s:]]) # hp = np.asarray([float(dat[1]) for dat in sim_data[line_s:]]) / D # if ccsn_paper == 'abdikamalov': # hc = np.zeros(hp.shape) # else: # hc = np.asarray([float(dat[2]) for dat in sim_data[line_s:]]) / D # dt = sim_times[1] - sim_times[0] h = fp * hp + fc * hc # h = TimeSeries(h, t0=sim_times[0], dt=dt) # h = h.resample(rate=fw, ftype = 'iir', n=20) # downsample to working frequency fw # h = h.highpass(frequency=11, filtfilt=True) # filter out frequencies below 20Hz # inj_window = scisig.tukey(M=len(h), alpha=0.08, sym=True) # h = h * inj_window # h = h.pad(int((fw * Tc - len(h)) / 2)) wf_times = data.times.value shift = int((t_inj - (wf_times[0] + Tc / 2)) * fw) h = np.roll(h.value, shift) h = TimeSeries(h, t0=wf_times[0], dt=data.dt) try: h = h.taper() except: pass injected_data = data.inject(h) del data gc.collect() cond_data = condition_data(injected_data, To, fw, window, qtrans, qsplit, dT) del injected_data gc.collect() x = [] times = [] for dat in cond_data: x.append(dat.values) times.append(dat.t0) del cond_data gc.collect() x = np.asarray(x) times = np.asarray(times) idx = find_closest_index(t_inj, times) x = x[idx] times = times[idx] return x, times
def load_inject_condition(t_i, t_f, t_inj, ra, dec, pol, alpha, inj_type, inj_params=None, local=False, Tc=16, To=2, fw=2048, window='tukey', detector='H', qtrans=False, qsplit=False, dT=2.0, hp=None, save=False, data_path=None): """Fucntion to load a chunk, inject a waveform and condition, created to enable parallelizing. """ vmem = psutil.virtual_memory() free_mem = vmem.free >> 20 avail_mem = vmem.available >> 20 # if free_mem < 3e5: if avail_mem < 3e5: return if local: files = get_files(detector) try: data = TimeSeries.read(files, start=t_i, end=t_f, format='hdf5.losc') # load data locally except: return else: # load data from losc try: data = TimeSeries.fetch_open_data(detector + '1', *(t_i, t_f), sample_rate=fw, verbose=False, cache=True) except: return if np.isnan(data.value).any(): return det_obj = Detector(detector + '1') delay = det_obj.time_delay_from_detector(Detector('H1'), ra, dec, t_inj) t_inj += delay fp, fc = det_obj.antenna_pattern(ra, dec, pol, t_inj) wf_times = data.times.value hp, hc = gen_inject(wf_times, data.dt, t_inj, alpha, inj_type, inj_params, Tc, fw) h = fp * hp + fc * hc injected_data = data.inject(h) del data gc.collect() cond_data = condition_data(injected_data, To, fw, window, qtrans, qsplit, dT) del injected_data gc.collect() x = [] times = [] for dat in cond_data: x.append(dat.values) times.append(dat.t0) del cond_data gc.collect() x = np.asarray(x) times = np.asarray(times) idx = find_closest_index(t_inj, times) x = x[idx] times = times[idx] return x, times
def load_inject_condition_ccsn_multi_scale(t_i, t_f, t_inj, ra, dec, pol, hp, hc, local=False, Tc=16, To=2, fw=2048, window='tukey', detector='H', input_shape=(299, 299), scales=[0.5, 1.0, 2.0], frange=(10, 2048), qrange=(4, 100), save=False, data_path=None): """Fucntion to load a chunk, inject a waveform and condition, created to enable parallelizing. """ vmem = psutil.virtual_memory() free_mem = vmem.free >> 20 avail_mem = vmem.available >> 20 # if free_mem < 3e5: if avail_mem < 3e5: return if local: files = get_files(detector) try: data = TimeSeries.read(files, start=t_i, end=t_f, format='hdf5.losc') # load data locally except: return else: # load data from losc try: data = TimeSeries.fetch_open_data(detector + '1', *(t_i, t_f), sample_rate=fw, verbose=False, cache=True) except: return if np.isnan(data.value).any(): return det_obj = Detector(detector + '1') delay = det_obj.time_delay_from_detector(Detector('H1'), ra, dec, t_inj) t_inj += delay fp, fc = det_obj.antenna_pattern(ra, dec, pol, t_inj) h = fp * hp + fc * hc wf_times = data.times.value shift = int((t_inj - (wf_times[0] + Tc / 2)) * fw) h = np.roll(h.value, shift) h = TimeSeries(h, t0=wf_times[0], dt=data.dt) try: h = h.taper() except: pass injected_data = data.inject(h) del data gc.collect() # cond_data = condition_data(injected_data, To, fw, window, qtrans, qsplit, dT) cond_data = condition_data(injected_data, To, fw, window, qtrans=False) del injected_data gc.collect() # x = [] # times = [] # for dat in cond_data: # x.append(dat.values) # times.append(dat.t0) x, times = qsplit_multi_scale(cond_data, t_i, t_f, To=To, frange=frange, qrange=qrange, input_shape=input_shape, scales=scales) del cond_data gc.collect() x = np.asarray(x) times = np.asarray(times) # idx = find_closest_index(t_inj, times) idx = find_closest_index(t_inj, times - min(scales) / 2) x = x[idx] times = times[idx] return x, times