Update to use wavelength_calibration
This commit is contained in:
parent
f3e62bfca3
commit
4e54a1b433
1 changed files with 44 additions and 25 deletions
69
ETA.py
69
ETA.py
|
@ -384,39 +384,58 @@ else:
|
||||||
# Calibration
|
# Calibration
|
||||||
|
|
||||||
if calibration != None:
|
if calibration != None:
|
||||||
calib_peaks = np.loadtxt( calibration )
|
import wavelength_calibration as wave_calib
|
||||||
mean_calib_up = np.mean( data[
|
peaks_calib = np.loadtxt( calibration ) # sorted list
|
||||||
|
peaks_calib = np.sort( peaks_calib )
|
||||||
|
mean_up = np.mean( data[
|
||||||
calibrations[ 'top' ][ 'y' ][ 'min' ] : calibrations[ 'top' ][ 'y' ][ 'max' ],
|
calibrations[ 'top' ][ 'y' ][ 'min' ] : calibrations[ 'top' ][ 'y' ][ 'max' ],
|
||||||
calibrations[ 'top' ][ 'x' ][ 'min' ] : calibrations[ 'top' ][ 'x' ][ 'max' ]
|
calibrations[ 'top' ][ 'x' ][ 'min' ] : calibrations[ 'top' ][ 'x' ][ 'max' ]
|
||||||
] , axis = 0 )
|
] , axis = 0 )
|
||||||
mean_calib_up -= np.min( mean_calib_up )
|
peaks_up = np.array(
|
||||||
mean_calib_up /= np.max( mean_calib_up )
|
utils.retrieve_peaks(
|
||||||
|
mean_up ,
|
||||||
|
window_size = 1 ,
|
||||||
|
max_window_size = 1,
|
||||||
|
)
|
||||||
|
).astype( int )
|
||||||
|
|
||||||
peaks_up = find_peaks( mean_calib_up , height = 0.5 )[0] + calibrations[ 'top' ][ 'x' ][ 'min' ]
|
peakless_up = wave_calib.remove_peaks( mean_up , peaks_up )
|
||||||
diff = np.array( [ np.inf ] )
|
calib = { # hard-coded for now
|
||||||
polyval = np.polyfit( peaks_up[ : len( calib_peaks ) ] , calib_peaks[ : len( peaks_up ) ] , 1 )
|
'first': 3 ,
|
||||||
|
'last': 20,
|
||||||
|
}
|
||||||
|
first , last = wave_calib.get_extremities( peakless_up , peaks_up , mean_up )
|
||||||
|
up = {
|
||||||
|
'first': first,
|
||||||
|
'last' : last ,
|
||||||
|
}
|
||||||
|
peaks_up = peaks_up[ up[ 'first' ] : up[ 'last' ] + 1 ]
|
||||||
|
peaks_calib = peaks_calib[ calib[ 'first' ] : calib[ 'last' ] + 1 ]
|
||||||
|
|
||||||
while np.max( diff ) > 1000: # we do not have the exact same number of peak (and the same peaks) in calibration model
|
peaks_up = wave_calib.only_keep_calib( peaks_up , peaks_calib )
|
||||||
diff = abs( np.polyval( polyval , peaks_up[ : len( calib_peaks ) ] ) - calib_peaks[ : len( peaks_up ) ] )
|
|
||||||
point_to_delete = np.argmax( diff ) # get the "worst" point
|
|
||||||
peaks_up_new = np.delete( peaks_up , [ point_to_delete ] ) # remove from data value ( other peak detected )
|
|
||||||
calib_peaks_new = np.delete( calib_peaks , [ point_to_delete ] ) # remove from model ( peak not detected )
|
|
||||||
|
|
||||||
polyfull_up = np.polyfit( peaks_up_new[ : len( calib_peaks ) ] , calib_peaks[ : len( peaks_up_new ) ] , 1 , full = True )
|
polyval_wavelength = np.polyfit( # x = 0 begins at the start of
|
||||||
polyfull_calib = np.polyfit( peaks_up[ : len( calib_peaks_new ) ] , calib_peaks_new[ : len( peaks_up ) ] , 1 , full = True )
|
peaks_up , # calibartions[ 'top' ][ 'x' ][ 'min' ]
|
||||||
|
peaks_calib,
|
||||||
|
1 ,
|
||||||
|
)
|
||||||
|
|
||||||
if polyfull_up[ 1 ][ 0 ] < polyfull_calib[ 1 ][ 0 ]: # which one is a better fit ?
|
wavelength = np.polyval(
|
||||||
peaks_up = peaks_up_new
|
polyval_wavelength,
|
||||||
polyval = polyfull_up[ 0 ]
|
np.arange(
|
||||||
else:
|
0 ,
|
||||||
calib_peaks = calib_peaks_new
|
len( mean_up ),
|
||||||
polyval = polyfull_calib[ 0 ]
|
1 ,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
x = np.arange( calibrations[ 'top' ][ 'x' ][ 'min' ] , calibrations[ 'top' ][ 'x' ][ 'max' ] , 1 )
|
plt.plot(
|
||||||
x = np.polyval( polyval , x )
|
peaks_up,
|
||||||
|
peaks_calib - np.polyval(
|
||||||
plt.margins( x = 0 )
|
polyval_wavelength,
|
||||||
plt.plot( x , mean_calib_up )
|
peaks_up ,
|
||||||
|
) ,
|
||||||
|
)
|
||||||
plt.show()
|
plt.show()
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue