Example #1
0
# fit_tolerance (A) :: the RMS
c.set_fit_constraints(n_pix=len(spectrum),
                      min_intercept=3000.,
                      max_intercept=5000.,
                      fit_tolerance=pix_scale * 0.5,
                      thresh=pix_scale * 1.,
                      polydeg=4)

pix = np.array((241., 269., 280., 294., 317., 359., 462.5, 468.4, 477., 530.3,
                752., 836., 900., 912., 980.))
wave = np.array(
    (4500.98, 4624.28, 4671.23, 4734.15, 4844.33, 5023.88, 5488.56, 5531.07,
     5581.88, 5823.89, 6872.11, 7284.3, 7584.68, 7642.02, 7967.34))

# Providing known pixel-wavelength mapping
c.set_known_pairs(pix, wave)

manual_p = np.polyfit(pix, wave, deg=4)
c.plot_fit(spectrum,
           c.match_peaks_to_atlas(manual_p)[0],
           tolerance=pix_scale * 1.)
# best solution to date (18-9-2019)
# array([ 9.14196336e-11, -7.08052801e-07,  1.32941263e-03,  3.84120934e+00, 3.50802551e+03])

best_p = c.fit(sample_size=20, max_tries=10000, top_n=10, n_slope=30000)
#c.plot_fit(spectrum, best_p_fast, tolerance=pix_scale)
#c.plot_fit(spectrum, best_p, tolerance=pix_scale*1.)
c.plot_fit(spectrum,
           c.match_peaks_to_atlas(best_p)[0],
           tolerance=pix_scale * 1.)
Example #2
0
#peaks, _ = getPeaks(spectrum, min_dist=25, thres=0.3)
from scipy.signal import find_peaks

spectrum /= spectrum.max()
peaks, _ = find_peaks(spectrum, height=0.1, distance=10, width=(0,40))

plt.plot(spectrum)
plt.vlines(peaks, 0, max(spectrum))
plt.show()

if len(peaks) == 0:
    print("No peaks found, try again!")
    exit(1)

c = Calibrator(peaks, atlas)
c.set_fit_constraints(min_slope=0.043,
                      max_slope=0.053,
                      min_intercept=550,
                      max_intercept=650,
                      line_fit_thresh=2)
 
best_p = c.match_peaks_to_atlas(c.fit(2))

if best_p is not None:
    c.plot_fit(spectrum, best_p)

print("Start wavelength: ", best_p[-1])
print("Centre wavelenght: ", polyfit_value(len(spectrum)/2, best_p[::-1]))
print("Dispersion: ", best_p[-2])