Skip to content

Commit 318e16a

Browse files
committed
Added median tSNR calculation.
1 parent c0d3ec2 commit 318e16a

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

qap/temporal_qc.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,14 @@ def mean_quality_timepoints(*args, **kwrds):
173173
qualities = quality_timepoints(*args, **kwrds)
174174
mean_qualities = np.mean(qualities)
175175
return mean_qualities
176+
177+
def median_tsnr(func_data, mask_data):
178+
""" Calculates median of temporal Signal to Noise ratio within a mask"""
179+
180+
data_std = func_data.std(axis=0)
181+
# exclude voxels with no variance
182+
std_mask = (data_std !=0)
183+
tsnr = func_data.mean(axis=0)[std_mask]/data_std[std_mask]
184+
print tsnr.shape
185+
186+
return np.median(tsnr)

usage.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ You should know the phase encoding direction to decide if you want to use `func_
129129
* **Mean Fractional Displacement - Jenkinson [func_mean_fd]:** A measure of subject head motion, which compares the motion between the current and previous volumes. This is calculated by summing the absolute value of displacement changes in the x, y and z directions and rotational changes about those three axes. The rotational changes are given distance values based on the changes across the surface of a 50mm radius sphere [^5][^8]. _Uses functional time-series._
130130
* **Number of volumes with FD greater than 0.2mm [func_num_fd]:** _Uses functional time-series._
131131
* **Percent of volumes with FD greater than 0.2mm [func_perc_fd]:** _Uses functional time-series._
132+
* **Median temporal Signal to Noise ratio [tsnr]:** _Uses functional time-series and a mask._
132133

133134

134135
### Standardized DVARS
@@ -158,6 +159,13 @@ Here we describe computing `mean_fd`, `num_fd`, and `perc_fd`. This requires tha
158159

159160
from qap import summarize_fd
160161
mean_fd, num_fd, perc_fd = summarize_fd(motion_matrix_file, threshold=0.2)
162+
163+
### tSNR
164+
165+
tSNR is a ratio of signal (mean across time) and noise (standard deviation around the mean across time) averaged over all voxels withing the specified mask
166+
167+
from qap import median_tsnr
168+
tsnr = median_tsnr(func_data, func_mask_data)
161169

162170

163171
## Determining Outliers

0 commit comments

Comments
 (0)