def rvs(self, size=1): """ Rejection samples the prior parameter space. """ # create output FieldArray out = record.FieldArray(size, dtype=[(arg, float) for arg in self.variable_args]) # loop until enough samples accepted n = 0 while n < size: # draw samples samples = {} for dist in self.distributions: draw = dist.rvs(1) for param in dist.params: samples[param] = draw[param][0] vals = numpy.array([samples[arg] for arg in self.variable_args]) # determine if all parameter values are in prior space # if they are then add to output if self(**dict(zip(self.variable_args, vals))) > -numpy.inf: out[n] = vals n += 1 return out
def check_coinc_results(): coinc_fail = False # gather coincident triggers coinc_trig_paths = sorted(glob.glob('output/coinc*.xml.gz')) n_coincs=len(coinc_trig_paths) if n_coincs==0: log.error('No coincident triggers detected') coinc_fail = True elif n_coincs>=10: log.error('Too many coincident triggers detected') coinc_fail = True else: log.info('%d coincident trigger(s) detected', n_coincs) injs = sorted(glob.glob('test_inj*.hdf')) n_injs = len(injs) inj_mass1 = np.empty(n_injs) inj_mass2 = np.empty(n_injs) inj_spin1z = np.empty(n_injs) inj_spin2z = np.empty(n_injs) inj_time = np.empty(n_injs) for idx, inj_path in enumerate(injs): with h5py.File(inj_path, 'r') as inj: inj_mass1[idx] = inj['mass1'][0] inj_mass2[idx] = inj['mass2'][0] inj_spin1z[idx] = inj['spin1z'][0] inj_spin2z[idx] = inj['spin2z'][0] inj_time[idx] = inj['tc'][0] if n_injs > n_coincs : log.error('More injections than coincident triggers') coinc_fail = True #create field array to store properties of triggers trig_props = record.FieldArray(n_coincs, dtype=[('mass1', float), \ ('mass2', float), ('spin1z', float), ('spin2z', float), \ ('tc', float), ('net_snr', float)]) #store properties of coincident triggers for x, ctrigfp in enumerate(coinc_trig_paths): log.info('Checking trigger %s', ctrigfp) xmldoc = ligolw_utils.load_filename( ctrigfp, False, contenthandler=LIGOLWContentHandler) sngl_inspiral_table = lsctables.SnglInspiralTable.get_table(xmldoc) trig_props['tc'][x]=sngl_inspiral_table.get_column('end_time')[0] trig_props['mass1'][x]=sngl_inspiral_table.get_column('mass1')[0] trig_props['mass2'][x]=sngl_inspiral_table.get_column('mass2')[0] trig_props['spin1z'][x]=sngl_inspiral_table.get_column('spin1z')[0] trig_props['spin2z'][x]=sngl_inspiral_table.get_column('spin2z')[0] snr_list=sngl_inspiral_table.get_column('snr') network_snr = sum([snr ** 2 for snr in snr_list]) ** 0.5 trig_props['net_snr'][x]=network_snr log.info('IFO SNRs: '+str(snr_list)) log.info('Network SNR: %f', network_snr) log.info('IFO End Time: %f', trig_props['tc'][x]) log.info('Mass 1: %f', trig_props['mass1'][x]) log.info('Mass 2: %f', trig_props['mass2'][x]) log.info('Spin1z: %f', trig_props['spin1z'][x]) log.info('Spin2z: %f', trig_props['spin2z'][x]) # check if injections match trigger params for i in range(n_injs): has_match = False for j in range(n_coincs): if (close(inj_time[i],trig_props['tc'][j],1.0) and close(inj_mass1[i], trig_props['mass1'][j], 5e-7) and close(inj_mass2[i], trig_props['mass2'][j], 5e-7) and close(inj_spin1z[i], trig_props['spin1z'][j], 5e-7) and close(inj_spin2z[i], trig_props['spin2z'][j], 5e-7) and close(15.0, trig_props['net_snr'][j], 1.0)): has_match = True break if not has_match: coinc_fail = True log.error('Injection %i has no match',i) if coinc_fail: log.error('Coincident Trigger Test Failed') return coinc_fail
from pycbc.inject import InjectionSet if os.path.exists('./test_inj1.hdf'): raise OSError("output-file 1 already exists") if os.path.exists('./test_inj2.hdf'): raise OSError("output-file 2 already exists") # injection 1 static_params = { 'f_lower': 18.0, 'f_ref': 18.0, 'approximant': 'SEOBNRv4', 'taper': 'start', 'ra': 45.0, 'dec': 45.0, 'inclination': 0.0, 'coa_phase': 0.0, 'polarization': 0.0} samples = record.FieldArray(2, dtype=[('mass1', float), ('mass2', float), ('spin1z', float), ('spin2z', float), ('tc', float), ('distance', float)]) # The following 'magic numbers' are intended to match the highest # mass injection in the template bank samples['mass1'] = [290.929321] samples['mass2'] = [3.6755455] samples['spin1z'] = [0.9934847] samples['spin2z'] = [0.92713535] samples['tc'] = [1272790100.1] samples['distance'] = [603.0] InjectionSet.write('test_inj1.hdf', samples, static_args = static_params, injtype = 'cbc', cmd=" ".join(sys.argv))