#NEWLINE# def test( data_path ) : #NEWLINE# #INDENT# folder_data = [ 'mt/' , 't2/' , 'dmri/' ] #NEWLINE# file_data = [ 'mtr.nii.gz' , 't2.nii.gz' , 'dmri.nii.gz' ] #NEWLINE# output = '' #NEWLINE# status = 0 #NEWLINE# pad = 2 #NEWLINE# cmd = ( ( ( ( ( ( 'sct_image -i ' + data_path ) + folder_data [ 0 ] ) + file_data [ 0 ] ) + ' -o test.nii.gz' ) + ' -pad 0,0,' ) + str ( pad ) ) #NEWLINE# output += ( ( '\n====================================================================================================\n' + cmd ) + '\n====================================================================================================\n\n' ) #NEWLINE# ( s0 , o0 ) = commands . getstatusoutput ( cmd ) #NEWLINE# status += s0 #NEWLINE# output += o0 #NEWLINE# cmd = ( ( ( ( 'sct_image -i ' + data_path ) + folder_data [ 1 ] ) + file_data [ 1 ] ) + ' -getorient ' ) #NEWLINE# output += ( ( '\n====================================================================================================\n' + cmd ) + '\n====================================================================================================\n\n' ) #NEWLINE# ( s1 , o1 ) = commands . getstatusoutput ( cmd ) #NEWLINE# status += s1 #NEWLINE# output += o1 #NEWLINE# from time import sleep #NEWLINE# sleep ( 1 ) #NEWLINE# cmd = ( ( ( ( 'sct_image -i ' + data_path ) + folder_data [ 2 ] ) + file_data [ 2 ] ) + ' -getorient ' ) #NEWLINE# output += ( ( '\n====================================================================================================\n' + cmd ) + '\n====================================================================================================\n\n' ) #NEWLINE# ( s2 , o2 ) = commands . getstatusoutput ( cmd ) #NEWLINE# status += s2 #NEWLINE# output += o2 #NEWLINE# cmd = ( ( ( ( 'sct_image -i ' + data_path ) + folder_data [ 2 ] ) + file_data [ 2 ] ) + ' -split t' ) #NEWLINE# output += ( ( '\n====================================================================================================\n' + cmd ) + '\n====================================================================================================\n\n' ) #NEWLINE# ( s3 , o3 ) = commands . getstatusoutput ( cmd ) #NEWLINE# status += s3 #NEWLINE# output += o3 #NEWLINE# l = file_data [ 2 ] . split ( '.' ) #NEWLINE# file_name = l [ 0 ] #NEWLINE# ext = ( '.' + '.' . join ( l [ 1 : ] ) ) #NEWLINE# dmri_t_slices = [ ( ( ( ( ( data_path + folder_data [ 2 ] ) + file_name ) + '_T' ) + str ( i ) . zfill ( 4 ) ) + ext ) for i in range ( 7 ) ] #NEWLINE# input_concat = ',' . join ( dmri_t_slices ) #NEWLINE# cmd = ( ( 'sct_image -i ' + input_concat ) + ' -concat t -o dmri_concat.nii.gz' ) #NEWLINE# output += ( ( '\n====================================================================================================\n' + cmd ) + '\n====================================================================================================\n\n' ) #NEWLINE# ( s4 , o4 ) = commands . getstatusoutput ( cmd ) #NEWLINE# status += s4 #NEWLINE# output += o4 #NEWLINE# if ( s0 == 0 ) : #NEWLINE# #INDENT# from msct_image import Image #NEWLINE# ( nx , ny , nz , nt , px , py , pz , pt ) = Image ( ( ( data_path + folder_data [ 0 ] ) + file_data [ 0 ] ) ) . dim #NEWLINE# ( nx2 , ny2 , nz2 , nt2 , px2 , py2 , pz2 , pt2 ) = Image ( 'test.nii.gz' ) . dim #NEWLINE# if ( nz2 != ( nz + ( 2 * pad ) ) ) : #NEWLINE# #INDENT# status = 99 #NEWLINE# output += "\nResulting pad image's dimension differs from expected:\n" #NEWLINE# output += ( ( ( ( ( ( 'dim : ' + str ( nx2 ) ) + 'x' ) + str ( ny2 ) ) + 'x' ) + str ( nz2 ) ) + '\n' ) #NEWLINE# output += ( ( ( ( ( ( 'expected : ' + str ( nx ) ) + 'x' ) + str ( ny ) ) + 'x' ) + str ( ( nz + ( 2 * pad ) ) ) ) + '\n' ) #NEWLINE# #UNINDENT# #UNINDENT# '\n    if s1 == 0:\n        if o1 != "AIL":\n            status = 99\n            output += \'\nResulting orientation differs from expected:\n\'                       \'orientation: \'+o1+\'\n\'                       \'expected: AIL\'\n    if s2 == 0:\n        if o2 != "RPI":\n            status = 99\n            output += \'\nResulting orientation differs from expected:\n\'                       \'orientation: \'+o2+\'\n\'                       \'expected: RPI\'\n    ' #NEWLINE# if ( s3 == 0 ) : #NEWLINE# #INDENT# from msct_image import Image #NEWLINE# from numpy import sum #NEWLINE# threshold = 0.001 #NEWLINE# ref = Image ( dmri_t_slices [ 0 ] ) #NEWLINE# new = Image ( ( ( file_name + '_T0000' ) + ext ) ) #NEWLINE# diff = ( ref . data - new . data ) #NEWLINE# if ( sum ( diff ) > threshold ) : #NEWLINE# #INDENT# status = 99 #NEWLINE# output += '\nResulting split image differs from gold-standard.\n' #NEWLINE# #UNINDENT# #UNINDENT# if ( s4 == 0 ) : #NEWLINE# #INDENT# from msct_image import Image #NEWLINE# from numpy import sum #NEWLINE# threshold = 0.001 #NEWLINE# ref = Image ( ( ( data_path + folder_data [ 2 ] ) + pt2 [ 2 ] ) ) #NEWLINE# new = Image ( 'dmri_concat.nii.gz' ) #NEWLINE# diff = ( ref . data - new . data ) #NEWLINE# if ( sum ( diff ) > threshold ) : #NEWLINE# #INDENT# status = 99 #NEWLINE# output += '\nResulting concatenated image differs from gold-standard (original dmri image).\n' #NEWLINE# #UNINDENT# #UNINDENT# return ( status , output )