Last active
September 20, 2022 10:12
-
-
Save sdres/7a8e1831715f183750eaefbc9d3ac37d to your computer and use it in GitHub Desktop.
Computes T1w image in EPI-space from motion-corrected 'nulled' and 'notnulled' timeseries as acquired with SS-SI VASO.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Computes T1w image in EPI-space from motion-corrected 'nulled' and 'notnulled' | |
timeseries as acquired with SS-SI VASO. | |
''' | |
import numpy as np | |
import nibabel as nb | |
from scipy import signal | |
def computeT1w(nulledFile, notnulledFile, detrend = False): | |
''' | |
Takes nulled and notnulled files as input and computes T1w image | |
in EPI space. Returns array instead of saving a file to allow different | |
naming conventions. | |
''' | |
# Load nulled motion corrected timeseries | |
nulledNii = nb.load(nulledFile) | |
nulledData = nulledNii.get_fdata() | |
# Load notnulled motion corrected timeseries | |
notnulledNii = nb.load(notnulledFile) | |
notnulledData = notnulledNii.get_fdata() | |
# Concatenate nulled and notnulled timeseries | |
combined = np.concatenate((notnulledData,nulledData), axis=3) | |
if detrend == True: | |
# Detrend before std. dev. calculation | |
combinedDemean = signal.detrend(combined, axis = 3, type = 'constant') | |
combinedDetrend = signal.detrend(combinedDemean, axis = 3, type = 'linear') | |
stdDev = np.std(combinedDetrend, axis = 3) | |
else: | |
stdDev = np.std(combined, axis = 3) | |
#Compute mean | |
mean = np.mean(combined, axis = 3) | |
# Compute variation | |
cvar = stdDev/mean | |
# Take inverse | |
cvarInv = 1/cvar | |
return cvarInv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment