def test_find_nearest(self): trace = np.arange(10) assert(ta.find_nearest(trace, 1.4) == 1) assert(ta.find_nearest(trace, 1.6) == 2) assert(ta.find_nearest(trace, 1.4, -1) == 1) assert(ta.find_nearest(trace, 1.6, -1) == 1) assert(ta.find_nearest(trace, 1.4, 1) == 2) assert(ta.find_nearest(trace, 1.6, 1) == 2) assert(ta.find_nearest(trace, -1, -1) is None) assert(ta.find_nearest(trace, 11, 1) is None)
np.ceil((end_time - start_time) / plane_mean_frame_dur)) plane_chunk_frame_start = int(np.floor(start_time / plane_mean_frame_dur)) plane_t = (np.arange(plane_chunk_frame_dur) + plane_chunk_frame_start) * plane_mean_frame_dur print '{}: STRF time axis: \n{}'.format(plane_n, plane_t) plane_roi_traces = [] trigger_ts = [] for probe_ind, probe_n in enumerate(probe_ns): probe_ts = probe_grp[probe_n]['pd_onset_ts_sec'].value probe_traces = [] probe_trigger_ts = [] for curr_probe_ts in probe_ts: curr_frame_start = ta.find_nearest( plane_trace_ts, curr_probe_ts) + plane_chunk_frame_start curr_frame_end = curr_frame_start + plane_chunk_frame_dur if curr_frame_start >= 0 and curr_frame_end <= len(plane_trace_ts): probe_traces.append( plane_traces[:, curr_frame_start:curr_frame_end]) probe_trigger_ts.append(curr_probe_ts) plane_roi_traces.append(np.array(probe_traces)) trigger_ts.append(probe_trigger_ts) print('probe: {} / {}; shape: {}'.format(probe_ind + 1, len(probe_ns), np.array(probe_traces).shape)) # plane_roi_traces = np.array(plane_roi_traces) print('saving ...') for roi_ind in range(roi_num):