MNE官网解读文章《Annotating continuous data》(https://mne.tools/stable/auto_tutorials/raw/30_annotate_raw.html?highlight=annotation,以下简称《文章》)

说明:本博客作为个人学习mne和发现和处理问题的记录

按照《文章》指导,本人编写代码如下——

import os
from datetime import timedelta
import mnesample_data_folder = mne.datasets.sample.data_path()
sample_data_raw_file = os.path.join(sample_data_folder, 'MEG', 'sample','sample_audvis_raw.fif')
raw = mne.io.read_raw_fif(sample_data_raw_file, verbose=False)
raw.crop(tmax=60).load_data()my_annot = mne.Annotations(onset=[3, 5, 7],  # in secondsduration=[1, 0.5, 0.25],  # in seconds, toodescription=['AAA', 'BBB', 'CCC'])
print(my_annot)raw.set_annotations(my_annot)
print(raw.annotations)# convert meas_date (a tuple of seconds, microseconds) into a float:
meas_date = raw.info['meas_date']
orig_time = raw.annotations.orig_time
print(meas_date)
print(meas_date == orig_time)time_of_first_sample = raw.first_samp / raw.info['sfreq']
print(time_of_first_sample)  # 第一个样本时间
print(my_annot.onset + time_of_first_sample)
print(raw.annotations.onset)time_format = '%Y-%m-%d %H:%M:%S.%f'
# timedelta(seconds=50)) 这里添加了长达50s的时间戳,即在meas_date基础上往后延了50s
new_orig_time = (meas_date + timedelta(seconds=50)).strftime(time_format)
print(new_orig_time)later_annot = mne.Annotations(onset=[1, 2, 5],duration=[1, 0.5, 0.25],description=['DDD', 'EEE', 'FFF'],orig_time=new_orig_time)
import matplotlib.pyplot as plt
raw2 = raw.copy().set_annotations(later_annot)
print(later_annot.onset)
print(raw2.annotations.onset)
print(raw2.info['meas_date'])
fig = raw2.plot()
plt.show()fig = raw.plot(start=2, duration=6)
# plt.show()fig.canvas.key_press_event('a')
plt.show()
interactive_annot = raw.annotations  # 这里为了不影响原row对象,使用官网提示代raw3 = raw.copy().set_annotations(interactive_annot)
fig = raw3.plot()
plt.show()new_annot = mne.Annotations(onset=3.75, duration=0.75, description='AAA')
raw.set_annotations(my_annot + new_annot)
raw.plot(start=2, duration=6)
plt.show()print(raw.annotations[0])       # just the first annotation
print(raw.annotations[:2])      # the first two annotations
print(raw.annotations[(3, 2)])  # the fourth and third annotationsfor ann in raw.annotations:descr = ann['description']start = ann['onset']end = ann['onset'] + ann['duration']print("'{}' goes from {} to {}".format(descr, start, end))# later_annot WILL be changed, because we're modifying the first element of# later_annot.onset directly:later_annot.onset[0] = 99# later_annot WILL NOT be changed, because later_annot[0] returns a copy# before the 'onset' field is changed:later_annot[0]['onset'] = 77print(later_annot[0]['onset'])raw.annotations.save('saved-annotations.csv', overwrite=True)annot_from_file = mne.read_annotations('saved-annotations.csv')print(annot_from_file)

对比官网,多写了以下几行代码:

raw2 = raw.copy().set_annotations(later_annot)
print(later_annot.onset)
print(raw2.annotations.onset)
print(raw2.info['meas_date'])
fig = raw2.plot()
plt.show()fig = raw.plot(start=2, duration=6)
# plt.show()fig.canvas.key_press_event('a')
plt.show()
interactive_annot = raw.annotations  # 这里为了不影响原row对象,使用官网提示代码raw3 = raw.copy().set_annotations(interactive_annot)
fig = raw3.plot()
plt.show()

主要量为了进行对比,不同的annotations对row对象的影响

以下是本次学习过程遇到的问题以及解决输入法——

  1. 问题代码如下:
import os
from datetime import timedelta
import mnesample_data_folder = mne.datasets.sample.data_path()
sample_data_raw_file = os.path.join(sample_data_folder, 'MEG', 'sample','sample_audvis_raw.fif')
raw = mne.io.read_raw_fif(sample_data_raw_file, verbose=False)
raw.crop(tmax=60).load_data()my_annot = mne.Annotations(onset=[3, 5, 7],  # in secondsduration=[1, 0.5, 0.25],  # in seconds, toodescription=['AAA', 'BBB', 'CCC'])
print(my_annot)raw.set_annotations(my_annot)
print(raw.annotations)# convert meas_date (a tuple of seconds, microseconds) into a float:
meas_date = raw.info['meas_date']
orig_time = raw.annotations.orig_time
print(meas_date)
print(meas_date == orig_time)time_of_first_sample = raw.first_samp / raw.info['sfreq']
print(time_of_first_sample)  # 第一个样本时间
print(my_annot.onset + time_of_first_sample)
print(raw.annotations.onset)time_format = '%Y-%m-%d %H:%M:%S.%f'
# timedelta(seconds=50)) 这里添加了长达50s的时间戳,即在meas_date基础上往后延了50s
new_orig_time = (meas_date + timedelta(seconds=50)).strftime(time_format)
print(new_orig_time)later_annot = mne.Annotations(onset=[1, 2, 5],duration=[1, 0.5, 0.25],description=['DDD', 'EEE', 'FFF'],orig_time=new_orig_time)
import matplotlib.pyplot as plt
raw2 = raw.copy().set_annotations(later_annot)
print(later_annot.onset)
print(raw2.annotations.onset)
print(raw2.info['meas_date'])
fig = raw2.plot()
plt.show()fig = raw.plot(start=2, duration=6)
plt.show()fig.canvas.key_press_event('a')
plt.show()
interactive_annot = raw.annotations  # 这里为了不影响原row对象,使用官网提示代raw3 = raw.copy().set_annotations(interactive_annot)
fig = raw3.plot()
plt.show()new_annot = mne.Annotations(onset=3.75, duration=0.75, description='AAA')
raw.set_annotations(my_annot + new_annot)
raw.plot(start=2, duration=6)
plt.show()print(raw.annotations[0])       # just the first annotation
print(raw.annotations[:2])      # the first two annotations
print(raw.annotations[(3, 2)])  # the fourth and third annotationsfor ann in raw.annotations:descr = ann['description']start = ann['onset']end = ann['onset'] + ann['duration']print("'{}' goes from {} to {}".format(descr, start, end))# later_annot WILL be changed, because we're modifying the first element of# later_annot.onset directly:later_annot.onset[0] = 99# later_annot WILL NOT be changed, because later_annot[0] returns a copy# before the 'onset' field is changed:later_annot[0]['onset'] = 77print(later_annot[0]['onset'])raw.annotations.save('saved-annotations.csv', overwrite=True)annot_from_file = mne.read_annotations('saved-annotations.csv')print(annot_from_file)

运行过程中发现无法实现《文章》 中的“Annotating Raw objects interactively”功能,包括删除、添加、修改annotations,想了一会发现这个对annoations的动态交互功能应该是基于python的图层,即plt.show(),但是上面代码中我先手使用了这条代码所以导致“Annotating Raw objects interactively”功能失效,所以将如下代码

fig = raw.plot(start=2, duration=6)
plt.show()fig.canvas.key_press_event('a')
plt.show()

修改为

fig = raw.plot(start=2, duration=6)
plt.show()fig.canvas.key_press_event('a')
plt.show()

即可

注:这里输入好需要add的annotation的descriptionclick“Add new label”button后需要再clidk一下当前plt.plot()输出的图,就能实现add annotation功能了,这个也是琢磨了半天…

MNE官网解读《Annotating continuous data》相关推荐

  1. gateway官网解读(三)

    速度速度速度......老大在催了 本人是一名java架构师, 前人挖坑后人填. 没办法所以抓紧看看官方文档, 主要就是gateway和consul. 也和伙伴们分享个心得.架构不见得真的多牛逼, 但 ...

  2. spring官网解读以及个版本下载地址

    一.spring的官方网址:http://spring.io/ 二.看到这个简洁清新的界面,导航很明确,进入projects whatever the infrastructure needs of ...

  3. gateway官网解读(四)

    这是最后一块了, 要吐了......读官网真的不是一件人干的事情啊,尤其是我这种四级都是磕磕绊绊的人. 读完之后我会产出一篇总结.算是对我, 主要是对我老大有个交代. 9. TLS and SSL 我 ...

  4. MNE溯源fieldtrip官网教程

    MNE溯源fieldtrip官网教程 Introduction 在本教程中,您可以找到有关如何使用最小范数估计进行源重构的信息,以重构单个主题的事件相关字段(MEG).我们将使用预处理教程中描述的数据 ...

  5. 1.3 Quick Start中 Step 7: Use Kafka Connect to import/export data官网剖析(博主推荐)

    不多说,直接上干货! 一切来源于官网 http://kafka.apache.org/documentation/ Step 7: Use Kafka Connect to import/export ...

  6. MySql.Data.dll官网下载

    Mysql.Data.dll官网下载 在项目开发中链接MySQL数据库经常要用到Mysql.Data.dll,网上虽然有很多,但是还是比较信赖官网的 今天就从官网下载一次记录一下过程 1.下载地址 官 ...

  7. 新手学Python之学习官网教程(五: Data Structures)

    文章目录 1. 前言 2. 数据结构 2.1. 列表 2.1.1 将列表作为栈进行使用 2.1.2 将列表作为队列进行使用 2.1.3 列表生成式 2.1.4 嵌套的列表生成式 2.2 del语句 2 ...

  8. 大数据实战之hadoop生态概况和官网文档解读

    本小节 jacky 分享的是: Hadoop 核心的组成模块,依赖于 Hadoop 的其他的生态系统.随着jacky后面逐步的分享,会对本小节 Hadoop 概况中的这些概念有更好的加深与了解. (一 ...

  9. 小马识途营销顾问解读百度官网认证的价值和意义

    近来,有不少小伙伴咨询百度官网认证,一起探讨了百度官网认证的价值,以及标准版和高级版的区别等.小马识途营销顾问总结官网认证算是一种锦上添花,而能够低成本引流拓客的SEO才是雪中送炭. 百度官网认证是什 ...

最新文章

  1. .NET使用OpenSSL生成的pem密钥文件[1024位]
  2. Web Storage
  3. 2013 全国高校计算机等级考试(广西考区)一级笔试试题,全国高校计算机等级考试(广西考区)一级笔试试题卷.PDF...
  4. oracle表设置主键自增长,笔记:oracle表设置主键自增长
  5. The whole Fiori application is wrapped in a big shell xml view
  6. 线程的组成 java 1615387415
  7. JavaScript 设计模式核⼼原理与应⽤实践 之 开篇:前端工程师的成长论
  8. Node+GitLab实现小程序CI系统
  9. JavaWeb学习笔记7--JSP脚本元素、指令元素、动作元素
  10. Spring jar包下载
  11. 红外遥控接收头 的引脚参数
  12. user declined directory sharing Creating xxxx
  13. Win10系统打开共享文件提示没有权限使用网络资源怎么处理?
  14. python鼠标键盘事件代码_Python鼠标键盘事件
  15. 关于PEND SV的引入思考
  16. Keil看不见头文件
  17. 面向对象系列(一)-关键字
  18. toupper在c语言中是什么意思,C语言中toupper 是什么?
  19. 一线互联网大厂面试真题系统收录!轻松拿下offer
  20. 百度红包架构分析与推测

热门文章

  1. 内耗自救指南|5招停止内耗让你逆风翻盘
  2. 网易2019年实习生招聘笔试题
  3. IDEA 运行 springboot运行出现 错误: 找不到或无法加载主类和找不到资源文件类
  4. java登陆密码加密怎么做,Java如何实现密码加密
  5. android 后台运行清理,【Android】App在后台被清理后的终极应对手段——重启应用...
  6. 这些各行各业优秀的ppt模板推荐给大家
  7. 细数WOW里暴雪的“亲儿子”们
  8. 那个卖了房子去大理的姑娘,4个月后又回来了
  9. Seq2Seq and NMT(基于cs224n的最全综述神经机器翻译技术)
  10. 基于MATLAB的求解线性方程组(附完整代码和例题)