Update calibration
- Update normalization of window - Clean up exception logging - Fix edge case
This commit is contained in:
parent
920374b144
commit
d97c041ea0
1 changed files with 8 additions and 10 deletions
|
@ -9,13 +9,13 @@ def remove_peaks( signal , peaks ):
|
|||
for peak in peaks:
|
||||
first = peak
|
||||
peak , old = first - 2 , first - 1
|
||||
while peakless_signal[ peak ] <= peakless_signal[ old ]:
|
||||
while peakless_signal[ peak ] <= peakless_signal[ old ] and peak > 0:
|
||||
old = peak
|
||||
peak -= 1
|
||||
peakless_signal[ peak : first ] = peakless_signal[ peak ] * np.ones( first - peak )
|
||||
|
||||
peak , old = first + 2 , first + 1
|
||||
while peakless_signal[ peak ] <= peakless_signal[ old ]:
|
||||
while peakless_signal[ peak ] <= peakless_signal[ old ] and peak < len( peakless_signal ) - 1:
|
||||
old = peak
|
||||
peak += 1
|
||||
peakless_signal[ first : peak ] = peakless_signal[ peak ] * np.ones( peak - first )
|
||||
|
@ -61,7 +61,7 @@ def get_extremities( signal , peaks ):
|
|||
peaks_inside = np.where(
|
||||
argmin_1 < peaks,
|
||||
)[0]
|
||||
if len( peaks_inside ) < 1:
|
||||
if len( peaks_inside ) == 0:
|
||||
raise Exception( 'unknown plage, cannot autocalibrate' )
|
||||
return ( first_peak , peaks_inside[0] )
|
||||
|
||||
|
@ -70,12 +70,10 @@ def only_keep_calib( peaks_data , peaks_calib ):
|
|||
only keep data peaks corresponding to calibration
|
||||
"""
|
||||
diff_calib = ( peaks_calib[ 1 : ] - peaks_calib[ : -1 ] ).astype( float )
|
||||
diff_calib -= np.min( diff_calib )
|
||||
diff_calib /= np.max( diff_calib )
|
||||
diff_calib /= np.sum( diff_calib )
|
||||
|
||||
diff_data = ( peaks_data[ 1 : ] - peaks_data[ : -1 ] ).astype( float )
|
||||
diff_data -= np.min( diff_data )
|
||||
diff_data /= np.max( diff_data )
|
||||
diff_data /= np.sum( diff_data )
|
||||
|
||||
peaks = [ -1 ]
|
||||
for i in range( len( diff_calib ) ):
|
||||
|
@ -83,7 +81,6 @@ def only_keep_calib( peaks_data , peaks_calib ):
|
|||
for j in range( peaks[ - 1 ] + 1 , len( diff_data ) ):
|
||||
sum_ += diff_data[ j ]
|
||||
if sum_ - diff_calib[ i ] > 0.002:
|
||||
print( sum_ - diff_calib[ i ] )
|
||||
raise Exception( 'reference peak not found' )
|
||||
if sum_ - diff_calib[ i ] > - 0.002:
|
||||
good = j
|
||||
|
@ -94,5 +91,6 @@ def only_keep_calib( peaks_data , peaks_calib ):
|
|||
peaks.append( peaks[-1] + 1 ) # append the last peak
|
||||
|
||||
return np.array(
|
||||
[ peaks_data[ i ] for i in peaks[ 1 : ] ] # remove the first -1 value
|
||||
).astype( int )
|
||||
[ peaks_data[ i ] for i in peaks[ 1 : ] ], # remove the first -1 value
|
||||
dtyp = int,
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue