def decode_data(self, chdata, tsdata, sync_offset): """ The qutau data has two arrays: one channel array containing the channel numbers where clicks were observed. The other one contains the time stamps. Here I assign to each event a third and fourth array. The third array contains the sync number, and a fourth array replaces the second array with timestamps. It contains the times with respect to the last sync. Finally we reshape the data in the well known HydraHarp format. """ chdata = chdata.astype(np.uint8) tsdata = tsdata.astype(np.uintc) sync_mask = chdata != self.sync_chan special = np.logical_or(chdata == self.marker1_chan, chdata == self.marker2_chan) sync_number = hhopt.get_sync_number(chdata, self.sync_chan, sync_offset) timings_wrt_sync = hhopt.get_dt_wrt_sync(chdata, tsdata, self.sync_chan) datastack = hhopt.stack(sync_number.astype(np.uintc), timings_wrt_sync.astype(np.uintc), chdata.astype(np.uintc), special.astype(np.uintc)) #adjust the sync number offset to the last sync number sync_offset = datastack[-1, 0] #delete syncs from the arrays decoded_data = hhopt.apply_filter_to_2darray( datastack, sync_mask.astype(np.uintc)) return decoded_data, sync_offset
def filter_marker_on_counts(data, mchan, delta_syncs=[0], print_status=False): t0 = time.time() if print_status: print '* filter mrkr %s on counts' % mchan special = data[:, 3] == 1 mrkr = np.logical_and(special, data[:, 2] == mchan) other_mrkr = np.logical_and(special, np.logical_not(mrkr)) clicks = np.logical_not(special) good = data[mrkr, 0] < 0 for d in delta_syncs: good = np.logical_or(good, np.in1d(data[mrkr, 0] + d, data[clicks, 0])) for i, idx in np.ndenumerate(np.where(mrkr)[0]): if not good[i]: mrkr[idx] = False if print_status: print ' %d markers are valid.' % len(data[mrkr]) print ' processing took %.2f secs.' % (time.time() - t0) filtered = np.logical_or(np.logical_or(other_mrkr, mrkr), clicks) if len(np.where(filtered)[0]) == 0: return np.zeros((0, 4), dtype=np.uint) return hhopt.apply_filter_to_2darray(data, filtered.astype(np.uint))
def decode_data(self, chdata, tsdata, sync_offset): """ The qutau data has two arrays: one channel array containing the channel numbers where clicks were observed. The other one contains the time stamps. Here I assign to each event a third and fourth array. The third array contains the sync number, and a fourth array replaces the second array with timestamps. It contains the times with respect to the last sync. Finally we reshape the data in the well known HydraHarp format. """ chdata = chdata.astype(np.uint8) tsdata = tsdata.astype(np.uintc) sync_mask = chdata != self.sync_chan special = np.logical_or(chdata == self.marker1_chan, chdata == self.marker2_chan) sync_number = hhopt.get_sync_number(chdata, self.sync_chan, sync_offset) timings_wrt_sync = hhopt.get_dt_wrt_sync(chdata, tsdata, self.sync_chan) datastack = hhopt.stack(sync_number.astype(np.uintc), timings_wrt_sync.astype(np.uintc), chdata.astype(np.uintc), special.astype(np.uintc)) #adjust the sync number offset to the last sync number sync_offset = datastack[-1,0] #delete syncs from the arrays decoded_data = hhopt.apply_filter_to_2darray(datastack, sync_mask.astype(np.uintc)) return decoded_data, sync_offset
def filter_timewindow(data, chan, mintime, maxtime, print_status=False): t0 = time.time() if print_status: print '* filter ch %d timewindow' % chan if len(data) == 0: print ' empty data, cannot time-filter' return data notspecial = data[:, 3] == 0 ch = data[:, 2] == chan click = np.logical_and(notspecial, ch) clickstartbad = np.logical_and(click, data[:, 1] < mintime) clickstopbad = np.logical_and(click, data[:, 1] > maxtime) clickbad = np.logical_or(clickstartbad, clickstopbad) if print_status: print ' found %d of %d clicks out of time window' % \ (len(data[clickbad]), len(data[click])) print ' processing took %.2f secs.' % (time.time() - t0) filtered = np.logical_not(clickbad) if len(np.where(filtered)[0]) == 0: return np.zeros((0, 4), dtype=np.uint) return hhopt.apply_filter_to_2darray(data, filtered.astype(np.uint))
def filter_marker_on_counts(data, mchan, delta_syncs=[0], print_status = False): t0 = time.time() if print_status: print '* filter mrkr %s on counts' % mchan special = data[:,3] == 1 mrkr = np.logical_and(special, data[:,2] == mchan) other_mrkr = np.logical_and(special, np.logical_not(mrkr)) clicks = np.logical_not(special) good = data[mrkr,0] < 0 for d in delta_syncs: good = np.logical_or(good, np.in1d(data[mrkr,0]+d, data[clicks,0])) for i,idx in np.ndenumerate(np.where(mrkr)[0]): if not good[i]: mrkr[idx] = False if print_status: print ' %d markers are valid.' % len(data[mrkr]) print ' processing took %.2f secs.' % (time.time()-t0) filtered = np.logical_or(np.logical_or(other_mrkr, mrkr), clicks) if len(np.where(filtered)[0]) == 0: return np.zeros((0,4), dtype=np.uint) return hhopt.apply_filter_to_2darray(data, filtered.astype(np.uint))
def filter_timewindow(data, chan, mintime, maxtime, print_status = False): t0 = time.time() if print_status: print '* filter ch %d timewindow' % chan if len(data) == 0: print ' empty data, cannot time-filter' return data notspecial = data[:,3] == 0 ch = data[:,2] == chan click = np.logical_and(notspecial, ch) clickstartbad = np.logical_and(click, data[:,1] < mintime) clickstopbad = np.logical_and(click, data[:,1] > maxtime) clickbad = np.logical_or(clickstartbad, clickstopbad) if print_status: print ' found %d of %d clicks out of time window' % \ (len(data[clickbad]), len(data[click])) print ' processing took %.2f secs.' % (time.time()-t0) filtered = np.logical_not(clickbad) if len(np.where(filtered)[0]) == 0: return np.zeros((0,4), dtype=np.uint) return hhopt.apply_filter_to_2darray(data, filtered.astype(np.uint))
def delete_markers(data, mchan): """ Delete markers from the data on marker channel "mchan". Useful for throwing away useless clicks. """ special = data[:, 3] == 1 mrkr = np.logical_and(special, data[:, 2] == mchan) filtered = np.logical_not(mrkr) if len(np.where(filtered)[0]) == 0: return np.zeros((0, 4), dtype=np.uint) return hhopt.apply_filter_to_2darray(data, filtered.astype(np.uint))
def delete_markers(data, mchan): """ Delete markers from the data on marker channel "mchan". Useful for throwing away useless clicks. """ special = data[:,3] == 1 mrkr = np.logical_and(special, data[:,2] == mchan) filtered = np.logical_not(mrkr) if len(np.where(filtered)[0]) == 0: return np.zeros((0,4), dtype=np.uint) return hhopt.apply_filter_to_2darray(data, filtered.astype(np.uint))