<s> import getopt <EOL> import os <EOL> import sys <EOL> import time <EOL> import sct_utils as sct <EOL> from sct_image import set_orientation <EOL> from shutil import move <EOL> from numpy import append , insert , nonzero , transpose , array <EOL> from nibabel import load , Nifti1Image , save <EOL> from scipy import ndimage <EOL> from copy import copy <EOL> from sct_convert import convert <EOL> from msct_parser import Parser <EOL> class Param : <EOL> def __init__ ( self ) : <EOL> self . remove_temp_files = <NUM_LIT:1> <EOL> self . verbose = <NUM_LIT:1> <EOL> def main ( ) : <EOL> fname_anat = '<STR_LIT>' <EOL> fname_centerline = '<STR_LIT>' <EOL> sigma = <NUM_LIT:3> <EOL> remove_temp_files = param . remove_temp_files <EOL> verbose = param . verbose <EOL> start_time = time . time ( ) <EOL> parser = get_parser ( ) <EOL> arguments = parser . parse ( sys . argv [ <NUM_LIT:1> : ] ) <EOL> fname_anat = arguments [ '<STR_LIT>' ] <EOL> fname_centerline = arguments [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' in arguments : <EOL> sigma = arguments [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' in arguments : <EOL> remove_temp_files = int ( arguments [ '<STR_LIT>' ] ) <EOL> if '<STR_LIT>' in arguments : <EOL> verbose = int ( arguments [ '<STR_LIT>' ] ) <EOL> print '<STR_LIT>' <EOL> print '<STR_LIT>' + fname_anat <EOL> print '<STR_LIT>' + fname_centerline <EOL> print '<STR_LIT>' + str ( sigma ) <EOL> print '<STR_LIT>' + str ( verbose ) <EOL> from msct_image import Image <EOL> nx , ny , nz , nt , px , py , pz , pt = Image ( fname_anat ) . dim <EOL> dim = <NUM_LIT:4> <EOL> if nt == <NUM_LIT:1> : <EOL> dim = <NUM_LIT:3> <EOL> if nz == <NUM_LIT:1> : <EOL> dim = <NUM_LIT:2> <EOL> if dim == <NUM_LIT:4> : <EOL> sct . printv ( '<STR_LIT>' <EOL> '<STR_LIT>' + fname_anat + '<STR_LIT>' + fname_anat , verbose , '<STR_LIT>' ) <EOL> sct . printv ( '<STR_LIT>' , verbose , '<STR_LIT:error>' ) <EOL> path_anat , file_anat , ext_anat = sct . extract_fname ( fname_anat ) <EOL> path_centerline , file_centerline , ext_centerline = sct . extract_fname ( fname_centerline ) <EOL> sct . printv ( '<STR_LIT>' , verbose ) <EOL> path_tmp = sct . slash_at_the_end ( '<STR_LIT>' + time . strftime ( "<STR_LIT>" ) , <NUM_LIT:1> ) <EOL> sct . run ( '<STR_LIT>' + path_tmp , verbose ) <EOL> sct . printv ( '<STR_LIT>' , verbose ) <EOL> sct . run ( '<STR_LIT>' + fname_anat + '<STR_LIT:U+0020>' + path_tmp + '<STR_LIT>' + ext_anat , verbose ) <EOL> sct . run ( '<STR_LIT>' + fname_centerline + '<STR_LIT:U+0020>' + path_tmp + '<STR_LIT>' + ext_centerline , verbose ) <EOL> os . chdir ( path_tmp ) <EOL> convert ( '<STR_LIT>' + ext_anat , '<STR_LIT>' ) <EOL> convert ( '<STR_LIT>' + ext_centerline , '<STR_LIT>' ) <EOL> print '<STR_LIT>' <EOL> fname_anat_rpi = set_orientation ( '<STR_LIT>' , '<STR_LIT>' , filename = True ) <EOL> move ( fname_anat_rpi , '<STR_LIT>' ) <EOL> print '<STR_LIT>' <EOL> fname_centerline_rpi = set_orientation ( '<STR_LIT>' , '<STR_LIT>' , filename = True ) <EOL> move ( fname_centerline_rpi , '<STR_LIT>' ) <EOL> print '<STR_LIT>' <EOL> sct . run ( '<STR_LIT>' + str ( verbose ) ) <EOL> print '<STR_LIT>' <EOL> sct . run ( '<STR_LIT>' + str ( sigma ) + '<STR_LIT>' , verbose ) <EOL> print '<STR_LIT>' <EOL> sct . run ( '<STR_LIT>' , verbose ) <EOL> os . chdir ( '<STR_LIT:..>' ) <EOL> print '<STR_LIT>' <EOL> sct . generate_output_file ( path_tmp + '<STR_LIT>' , file_anat + '<STR_LIT>' + ext_anat ) <EOL> if remove_temp_files == <NUM_LIT:1> : <EOL> print ( '<STR_LIT>' ) <EOL> sct . run ( '<STR_LIT>' + path_tmp ) <EOL> elapsed_time = time . time ( ) - start_time <EOL> print '<STR_LIT>' + str ( int ( round ( elapsed_time ) ) ) + '<STR_LIT>' <EOL> sct . printv ( '<STR_LIT>' , verbose ) <EOL> sct . printv ( '<STR_LIT>' + file_anat + '<STR_LIT:U+0020>' + file_anat + '<STR_LIT>' , verbose , '<STR_LIT:info>' ) <EOL> def get_parser ( ) : <EOL> parser = Parser ( __file__ ) <EOL> parser . usage . set_description ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> parser . add_option ( name = "<STR_LIT>" , <EOL> type_value = "<STR_LIT:file>" , <EOL> description = "<STR_LIT>" , <EOL> mandatory = True , <EOL> example = '<STR_LIT>' ) <EOL> parser . add_option ( name = "<STR_LIT>" , <EOL> type_value = "<STR_LIT:file>" , <EOL> description = "<STR_LIT>" , <EOL> mandatory = True , <EOL> example = '<STR_LIT>' ) <EOL> parser . add_option ( name = "<STR_LIT:-c>" , <EOL> type_value = None , <EOL> description = "<STR_LIT>" , <EOL> mandatory = False , <EOL> deprecated_by = '<STR_LIT>' ) <EOL> parser . add_option ( name = "<STR_LIT>" , <EOL> type_value = "<STR_LIT:int>" , <EOL> description = "<STR_LIT>" , <EOL> mandatory = False , <EOL> default_value = <NUM_LIT:3> , <EOL> example = '<STR_LIT:2>' ) <EOL> parser . usage . addSection ( '<STR_LIT>' ) <EOL> parser . add_option ( name = "<STR_LIT>" , <EOL> type_value = "<STR_LIT>" , <EOL> description = '<STR_LIT>' , <EOL> mandatory = False , <EOL> default_value = '<STR_LIT:1>' , <EOL> example = [ '<STR_LIT:0>' , '<STR_LIT:1>' ] ) <EOL> parser . add_option ( name = "<STR_LIT>" , <EOL> type_value = '<STR_LIT>' , <EOL> description = "<STR_LIT>" , <EOL> mandatory = False , <EOL> example = [ '<STR_LIT:0>' , '<STR_LIT:1>' , '<STR_LIT:2>' ] , <EOL> default_value = '<STR_LIT:1>' ) <EOL> return parser <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> param = Param ( ) <EOL> param_default = Param ( ) <EOL> main ( ) </s>
