Source code for allensdk.brain_observatory.ecephys.file_io.stim_file
import pandas as pd
import numpy as np
[docs]class CamStimOnePickleStimFile(object):
@property
def stimuli(self):
'''List of dictionaries containing information about individual stimuli
'''
return self.data['stimuli']
@property
def frames_per_second(self):
'''Framerate of stimulus presentation
'''
return self.data['fps']
@property
def pre_blank_sec(self):
'''Time (s) before initial stimulus presentation
'''
return self.data['pre_blank_sec']
@property
def angular_wheel_velocity(self):
''' Extract the mean angular velocity of the running wheel (degrees / s) for each
frame.
'''
return self.frames_per_second * self.angular_wheel_rotation
@property
def angular_wheel_rotation(self):
''' Extract the total rotation of the running wheel on each frame.
'''
return self._extract_running_array("dx")
@property
def vsig(self):
"""Running speed signal voltage
"""
return self._extract_running_array("vsig")
@property
def vin(self):
return self._extract_running_array("vin")
def __init__(self, data, **kwargs):
self.data = data
def _extract_running_array(self, key):
try:
result = self.data['items']['foraging']['encoders'][0][key]
except (KeyError, IndexError):
try:
result = self.data[key]
except KeyError:
raise KeyError(f'unable to extract {key} from this stimulus pickle')
return np.array(result)
[docs] @classmethod
def factory(cls, path, **kwargs):
data = pd.read_pickle(path)
return cls(data, **kwargs)