@@ -1102,17 +1102,27 @@ class SessionLoader:
11021102 3 motion_energy True
11031103 4 pupil False
11041104
1105- # You can access the data via the respective attributes, e.g.
1105+ # The data is loaded in pandas dataframes that you can access via the respective attributes, e.g.
1106+ >>> type(sess_loader.trials)
1107+ pandas.core.frame.DataFrame
11061108 >>> sess_loader.trials.shape
11071109 (626, 18)
11081110 # Each data comes with its own timestamps in a column called 'times'
1109- >>> sess_loader.pose['bodyCamera']['times']
1110- 0 6.201239
1111- 1 6.234569
1112- 2 6.267899
1113- 3 6.301229
1114- 4 6.334592
1115- ...
1111+ >>> sess_loader.wheel['times']
1112+ 0 0.134286
1113+ 1 0.135286
1114+ 2 0.136286
1115+ 3 0.137286
1116+ 4 0.138286
1117+ ...
1118+ # For camera data (pose, motionEnergy) the respective functions load the data into one dataframe per camera.
1119+ # The dataframes of all cameras are collected in a dictionary
1120+ >>> type(sess_loader.pose)
1121+ dict
1122+ >>> sess_loader.pose.keys()
1123+ dict_keys(['leftCamera', 'rightCamera', 'bodyCamera'])
1124+ >>> sess_loader.pose['bodyCamera'].columns
1125+ Index(['times', 'tail_start_x', 'tail_start_y', 'tail_start_likelihood'], dtype='object')
11161126 # In order to control the loading of specific data by e.g. specifying parameters, use the individual loading
11171127 functions:
11181128 >>> sess_loader.load_wheel(sampling_rate=100)
@@ -1214,7 +1224,7 @@ def load_trials(self):
12141224 """
12151225 Function to load trials data into SessionLoader.trials
12161226 """
1217- self .trials = self .one .load_object (self .eid , 'trials' ).to_df ()
1227+ self .trials = self .one .load_object (self .eid , 'trials' , collection = 'alf' ).to_df ()
12181228 self .data_info .loc [self .data_info ['name' ] == 'trials' , 'is_loaded' ] = True
12191229
12201230 def load_wheel (self , sampling_rate = 1000 , smooth_size = 0.03 ):
@@ -1235,8 +1245,8 @@ def load_wheel(self, sampling_rate=1000, smooth_size=0.03):
12351245 if wheel_raw ['position' ].shape [0 ] != wheel_raw ['timestamps' ].shape [0 ]:
12361246 raise ValueError ("Length mismatch between 'wheel.position' and 'wheel.timestamps" )
12371247 # resample the wheel position and compute velocity, acceleration
1238- self .wheel = pd .DataFrame (columns = ['timestamps ' , 'position' , 'velocity' , 'acceleration' ])
1239- self .wheel ['position' ], self .wheel ['timestamps ' ] = interpolate_position (
1248+ self .wheel = pd .DataFrame (columns = ['times ' , 'position' , 'velocity' , 'acceleration' ])
1249+ self .wheel ['position' ], self .wheel ['times ' ] = interpolate_position (
12401250 wheel_raw ['timestamps' ], wheel_raw ['position' ], freq = sampling_rate )
12411251 self .wheel ['velocity' ], self .wheel ['acceleration' ] = velocity_smoothed (
12421252 self .wheel ['position' ], freq = sampling_rate , smooth_size = smooth_size )
@@ -1253,11 +1263,13 @@ def load_pose(self, likelihood_thr=0.9, views=['left', 'right', 'body']):
12531263 ----------
12541264 likelihood_thr: float
12551265 The position of each tracked body part come with a likelihood of that estimate for each time point.
1256- Estimates for time points with likelihood < likelihhood_thr are set to NaN. To skip thresholding set
1266+ Estimates for time points with likelihood < likelihood_thr are set to NaN. To skip thresholding set
12571267 likelihood_thr=1. Default is 0.9
12581268 views: list
12591269 List of camera views for which to try and load data. Possible options are {'left', 'right', 'body'}
12601270 """
1271+ # empty the dictionary so that if one loads only one view, after having loaded several, the others don't linger
1272+ self .pose = {}
12611273 for view in views :
12621274 try :
12631275 pose_raw = self .one .load_object (self .eid , f'{ view } Camera' , attribute = ['dlc' , 'times' ])
@@ -1267,7 +1279,7 @@ def load_pose(self, likelihood_thr=0.9, views=['left', 'right', 'body']):
12671279 self .pose [f'{ view } Camera' ].insert (0 , 'times' , times_fixed )
12681280 self .data_info .loc [self .data_info ['name' ] == 'pose' , 'is_loaded' ] = True
12691281 except BaseException as e :
1270- _logger .error (f'Could not load pose data for { view } Camera. Skipping camera.' )
1282+ _logger .warning (f'Could not load pose data for { view } Camera. Skipping camera.' )
12711283 _logger .debug (e )
12721284
12731285 def load_motion_energy (self , views = ['left' , 'right' , 'body' ]):
@@ -1287,6 +1299,8 @@ def load_motion_energy(self, views=['left', 'right', 'body']):
12871299 names = {'left' : 'whiskerMotionEnergy' ,
12881300 'right' : 'whiskerMotionEnergy' ,
12891301 'body' : 'bodyMotionEnergy' }
1302+ # empty the dictionary so that if one loads only one view, after having loaded several, the others don't linger
1303+ self .motion_energy = {}
12901304 for view in views :
12911305 try :
12921306 me_raw = self .one .load_object (self .eid , f'{ view } Camera' , attribute = ['ROIMotionEnergy' , 'times' ])
@@ -1297,7 +1311,7 @@ def load_motion_energy(self, views=['left', 'right', 'body']):
12971311 self .motion_energy [f'{ view } Camera' ].insert (0 , 'times' , times_fixed )
12981312 self .data_info .loc [self .data_info ['name' ] == 'motion_energy' , 'is_loaded' ] = True
12991313 except BaseException as e :
1300- _logger .error (f'Could not load motion energy data for { view } Camera. Skipping camera.' )
1314+ _logger .warning (f'Could not load motion energy data for { view } Camera. Skipping camera.' )
13011315 _logger .debug (e )
13021316
13031317 def load_licks (self ):
@@ -1351,8 +1365,8 @@ def load_pupil(self, snr_thresh=5.):
13511365 snr = (np .var (self .pupil ['pupilDiameter_smooth' ][good_idxs ]) /
13521366 (np .var (self .pupil ['pupilDiameter_smooth' ][good_idxs ] - self .pupil ['pupilDiameter_raw' ][good_idxs ])))
13531367 if snr < snr_thresh :
1354- self .pupil = pd .DataFrame
1355- raise ValueError (f'Pupil diameter SNR ({ snr :.2f} ) below threshold SNR ({ snr_thresh } ), removing data.' )
1368+ self .pupil = pd .DataFrame ()
1369+ _logger . error (f'Pupil diameter SNR ({ snr :.2f} ) below threshold SNR ({ snr_thresh } ), removing data.' )
13561370
13571371 def _check_video_timestamps (self , view , video_timestamps , video_data ):
13581372 """
0 commit comments