22import pandas as pd
33import numpy as np
44from scipy .signal import medfilt
5+ from .extract import get_end_time
56from ...utilities import calc_deriv , rad_to_dist , local_time
67
78warnings .warn (
@@ -81,6 +82,25 @@ def load_metadata(data):
8182 timezone = 'America/Los_Angeles' ,
8283 )
8384
85+ metadata ['auto_reward_vol' ] = 0.05 # hard coded
86+ metadata ['max_session_duration' ] = 60.0 # hard coded
87+ metadata ['min_no_lick_time' ] = data ['minimum_no_lick_time' ]
88+ metadata ['abort_on_early_response' ] = data ['ignore_false_alarms' ] == False
89+ metadata ['even_sampling_enabled' ] = data ['image_category_sampling_mode' ] == 'even_sampling'
90+ metadata ['failure_repeats' ] = data ['max_number_trial_repeats' ]
91+ metadata ['catch_frequency' ] = data ['catch_frequency' ]
92+ metadata ['volume_limit' ] = data ['volumelimit' ]
93+ metadata ['initial_blank_duration' ] = data ['initial_blank' ]
94+ metadata ['warm_up_trials' ] = data ['warmup_trials' ]
95+ metadata ['stimulus_window' ] = data ['trial_duration' ] - data ['delta_minimum' ]
96+
97+ block_length = data ['lick_detect_training_block_length' ]
98+
99+ try :
100+ metadata ['free_reward_trials' ] = block_length [0 ]
101+ except TypeError :
102+ metadata ['free_reward_trials' ] = block_length
103+
84104 return metadata
85105
86106
@@ -97,6 +117,9 @@ def load_trials(data, time=None):
97117
98118 """
99119
120+ if time is None :
121+ time = load_time (data )
122+
100123 columns = (
101124 'auto_rewarded' ,
102125 'change_contrast' ,
@@ -164,7 +187,8 @@ def stringify(x):
164187 for col in forced_string :
165188 trials [col ] = trials [col ].map (stringify )
166189
167- trials ['change_frame' ] = trials ['change_frame' ].map (lambda x : int (x ) if np .isfinite (x ) else None )
190+ trials ['change_frame' ] = trials ['change_frame' ].map (lambda x : int (x ) if np .isfinite (x ) else None ) + 1
191+
168192 trials ["change_image_category" ] = trials ["change_image_category" ].apply (lambda x : x if x else '' ) # use empty string instead of NoneType
169193 trials ["change_image_name" ] = trials ["change_image_name" ].apply (lambda x : x if x else '' ) # use empty string instead of NoneType
170194 trials ["initial_image_category" ] = trials ["initial_image_category" ].apply (lambda x : x if x else '' ) # use empty string instead of NoneType
@@ -175,7 +199,10 @@ def stringify(x):
175199
176200 # add endframe column as startframe of last frame. Last endframe is last frame of session
177201 trials ['endframe' ] = trials ['startframe' ].shift (periods = - 1 )
178- trials .at [trials .index [- 1 ], 'endframe' ] = len (load_time (data )) - 1
202+ trials .at [trials .index [- 1 ], 'endframe' ] = len (time ) - 1
203+
204+ trials ['endtime' ] = get_end_time (trials , time )
205+ trials ['trial_length' ] = trials ['endtime' ] - trials ['starttime' ]
179206
180207 return trials
181208
@@ -272,6 +299,7 @@ def load_running_speed(data, smooth=False, time=None):
272299
273300 running_speed = pd .DataFrame ({
274301 'time' : time ,
302+ 'frame' : range (len (time )),
275303 'speed' : speed ,
276304 # 'acceleration (cm/s^2)': accel,
277305 # 'jerk (cm/s^3)': jerk,
@@ -329,15 +357,18 @@ def load_visual_stimuli(data, time=None):
329357 stimdf = pd .DataFrame (data ['stimuluslog' ])
330358
331359 stimdf = find_ends (stimdf )
332- stimdf ['end' ] = stimdf ['frames_to_end' ] + stimdf ['frame' ]
360+ stimdf ['end_frame' ] = stimdf ['frames_to_end' ] + stimdf ['frame' ]
361+
362+ stimdf ['frame' ] += 1
363+ stimdf ['end_frame' ] += 1
333364
334365 def find_time (fr ):
335366 try :
336367 return time [fr ]
337368 except IndexError :
338369 return np .nan
339370
340- stimdf ['end_time' ] = stimdf ['end ' ].map (find_time )
371+ stimdf ['end_time' ] = stimdf ['end_frame ' ].map (find_time )
341372 stimdf ['duration' ] = stimdf ['end_time' ] - stimdf ['time' ]
342373
343374 onset_mask = (
@@ -348,13 +379,13 @@ def find_time(fr):
348379 ) > 0
349380
350381 if pd .isnull (stimdf ['image_name' ]).any () == False : # 'image_category' in stimdf.columns:
351- cols = ['frame' , 'time' , 'duration' , 'image_category' , 'image_name' ]
382+ cols = ['frame' , 'end_frame' , ' time' , 'duration' , 'image_category' , 'image_name' ]
352383 stimuli = stimdf [onset_mask ][cols ]
353384 stimuli ['orientation' ] = None
354385 stimuli ['contrast' ] = None
355386
356387 elif 'ori' in stimdf .columns :
357- cols = ['frame' , 'time' , 'duration' , 'ori' , 'contrast' ]
388+ cols = ['frame' , 'end_frame' , ' time' , 'duration' , 'ori' , 'contrast' ]
358389 stimuli = stimdf [onset_mask ][cols ]
359390 stimuli .rename (columns = {'ori' : 'orientation' }, inplace = True )
360391 stimuli ['image_category' ] = None
0 commit comments