功能磁共振成像的时间序列方差分析
项目描述
茨瓦拉纳
关于
Tsvarana对 fMRI 数据执行 (t)time(s)eries (var)iance (ana)lysis,用 Python 3 编写。它是一种诊断工具,旨在检测 MRI 信号中的异常波动,您可能希望将其从进一步分析中删除.
Tsvarana 背后的逻辑基于一个简单的观察:由非生理噪声源引起的 fMRI 数据中的异常信号强度与时间序列中的中值信号强度有很大差异。精心设计的 fMRI 实验将引发 1-4% 信号变化量级的 BOLD 信号波动,超出此范围的变化可能归因于非生理噪声源。因此,通过计算每个时间点的信号强度与中值信号强度之间的体素方差,我们可以检测异常体素、切片或体积,以便进一步检查或去除。
Tsvarana 是tsdiffana的精神继承者,作者Matthew Brett. 这两种工具在一些重要方面有所不同。首先,通过将时域中的信号方差与中值信号幅度进行比较来进行信号评估。这种方法比滑动窗口方法更可取,因为它对于跨越连续时间点的持续异常强度的情况更加稳健。其次,时间点删除或“擦洗”是迭代执行的。迭代算法定义如下;(a) 根据用户定义的最大方差阈值检查所有时间点到中位数的方差,(b) 删除所有未通过测试的时间点,(c) 将删除的时间点替换为前一个和后一个保留时间点的平均值,其中可用的。重复步骤 (a)-(c),直到不再标记要删除的时间点。
Tsvarana 是实验性软件,不提供任何形式的保证。
安装
安装pip
pip install tsvarana
Tsvarana 具有以下依赖项:NumPy、SciPy、Bokeh、Nibabel
用法
有两种使用 Tsvarana 的方法。要执行基本的时间序列方差分析和清理,您可以从 shell 调用 tsvarana
python -m tsvarana --data <4d_nifti>
或者,您可以在 Python 环境中使用 tsvarana 库
import tsvarana
请参阅下面的分步教程。
教程
# Load library
import tsvarana
# Start by loading a 4D BOLD timeseries to the workspace. We will use the nibabel library for this
# This example dataset contains (x,y,z,t) dimensions
import nibabel as nib
header = nib.load('my_4D_data.nii.gz')
data = header.get_fdata()
# Define a variance analysis object
varana = tsvarana.classes.varana()
# First, we will define the spatial unit. Variance will be calculated at the specified spatial level,
# which can be 'voxel', 'slice' or 'volume'. If slice is selected, you must specify the dimension
# axis along which slices are taken
# For our example dataset with (x,y,z,t) dimensions, we'll pick slices along the z dimension
varana.spatial_unit = 'slice'
varana.slice_axis = 2
# We can also modify the axis along which time is stored
# In our example of (x,y,z,t) data, that will be the 3rd axis
varana.time_axis = 3
# Next, define the variance threshold, expressed in normalised variance units
# A value in the range of 5-10 is a reasonable starting point for fMRI data
# Note this threshold must be selected while considering the nature of your data acquisition
# protocol, and the type of signal abnormalities you wish to detect
varana.var_threshold = 5
# Perform diagnostics
# Calculate the timepoint-to-median variance using the settings specified above, and compare the
# empirical normalised variance against the previously-specified variance threshold
varana.detect(data)
# Plot the resulting variance diagnostics
tsvarana.plot_diagnostic(varana, show=True)
# Perform iterative scrubbing
# This step iterates the timepoint removal algorithm, until no timepoints display normalised
# variance-to-median above the specified threshold. Note that timepoints removed are replaced
# with the mean of the first valid preceeding and first valid following timepoint. If ony one
# is valid, a copy of that timepoint is used for replacement
varana.scrub_iterative(data)
# Plot every step of the diagnostic variance calculation
# This will create a HTML page, containing one figure for each iteration pass
tsvarana.plot_diagnostic(varana, outfile='variance.html')
# Plot every step of the binary thresholding
# As above, This will make one figure for each iteration pass
tsvarana.plot_regressor(varana, outfile='regressors.html')
# We can also obtain a regressor matrix, with all timepoints excluded flagged as 1s and timepoints
# that were never excluded as 0s
regressor = varana.get_final_regressor()
# Finally, we pull out the scrubbed timeseries data, and save it to a NIFTI file
data_scrub = varana.get_data_scrub()
img = nib.Nifti1Image(data_scrub, header.affine)
nib.save(img, 'my_scrubbed_data.nii.gz')
发展
Tsvarana 由Ivan Alvarez创建和维护。要查看代码或报告错误,请访问GitHub 存储库。
项目详情
下载文件
下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。