使用Psychopy刺激软件与EGI脑电设备连接
平均阅读时长为 10分钟
大家好,我是陈锐。
今天分享内容来源官网教程参考已测试,内容仅供参考学习分享。
第一步:安装 EGI NetStation Python 库
使用PsychoPy版本2022.1.3 或最新版本,则软件自带有该egi-netstation库,可直接使用。如无,则需要使用 终端命令安装 egi-NetStation 库。
第二步:将代码组件添加到Builder 实验
与NetStation EEG脑电进行通信,将一些 Python 代码组件添加到实验中,即可完成。
首先,在Instructions中添加一个代码组件,如下图:
在Begin Experiment选项卡中,复制并粘贴以下代码,该代码将导入egi-netstation库并匹配IP地址进行通信,按照所连接的放大器型号,修改其ip地址:
#导入库egi-netstation
fromegi_pynetstation.NetStationimportNetStation
#设置苹果主机IP
IP_ns='10.10.10.42'
#如果是NA300放大器,则设置为42;NA400/410放大器,则设置为51
IP_amp='10.10.10.51'
#配置ECI端口,默认为55513,具体可参考采集软件上的port
port_ns=55513
#开始记录和发送开始标记STRT
eci_client=NetStation(IP_ns, port_ns)
eci_client.connect(ntp_ip=IP_amp)
eci_client.begin_rec()
eci_client.send_event(event_type='STRT', start=0.0)
fromegi_pynetstation.NetStationimportNetStation
#设置苹果主机IP
IP_ns='10.10.10.42'
#如果是NA300放大器,则设置为42;NA400/410放大器,则设置为51
IP_amp='10.10.10.51'
#配置ECI端口,默认为55513,具体可参考采集软件上的port
port_ns=55513
#开始记录和发送开始标记STRT
eci_client=NetStation(IP_ns, port_ns)
eci_client.connect(ntp_ip=IP_amp)
eci_client.begin_rec()
eci_client.send_event(event_type='STRT', start=0.0)
然后,将以下代码输入带trial层中Begin Routine中,表示在试次开始前还没有触发值。
triggerSent = False
接着在同一代码组件的Each Frame中,添加以下代码以在呈现刺激时发送不超过四个字符的触发器。这里的
.status
属性是检查我们的刺激是否已经开始,如果已经开始,PsychoPy 会将触发器发送到 EGI NetStation。请注意,PsychoPy 中的大多数组件都具有该.status
属性,因此您可以轻松地调整此代码,例如,在按下响应键时发送触发器:#发送标记到netstation,需要四字符编码,如"code"
#如需条件分类,则可以设置为文件调用即可
iftext_stim.status==STARTEDandnottriggerSent: #表示text_stim(根据自己的实验名称修改)的.status状态已经开始并且不是False的,那么就发送下面的标记
win.callOnFlip(eci_client.send_event, event_type='code') #发送标记,同步每屏的刷新
triggerSent=True#写上这句,表示已发送trigger。
#如需条件分类,则可以设置为文件调用即可
iftext_stim.status==STARTEDandnottriggerSent: #表示text_stim(根据自己的实验名称修改)的.status状态已经开始并且不是False的,那么就发送下面的标记
win.callOnFlip(eci_client.send_event, event_type='code') #发送标记,同步每屏的刷新
triggerSent=True#写上这句,表示已发送trigger。
- 最后,在实验结束时,添加代码以下内容:#停止记录,断开连接
eci_client.end_rec()
eci_client.disconnect()
除此之外呢,如使用的Psychopy code,则直接使用以下代码即可
fromegi_pynetstationimportNetStation
# Set an IP address for the computer running NetStation as an IPv4 string
IP_ns='10.10.10.42'
# Set a port that NetStation will be listening to as an integer
port_ns=55513
ns=NetStation(IP_ns, port_ns)
# Set an NTP clock server (the amplifier) address as an IPv4 string
IP_amp='10.10.10.51'
ns.connect(ntp_ip=IP_amp)
# Do whatever setup for your experiment here...
# Begin recording
ns.begin_rec()
# You can now send events; this one just says "HIYA" and automatically
# marks the time for you
ns.send_event(event_type="HIYA")
# You can include a data dictionary; perhaps you have a dog stimulus
my_data= {"dogs": "fido"}
# Send this data with the event type of "STIM"
ns.send_event(event_type="STIM", data=my_data)
# With the experiment concluded, you can end the recording
ns.end_rec()
# You'll want to disconnect the amplifier when your program is done
ns.disconnect()
# Set an IP address for the computer running NetStation as an IPv4 string
IP_ns='10.10.10.42'
# Set a port that NetStation will be listening to as an integer
port_ns=55513
ns=NetStation(IP_ns, port_ns)
# Set an NTP clock server (the amplifier) address as an IPv4 string
IP_amp='10.10.10.51'
ns.connect(ntp_ip=IP_amp)
# Do whatever setup for your experiment here...
# Begin recording
ns.begin_rec()
# You can now send events; this one just says "HIYA" and automatically
# marks the time for you
ns.send_event(event_type="HIYA")
# You can include a data dictionary; perhaps you have a dog stimulus
my_data= {"dogs": "fido"}
# Send this data with the event type of "STIM"
ns.send_event(event_type="STIM", data=my_data)
# With the experiment concluded, you can end the recording
ns.end_rec()
# You'll want to disconnect the amplifier when your program is done
ns.disconnect()
参考网址:
https://github.com/nimh-sfim/egi-pynetstation
https://egi-pynetstation.readthedocs.io/en/latest/
https://psychopy.org/hardware/egiNetStation.html#egi
谢谢大家观看,如有帮助,来个喜欢或者关注吧!
本文作者:陈锐
本文仅供学习参考,有任何疑问及建议,扫描以下公众号二维码添加交流:
更多学习内容,仅在知识星球发布:
关键词
版本
地址
设备
软件
内容
最新评论
推荐文章
作者最新文章
你可能感兴趣的文章
Copyright Disclaimer: The copyright of contents (including texts, images, videos and audios) posted above belong to the User who shared or the third-party website which the User shared from. If you found your copyright have been infringed, please send a DMCA takedown notice to [email protected]. For more detail of the source, please click on the button "Read Original Post" below. For other communications, please send to [email protected].
版权声明:以上内容为用户推荐收藏至CareerEngine平台,其内容(含文字、图片、视频、音频等)及知识版权均属用户或用户转发自的第三方网站,如涉嫌侵权,请通知[email protected]进行信息删除。如需查看信息来源,请点击“查看原文”。如需洽谈其它事宜,请联系[email protected]。
版权声明:以上内容为用户推荐收藏至CareerEngine平台,其内容(含文字、图片、视频、音频等)及知识版权均属用户或用户转发自的第三方网站,如涉嫌侵权,请通知[email protected]进行信息删除。如需查看信息来源,请点击“查看原文”。如需洽谈其它事宜,请联系[email protected]。