Esempio n. 1
0
λs, ctss, lbs = prd_file_import.load_spec_dir(p0)
xs0 = λs[1]
ys0 = ctss[1]

# Use gin to get first approximation for peak location
pts = prd_plots.gin(λs[0], ctss[0], 0,
                    'politely click peak locations and smash enter')

pk_λs = []
pk_idxs = []
fit_data = []
# Loop over data in directory and perform fits on each spec, for each peak
for i0, val0 in enumerate(pts):
    pk_λ = str(int(np.round(pts[i0][0])))
    pk_lb = 'peak ' + str(i0) + ' (' + pk_λ + ' nm)'
    λ_pk, idx_pk = prd_maths.find_nearest(xs0, pts[i0, 0])
    pk_λs.append(λ_pk)
    pk_idxs.append(idx_pk)
    # Restrict data set to roi of interest
    x_roi = xs0[int(idx_pk - roi / 2):int(idx_pk + roi / 2)]
    y_roi = ys0[int(idx_pk - roi / 2):int(idx_pk + roi / 2)]
    # Extract first guess values for fitting
    μ = λ_pk
    σ = 0.1
    bkg = np.mean(y_roi)
    # Set up higher resolution x axis for fit
    x_fit = np.linspace(min(x_roi), max(x_roi), 1000)
    # Perform fit
    popt, pcov = curve_fit(prd_maths.Gaussian_1D,
                           x_roi, y_roi, p0=[1, μ, σ, bkg])
p0 = (
    r"C:\local files\Experimental Data\F5 L10 Spectrometer\Spec data 20190611")
os.chdir(p0)
datafiles = glob.glob(p0 + r'\*nm).dat')

fit_pts = []
idx_lims = []

for i0, val0 in enumerate(datafiles):
    print(val0)
    data = np.genfromtxt(datafiles[i0])
    Ps = (data[:, 0])
    As = (data[:, 1])
    pts = prd_plots.gin(Ps, As, 1, 'click max ct rate')
    fit_pts.append(pts)
    Ps_lim, idx_lim = prd_maths.find_nearest(Ps, pts[0, 0])
    idx_lims.append(idx_lim)

size = 4
prd_plots.ggplot()
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('Power (μW)')
ax1.set_ylabel('Fit amplitude')
ax1.set_xscale('log')
ax1.set_yscale('log')

colors = plt.cm.viridis(np.linspace(0, 1, 10 * len(datafiles)))
for i0, val0 in enumerate(datafiles):
    print(val0)
# Specify results directory and change working directory to this location
p0 = (r"C:\local files\Experimental Data\F5 L10 Spectrometer\Spec data 20200214")
# p0 = (r"D:\Experimental Data\Internet Thorlabs optics data"))
os.chdir(p0)
# Generate list of relevant data files and sort them chronologically
datafile = p0 + r'\HeNe.txt'
roi = 200
λ, cts = prd_file_import.load_spec(datafile)
print('resolution = ', np.round(λ[1] - λ[0], 5), ' nm')
cts = cts[:, 0]

λ = λ[2000:6000]
cts = cts[2000:6000]
# Use gin to get first approximation for peak location
pts = prd_plots.gin(λ, cts, 0, 'click once and tap enter to fit peak')
λ_pk, idx_pk = prd_maths.find_nearest(λ, pts[0, 0])
print(λ_pk, idx_pk)
# Restrict data set to roi of interest
x_roi = λ[int(idx_pk - roi / 2):int(idx_pk + roi / 2)]
y_roi = cts[int(idx_pk - roi / 2):int(idx_pk + roi / 2)]
# Extract first guess values for fitting
mean = λ_pk
sigma = 0.1
bkg = np.mean(y_roi)
# Set up higher resolution x axis for fit
x_fit = np.linspace(min(x_roi), max(x_roi), 1000)
# Perform fit
popt_G, pcov = curve_fit(prd_maths.Gaussian_1D,
                         x_roi, y_roi, p0=[10000, mean, sigma, bkg])

popt_L, pcov = curve_fit(prd_maths.Lorentzian_1D,
Esempio n. 4
0
def HH_data_subset(τs, cts, τ, points):
    τ_nearest, τ_idx = prd_maths.find_nearest(τs, τ)
    print(τ_nearest, τ_idx)
    τs_ss = τs[int(τ_idx - points / 2):int(τ_idx + points / 2)]
    cts_ss = cts[int(τ_idx - points / 2):int(τ_idx + points / 2)]
    return τs_ss, cts_ss