<s> __author__ = '<STR_LIT>' <EOL> import os <EOL> import glob <EOL> import getopt <EOL> import commands <EOL> import sys <EOL> import numpy <EOL> import matplotlib <EOL> import matplotlib . pyplot as plt <EOL> from matplotlib . legend_handler import * <EOL> class Param : <EOL> def __init__ ( self ) : <EOL> self . debug = <NUM_LIT:0> <EOL> self . results_folder = "<STR_LIT>" <EOL> self . methods_to_display = '<STR_LIT>' <EOL> self . fname_folder_to_save_fig = '<STR_LIT>' <EOL> def main ( ) : <EOL> results_folder = param_default . results_folder <EOL> methods_to_display = param_default . methods_to_display <EOL> if param_default . debug : <EOL> print '<STR_LIT>' <EOL> results_folder = "<STR_LIT>" <EOL> path_sct = '<STR_LIT>' <EOL> methods_to_display = '<STR_LIT>' <EOL> else : <EOL> status , path_sct = commands . getstatusoutput ( '<STR_LIT>' ) <EOL> try : <EOL> opts , args = getopt . getopt ( sys . argv [ <NUM_LIT:1> : ] , '<STR_LIT>' ) <EOL> except getopt . GetoptError as err : <EOL> print str ( err ) <EOL> for opt , arg in opts : <EOL> if opt in '<STR_LIT>' : <EOL> results_folder = arg <EOL> if opt in '<STR_LIT>' : <EOL> methods_to_display = arg <EOL> sys . path . append ( path_sct + '<STR_LIT>' ) <EOL> import sct_utils as sct <EOL> sct . printv ( "<STR_LIT>" + os . getcwd ( ) ) <EOL> results_folder_csf = results_folder + '<STR_LIT>' <EOL> sct . printv ( '<STR_LIT>' + results_folder_csf + '<STR_LIT:.>' , '<STR_LIT>' ) <EOL> sct . printv ( '<STR_LIT>' ) <EOL> sct . check_folder_exist ( results_folder_csf ) <EOL> methods_to_display = methods_to_display . strip ( ) . split ( '<STR_LIT:U+002C>' ) <EOL> fname_results_csf = glob . glob ( results_folder_csf + '<STR_LIT>' ) <EOL> file_results = [ ] <EOL> for fname in fname_results_csf : <EOL> file_results . append ( os . path . basename ( fname ) ) <EOL> for file in file_results : <EOL> if file_results . count ( file ) > <NUM_LIT:1> : <EOL> ind = file_results . index ( file ) <EOL> fname_results_csf . remove ( fname_results_csf [ ind ] ) <EOL> file_results . remove ( file ) <EOL> nb_results_file = len ( fname_results_csf ) <EOL> snr = numpy . zeros ( ( nb_results_file ) ) <EOL> tracts_std = numpy . zeros ( ( nb_results_file ) ) <EOL> csf_values = numpy . zeros ( ( nb_results_file ) ) <EOL> methods_name = [ ] <EOL> error_per_label = [ ] <EOL> std_per_label = [ ] <EOL> labels_id = [ ] <EOL> median_results = numpy . zeros ( ( nb_results_file , <NUM_LIT:5> ) ) <EOL> median_std = numpy . zeros ( ( nb_results_file , <NUM_LIT:5> ) ) <EOL> min_results = numpy . zeros ( ( nb_results_file , <NUM_LIT:5> ) ) <EOL> max_results = numpy . zeros ( ( nb_results_file , <NUM_LIT:5> ) ) <EOL> for i_file in range ( <NUM_LIT:0> , nb_results_file ) : <EOL> f = open ( fname_results_csf [ i_file ] ) <EOL> lines = [ line for line in f . readlines ( ) if line . strip ( ) ] <EOL> ind_line_noise = [ lines . index ( line_noise ) for line_noise in lines if "<STR_LIT>" in line_noise ] <EOL> if len ( ind_line_noise ) != <NUM_LIT:1> : <EOL> sct . printv ( "<STR_LIT>" , '<STR_LIT:error>' ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> else : <EOL> snr [ i_file ] = int ( '<STR_LIT>' . join ( c for c in lines [ ind_line_noise [ <NUM_LIT:0> ] ] if c . isdigit ( ) ) ) <EOL> ind_line_tract_std = [ lines . index ( line_tract_std ) for line_tract_std in lines if <EOL> "<STR_LIT>" in line_tract_std ] <EOL> if len ( ind_line_tract_std ) != <NUM_LIT:1> : <EOL> sct . printv ( "<STR_LIT>" , '<STR_LIT:error>' ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> else : <EOL> tracts_std [ i_file ] = int ( '<STR_LIT>' . join ( c for c in lines [ ind_line_tract_std [ <NUM_LIT:0> ] ] . split ( '<STR_LIT::>' ) [ <NUM_LIT:1> ] if c . isdigit ( ) ) ) <EOL> ind_line_csf_value = [ lines . index ( line_csf_value ) for line_csf_value in lines if <EOL> "<STR_LIT>" in line_csf_value ] <EOL> if len ( ind_line_csf_value ) != <NUM_LIT:1> : <EOL> sct . printv ( "<STR_LIT>" , '<STR_LIT:error>' ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> else : <EOL> csf_values [ i_file ] = int ( '<STR_LIT>' . join ( c for c in lines [ ind_line_csf_value [ <NUM_LIT:0> ] ] . split ( '<STR_LIT::>' ) [ <NUM_LIT:1> ] if c . isdigit ( ) ) ) <EOL> ind_line_label = [ lines . index ( line_label ) for line_label in lines if "<STR_LIT>" in line_label ] <EOL> if len ( ind_line_label ) != <NUM_LIT:1> : <EOL> sct . printv ( "<STR_LIT>" , '<STR_LIT:error>' ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> else : <EOL> methods_name . append ( lines [ ind_line_label [ <NUM_LIT:0> ] ] . strip ( ) . replace ( '<STR_LIT:U+0020>' , '<STR_LIT>' ) . split ( '<STR_LIT:U+002C>' ) [ <NUM_LIT:1> : ] ) <EOL> ind_line_median = [ lines . index ( line_median ) for line_median in lines if "<STR_LIT>" in line_median ] <EOL> if len ( ind_line_median ) != <NUM_LIT:1> : <EOL> sct . printv ( "<STR_LIT>" , '<STR_LIT>' ) <EOL> else : <EOL> median = lines [ ind_line_median [ <NUM_LIT:0> ] ] . strip ( ) . split ( '<STR_LIT:U+002C>' ) [ <NUM_LIT:1> : ] <EOL> median_results [ i_file , : ] = numpy . array ( [ float ( m . split ( '<STR_LIT:(>' ) [ <NUM_LIT:0> ] ) for m in median ] ) <EOL> median_std [ i_file , : ] = numpy . array ( [ float ( m . split ( '<STR_LIT:(>' ) [ <NUM_LIT:1> ] [ : - <NUM_LIT:1> ] ) for m in median ] ) <EOL> ind_line_min = [ lines . index ( line_min ) for line_min in lines if "<STR_LIT>" in line_min ] <EOL> if len ( ind_line_min ) != <NUM_LIT:1> : <EOL> sct . printv ( "<STR_LIT>" , '<STR_LIT>' ) <EOL> else : <EOL> min = lines [ ind_line_min [ <NUM_LIT:0> ] ] . strip ( ) . split ( '<STR_LIT:U+002C>' ) [ <NUM_LIT:1> : ] <EOL> min_results [ i_file , : ] = numpy . array ( [ float ( m . split ( '<STR_LIT:(>' ) [ <NUM_LIT:0> ] ) for m in min ] ) <EOL> ind_line_max = [ lines . index ( line_max ) for line_max in lines if "<STR_LIT>" in line_max ] <EOL> if len ( ind_line_max ) != <NUM_LIT:1> : <EOL> sct . printv ( "<STR_LIT>" , '<STR_LIT>' ) <EOL> else : <EOL> max = lines [ ind_line_max [ <NUM_LIT:0> ] ] . strip ( ) . split ( '<STR_LIT:U+002C>' ) [ <NUM_LIT:1> : ] <EOL> max_results [ i_file , : ] = numpy . array ( [ float ( m . split ( '<STR_LIT:(>' ) [ <NUM_LIT:0> ] ) for m in max ] ) <EOL> error_per_label_for_file_i = [ ] <EOL> std_per_label_for_file_i = [ ] <EOL> labels_id_for_file_i = [ ] <EOL> if not ind_line_median : <EOL> ind_line_median = [ len ( lines ) + <NUM_LIT:1> ] <EOL> for i_line in range ( ind_line_label [ <NUM_LIT:0> ] + <NUM_LIT:1> , ind_line_median [ <NUM_LIT:0> ] - <NUM_LIT:1> ) : <EOL> line_label_i = lines [ i_line ] . strip ( ) . split ( '<STR_LIT:U+002C>' ) <EOL> error_per_label_for_file_i . append ( [ float ( error . strip ( ) . split ( '<STR_LIT:(>' ) [ <NUM_LIT:0> ] ) for error in line_label_i [ <NUM_LIT:1> : ] ] ) <EOL> std_per_label_for_file_i . append ( [ float ( error . strip ( ) . split ( '<STR_LIT:(>' ) [ <NUM_LIT:1> ] [ : - <NUM_LIT:1> ] ) for error in line_label_i [ <NUM_LIT:1> : ] ] ) <EOL> labels_id_for_file_i . append ( line_label_i [ <NUM_LIT:0> ] ) <EOL> error_per_label . append ( error_per_label_for_file_i ) <EOL> std_per_label . append ( std_per_label_for_file_i ) <EOL> labels_id . append ( labels_id_for_file_i ) <EOL> f . close ( ) <EOL> if not all ( x == methods_name [ <NUM_LIT:0> ] for x in methods_name ) : <EOL> sct . printv ( <EOL> '<STR_LIT>' + results_folder + '<STR_LIT>' , <EOL> '<STR_LIT:error>' ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> if not all ( x == labels_id [ <NUM_LIT:0> ] for x in labels_id ) : <EOL> sct . printv ( <EOL> '<STR_LIT>' + results_folder + '<STR_LIT>' , <EOL> '<STR_LIT:error>' ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> error_per_label = numpy . array ( error_per_label ) <EOL> std_per_label = numpy . array ( std_per_label ) <EOL> abs_error_per_labels = numpy . absolute ( error_per_label ) <EOL> max_abs_error_per_meth = numpy . amax ( abs_error_per_labels , axis = <NUM_LIT:1> ) <EOL> min_abs_error_per_meth = numpy . amin ( abs_error_per_labels , axis = <NUM_LIT:1> ) <EOL> mean_abs_error_per_meth = numpy . mean ( abs_error_per_labels , axis = <NUM_LIT:1> ) <EOL> std_abs_error_per_meth = numpy . std ( abs_error_per_labels , axis = <NUM_LIT:1> ) <EOL> nb_method = len ( methods_to_display ) <EOL> sct . printv ( '<STR_LIT>' + str ( nb_results_file ) + '<STR_LIT>' ) <EOL> print snr <EOL> print '<STR_LIT>' <EOL> sct . printv ( '<STR_LIT>' + str ( nb_results_file ) + '<STR_LIT>' ) <EOL> print tracts_std <EOL> print '<STR_LIT>' <EOL> sct . printv ( '<STR_LIT>' + str ( nb_results_file ) + '<STR_LIT>' ) <EOL> print csf_values <EOL> print '<STR_LIT>' <EOL> sct . printv ( '<STR_LIT>' + str ( nb_results_file ) + '<STR_LIT>' ) <EOL> print methods_name <EOL> print '<STR_LIT>' <EOL> sct . printv ( <EOL> '<STR_LIT>' + str ( nb_results_file ) + '<STR_LIT>' ) <EOL> print median_results <EOL> print '<STR_LIT>' <EOL> sct . printv ( '<STR_LIT>' + str ( <EOL> nb_results_file ) + '<STR_LIT>' ) <EOL> print min_results <EOL> print '<STR_LIT>' <EOL> sct . printv ( '<STR_LIT>' + str ( <EOL> nb_results_file ) + '<STR_LIT>' ) <EOL> print max_results <EOL> print '<STR_LIT>' <EOL> sct . printv ( '<STR_LIT>' + str ( nb_results_file ) + '<STR_LIT>' ) <EOL> print labels_id <EOL> print '<STR_LIT>' <EOL> sct . printv ( <EOL> '<STR_LIT>' + str ( nb_results_file ) + '<STR_LIT>' ) <EOL> print error_per_label <EOL> ind_files_csf_sort = numpy . argsort ( csf_values ) <EOL> matplotlib . rcParams . update ( { '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> plt . rcParams [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> plt . rcParams [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> plt . figure ( figsize = ( <NUM_LIT:30> , <NUM_LIT:16> ) ) <EOL> width = <NUM_LIT:1.0> / ( nb_method + <NUM_LIT:1> ) <EOL> ind_fig = numpy . arange ( len ( ind_files_csf_sort ) ) * ( <NUM_LIT:1.0> + width ) <EOL> plt . ylabel ( '<STR_LIT>' , fontsize = <NUM_LIT> ) <EOL> plt . xlabel ( '<STR_LIT>' , fontsize = <NUM_LIT> ) <EOL> plt . title ( '<STR_LIT>' , fontsize = <NUM_LIT> ) <EOL> colors = [ '<STR_LIT:b>' , '<STR_LIT:g>' , '<STR_LIT:r>' , '<STR_LIT:c>' , '<STR_LIT:m>' , '<STR_LIT:y>' , '<STR_LIT:k>' ] <EOL> box_plots = [ ] <EOL> for meth , color in zip ( methods_to_display , colors ) : <EOL> i_meth = methods_name [ <NUM_LIT:0> ] . index ( meth ) <EOL> i_meth_to_display = methods_to_display . index ( meth ) <EOL> boxprops = dict ( linewidth = <NUM_LIT:4> , color = color ) <EOL> flierprops = dict ( color = color , markeredgewidth = <NUM_LIT> , markersize = <NUM_LIT:15> , marker = '<STR_LIT:.>' ) <EOL> whiskerprops = dict ( color = color , linewidth = <NUM_LIT:3> ) <EOL> capprops = dict ( color = color , linewidth = <NUM_LIT:3> ) <EOL> medianprops = dict ( linewidth = <NUM_LIT:4> , color = color ) <EOL> meanpointprops = dict ( marker = '<STR_LIT:D>' , markeredgecolor = '<STR_LIT>' , markerfacecolor = '<STR_LIT>' ) <EOL> meanlineprops = dict ( linestyle = '<STR_LIT>' , linewidth = <NUM_LIT> , color = '<STR_LIT>' ) <EOL> plot_i = plt . boxplot ( numpy . transpose ( abs_error_per_labels [ ind_files_csf_sort , : , i_meth ] ) , positions = ind_fig + i_meth_to_display * width + ( float ( i_meth_to_display ) * width ) / ( nb_method + <NUM_LIT:1> ) , widths = width , boxprops = boxprops , medianprops = medianprops , flierprops = flierprops , whiskerprops = whiskerprops , capprops = capprops ) <EOL> box_plots . append ( plot_i [ '<STR_LIT>' ] [ <NUM_LIT:0> ] ) <EOL> for i_xtick in range ( <NUM_LIT:0> , len ( ind_fig ) , <NUM_LIT:2> ) : <EOL> plt . axvspan ( ind_fig [ i_xtick ] - width - width / <NUM_LIT:4> , ind_fig [ i_xtick ] + ( nb_method + <NUM_LIT:1> ) * width - width / <NUM_LIT:4> , facecolor = '<STR_LIT>' , alpha = <NUM_LIT:0.1> ) <EOL> xtick_labels = [ int ( xtick ) for xtick in csf_values [ ind_files_csf_sort ] ] <EOL> plt . xticks ( ind_fig + ( numpy . floor ( nb_method / <NUM_LIT:2> ) ) * width * ( <NUM_LIT:1.0> + <NUM_LIT:1.0> / ( nb_method + <NUM_LIT:1> ) ) , xtick_labels ) <EOL> plt . gca ( ) . set_xlim ( [ - width , numpy . max ( ind_fig ) + ( nb_method + <NUM_LIT:0.5> ) * width ] ) <EOL> plt . gca ( ) . set_ylim ( [ <NUM_LIT:0> , <NUM_LIT> ] ) <EOL> plt . gca ( ) . yaxis . set_major_locator ( plt . MultipleLocator ( <NUM_LIT> ) ) <EOL> plt . gca ( ) . yaxis . set_minor_locator ( plt . MultipleLocator ( <NUM_LIT:0.5> ) ) <EOL> plt . grid ( b = True , axis = '<STR_LIT:y>' , which = '<STR_LIT>' , alpha = <NUM_LIT:0.5> ) <EOL> plt . subplots_adjust ( left = <NUM_LIT:0.1> ) <EOL> plt . savefig ( param_default . fname_folder_to_save_fig + '<STR_LIT>' , format = '<STR_LIT>' ) <EOL> plt . show ( block = False ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> param_default = Param ( ) <EOL> main ( ) </s>
