def search_coincidences(self): if '/c_index' not in self.data and '/timestamps' not in self.data: c_index, timestamps = \ coincidences.search_coincidences(self.data, self.station_groups) timestamps = np.array(timestamps, dtype=np.uint64) self.data.createArray('/', 'timestamps', timestamps) self.data.createVLArray('/', 'c_index', tables.UInt32Atom()) for coincidence in c_index: self.data.root.c_index.append(coincidence)
def determine_station_offsets(self, overwrite=False): offsets_group = '/station_offsets' if offsets_group in self.data and not overwrite: self.station_offsets = self.data.root.station_offsets.read() else: ref_group = '/s501' station_groups = list(self.station_groups) station_groups.remove(ref_group) gauss = lambda x, N, mu, sigma: N * norm.pdf(x, mu, sigma) bins = linspace(-1e3, 1e3, 101) for station_id, station_group in enumerate(station_groups): c_index, timestamps = coincidences.search_coincidences( self.data, [ref_group, station_group]) dt = [] c_index = [c for c in c_index if len(c) == 2] for i, j in c_index: stations = [timestamps[u][1] for u in [i, j]] t0, t1 = [int(timestamps[u][0]) for u in [i, j]] if stations[0] > stations[1]: t0, t1 = t1, t0 dt.append(t1 - t0) print ref_group, station_group, len(dt), y, bins = np.histogram(dt, bins=bins) x = (bins[:-1] + bins[1:]) / 2 popt, pcov = curve_fit(gauss, x, y, p0=(len(dt), 0, 100.)) print popt self.station_offsets.append(popt[1]) ref_idx = self.station_groups.index(ref_group) self.station_offsets.insert(ref_idx, 0.) if offsets_group in self.data: self.data.removeNode(offsets_group) group, node = os.path.split(offsets_group) self.data.createArray(group, node, self.station_offsets)
import tables import datetime from hisparc.publicdb import download_data from hisparc.analysis import coincidences import time if __name__ == '__main__': data = tables.openFile('test.h5', 'w') t0 = time.time() for station in range(501, 506): download_data( data, '/hisparc/station' + str(station), station_id=station, start=datetime.datetime(2009, 2, 24, 12), end=datetime.datetime(2009, 2, 24, 13)) t1 = time.time() coincidences, timestamps = coincidences.search_coincidences( data, ['/hisparc/station501', '/hisparc/station502', '/hisparc/station503', '/hisparc/station504', '/hisparc/station505'], shifts=[None, None, -15, None, None]) t2 = time.time() print 'Download: %f (%.1f%%)' % (t1 - t0, 100 * (t1 - t0) / (t2 - t0)) print 'Processing: %f (%.1f%%)' % (t2 - t1, 100 * (t2 - t1) / (t2 - t0)) print 'Total:', t2 - t0