Skip to content

Commit a86a6d9

Browse files
committed
finish docstrings
1 parent ea4d6c4 commit a86a6d9

File tree

1 file changed

+52
-19
lines changed

1 file changed

+52
-19
lines changed

brainbox/io/one.py

Lines changed: 52 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,7 @@ class SessionLoader:
10881088
name is_loaded
10891089
0 trials False
10901090
1 wheel False
1091-
2 poses False
1091+
2 pose False
10921092
3 motion_energy False
10931093
4 pupil False
10941094
@@ -1098,7 +1098,7 @@ class SessionLoader:
10981098
name is_loaded
10991099
0 trials True
11001100
1 wheel True
1101-
2 poses True
1101+
2 pose True
11021102
3 motion_energy True
11031103
4 pupil False
11041104
@@ -1149,13 +1149,13 @@ def __post_init__(self):
11491149
data_names = [
11501150
'trials',
11511151
'wheel',
1152-
'poses',
1152+
'pose',
11531153
'motion_energy',
11541154
'pupil'
11551155
]
11561156
self.data_info = pd.DataFrame(columns=['name', 'is_loaded'], data=zip(data_names, [False]*len(data_names)))
11571157

1158-
def load_session_data(self, trials=True, wheel=True, poses=True, motion_energy=True, pupil=True, reload=False):
1158+
def load_session_data(self, trials=True, wheel=True, pose=True, motion_energy=True, pupil=True, reload=False):
11591159
"""
11601160
Function to load available session data into the SessionLoader object. Input parameters allow to control which
11611161
data is loaded. Data is loaded into an attribute of the SessionLoader object with the same name as the input
@@ -1168,8 +1168,8 @@ def load_session_data(self, trials=True, wheel=True, poses=True, motion_energy=T
11681168
Whether to load all trials data into SessionLoader.trials, default is True
11691169
wheel: boolean
11701170
Whether to load wheel data (position, velocity, acceleration) into SessionLoader.wheel, default is True
1171-
poses: boolean
1172-
Whether to load pose tracking results (DLC) for each available camera into SessionLoader.poses,
1171+
pose: boolean
1172+
Whether to load pose tracking results (DLC) for each available camera into SessionLoader.pose,
11731173
default is True
11741174
motion_energy: boolean
11751175
Whether to load motion energy data (whisker pad for left/right camera, body for body camera)
@@ -1184,7 +1184,7 @@ def load_session_data(self, trials=True, wheel=True, poses=True, motion_energy=T
11841184
load_df['to_load'] = [
11851185
trials,
11861186
wheel,
1187-
poses,
1187+
pose,
11881188
motion_energy,
11891189
pupil
11901190
]
@@ -1221,14 +1221,14 @@ def load_wheel(self, sampling_rate=1000, smooth_size=0.03):
12211221
"""
12221222
Function to load wheel data (position, velocity, acceleration) into SessionLoader.wheel. The wheel position
12231223
is first interpolated to a uniform sampling rate. Then velocity and acceleration are computed, during which
1224-
smoothing is applied.
1224+
Gaussian smoothing is applied.
12251225
12261226
Parameters
12271227
----------
12281228
sampling_rate: float
1229-
Rate at which to sample the wheel position
1229+
Rate at which to sample the wheel position, default is 1000 Hz
12301230
smooth_size: float
1231-
Kernel for smoothing the wheel data to compute velocity and acceleration
1231+
Size of Gaussian smoothing window in seconds, default is 0.03
12321232
"""
12331233
wheel_raw = self.one.load_object(self.eid, 'wheel')
12341234
# TODO: Fix this instead of raising error?
@@ -1245,15 +1245,18 @@ def load_wheel(self, sampling_rate=1000, smooth_size=0.03):
12451245

12461246
def load_pose(self, likelihood_thr=0.9, views=['left', 'right', 'body']):
12471247
"""
1248-
Function to load the pose estimation results (DLC) into SessionLoader.poses
1248+
Function to load the pose estimation results (DLC) into SessionLoader.pose. SessionLoader.pose is a
1249+
dictionary where keys are the names of the cameras for which pose data is loaded, and values are pandas
1250+
Dataframes with the timestamps and pose data, one row for each body part tracked for that camera.
1251+
12491252
Parameters
12501253
----------
1251-
likelihood_thr
1252-
views
1253-
1254-
Returns
1255-
-------
1256-
1254+
likelihood_thr: float
1255+
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
1257+
likelihood_thr=1. Default is 0.9
1258+
views: list
1259+
List of camera views for which to try and load data. Possible options are {'left', 'right', 'body'}
12571260
"""
12581261
for view in views:
12591262
try:
@@ -1268,6 +1271,19 @@ def load_pose(self, likelihood_thr=0.9, views=['left', 'right', 'body']):
12681271
_logger.debug(e)
12691272

12701273
def load_motion_energy(self, views=['left', 'right', 'body']):
1274+
"""
1275+
Function to load the motion energy data into SessionLoader.motion_energy. SessionLoader.motion_energy is a
1276+
dictionary where keys are the names of the cameras for which motion energy data is loaded, and values are
1277+
pandas Dataframes with the timestamps and motion energy data.
1278+
The motion energy for the left and right camera is calculated for a square roughly covering the whisker pad
1279+
(whiskerMotionEnergy). The motion energy for the body camera is calculated for a square covering much of the
1280+
body (bodyMotionEnergy).
1281+
1282+
Parameters
1283+
----------
1284+
views: list
1285+
List of camera views for which to try and load data. Possible options are {'left', 'right', 'body'}
1286+
"""
12711287
names = {'left': 'whiskerMotionEnergy',
12721288
'right': 'whiskerMotionEnergy',
12731289
'body': 'bodyMotionEnergy'}
@@ -1285,9 +1301,21 @@ def load_motion_energy(self, views=['left', 'right', 'body']):
12851301
_logger.debug(e)
12861302

12871303
def load_licks(self):
1304+
"""
1305+
Not yet implemented
1306+
"""
12881307
pass
12891308

1290-
def load_pupil(self, snr_thresh=5):
1309+
def load_pupil(self, snr_thresh=5.):
1310+
"""
1311+
Function to load raw and smoothed pupil diameter data from the left camera into SessionLoader.pupil.
1312+
1313+
Parameters
1314+
----------
1315+
snr_thresh: float
1316+
An SNR is calculated from the raw and smoothed pupil diameter. If this snr < snr_thresh the data
1317+
will be considered unusable and will be discarded.
1318+
"""
12911319
# Try to load from features
12921320
feat_raw = self.one.load_object(self.eid, 'leftCamera', attribute=['times', 'features'])
12931321
if 'features' in feat_raw.keys():
@@ -1298,7 +1326,8 @@ def load_pupil(self, snr_thresh=5):
12981326
# If unavailable compute on the fly
12991327
else:
13001328
_logger.info('Pupil diameter not available, trying to compute on the fly.')
1301-
if self.data_info[self.data_info['name'] == 'pose', 'is_loaded'] and 'leftCamera' in self.pose.keys():
1329+
if (self.data_info[self.data_info['name'] == 'pose']['is_loaded'].values[0]
1330+
and 'leftCamera' in self.pose.keys()):
13021331
# If pose data is already loaded, we don't know if it was threshold at 0.9, so we need a little stunt
13031332
copy_pose = self.pose['leftCamera'].copy() # Save the previously loaded pose data
13041333
self.load_pose(views=['left'], likelihood_thr=0.9) # Load new with threshold 0.9
@@ -1326,6 +1355,10 @@ def load_pupil(self, snr_thresh=5):
13261355
raise ValueError(f'Pupil diameter SNR ({snr:.2f}) below threshold SNR ({snr_thresh}), removing data.')
13271356

13281357
def _check_video_timestamps(self, view, video_timestamps, video_data):
1358+
"""
1359+
Helper function to check for the length of the video frames vs video timestamps and fix in case
1360+
timestamps are longer than video frames.
1361+
"""
13291362
# If camera times are shorter than video data, or empty, no current fix
13301363
if video_timestamps.shape[0] < video_data.shape[0]:
13311364
if video_timestamps.shape[0] == 0:

0 commit comments

Comments
 (0)