def add_zerolag(self, full_file): start = get_start_dur(full_file)[0] self.starttimes.append(start) with h5py.File(full_file, 'r') as f: # get stat values & threshold _stats = f['foreground/stat'][:] _keepstat = _stats > self.thr # get templates & apply filter _tids = f['foreground/template_id'][:] # we need the template filter to have already been made assert self.in_bin is not None _keep = np.logical_and(_keepstat, self.in_bin[_tids]) massp = self.tpars[_tids][_keep] # filtered template params # assign times and coinc types _times = {} for i in self.ifos: _times[i] = f['foreground/' + i + '/time'][:][_keep] # if an ifo doesn't participate, time is sentinel value -1 # event time is mean of remaining positive GPS times meantimes = np.array( [coinc_meanigz(ts)[0] for ts in zip(*_times.values())]) _ctype = self.get_ctypes(_times) if len(_ctype) == 0: if self.args.verbose: print('No events in ' + start) return # filter events in_ctypes = np.array([cty in self.coinc_types for cty in _ctype]) meantimes = meantimes[in_ctypes] # get coinc time as strings # (strings may have different lengths) _ctime = np.repeat(np.array([''], dtype=object), len(meantimes)) for ct in self.allctimestring: intime = self.in_coinc_time_excl(f, ct, meantimes) _ctime[intime == 1] = ct if self.args.verbose: print('Got %i events in %s time' % (len(_ctime[intime == 1]), ct)) # store self.stat = np.append(self.stat, _stats[_keep][in_ctypes]) try: # injection analyses only have 'ifar_exc', not 'ifar' self.ifar = np.append( self.ifar, f['foreground/ifar'][:][_keep][in_ctypes]) except KeyError: self.ifar = np.append( self.ifar, f['foreground/ifar_exc'][:][_keep][in_ctypes]) self.gpst = np.append(self.gpst, meantimes) self.masspars = np.append(self.masspars, massp) self.start = np.append(self.start, int(start) * np.ones_like(meantimes)) self.ctime = np.append(self.ctime, _ctime) self.ctype = np.append(self.ctype, _ctype[in_ctypes])
def add_injections(self, inj_file, fg_file): # fg_file only needed for coinc time info :/ self.starts.append(get_start_dur(inj_file)[0]) self.get_livetimes(inj_file) with h5py.File(inj_file, 'r') as jf: # get stat values and threshold _injstat = jf['found_after_vetoes/stat'][:] _keepstat = _injstat > self.thr # get template ids and filter _injtid = jf['found_after_vetoes/template_id'][:] assert self.in_bin is not None _keep = np.logical_and(_keepstat, self.in_bin[_injtid]) _injstat = _injstat[_keep] # assign coinc types _times = {} for i in self.ifos: _times[i] = jf['found_after_vetoes/' + i + '/time'][:][_keep] meantimes = np.array( [coinc_meanigz(ts)[0] for ts in zip(*_times.values())]) _ctype = self.get_ctypes(_times) # get coinc time as strings # (strings may have different lengths) _ctime = np.repeat(np.array([''], dtype=object), len(meantimes)) for ct in self.allctimestring: # get coinc time info from segments in fg file intime = self.in_coinc_time_excl(h5py.File(fg_file, 'r'), ct, meantimes) _ctime[intime == 1] = ct # do we need this? if self.args.verbose: print('Got %i ' % (intime == 1).sum() + 'inj in %s time' % ct) # filter by coinc type and add to array for cty in self.coinc_types: if not type_in_time(ct, cty): continue my_vals = _injstat[np.logical_and(_ctype == cty, intime == 1)] if self.args.verbose: print('%d ' % len(my_vals) + 'are %s coincs' % cty) if (ct, cty) not in self.inj_vals: # initialize self.inj_vals[(ct, cty)] = np.array([]) if len(my_vals) > 0: self.inj_vals[(ct, cty)] = \ np.append(self.inj_vals[(ct, cty)], my_vals) del intime, my_vals