Update how to find start and stop position of a peak
This commit is contained in:
parent
08e3b850e5
commit
b85c2d69d6
2 changed files with 50 additions and 17 deletions
|
@ -271,16 +271,18 @@ class Plate:
|
||||||
Set spectrum area
|
Set spectrum area
|
||||||
"""
|
"""
|
||||||
self.spectrum = Border()
|
self.spectrum = Border()
|
||||||
|
list_ = convolve(
|
||||||
indexes = find_peak_low_high(
|
|
||||||
convolve(
|
|
||||||
mean(
|
mean(
|
||||||
self.data[ self.border.slice() ],
|
self.data[ self.border.slice() ],
|
||||||
axis = 1 ,
|
axis = 1 ,
|
||||||
) ,
|
) ,
|
||||||
ones( 200 ),
|
ones( 200 ),
|
||||||
'valid' ,
|
'valid' ,
|
||||||
),
|
)
|
||||||
|
|
||||||
|
indexes = find_peak_low_high(
|
||||||
|
list_ ,
|
||||||
|
( max( list_ ) + mean( list_ ) ) / 2,
|
||||||
)[0]
|
)[0]
|
||||||
|
|
||||||
self.spectrum.y.min = indexes[0] + self.border.y.min + 100
|
self.spectrum.y.min = indexes[0] + self.border.y.min + 100
|
||||||
|
@ -289,15 +291,17 @@ class Plate:
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
plt.imshow( self.data[ self.border.slice() ] , aspect = 'auto' )
|
plt.imshow( self.data[ self.border.slice() ] , aspect = 'auto' )
|
||||||
plt.show()
|
plt.show()
|
||||||
indexes = find_peak_low_high(
|
list_ = convolve(
|
||||||
convolve(
|
|
||||||
mean(
|
mean(
|
||||||
self.data[ self.border.slice() ],
|
self.data[ self.border.slice() ],
|
||||||
axis = 0 ,
|
axis = 0 ,
|
||||||
) ,
|
) ,
|
||||||
ones( 200 ),
|
ones( 200 ),
|
||||||
'valid' ,
|
'valid' ,
|
||||||
),
|
)
|
||||||
|
indexes = find_peak_low_high(
|
||||||
|
list_ ,
|
||||||
|
mean( list_ ) + max( list_ ) / 2,
|
||||||
)[0]
|
)[0]
|
||||||
|
|
||||||
self.spectrum.x.min = indexes[0] + self.border.x.min + 100
|
self.spectrum.x.min = indexes[0] + self.border.x.min + 100
|
||||||
|
|
|
@ -208,10 +208,39 @@ def near_value( list_ , value ):
|
||||||
index = np.append( index , np.where( list_ == value ) )
|
index = np.append( index , np.where( list_ == value ) )
|
||||||
return np.round( np.sort( index ) ).astype( int ) # triage
|
return np.round( np.sort( index ) ).astype( int ) # triage
|
||||||
|
|
||||||
def find_peak_low_high( list_ ):
|
def find_peak_low_high( list_ , value ):
|
||||||
"""
|
"""
|
||||||
Return index of start and end of the biggest peak in a list
|
Return index of start and end of the biggest peak in a list
|
||||||
"""
|
"""
|
||||||
|
indexes = near_value(
|
||||||
|
list_,
|
||||||
|
value,
|
||||||
|
)
|
||||||
|
list_ = np.gradient( list_ )
|
||||||
|
if list_[ indexes[0] ] < 0:
|
||||||
|
indexes.insert( 0 , 0 )
|
||||||
|
if list_[ indexes[0] ] < 0:
|
||||||
|
indexes.insert( 0 , 0 ) # start with a descent
|
||||||
|
if list_[ indexes[-1] ] > 0:
|
||||||
|
indexes.append( len( list_ ) - 1 )
|
||||||
|
if list_[ indexes[-1] ] > 0:
|
||||||
|
indexes.append( len( list_ ) - 1 ) # end with a rise
|
||||||
|
|
||||||
|
if len( indexes ) % 2 == 1:
|
||||||
|
raise Exception(
|
||||||
|
'number of peaks doesn\'t match what it should be'
|
||||||
|
)
|
||||||
|
rises = [
|
||||||
|
indexes[ i ] for i in range( 0 , len( indexes ) , 2 )
|
||||||
|
]
|
||||||
|
descents = [
|
||||||
|
indexes[ i ] for i in range( 1 , len( indexes ) , 2 )
|
||||||
|
]
|
||||||
|
np.where( list_[ : rises[0] ] < 0 )[-1]
|
||||||
|
np.where( list_[ descents[ i - 1 ] : rises[ i ] ] < 0 )[-1]
|
||||||
|
np.where( list_[ rises[ i - 1 ] : descents[ i ] ] < 0 )[-1]
|
||||||
|
first_rise , last_rise = indexes[0] , indexes[0]
|
||||||
|
first_descent , last_descent = indexes[1] , indexes[1]
|
||||||
min_diff = ( max( list_ ) - min( list_ ) ) * 0.001
|
min_diff = ( max( list_ ) - min( list_ ) ) * 0.001
|
||||||
max_high_value = max( list_ )
|
max_high_value = max( list_ )
|
||||||
min_high_value = min( list_ )
|
min_high_value = min( list_ )
|
||||||
|
|
Loading…
Reference in a new issue