def load_traces_and_frametimes(self, key): # -- find number of recording depths pipe = (fuse.Activity() & key).fetch('pipe') assert len( np.unique(pipe)) == 1, 'Selection is from different pipelines' pipe = dj.create_virtual_module(pipe[0], 'pipeline_' + pipe[0]) k = dict(key) k.pop('field', None) ndepth = len(dj.U('z') & (pipe.ScanInfo.Field() & k)) frame_times = (stimulus.Sync() & key).fetch1('frame_times').squeeze()[::ndepth] soma = pipe.MaskClassification.Type() & dict(type='soma') spikes = (dj.U('field', 'channel') * pipe.Activity.Trace() * StaticScan.Unit() \ * pipe.ScanSet.UnitInfo() & soma & key) traces, ms_delay, trace_keys = spikes.fetch( 'trace', 'ms_delay', dj.key, order_by='animal_id, session, scan_idx, unit_id') delay = np.fromiter(ms_delay / 1000, dtype=np.float) frame_times = (delay[:, None] + frame_times[None, :]) traces = np.vstack( [fill_nans(tr.astype(np.float32)).squeeze() for tr in traces]) traces, frame_times = self.adjust_trace_len(traces, frame_times) return traces, frame_times, trace_keys
def load_eye_traces(self, key): #r, center = (pupil.FittedPupil.Ellipse() & key).fetch('major_r', 'center', order_by='frame_id ASC') r, center = (pupil.FittedPupil.Circle() & key).fetch( 'radius', 'center', order_by='frame_id') detectedFrames = ~np.isnan(r) xy = np.full((len(r), 2), np.nan) xy[detectedFrames, :] = np.vstack(center[detectedFrames]) xy = np.vstack(map(partial(fill_nans, preserve_gap=3), xy.T)) if np.any(np.isnan(xy)): log.info('Keeping some nans in the pupil location trace') pupil_radius = fill_nans(r.squeeze(), preserve_gap=3) if np.any(np.isnan(pupil_radius)): log.info('Keeping some nans in the pupil radius trace') eye_time = (pupil.Eye() & key).fetch1('eye_time').squeeze() return pupil_radius, xy, eye_time