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:
|
for peak in peaks:
|
||||||
first = peak
|
first = peak
|
||||||
peak , old = first - 2 , first - 1
|
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
|
old = peak
|
||||||
peak -= 1
|
peak -= 1
|
||||||
peakless_signal[ peak : first ] = peakless_signal[ peak ] * np.ones( first - peak )
|
peakless_signal[ peak : first ] = peakless_signal[ peak ] * np.ones( first - peak )
|
||||||
|
|
||||||
peak , old = first + 2 , first + 1
|
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
|
old = peak
|
||||||
peak += 1
|
peak += 1
|
||||||
peakless_signal[ first : peak ] = peakless_signal[ peak ] * np.ones( peak - first )
|
peakless_signal[ first : peak ] = peakless_signal[ peak ] * np.ones( peak - first )
|
||||||
|
@ -61,7 +61,7 @@ def get_extremities( signal , peaks ):
|
||||||
peaks_inside = np.where(
|
peaks_inside = np.where(
|
||||||
argmin_1 < peaks,
|
argmin_1 < peaks,
|
||||||
)[0]
|
)[0]
|
||||||
if len( peaks_inside ) < 1:
|
if len( peaks_inside ) == 0:
|
||||||
raise Exception( 'unknown plage, cannot autocalibrate' )
|
raise Exception( 'unknown plage, cannot autocalibrate' )
|
||||||
return ( first_peak , peaks_inside[0] )
|
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
|
only keep data peaks corresponding to calibration
|
||||||
"""
|
"""
|
||||||
diff_calib = ( peaks_calib[ 1 : ] - peaks_calib[ : -1 ] ).astype( float )
|
diff_calib = ( peaks_calib[ 1 : ] - peaks_calib[ : -1 ] ).astype( float )
|
||||||
diff_calib -= np.min( diff_calib )
|
diff_calib /= np.sum( diff_calib )
|
||||||
diff_calib /= np.max( diff_calib )
|
|
||||||
|
|
||||||
diff_data = ( peaks_data[ 1 : ] - peaks_data[ : -1 ] ).astype( float )
|
diff_data = ( peaks_data[ 1 : ] - peaks_data[ : -1 ] ).astype( float )
|
||||||
diff_data -= np.min( diff_data )
|
diff_data /= np.sum( diff_data )
|
||||||
diff_data /= np.max( diff_data )
|
|
||||||
|
|
||||||
peaks = [ -1 ]
|
peaks = [ -1 ]
|
||||||
for i in range( len( diff_calib ) ):
|
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 ) ):
|
for j in range( peaks[ - 1 ] + 1 , len( diff_data ) ):
|
||||||
sum_ += diff_data[ j ]
|
sum_ += diff_data[ j ]
|
||||||
if sum_ - diff_calib[ i ] > 0.002:
|
if sum_ - diff_calib[ i ] > 0.002:
|
||||||
print( sum_ - diff_calib[ i ] )
|
|
||||||
raise Exception( 'reference peak not found' )
|
raise Exception( 'reference peak not found' )
|
||||||
if sum_ - diff_calib[ i ] > - 0.002:
|
if sum_ - diff_calib[ i ] > - 0.002:
|
||||||
good = j
|
good = j
|
||||||
|
@ -94,5 +91,6 @@ def only_keep_calib( peaks_data , peaks_calib ):
|
||||||
peaks.append( peaks[-1] + 1 ) # append the last peak
|
peaks.append( peaks[-1] + 1 ) # append the last peak
|
||||||
|
|
||||||
return np.array(
|
return np.array(
|
||||||
[ peaks_data[ i ] for i in peaks[ 1 : ] ] # remove the first -1 value
|
[ peaks_data[ i ] for i in peaks[ 1 : ] ], # remove the first -1 value
|
||||||
).astype( int )
|
dtyp = int,
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in a new issue