-
Notifications
You must be signed in to change notification settings - Fork 18
Description
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. Under element_trial/readers/, there is a reader draft in need of further development, Bpod.py, and eventual inclusion in element_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.
from workflow_trial.pipeline import subject, session, trial
from workflow_trial.ingest import ingest_subjects, ingest_sessions
ingest_subjects(); _ = ingest_sessions()
# Download from djarchive, set root trial directory in workflow
from djarchive_client import client; c = client()
c.download('workflow-trial', '0.0.0b1', '<local-path>', create_target=True)
def get_trial_root_dir(): # also defined in workflow_trial.paths
return '<local-path>'
# List of files
bpods_filepath=[
"Bpod_Behavior_Data/BalbC_Ph_W1_LH_Randdelay_changeover_Aug08_2021_Session1.mat",
"Bpod_Behavior_Data/1119A_3_LoomingThreat_Dec26_2019_Session1.mat",
"Bpod_Behavior_Data_and_TrialEvents/NeuroPixels/TQ03_Dual2AFC_Jun18_2021_Session1.mat",
"Bpod_Behavior_Data_and_TrialEvents/NeuroPixels/TrialEvents.mat",
"Bpod_Behavior_Data_and_TrialEvents/Neuralynx/TP24_Dual2AFC_Feb12_2019_Session1.mat",
"Bpod_Behavior_Data_and_TrialEvents/Neuralynx/TrialEvents.mat"]
import scipy.io as spio
def load_bpod_matfile(matlab_filepath):
"""Loading routine for behavioral file, bpod .mat """
SessionData = spio.loadmat(matlab_filepath.as_posix(),
squeeze_me=True,simplify_cells=True,
struct_as_record=False)['SessionData']
return SessionData # functionally a dictionary
# See how files differ
for f in bpods_filepath:
filepath = find_full_path(get_trial_root_dir(),f)
print(str(filepath).split("/")[-1])
data = load_bpod_matfile(filepath)
try: print(data['RawEvents']['Trial'][0]) # replace with other fields
except KeyError: pass