解析Open Ephys数据的Python包。
项目描述
pyopenephys
Open Ephys的Python读取器。
安装
为了安装pyopenephys包,打开终端并运行
pip install pyopenephys
如果您想从源代码安装并获取最新更新,克隆仓库并在本地安装
git clone https://github.com/CINPLA/pyopenephys
cd pyopenephys
python setup.py install
# use 'python setup.py develop' to install fixed bugs
基本用法
Pyopenephys允许用户加载使用Open Ephys记录的数据。目前,仅支持二进制(推荐)和openephys(未来版本将不再支持此格式)。
第一步是创建一个File对象。只需传递记录文件夹的路径即可。
import pyopenephys
file = pyopenephys.File("path-to-recording-folder")
文件对象包含不同的实验(对应不同的设置文件),每个实验包含一组记录。
# all experiments
experiments = file.experiments
print(len(experiments))
# recordings of first experiment
experiment = experiments[0]
recordings = experiment.recordings
print(len(experiments))
# access first recording
recording = recordings[0]
实验存储了一些有用的信息
experiment.datetime包含实验创建的起始日期和时间experiment.sig_chain是一个包含信号链中的处理器和节点的字典experiment.settings是一个包含解析后的setting.xml文件的字典experiment.acquisition_system包含用于输入连续数据(例如'Rhythm FPGA')的系统
记录包含实际数据
recording.duration是记录的持续时间(以秒为单位)recording.sample_rate是采样频率(以Hz为单位)recording.analog_signals是AnalogSignal对象的列表,这些对象又具有signal、times(以s为单位)和channel_id字段。recording.events是EventData对象的列表,这些对象又具有times(以s为单位)、channels、channel_states、full_words、processor、node_id和metadata字段。recording.tracking是一个TrackingData对象的列表,每个对象都有times(以秒为单位),x,y,width,height,channels和metadata字段。跟踪数据使用Tracking插件(https://github.com/CINPLA/tracking-plugin)记录,并以 二进制 格式保存(不是 openephys 格式)。recording.spiketrains是一个SpikeTrain对象的列表,每个对象都有times,waveforms,electrode_indices,clusters和metadata字段。Spiketrains 由 Open Ephys GUI 中的Spike Viewer源保存,与Spike Detector和Spike Viewer结合使用。
只需几行代码,就可以轻松解析和访问数据和相关信息
import pyopenephys
import matplotlib.pylab as plt
file = pyopenephys.File("path-to-recording-folder")
# experiment 1 (0 in Python)
experiment = file.experiments[0]
# recording 1
recording = experiment.recordings[0]
print('Duration: ', recording.duration)
print('Sampling Rate: ', recording.sample_rate)
analog_signals = recording.analog_signals
events_data = recording.events
spiketrains = recording.spiketrains
# tracking_data are accessible only using binary format
tracking_data = recording.tracking
# plot analog signal of channel 4
signals = analog_signals[0]
fig_an, ax_an = plt.subplots()
ax_an.plot(signals.times, signals.signal[3])
# plot raster for spike trains
fig_sp, ax_sp = plt.subplots()
for i_s, sp in enumerate(spiketrains):
ax_sp.plot(sp.times, i_s*np.ones(len(sp.times)), '|')
plt.show()
项目详情
下载文件
下载适用于您平台的文件。如果您不确定该选择哪个,请了解更多关于 安装包 的信息。
源分发
pyopenephys-1.2.0.tar.gz (30.4 kB 查看哈希值)
构建分发
pyopenephys-1.2.0-py3-none-any.whl (28.8 kB 查看哈希值)