Add bad calib peak deletion with ratio
This commit is contained in:
parent
fa0d433244
commit
7a0d016905
1 changed files with 67 additions and 6 deletions
|
@ -62,7 +62,7 @@ peaks_inside = np.where(
|
||||||
)
|
)
|
||||||
)[0]
|
)[0]
|
||||||
if len( peaks_inside ) < 1:
|
if len( peaks_inside ) < 1:
|
||||||
raise Error( 'unknown plage, cannot autocalibrate' )
|
raise Exception( 'unknown plage, cannot autocalibrate' )
|
||||||
first_peak_cal = peaks_inside[0]
|
first_peak_cal = peaks_inside[0]
|
||||||
first_peak_ref = 3 # hard-coded
|
first_peak_ref = 3 # hard-coded
|
||||||
|
|
||||||
|
@ -79,15 +79,52 @@ peaks_inside = np.where(
|
||||||
argmin_1 < peaks_calib_top
|
argmin_1 < peaks_calib_top
|
||||||
)[0]
|
)[0]
|
||||||
if len( peaks_inside ) < 1:
|
if len( peaks_inside ) < 1:
|
||||||
raise Error( 'unknown plage, cannot autocalibrate' )
|
raise Exception( 'unknown plage, cannot autocalibrate' )
|
||||||
last_peak_cal = peaks_inside[0]
|
last_peak_cal = peaks_inside[0]
|
||||||
last_peak_ref = 20 # hard-coded
|
last_peak_ref = 20 # hard-coded
|
||||||
|
|
||||||
print( first_peak_cal , last_peak_cal )
|
"""
|
||||||
|
delete if too much peak in calib
|
||||||
|
"""
|
||||||
|
|
||||||
|
peaks_calib_top = peaks_calib_top[ first_peak_cal : last_peak_cal ]
|
||||||
|
peaks_reference = peaks_reference[ first_peak_ref : last_peak_ref ]
|
||||||
|
|
||||||
|
diff_ref = ( peaks_reference[ 1 : ] - peaks_reference[ : -1 ] ).astype( float )
|
||||||
|
diff_ref -= np.min( diff_ref )
|
||||||
|
diff_ref /= np.max( diff_ref )
|
||||||
|
diff_cal = ( peaks_calib_top[ 1 : ] - peaks_calib_top[ : -1 ] ).astype( float )
|
||||||
|
diff_cal -= np.min( diff_cal )
|
||||||
|
diff_cal /= np.max( diff_cal )
|
||||||
|
|
||||||
|
peaks = [ -1 ]
|
||||||
|
for i in range( len( diff_ref ) ):
|
||||||
|
good , sum_ = -1 , 0
|
||||||
|
for j in range( peaks[ - 1 ] + 1 , len( diff_cal ) ):
|
||||||
|
sum_ += diff_cal[ j ]
|
||||||
|
if sum_ - diff_ref[ i ] > 0.002:
|
||||||
|
print( sum_ - diff_ref[ i ] )
|
||||||
|
raise Exception( 'reference peak not found' )
|
||||||
|
if sum_ - diff_ref[ i ] > - 0.002:
|
||||||
|
good = j
|
||||||
|
break
|
||||||
|
if good == -1:
|
||||||
|
raise Exception( 'reference peak not found and not exceeded' )
|
||||||
|
peaks.append( good )
|
||||||
|
peaks.append( peaks[-1] + 1 )
|
||||||
|
|
||||||
|
peaks_calib_top = np.array(
|
||||||
|
[ peaks_calib_top[ i ] for i in peaks[ 1 : ] ]
|
||||||
|
).astype( int )
|
||||||
|
|
||||||
|
"""
|
||||||
|
Calibration
|
||||||
|
"""
|
||||||
|
|
||||||
polyval = np.polyfit(
|
polyval = np.polyfit(
|
||||||
peaks_calib_top[ first_peak_cal : last_peak_cal ],
|
peaks_calib_top,
|
||||||
peaks_reference[ first_peak_ref : last_peak_ref ],
|
peaks_reference,
|
||||||
1 ,
|
1 ,
|
||||||
) # We suppose there is as much calib peak than ref peak for now
|
) # We suppose there is as much calib peak than ref peak for now
|
||||||
|
|
||||||
peaks_values = [ reference[ 1 , i ] for i in peaks_reference ]
|
peaks_values = [ reference[ 1 , i ] for i in peaks_reference ]
|
||||||
|
@ -144,3 +181,27 @@ manager.canvas.figure.gca().vlines(
|
||||||
)
|
)
|
||||||
manager.show()
|
manager.show()
|
||||||
manager.start_main_loop()
|
manager.start_main_loop()
|
||||||
|
|
||||||
|
manager = qt.FigureManager(
|
||||||
|
qt.FigureCanvas(
|
||||||
|
fig.Figure(
|
||||||
|
figsize = ( 10 , 5 )
|
||||||
|
),
|
||||||
|
),
|
||||||
|
0,
|
||||||
|
)
|
||||||
|
|
||||||
|
manager.canvas.figure.add_subplot( 2 , 1 , 1 , xlim = ( 3800 , 4000 ) , xmargin = 0 ).plot(
|
||||||
|
wavelength ,
|
||||||
|
mean_calib_top,
|
||||||
|
)
|
||||||
|
manager.canvas.figure.axes[0].set_title( 'raw data' )
|
||||||
|
|
||||||
|
manager.canvas.figure.add_subplot( 2 , 1 , 2 , xlim = ( 3800 , 4000 ) , xmargin = 0 ).plot(
|
||||||
|
reference[0],
|
||||||
|
reference[1],
|
||||||
|
)
|
||||||
|
manager.canvas.figure.axes[1].set_title( 'reference' )
|
||||||
|
|
||||||
|
manager.show()
|
||||||
|
manager.start_main_loop()
|
||||||
|
|
Loading…
Reference in a new issue