def generate_error_graph(
    err_dirs,
    temperature_array,
    velocity_array,
    md_threshold_array,
    temperature_dict,
    flow_velocity_dict,
    md_threshold_dict,
    legendPosition='best',
    legendParam='None',
    graphPties='None',
    width=3,
    figPath='None',
    show=True,
    logScale=True,
    plot_ylim='None'):
    '''
    @description
    generate the graph showing the maximum of the error
    as a function of time
    '''


    # extract the error data
    data = []        

    for md_threshold in md_threshold_array:
        for flow_velocity in flow_velocity_array:
            for temperature in temperature_array:

                # get the path to the error data
                T_i  = temperature_dict[str(temperature)]
                v_i  = flow_velocity_dict[str(flow_velocity)]
                md_i = md_threshold_dict[str(md_threshold)]

                errorPath = err_dirs[T_i][v_i][md_i]

                # extract the error data
                [time_rescaled,error] = extract_max_error_in_time(errorPath)
        
                # stored the error data for the graph
                data.append([time_rescaled,error])

    # create the graph
    create_error_graph(
        data,
        legendPosition=legendPosition,
        legendParam=legendParam,
        graphPties=graphPties,
        width=width,
        figPath=figPath,
        show=show,
        logScale=logScale,
        plot_ylim=plot_ylim)
def generate_error_position_graph(
    temperature,
    flow_velocity,
    md_threshold=0,
    width=3,
    figPath='None',
    show=True,
    logScale=False,
    plot_ylim='None'):
    '''
    @description
    generate the figure showing the maximum of the mass error
    and the y-position as functions of time
    '''

    
    T_i  = temperature_dict[str(temperature)]
    v_i  = flow_velocity_dict[str(flow_velocity)]
    md_i = md_threshold_dict[str(0)]
    
    errorPath = err_dirs[T_i][v_i][md_i]
    
    data = extract_max_error_in_time(
        errorPath,
        var_names=['time','max_error_mass','y_max_error_mass'])
    
    dataError    = [data[0],data[1]]
    dataPosition = [data[0],data[2]]
    
    create_error_graph_with_location(
        dataError,
        dataPosition,
        legendParam='None',
        graphPties=[['black','-'],[grayscale_to_RGB(0.50),'-']],
        width=width,
        figPath=figPath_error,
        show=show,
        logScale=logScale,
        plot_ylim=plot_ylim)
            data_error.append([])
            data_error.append([])

            for dct_distance in dctDistance_array:

                # get the path for the error file
                dir_name = get_simulation_dir(temperature,
                                              flow_velocity,
                                              dct_distance=dct_distance)

                errorPath = os.path.join(mainDir,dir_name,'error','error_max.nc')

                if(os.path.isfile(errorPath)):

                    # extract the error data
                    [time_rescaled,error] = extract_max_error_in_time(errorPath)
        
                    # stored the error data for the graph
                    data.append([time_rescaled,error])

                    #set the legend properties            
                    legendParam.append(dct_distance)

                    # set the graph properties
                    T_i   = temperature_dict[str(temperature)]
                    dct_i = dctDistance_dict[str(dct_distance)]
                    graphPties.append([color_temperature[T_i],style_detector[dct_i]])

                else:
                    print errorPath+' does not exist'