Exemple #1
0
         bins=bin_N,
         alpha=0.5,
         facecolor=cs['ggred'],
         edgecolor=cs['ggred'],
         label='Probabilistic',
         density=False)
plt.plot(bin_centres, h1, '.', color=cs['ggblue'])
plt.savefig('hist.svg')
plt.title('count rate = ' +
          str(np.round(1e3 * ((γs_det2 + γs_det1) / t_clk), 2)) + ' Mcps')
plt.tight_layout()

fig1 = plt.figure('fig1', figsize=(plot_size * np.sqrt(2), plot_size))
ax1 = fig1.add_subplot(1, 1, 1)
fig1.patch.set_facecolor(cs['mnk_dgrey'])
ax1.set_xlabel('τ (ns)')
ax1.set_ylabel('g$^2$(τ)')
# ax1.set_yscale('log')
plt.plot(bin_centres, y2, '.', color=cs['ggblue'])
plt.savefig('g2s.svg')
plt.title('count rate = ' +
          str(np.round(1e3 * ((γs_det2 + γs_det1) / t_clk), 2)) + ' Mcps')
plt.plot(x3 + t_excite, 0.8 * y3)
plt.tight_layout()

plt.show()
prd_plots.PPT_save_2d(fig1, ax1, p0 + '-g2.png')
prd_plots.PPT_save_2d(fig2, ax2, p0 + '-hist.png')
# prd_plots.PPT_save_2d(fig1, ax1, p0 + '-g2 log.png')
# prd_plots.PPT_save_2d(fig2, ax2, p0 + '-hist log.png')
Exemple #2
0
    # import x/y data from filename (v0)
    ts, cts = load_HH(v0)
    
    # set plot parameters
    ggplot()
    size = 4

    # begin populating figure
    fig2 = plt.figure('fig2', figsize=(size * np.sqrt(2), size))
    ax2 = fig2.add_subplot(111)
    fig2.patch.set_facecolor(cs['mnk_dgrey'])
    ax2.set_xlabel('Δt (ns)')
    ax2.set_ylabel('counts')
    t_shift = 93
    plt.plot(ts - t_shift, cts, lw=0.5,
             alpha=0.4, color=cs['ggdred'], label=lb)
    plt.plot(ts - t_shift, cts, 'o', lw=0.5,
             alpha=1, color=cs['gglred'], markersize=2)
    plt.xlim((-t_shift, 500))
    plt.ylim((0, np.max(cts)))
    plt.tight_layout()

    # show figure (pop up)
    plt.show()

    # generate filename
    plot_file_name = lb

    # save figure
    prd_plots.PPT_save_2d(fig2, ax2, 'plot')
ax2.get_xaxis().set_visible(False)
fig2.tight_layout()

# img plot ###################################################################
t_ax = thrs
fq_ax = np.flip(fs)
size = 4
fig4 = plt.figure('fig4', figsize=(size * np.sqrt(2), size))
ax4 = fig4.add_subplot(1, 1, 1)
fig4.patch.set_facecolor(cs['mnk_dgrey'])
ax4.set_xlabel('time, hrs')
ax4.set_ylabel('frequency, Hz')
im4 = plt.imshow(
    np.flipud(np.transpose(dBs_tf_R)),
    cmap='magma',
    aspect='auto',
    extent=[np.min(t_ax),
            np.max(t_ax),
            np.min(fq_ax), (np.max(fq_ax))])
divider = make_axes_locatable(ax4)
cax = divider.append_axes("right", size="5%", pad=0.05)
cb4 = fig4.colorbar(im4, cax=cax)
plt.show()

# save plots #################################################################
os.chdir(dirpath)

prd_plots.PPT_save_2d(fig1, ax1, 'integrated spectrum')
prd_plots.PPT_save_2d(fig2, ax2, 'time series')
prd_plots.PPT_save_2d_im(fig4, ax4, cb4, 'spectral timeline')
global_cps0 = np.mean(global_cps0)
global_cps1 = np.mean(global_cps1)

##############################################################################
# Plot some figures
##############################################################################
# plot_path = r"C:\Users\Phil\Documents\GitHub\plots"
prd_plots.ggplot()
# xy plot ####################################################################
size = 4
fig1 = plt.figure('fig1', figsize=(size * np.sqrt(2), size))
ax1 = fig1.add_subplot(111)
fig1.patch.set_facecolor(cs['mnk_dgrey'])
ax1.set_xlabel('x axis')
ax1.set_ylabel('y axis')
plt.hist(dt0_ns,
         bins=200,
         range=(0, 150),
         edgecolor=cs['mnk_dgrey'],
         alpha=0.8)
plt.hist(dt1_ns,
         bins=200,
         range=(0, 150),
         edgecolor=cs['mnk_dgrey'],
         alpha=0.8)
fig1.tight_layout()
plt.show()

# save figure
prd_plots.PPT_save_2d(fig1, ax1, 'hist_ts')
Exemple #5
0
# θs are the divergence angles of the beam at each point
θs = np.array(ps)[:, 1]

##############################################################################
# Plot the outputted waists
##############################################################################
# Scale values for appropriate plotting
prd_plots.ggplot()
plot_path = r"C:\local files\Python\Plots"
zs = 1e-3 * np.array(zs)
ws = 1e0 * ws
xs = 1e0 * xs

fig1 = plt.figure('fig1')
ax1 = fig1.add_subplot(1, 1, 1)
fig1.patch.set_facecolor(cs['mnk_dgrey'])
ax1.set_xlabel('optical axis (km)')
ax1.set_ylabel('y axis - beam waist (m)')
plt.plot(zs, ws, '-', c=cs['ggred'], label='Gaussian Beam')
plt.plot(zs, -ws, '-', c=cs['ggred'])
plt.plot(zs, xs, '-', c=cs['ggblue'], label='Raytrace')
plt.plot(zs, -xs, '-', c=cs['ggblue'])
ax1.legend(loc='upper right', fancybox=True, framealpha=1)
plt.tight_layout()
plt.show()

# Saving plots
plot_file_name = plot_path + r'\Gauss and Ray tracing Propagation.png'
ax1.legend(loc='upper left', fancybox=True, facecolor=(1.0, 1.0, 1.0, 0.0))
prd_plots.PPT_save_2d(fig1, ax1, plot_file_name)
Exemple #6
0
    header = "Powers, Gaussian Amplitudes, Gaussian centres, Gaussian widths"
    np.savetxt(data_name, data, header=header)
print(len(fit_data))
prd_plots.ggplot()
size = 4
fig1 = plt.figure('fig1', figsize=(size * np.sqrt(2), size))
ax1 = fig1.add_subplot(1, 1, 1)
fig1.patch.set_facecolor(cs['mnk_dgrey'])
ax1.set_xlabel('Wavelength (λ - nm)')
ax1.set_ylabel('Counts')
ax1.set_title('Labelled spectrum with fits')
ax1.plot(xs0, ys0, '.', markersize=2,
         alpha=0.5, color=cs['gglred'], label='')

pk_ys = [ys0[i] for i in pk_idxs]
for i0, val0 in enumerate(fit_data):
    pk_x = fit_data[i0][1][1]
    pk_y = prd_maths.Gaussian_1D(pk_x,
                                 fit_data[i0][0][1],
                                 fit_data[i0][1][1],
                                 fit_data[i0][2][1])
    ax1.plot(pk_x, pk_y, '.',
             mfc=cs['ggblue'],
             mec=cs['ggblue'],
             label='peak ' + str(i0))
    ax1.text(pk_x, pk_y, ' peak ' + str(i0))

fig1.tight_layout()
plt.show()
prd_plots.PPT_save_2d(fig1, ax1, 'peak labels.png')
Exemple #7
0
# # label='Probabilistic')
# # ax3.plot(hist_time, hist[0] * np.exp(-(hist_time / τ)), label='Analytic')
# ax3.legend(loc='upper right', fancybox=True, framealpha=0.5)
# plt.savefig('logplot.svg')
# plt.title('τs_rel')
# plt.tight_layout()

# plt.xlim(0, 1000)

plt.show()

# ax2.legend(loc='upper right', fancybox=True, facecolor=(1.0, 1.0, 1.0, 0.0))
# ax1.legend(loc='upper right', fancybox=True, facecolor=(1.0, 1.0, 1.0, 0.0))

# prd_plots.PPT_save_2d(fig1, ax1, 'plot.png')
prd_plots.PPT_save_2d(fig2, ax2, 'log plot.png')

# barchart time plot
# fig3 = plt.figure('fig3', figsize=(6 * np.sqrt(2), 3))
# ax3 = fig3.add_subplot(1, 1, 1)
# fig3.patch.set_facecolor(cs['mnk_dgrey'])
# ax3.set_xlabel('Time')
# ax3.set_ylabel('#')
# plt.bar(τs_abs[0:15], np.ones(len(τs_abs[0:15])), 2,
#         edgecolor=cs['mnk_dgrey'], label='all counts')
# plt.tight_layout()
# plt.xlim(0, 250)
# ax3.legend(loc='upper right', fancybox=True, framealpha=0.5)
# plt.savefig('barchart.svg')

# fig4 = plt.figure('fig4', figsize=(6 * np.sqrt(2), 3))
Exemple #8
0
# Do some stuff
##############################################################################
# Specify results directory and change working directory to this location

p0 = (r"C:\local files\Experimental Data\G4 L12 Rennishaw\20191101\spec")
os.chdir(p0)
# Generate list of relevant data files and sort them chronologically
datafiles = glob.glob(p0 + r'\*.txt')

# Initialise lists of datasets
sz = 5
prd_plots.ggplot()
fig1 = plt.figure('fig1', figsize=(sz * np.sqrt(2), sz))
ax1 = fig1.add_subplot(1, 1, 1)
fig1.patch.set_facecolor(cs['mnk_dgrey'])
ax1.set_xlabel('Wavelength (λ) / nm')
ax1.set_ylabel('Spectral signal (arb)')

for i0, val0 in enumerate(datafiles[0:]):

    data = np.genfromtxt(val0)
    λ = data[:, 0]
    cts = data[:, 1]
    ax1.plot(1e9 * λ, cts)
    plt.xlim((550, 775))
    plt.ylim((0, 1250))

plt.show()
ax1.figure.savefig('plot_name' + 'dark.svg')
prd_plots.PPT_save_2d(fig1, ax1, 'fig.svg')
    ts.append(np.mean(t))
    Ids.append(Id)

# save some of the series data
data_name = 'Power series.dat'
data = np.array(Ps)
header = "Powers"
np.savetxt(data_name, da, header=header)

# Perform fit on series data
x_fit = np.linspace(Ids[0], Ids[-1], 1000)
m = Ps[-1] / Ids[-1]
popt, pcov = curve_fit(prd_maths.straight_line,
                       Ids, Ps, p0=[m, 0])
m_str = str(np.round(popt[0], 2))
c_str = str(np.round(popt[1], 2))
fit_lb = 'y = ' + m_str + 'x ' + c_str

# plot series data
ax3.plot(x_fit, prd_maths.straight_line(x_fit, *popt),
         c=cs['ggred'],
         label=fit_lb)
ax3.legend(loc='upper left', fancybox=True, framealpha=1)
plt.show()

# save series plots
ax3.legend(loc='upper left', fancybox=True, facecolor=(1.0, 1.0, 1.0, 0.0))
prd_plots.PPT_save_2d(fig1, ax1, 'time series.png')
prd_plots.PPT_save_2d(fig2, ax2, 'histogram.png')
prd_plots.PPT_save_2d(fig3, ax3, 'scatter.png')
Exemple #10
0
# plot_path = r"C:\Users\Philip\Documents\GitHub\plots"
plot_path = r"D:\Python\Plots"

###### image plot ############################################################
# fig1 = plt.figure('fig1', figsize=(5, 5))
# ax1 = fig1.add_subplot(1, 1, 1)
# fig1.patch.set_facecolor(cs['mnk_dgrey'])
# ax1.set_xlabel('x axis')
# ax1.set_ylabel('y axis')
# plt.imshow(im, extent=prd.extents(x) + prd.extents(y))

###### xy plot ###############################################################
size = 4

fig2 = plt.figure('fig2', figsize=(size * np.sqrt(2), size))
ax2 = fig2.add_subplot(111)
fig2.patch.set_facecolor(cs['mnk_dgrey'])
ax2.set_xlabel('10ET reading (mV)')
ax2.set_ylabel('DUT reading (kct/s)')
ax2.errorbar(x, y, xerr=xerr, yerr=yerr, fmt='o',
             elinewidth=0.5, ecolor=cs['gglred'],
             alpha=1, color=cs['ggdred'], label='')
# ax2.grid(False)

plt.tight_layout()


plt.show()
plot_file_name = plot_path + r'\plot1.png'
prd_plots.PPT_save_2d(fig2, ax2, plot_file_name)
    label='Gaussian residuals',
    lw=0.5)

ax2.plot(x, y - prd_maths.Lorentzian_1D(
    x, *popt_L), '.-',
    color=cs['ggpurple'],
    label='Lorentzian residuals',
    lw=0.5)

ax2.plot(x, y - prd_maths.Voigt_1D(
    x, *popt_V), '.-',
    color=cs['ggyellow'],
    label='Voigt residuals',
    lw=0.5)

ax1.set_xlim((x[idx_pk - int(0.3 * roi)], x[idx_pk + int(0.3 * roi)]))
ax2.set_xlim((x[idx_pk - int(0.3 * roi)], x[idx_pk + int(0.3 * roi)]))
ax2.set_ylim((-1000, 1000))
ax1.legend(loc='upper right', fancybox=True, framealpha=0.5)
ax2.legend(loc='upper right', fancybox=True, framealpha=0.5)
ax1.set_title('spectrum with fits')
ax2.set_title('residuals')
fig1.tight_layout()
fig2.tight_layout()
plt.show()
ax1.figure.savefig('spectrum with fits dark' + '.png')
ax1.legend(loc='upper left', fancybox=True, facecolor=(1.0, 1.0, 1.0, 0.0))
ax2.legend(loc='upper left', fancybox=True, facecolor=(1.0, 1.0, 1.0, 0.0))
prd_plots.PPT_save_2d(fig1, ax1, 'spectrum with fits 30mA')
prd_plots.PPT_save_2d(fig2, ax2, 'residuals 30mA')
##############################################################################
V0 = 100
BO_rate = 0.009
days = 50
Vs = []
Vt = V0
for i0, j0 in enumerate(np.arange(days)):
    Vt = Vt - 0.009 * Vt
    Vs.append(Vt)
    print('day ', i0, ', V = ', np.round(Vt, 2), 'l')

##############################################################################
# Plot some figures
##############################################################################

prd_plots.ggplot()
###
scale = 5
fig1 = plt.figure('fig1', figsize=(scale * np.sqrt(2), scale * 1))
ax1 = fig1.add_subplot(1, 1, 1)
fig1.patch.set_facecolor(cs['mnk_dgrey'])
ax1.set_xlabel('Time, days')
ax1.set_ylabel('Volume (l)')
plt.plot(np.arange(days), Vs, 'o:', label='He lost forever')
plt.tight_layout()
ax1.legend(loc='upper right', fancybox=True, framealpha=0.5)
ax1.legend(loc='upper right', fancybox=True, facecolor=(1.0, 1.0, 1.0, 0.0))
plt.show()

prd_plots.PPT_save_2d(fig1, ax1, 'plot1.png')
Exemple #13
0
prd_plots.ggplot()

# histograms
x1 = τs_HBT
x1 = [i for i in x1 if i <= 100]
x1 = [i for i in x1 if i >= -100]

bin_N = 201
hist, bins = np.histogram(x1, bins=bin_N)
hist_time = np.linspace(bins[0] + (bins[1] - bins[0]) / 2,
                        bins[-2] + (bins[-1] - bins[-2]) / 2, 1000)

fig2 = plt.figure('fig2', figsize=(3 * np.sqrt(2), 3))
ax2 = fig2.add_subplot(1, 1, 1)
fig2.patch.set_facecolor(cs['mnk_dgrey'])
ax2.set_xlabel('Time')
ax2.set_ylabel('#')
plt.hist(x1,
         bins=bin_N,
         alpha=0.5,
         facecolor=cs['ggred'],
         edgecolor=cs['mnk_dgrey'],
         label='Probabilistic')
plt.savefig('logplot.svg')
plt.title('τs_HBT')
plt.tight_layout()
# plt.ylim(0, 1.5 * np.mean(hist))
plt.show()

prd_plots.PPT_save_2d(fig2, ax2, f4 + '.png')
for i0, val0 in enumerate(datafiles):
    print(val0)
    data = np.genfromtxt(datafiles[i0])
    Ps = (data[:, 0])
    Ps_2fit = (data[0:idx_lims[i0], 0])
    Ps_range = np.linspace(np.min(Ps_2fit), np.max(Ps_2fit), 100)
    As = (data[:, 1])
    As_2fit = (data[0:idx_lims[i0], 1])
    popt, pcov = curve_fit(prd_maths.Monomial, Ps_2fit, As_2fit, p0=[100, 2])

    ax1.plot(Ps_2fit,
             As_2fit,
             'o',
             mec=colors[10 * i0],
             mfc=colors[10 * i0 + 2])

    ax1.plot(Ps, As, '.', c=colors[10 * i0 + 4], lw=0.5)

    ax1.plot(Ps_range,
             prd_maths.Monomial(Ps_range, *popt),
             c=colors[10 * i0 + 6],
             label='Peak ' + str(i0) + ' m = ' + str(np.round(popt[1], 2)))

ax1.legend(loc='lower right', fancybox=True, framealpha=1)
ax1.set_title('Power saturation fits')
plt.tight_layout()
plt.show()
ax1.figure.savefig('Psat fits dark' + '.png')
ax1.legend(loc='upper left', fancybox=True, facecolor=(1.0, 1.0, 1.0, 0.0))
prd_plots.PPT_save_2d(fig1, ax1, 'Psat fits')
    x_fit = np.linspace(min(x_roi), max(x_roi), 1000)

    popt, pcov = curve_fit(prd_maths.Gaussian_1D,
                           x_roi, y_roi, p0=[popt])

    # Final plots
    prd_plots.ggplot()

    colors = plt.cm.viridis(np.linspace(0, 1, len(λs)))
    ax1.plot(x - popt[2], y, '--', alpha=0.5,
             color=colors[i1],
             label='',
             lw=0)

    plt.plot(x_roi - popt[2], y_roi, '.',
             c=colors[i1],
             alpha=0.3)
    plt.plot(x_fit - popt[2], prd_maths.Gaussian_1D(
        x_fit - popt[2], *popt),
        label='fit',
        c=colors[i1],
        lw=0.5)

    # plt.xlim((x[idx_pk - int(0.3 * roi)], x[idx_pk + int(0.3 * roi)]))
ax1.set_title('spectra with fits')
fig1.tight_layout()
plt.show()

ax1.figure.savefig('spectra with fits dark' + '.png')
prd_plots.PPT_save_2d(fig1, ax1, 'spectra with fits')
def spec_seq_Gauss_fit_20190611(d, popt, idx_pk, roi, pk_lb, Ps):
    print(d)
    λs, ctss, lbs = prd_file_import.load_spec_dir(d)
    prd_plots.ggplot()
    cs = prd_plots.palette()
    size = 4
    colors = plt.cm.viridis(np.linspace(0, 1, len(λs[0:])))

    fig1 = plt.figure('fig1', figsize=(size * np.sqrt(2), size))
    ax1 = fig1.add_subplot(1, 1, 1)
    fig1.patch.set_facecolor(cs['mnk_dgrey'])
    ax1.set_xlabel('Wavelength shifted with excitation power')
    ax1.set_ylabel('Counts')
    ax1.set_title('Spectra with fits - ' + pk_lb)
    fig1.tight_layout()

    fig2 = plt.figure('fig2', figsize=(size * np.sqrt(2), size))
    ax2 = fig2.add_subplot(1, 1, 1)
    fig2.patch.set_facecolor(cs['mnk_dgrey'])
    ax2.set_xlabel('Power (μW)')
    ax2.set_ylabel('Fit amplitude')
    ax2.set_title('Fit amplitude with power - ' + pk_lb)
    fig2.tight_layout()

    fig3 = plt.figure('fig3', figsize=(size * np.sqrt(2), size))
    ax3 = fig3.add_subplot(1, 1, 1)
    fig3.patch.set_facecolor(cs['mnk_dgrey'])
    ax3.set_xlabel('Power (μW)')
    ax3.set_ylabel('Peak location, (λ$_c$ - nm)')
    ax3.set_title('Peak location with power - ' + pk_lb)
    fig3.tight_layout()

    fig4 = plt.figure('fig4', figsize=(size * np.sqrt(2), size))
    ax4 = fig4.add_subplot(1, 1, 1)
    fig4.patch.set_facecolor(cs['mnk_dgrey'])
    ax4.set_xlabel('Power (P - μW)')
    ax4.set_ylabel('Peak width (σ - nm)')
    ax4.set_title('Peak widths with power - ' + pk_lb)
    fig4.tight_layout()

    μs = []
    σs = []
    As = []

    for i0, val0 in enumerate(λs[0:]):
        P = Ps[i0]
        x = λs[i0]
        y = ctss[i0]
        x_roi = x[int(idx_pk - roi / 2):int(idx_pk + roi / 2)]
        y_roi = y[int(idx_pk - roi / 2):int(idx_pk + roi / 2)]

        x_fit = np.linspace(min(x_roi), max(x_roi), 1000)

        popt, pcov = curve_fit(prd_maths.Gaussian_1D, x_roi, y_roi, p0=[popt])
        As.append(popt[0])
        μs.append(popt[1])
        σs.append(popt[2])

        # Final plots
        prd_plots.ggplot()

        colors = plt.cm.viridis(np.linspace(0, 1, len(λs)))
        ax1.plot(x - popt[1] + i0,
                 y,
                 '--',
                 alpha=0.5,
                 color=colors[i0],
                 label='',
                 lw=0)

        ax1.plot(x_roi - popt[1] + i0, y_roi, '.', c=colors[i0], alpha=0.3)

        ax1.plot(x_fit - popt[1] + i0,
                 prd_maths.Gaussian_1D(x_fit - popt[1] + i0,
                                       *(popt[0], i0, popt[2], popt[3])),
                 label='fit',
                 c=colors[i0],
                 lw=0.5)
        ax1.set_xlim((x[idx_pk - int(0.3 * roi)], x[idx_pk + int(0.3 * roi)]))
        ax1.set_xlim((-1, 12))
        fig1.tight_layout()

        ax2.plot(P, popt[0], 'o', c=colors[i0])
        fig2.tight_layout()

        ax3.plot(P, popt[1], 'o', c=colors[i0])
        fig3.tight_layout()

        ax4.plot(P, popt[2], 'o', c=colors[i0])
        fig4.tight_layout()

    plt.show()

    # ax1.figure.savefig(pk_lb + ' ' + ax1.get_title() + ' dark' + '.png')
    # ax2.figure.savefig(pk_lb + ' ' + ax2.get_title() + ' dark' + '.png')
    # ax3.figure.savefig(pk_lb+ ax3.get_title() + ' dark' + '.png')
    # ax4.figure.savefig(pk_lb + ' ' + ax4.get_title() + ' dark' + '.png')

    prd_plots.PPT_save_2d(fig1, ax1, pk_lb + ' ' + ax1.get_title())
    prd_plots.PPT_save_2d(fig2, ax2, pk_lb + ' ' + ax2.get_title())
    prd_plots.PPT_save_2d(fig3, ax3, pk_lb + ' ' + ax3.get_title())
    prd_plots.PPT_save_2d(fig4, ax4, pk_lb + ' ' + ax4.get_title())

    ax1.cla()
    ax2.cla()
    ax3.cla()
    ax4.cla()
    return As, μs, σs