Add first strategy to calibrate wavelength
It's don't seems good enough
This commit is contained in:
parent
bc493177bd
commit
0aa8a98cc7
1 changed files with 27 additions and 10 deletions
33
ETA.py
33
ETA.py
|
@ -387,21 +387,38 @@ if calibration != None:
|
|||
calib_peaks = np.loadtxt( calibration )
|
||||
mean_calib_up = np.mean( data[
|
||||
calibrations[ 'top' ][ 'y' ][ 'min' ] : calibrations[ 'top' ][ 'y' ][ 'max' ],
|
||||
border[ 'x' ][ 'min' ] : border[ 'x' ][ 'max' ]
|
||||
calibrations[ 'top' ][ 'x' ][ 'min' ] : calibrations[ 'top' ][ 'x' ][ 'max' ]
|
||||
] , axis = 0 )
|
||||
mean_calib_up -= np.min( mean_calib_up )
|
||||
mean_calib_up /= np.max( mean_calib_up )
|
||||
|
||||
peaks_up = find_peaks( mean_calib_up , height = 0.6 )[0] + border[ 'x' ][ 'min' ]
|
||||
peaks_up = find_peaks( mean_calib_up , height = 0.5 )[0] + calibrations[ 'top' ][ 'x' ][ 'min' ]
|
||||
diff = np.array( [ np.inf ] )
|
||||
polyval = np.polyfit( peaks_up[ : len( calib_peaks ) ] , calib_peaks[ : len( peaks_up ) ] , 1 )
|
||||
|
||||
if len( peaks_up ) != len( calib_peaks ):
|
||||
print( calib_peaks , peaks_up )
|
||||
print( len( calib_peaks ) , len( peaks_up ) )
|
||||
plt.plot( mean_calib_up )
|
||||
while np.max( diff ) > 1000: # we do not have the exact same number of peak (and the same peaks) in calibration model
|
||||
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 )
|
||||
polyfull_calib = np.polyfit( peaks_up[ : len( calib_peaks_new ) ] , calib_peaks_new[ : len( peaks_up ) ] , 1 , full = True )
|
||||
|
||||
if polyfull_up[ 1 ][ 0 ] < polyfull_calib[ 1 ][ 0 ]: # which one is a better fit ?
|
||||
peaks_up = peaks_up_new
|
||||
polyval = polyfull_up[ 0 ]
|
||||
else:
|
||||
calib_peaks = calib_peaks_new
|
||||
polyval = polyfull_calib[ 0 ]
|
||||
|
||||
x = np.arange( calibrations[ 'top' ][ 'x' ][ 'min' ] , calibrations[ 'top' ][ 'x' ][ 'max' ] , 1 )
|
||||
x = np.polyval( polyval , x )
|
||||
|
||||
plt.margins( x = 0 )
|
||||
plt.plot( x , mean_calib_up )
|
||||
plt.show()
|
||||
exit()
|
||||
polyval = np.polyfit( peaks_up , calib_peaks , 1 )
|
||||
print( polyval )
|
||||
|
||||
# First deformation
|
||||
|
||||
|
|
Loading…
Reference in a new issue