-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Establish full Bpod ingestion #3
Labels
enhancement
New feature or request
Comments
Merged
Early bpod loader draft, nonfunctional import pathlib
import scipy.io as spio
class BPod:
""" Parse a bpod file into the following objects
fields: top-level bpod fields
number_trials: total number of trials
trial_start_times: list of floats, seconds relative to session start
trial_types: array of tinyint designating condition number
"""
def __init__(self, full_dir):
try: # check for file in path
self.filepath = next(pathlib.Path(full_dir).glob('*.mat'))
except StopIteration:
raise FileNotFoundError(f'No .mat file found at: {full_dir}')
self.data = load_bpod_matfile(self.filepath) # see helper below
@property
def fields(self):
if self._fields is None:
self._fields = list(self.data.keys())
return self._fields
@property
def number_trials(self):
if self._number_trials is None:
self._number_trials = self.data['nTrials']
return self._number_trials
@property
def trial_start_times(self):
if self._trial_start_times is None:
self._trial_start_times = list(self.data['TrialStartTimestamp'])
return self._trial_start_times
@property
def trial_types(self):
if self._trial_types is None and 'TrialTypes' in self.fields:
self._trial_types = self.data['TrialTypes']
return self._trial_types
'''
@property
def [each relevant bpod property](self)]:
if self.[relevant property] is None:
self.[relevant property] = self.file.[specific structure]
'''
# --------------------- HELPER LOADER FUNCTIONS -----------------
def load_bpod_matfile(mat_filepath):
"""
Loading routine for behavioral file, bpod .mat
"""
# loadmat optionally takes mdict, existing dictionary which it loads into
# simplify_cells returns a simplified dict structure, instead of reversible
# mat-like files
# squeeze_me compresses matrix dimensions
mat_file = spio.loadmat(mat_filepath.as_posix(),squeeze_me=True,
struct_as_record=False,simplify_cells=True)
# bpod files load as dict with the following keys
# __header__ : mat version, flatform, creation date
# __version__ : file version
# __globals__
# SessionData : mat_struct
if 'SessionData' in mat_file.keys():
return mat_file['SessionData']
else:
raise FileNotFoundError('.mat file missing SessionData'
+ f'field at: {mat_filepath}') |
djarchive has a bucket for bpod data: |
ttngu207
pushed a commit
to ttngu207/element-event
that referenced
this issue
Apr 5, 2023
modify BehaviorTimeSeries table
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
MATLAB is the only environment officially supported by Bpod developers. SciPy has a lot of support for loading mat files. In the current draft, SciPy is used to import Bpod .mat files as embedded dictionaries. Micheal Wulf shared the Bpod files that are currently available via djarchive as
workflow-trial
, revision 0.0.0b1. They were shared as a diverse set of examples. Underelement_trial/readers/
, there is a reader draft in need of further development,Bpod.py
, and eventual inclusion inelement_interface
. It handles general ingestion for fields that are consistent across examples, but there are many differences across files. A fully realized loader may need to pull directly from Bpod 'raw' fields to reconstruct the experiment, as many other fields are organized differently across trials.Ecosystem: The SanWorks team (git repositories here) offers no offical python support, suggesting instead that users export to JSON. The PyBpod project (github, docs) offers a python-based GUI alternative for running Bpod hardware. So far as I could tell, they do not offer any useful ingestion functions we would want to incorporate.
The text was updated successfully, but these errors were encountered: