<s> import os . path <EOL> import commands <EOL> from msct_image import Image <EOL> from sct_get_centerline import ind2sub <EOL> import math <EOL> import sct_utils as sct <EOL> import numpy as np <EOL> from pandas import DataFrame <EOL> import sct_get_centerline <EOL> def test ( path_data = '<STR_LIT>' , parameters = '<STR_LIT>' ) : <EOL> if not parameters : <EOL> parameters = '<STR_LIT>' <EOL> folder_data = '<STR_LIT>' <EOL> file_data = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> parser = sct_get_centerline . get_parser ( ) <EOL> dict_param = parser . parse ( parameters . split ( ) , check_file_exist = False ) <EOL> contrast = dict_param [ '<STR_LIT:-c>' ] <EOL> dict_param_with_path = parser . add_path_to_file ( dict_param , path_data , input_file = True ) <EOL> param_with_path = parser . dictionary_to_string ( dict_param_with_path ) <EOL> if not ( os . path . isfile ( dict_param_with_path [ '<STR_LIT>' ] ) ) : <EOL> status = <NUM_LIT:200> <EOL> output = '<STR_LIT>' + path_data <EOL> return status , output , DataFrame ( data = { '<STR_LIT:status>' : status , '<STR_LIT>' : output , '<STR_LIT>' : float ( '<STR_LIT>' ) , '<STR_LIT>' : float ( '<STR_LIT>' ) } , index = [ path_data ] ) <EOL> cmd = '<STR_LIT>' + param_with_path <EOL> status , output = sct . run ( cmd , <NUM_LIT:0> ) <EOL> scad_centerline = Image ( contrast + "<STR_LIT>" ) <EOL> manual_seg = Image ( path_data + folder_data + contrast + '<STR_LIT>' ) <EOL> max_distance = <NUM_LIT:0> <EOL> standard_deviation = <NUM_LIT:0> <EOL> average = <NUM_LIT:0> <EOL> root_mean_square = <NUM_LIT:0> <EOL> overall_distance = <NUM_LIT:0> <EOL> max_distance = <NUM_LIT:0> <EOL> overall_std = <NUM_LIT:0> <EOL> rmse = <NUM_LIT:0> <EOL> try : <EOL> if status == <NUM_LIT:0> : <EOL> manual_seg . change_orientation ( ) <EOL> scad_centerline . change_orientation ( ) <EOL> from scipy . ndimage . measurements import center_of_mass <EOL> iterator = range ( manual_seg . data . shape [ <NUM_LIT:2> ] ) <EOL> com_x = [ <NUM_LIT:0> for ix in iterator ] <EOL> com_y = [ <NUM_LIT:0> for iy in iterator ] <EOL> for iz in iterator : <EOL> com_x [ iz ] , com_y [ iz ] = center_of_mass ( manual_seg . data [ : , : , iz ] ) <EOL> max_distance = { } <EOL> distance = { } <EOL> for iz in range ( <NUM_LIT:1> , scad_centerline . data . shape [ <NUM_LIT:2> ] - <NUM_LIT:1> ) : <EOL> ind1 = np . argmax ( scad_centerline . data [ : , : , iz ] ) <EOL> X , Y = ind2sub ( scad_centerline . data [ : , : , iz ] . shape , ind1 ) <EOL> com_phys = np . array ( manual_seg . transfo_pix2phys ( [ [ com_x [ iz ] , com_y [ iz ] , iz ] ] ) ) <EOL> scad_phys = np . array ( scad_centerline . transfo_pix2phys ( [ [ X , Y , iz ] ] ) ) <EOL> distance_magnitude = np . linalg . norm ( [ com_phys [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] - scad_phys [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , com_phys [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] - scad_phys [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] , <NUM_LIT:0> ] ) <EOL> if math . isnan ( distance_magnitude ) : <EOL> print "<STR_LIT>" <EOL> else : <EOL> distance [ iz ] = distance_magnitude <EOL> max_distance = max ( distance . values ( ) ) <EOL> standard_deviation = np . std ( np . array ( distance . values ( ) ) ) <EOL> average = sum ( distance . values ( ) ) / len ( distance ) <EOL> root_mean_square = np . sqrt ( np . mean ( np . square ( distance . values ( ) ) ) ) <EOL> overall_distance = average <EOL> max_distance = max ( distance . values ( ) ) <EOL> overall_std = standard_deviation <EOL> rmse = root_mean_square <EOL> except Exception , e : <EOL> sct . printv ( "<STR_LIT>" ) <EOL> output = e . message <EOL> result_mse , result_dist_max = rmse , max_distance <EOL> results = DataFrame ( data = { '<STR_LIT:status>' : status , '<STR_LIT>' : output , '<STR_LIT>' : result_mse , '<STR_LIT>' : result_dist_max } , index = [ path_data ] ) <EOL> cmd = '<STR_LIT>' + path_data + folder_data + file_data [ <NUM_LIT:0> ] + '<STR_LIT>' + '<STR_LIT>' + path_data + folder_data + file_data [ <NUM_LIT:2> ] + '<STR_LIT>' <EOL> output += '<STR_LIT>' + cmd + '<STR_LIT>' <EOL> s , o = commands . getstatusoutput ( cmd ) <EOL> status += s <EOL> output += o <EOL> return status , output , results <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> test ( ) </s>
