Last active
December 30, 2015 11:19
-
-
Save chrisgorgo/7821755 to your computer and use it in GitHub Desktop.
A little function to get TR and slicetime order from dicoms
This file contains hidden or 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
def get_tr_and_sliceorder(dicom_files, convention="SPM"): | |
import numpy as np | |
import dcmstack, dicom | |
my_stack = dcmstack.DicomStack() | |
for src_path in dicom_files: | |
src_dcm = dicom.read_file(src_path) | |
my_stack.add_dcm(src_dcm) | |
nii_wrp = my_stack.to_nifti_wrapper() | |
if convention == "french": | |
sliceorder = np.argsort(np.argsort(nii_wrp.meta_ext.get_values('CsaImage.MosaicRefAcqTimes')[0])).tolist() | |
elif convention == "SPM": | |
sliceorder = np.argsort(nii_wrp.meta_ext.get_values('CsaImage.MosaicRefAcqTimes')[0]).tolist() | |
tr = nii_wrp.meta_ext.get_values('RepetitionTime') | |
return tr/1000.,sliceorder |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment