Example #1
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])
Example #2
0
           spectrum[peaks.astype('int')],
           spectrum.max() * 1.1,
           colors='C1')
plt.ylim(0, spectrum.max() * 1.1)
plt.xlim(0, len(spectrum))

c = Calibrator(peaks,
               elements=["Xe"],
               min_wavelength=3000.,
               max_wavelength=9000.)

# thresh (A) :: the individual line fitting tolerance to accept as a valid fitting point
# 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],
Example #3
0
atlas = load_calibration_lines("C:/Users/Josh/Downloads/calibration_lines.csv", elements=["Hg", "Eu", "Tb"], min_wavelength=300,max_wavelength=700)

print(atlas)

#peaks, _ = getPeaks(spectrum, min_dist=25, thres=0.3)
from scipy.signal import find_peaks

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

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.8,
                      max_slope=1.2,
                      min_intercept=250,
                      max_intercept=350,
                      line_fit_thresh=5)
 
best_p = c.fit(5)

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