Load Bpod data with Python

Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Load Bpod data with Python
#1
Hi Josh,
 
I am trying to load the Bpod SessionData with Python notebook. I could load the first level of the struct data. But I do not know how to extract the raw event and state data (second level of struct data) from the RawEvents (below is the notebook code that I tried). Is there any convenient way to do that?


Code:
import numpy as np
import matplotlib.pyplot as plt
import glob
from scipy.io import loadmat

filename = 'C:/Users/xiaox/Desktop/Python_learning/Data'
filelist = glob.glob(filename + "/*.mat")
print(filelist)

mat = loadmat(filelist[0])  # mat.keys()
SessionData = mat['SessionData']
print(SessionData.dtype)

TrialTypes = SessionData[0,0]['TrialTypes']
print(TrialTypes)
ImagingFlag = SessionData[0,0]['ImagingFlag']
print(ImagingFlag)
RunSpeed = SessionData[0,0]['RunSpeed']
print(RunSpeed[0,0])

## How to extract raw event data (such as Wire1High) and state data (such as TrialStart) from RawEvents?
RawEvents = SessionData[0,0]['RawEvents']
print(RawEvents[0,0])

 
Thanks,
Xiong
Reply
#2
Hi Xiong,


If the data was collected with MATLAB, you should be able to have MATLAB export the data struct to JSON, and then decode it in Python.


-Josh
Reply
#3
(08-07-2019, 04:20 PM)Josh Wrote: Hi Xiong,


If the data was collected with MATLAB, you should be able to have MATLAB export the data struct to JSON, and then decode it in Python.


-Josh

Hi Josh,

This method worked very well. Thanks a lot!

Xiong
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)