Beispiel #1
0
def plot_bandwidths(bandwidths, experiments, spectra=[]):
    ''' 
    Plots the bandwidths of detection and pump pulses for multiple experiments .
    If the EPR spectrum of the spin system is provided, the bandwidths are overlayed with the EPR spectrum. 
    '''
    figsize = [10, 8]
    num_subplots = len(experiments)
    best_rcparams(num_subplots)
    layout = best_layout(figsize[0], figsize[1], num_subplots)
    fig = plt.figure(figsize=(figsize[0], figsize[1]),
                     facecolor='w',
                     edgecolor='w')
    for i in range(num_subplots):
        if num_subplots == 1:
            axes = fig.gca()
        else:
            axes = fig.add_subplot(layout[0], layout[1], i + 1)
        if (spectra != []) and (len(spectra) == num_subplots):
            plot_bandwidths_single_experiment(axes, bandwidths[i],
                                              experiments[i], spectra[i])
        else:
            plot_bandwidths_single_experiment(axes, bandwidths[i],
                                              experiments[i])
    plt.tight_layout()
    plt.draw()
    plt.pause(0.000001)
    return fig
def plot_epr_spectrum(spectrum):
    ''' Plots a simulated EPR spectrum '''
    best_rcparams(1)
    fig = plt.figure(facecolor='w', edgecolor='w')
    axes = fig.gca()
    axes.plot(spectrum['f'], spectrum['p'] / np.amax(spectrum['p']), 'k-')
    axes.set_xlabel(r'Frequency (GHz)')
    axes.set_ylabel('Intensity (arb. u.)')
    axes.set_xlim(np.amin(spectrum['f']), np.amax(spectrum['f']))
    axes.set_ylim(0.0, 1.1)
    plt.tight_layout()
    plt.draw()
    plt.pause(0.000001)  # needed for displaying the plot
    return fig
def plot_score(score, goodness_of_fit):
    ''' Plots the score as a function of optimization step '''
    best_rcparams(1)
    num_points = len(score)
    x = np.linspace(1,num_points,num_points)
    y = score
    fig = plt.figure(facecolor='w', edgecolor='w')
    axes = fig.gca()
    axes.semilogy(x, y, linestyle='-', marker='o', color='k')
    axes.set_xlim(0, x[-1] + 1)
    plt.xlabel('No. iteration')
    plt.ylabel(const['goodness_of_fit_axes_labels'][goodness_of_fit])
    plt.grid(True)
    plt.tight_layout()
    plt.draw()
    plt.pause(0.000001)
    return fig
def update_score_plot(fig, score, goodness_of_fit):
    ''' Re-plots the score as a function of optimization step '''
    best_rcparams(1)
    num_points = len(score)
    x = np.linspace(1,num_points,num_points)
    y = score
    axes = fig.gca()
    axes.clear()
    axes.semilogy(x, y, linestyle='-', marker='o', color='k')
    axes.set_xlim(0, x[-1] + 1)
    plt.xlabel('The number of optimization steps')
    plt.xlabel('No. iteration')
    plt.ylabel(const['goodness_of_fit_axes_labels'][goodness_of_fit])		
    plt.grid(True)
    plt.tight_layout()
    plt.draw()
    plt.pause(0.000001)
def plot_simulated_time_traces(simulated_time_traces, experiments):
    ''' Plots simulated PDS time traces '''
    figsize = [10, 8]
    num_subplots = len(experiments)
    best_rcparams(num_subplots)
    layout = best_layout(figsize[0], figsize[1], num_subplots)
    fig = plt.figure(figsize=(figsize[0], figsize[1]), facecolor='w', edgecolor='w')
    for i in range(num_subplots):
        if num_subplots == 1:
            axes = fig.gca()
        else:
            axes = fig.add_subplot(layout[0], layout[1], i+1)
        plot_simulated_time_trace(axes, simulated_time_traces[i], experiments[i])
    plt.tight_layout() 
    plt.draw()
    plt.pause(0.000001)
    return fig
def plot_error_surfaces(score_vs_parameter_subsets, error_analysis_parameters,
                        fitting_parameters, optimized_parameters,
                        score_threshold):
    ''' Plots the score as a function of one or two fitting parameters '''
    figsize = [10, 8]
    num_subplots = len(error_analysis_parameters)
    best_rcparams(num_subplots)
    layout = best_layout(figsize[0], figsize[1], num_subplots)
    fig = plt.figure(figsize=(figsize[0], figsize[1]),
                     facecolor='w',
                     edgecolor='w')
    for i in range(num_subplots):
        dim = len(error_analysis_parameters[i])
        if num_subplots == 1:
            axes = fig.gca()
        else:
            axes = fig.add_subplot(layout[0], layout[1], i + 1)
        if (dim == 1):
            im = plot_1d_error_surface(axes, score_vs_parameter_subsets[i],
                                       error_analysis_parameters[i],
                                       fitting_parameters,
                                       optimized_parameters, score_threshold)
        elif (dim == 2):
            im = plot_2d_error_surface(axes, score_vs_parameter_subsets[i],
                                       error_analysis_parameters[i],
                                       fitting_parameters,
                                       optimized_parameters, score_threshold)
        else:
            print(
                'The score cannot be yet plotted as function of three or more parameters!'
            )
    left = 0
    right = float(layout[1]) / float(layout[1] + 1)
    bottom = 0.5 * (1 - right)
    top = 1 - bottom
    plt.tight_layout(rect=[left, bottom, right, top])
    cax = plt.axes([right + 0.05, 0.3, 0.02, 0.4])
    plt.colorbar(im, cax=cax, orientation='vertical')
    plt.text(right + 0.1, 1.05, r'$\mathit{\chi^2}$', transform=cax.transAxes)
    plt.draw()
    plt.pause(0.000001)
    return fig