def main(): #Load network network = keras.models.load_model('network.hdf') #Generate and load data file_path = 'example_injections.hdf' if not os.path.isfile(file_path): print("Generating injections...") generate(file_path, 1024) L1 = load_timeseries(file_path, group='L1') H1 = load_timeseries(file_path, group='H1') print("Loading complete.") #Apply the network generator = time_series_generator([L1, H1], time_step=0.25, batch_size=128) snr_ts, psc_ts = evaluate_ts_from_generator(network, generator) snr_ts.save('snr_time_series.hdf') psc_ts.save('p-score_time_series.hdf') #Plot the two resulting time series fig, axs = plt.subplots(2) axs[0].plot(snr_ts.sample_times, snr_ts) axs[0].grid() axs[0].set_xlabel('Time in s') axs[0].set_ylabel('predicted SNR') axs[1].plot(psc_ts.sample_times, psc_ts) axs[1].grid() axs[1].set_xlabel('Time in s') axs[1].set_ylabel('predicted p-score') fig.subplots_adjust(hspace=0.5) plt.savefig('example_results.png') plt.show()
def make_strain_from_inj_object(self, inj, delta_t, detector_name, distance_scale=1, ts=None): if ts is None: ts = load_timeseries(inj.filename) self.set_ref_time(inj, ts) # slice and taper ts = self.slice_and_taper(inj, ts) # shift reference to the detector time ts._epoch += inj['{}_gps_time'.format(detector_name).lower()] # resample ts = resample_to_delta_t(ts, delta_t, method='ldas') # apply any phase shift try: phase_shift = inj[ '{}_phase_shift'.format(detector_name).lower()] except ValueError: phase_shift = 0 if phase_shift: fs = ts.to_frequencyseries() fs *= np.exp(1j*phase_shift) ts = fs.to_timeseries() # apply any scaling try: amp_scale = inj[ '{}_amp_scale'.format(detector_name).lower()] except ValueError: amp_scale = 1. amp_scale /= distance_scale ts *= amp_scale return ts
def loadts(self, inj): """Loads an injection time series. After the first time a time series is loaded it will be added to an internal buffer for faster in case another injection uses the same series. """ if self._buffer is None: # create the buffer self._buffer = LimitedSizeDict(size_limit=self._buffersize) try: return self._buffer[inj.filename] except KeyError: pass # not in buffer, so load if inj.filename.endswith('.gwf'): try: channel = inj.channel except AttributeError as _err: # Py3.XX: uncomment the "from _err" when we drop 2.7 raise ValueError("Must provide a channel for " "frame files") #from _err ts = frame.read_frame(inj.filename, channel) else: ts = load_timeseries(inj.filename) # cache self._buffer[inj.filename] = ts return ts
def get_residual_strain(window=198): strain = {} for ifo in ifos: strain[ifo] = load_timeseries('residuals.hdf', group='%s/residual' % ifo) strain[ifo] = strain[ifo].time_slice(event_time - window / 2, event_time + window / 2) return strain
def get_residual_strain(tev, window): strain = {} for ifo in ifos: strain[ifo] = load_timeseries('residuals.hdf', group='%s/residual' % ifo) strain[ifo] = strain[ifo].time_slice(tev - window / 2, tev + window / 2) return strain
def get_nrsub_strain(strain): nr = {} for ifo in ifos: nr[ifo] = load_timeseries('fig1-waveform-%s.txt' % ifo[0]) * 1e-21 nr[ifo] = resample_to_delta_t(nr[ifo], strain[ifo].delta_t) nr[ifo].start_time += event_time ts2 = {} for ifo in ifos: ts2[ifo] = strain[ifo].copy() spart = ts2[ifo].time_slice(nr[ifo].start_time, nr[ifo].end_time) nr[ifo].start_time = spart.start_time spart -= nr[ifo] return ts2
import pylab import numpy from pycbc.frame import read_frame from pycbc.types import load_timeseries lal_out_file = "H1-INSPIRAL_lalsuite_FULL_DATA-968605000-2048.gwf" # Take only the first 16 seconds to use as a small comparison lal_raw = read_frame(lal_out_file, 'H1:LDAS-STRAIN_RAW', start_time=968605000, duration="16") lal_resample = read_frame(lal_out_file, 'H1:LDAS-STRAIN_RAW_RESAMP', start_time=968605000, duration="16") lal_conditioned = read_frame(lal_out_file, 'H1:LDAS-STRAIN_FILTER', start_time=968605000, duration="16") # Take only the first 16 seconds to use as a small comparison start_offset = 8 # This is the offest between the output that PyCBC gives and lalapps_inspiral # lalapps_inspiral does not output the 8 second padding in the frame file pycbc_raw = load_timeseries("raw_pycbc.npy")[start_offset*16384:(start_offset+16)*16384].astype(lal_raw.dtype) pycbc_resample = load_timeseries("resampled_pycbc.npy")[start_offset*4096:(start_offset+16)*4096].astype(lal_raw.dtype) # the lalapps_inspiral gwf file misreportes the epoch for some of the streams pycbc_conditioned = load_timeseries("conditioned_pycbc.npy")[start_offset*4096:(start_offset+16)*4096].astype(lal_raw.dtype) pycbc_conditioned._epoch = lal_conditioned._epoch print float(pycbc_conditioned.start_time) def p(a, b, an, bn): t = numpy.arange(0, len(a), 1) mindif = 1e-7 pylab.figure() pylab.scatter(t, a, label=an, color="red", marker='x') pylab.scatter(t, b, label=bn, color="blue", marker='+')
def get_fig1_res(): strain = {} for ifo in ifos: strain[ifo] = load_timeseries('fig1-residual-%s.txt' % ifo[0]) * 1e-21 return strain
def get_fig1_observed(): strain = {} for ifo in ifos: strain[ifo] = load_timeseries('fig1-observed-%s.txt' % ifo[0]) * 1e-21 return strain
start_time=968605000, duration="16") lal_resample = read_frame(lal_out_file, 'H1:LDAS-STRAIN_RAW_RESAMP', start_time=968605000, duration="16") lal_conditioned = read_frame(lal_out_file, 'H1:LDAS-STRAIN_FILTER', start_time=968605000, duration="16") # Take only the first 16 seconds to use as a small comparison start_offset = 8 # This is the offest between the output that PyCBC gives and lalapps_inspiral # lalapps_inspiral does not output the 8 second padding in the frame file pycbc_raw = load_timeseries("raw_pycbc.npy")[start_offset * 16384:(start_offset + 16) * 16384].astype(lal_raw.dtype) pycbc_resample = load_timeseries( "resampled_pycbc.npy")[start_offset * 4096:(start_offset + 16) * 4096].astype(lal_raw.dtype) # the lalapps_inspiral gwf file misreportes the epoch for some of the streams pycbc_conditioned = load_timeseries( "conditioned_pycbc.npy")[start_offset * 4096:(start_offset + 16) * 4096].astype(lal_raw.dtype) pycbc_conditioned._epoch = lal_conditioned._epoch print float(pycbc_conditioned.start_time) def p(a, b, an, bn):
def get_Full_residual_strain(): strain = {} for ifo in ifos: strain[ifo] = load_timeseries('residuals.hdf', group='%s/residual' % ifo) return strain