Add label finder part
- remove the label part to clean the data
This commit is contained in:
parent
fcb3172399
commit
0060bddaef
1 changed files with 90 additions and 3 deletions
93
ETA.py
93
ETA.py
|
@ -1,4 +1,5 @@
|
|||
import numpy as np
|
||||
from scipy.optimize import curve_fit
|
||||
import utils
|
||||
import sys
|
||||
|
||||
|
@ -40,12 +41,24 @@ small_data = utils.compress( data , 5 )
|
|||
|
||||
points = utils.big_to_small( points , 5 )
|
||||
|
||||
# size - 1
|
||||
points[ 1 ][ 1 ] -= 1
|
||||
points[ 3 ][ 0 ] -= 1
|
||||
|
||||
# little shift to be inside the light
|
||||
points[ 2 ][ 1 ] += 3
|
||||
points[ 3 ][ 1 ] += 3
|
||||
|
||||
"""
|
||||
fill data
|
||||
"""
|
||||
|
||||
extremum = []
|
||||
for point in points:
|
||||
taken_points = utils.small_to_big( utils.fill( small_data , point , 1000 ) , 5 )
|
||||
taken_points = utils.small_to_big(
|
||||
utils.fill( small_data , point , 1000 ),
|
||||
5
|
||||
)
|
||||
extremum.append( [
|
||||
np.min( taken_points[ : , 1 ] ),
|
||||
np.max( taken_points[ : , 1 ] ),
|
||||
|
@ -64,6 +77,80 @@ border = {
|
|||
},
|
||||
}
|
||||
|
||||
"""
|
||||
label deletion
|
||||
"""
|
||||
|
||||
mean_data = np.mean( data[
|
||||
border['y']['min'] : border['y']['max'],
|
||||
border['x']['min'] : border['x']['max']
|
||||
] , axis = 0 )
|
||||
|
||||
gauss = lambda x , sigma , mu , a , b : a * (
|
||||
1 / sigma * np.sqrt(
|
||||
2 * np.pi
|
||||
) * np.exp(
|
||||
- ( x - mu ) ** 2 / ( 2 * sigma ** 2 )
|
||||
)
|
||||
) + b
|
||||
abciss = np.arange(
|
||||
border['x']['min'],
|
||||
border['x']['max'],
|
||||
1
|
||||
)
|
||||
guess_params = [
|
||||
1 ,
|
||||
border['x']['min'] + ( border['x']['max'] - border['x']['min'] ) // 2,
|
||||
np.max( mean_data ) ,
|
||||
np.min( mean_data ) ,
|
||||
]
|
||||
|
||||
first_estimate = curve_fit(
|
||||
gauss ,
|
||||
abciss ,
|
||||
mean_data ,
|
||||
guess_params
|
||||
)[0]
|
||||
|
||||
part_data = [
|
||||
mean_data[ : mean_data.shape[0] // 2 ],
|
||||
mean_data[ mean_data.shape[0] // 2 : ]
|
||||
]
|
||||
part_abciss = [
|
||||
abciss[ : abciss.shape[0] // 2 ],
|
||||
abciss[ abciss.shape[0] // 2 : ]
|
||||
]
|
||||
part_result = []
|
||||
for i in range( 2 ):
|
||||
part_result.append(
|
||||
curve_fit(
|
||||
gauss ,
|
||||
part_abciss[i],
|
||||
part_data[i] ,
|
||||
first_estimate
|
||||
)
|
||||
)
|
||||
|
||||
cov = np.array( [
|
||||
np.sum( np.diag( part_result[i][1] ) ) for i in range( 2 )
|
||||
] )
|
||||
i = np.argmax( cov ) # part where the label is
|
||||
|
||||
derivee = np.convolve(
|
||||
np.gradient( part_data[i] ),
|
||||
np.ones( part_data[i].shape[0] // 100 ),
|
||||
'same',
|
||||
)
|
||||
start_label = np.argmax( derivee )
|
||||
end_label = np.argmin( derivee[ start_label :: ( - 1 ) ** i ] )
|
||||
|
||||
keys = [ 'min' , 'max' ]
|
||||
|
||||
border['x'][keys[i]] += ( - 1 ) ** i * ( start_label + end_label )
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
plt.imshow( data[ border[ 'y' ][ 'min' ] : border[ 'y' ][ 'max' ] , border[ 'x' ][ 'min' ] : border[ 'x' ][ 'max' ] ] )
|
||||
plt.savefig( 'test.png' )
|
||||
plt.imshow( data[
|
||||
border[ 'y' ][ 'min' ] : border[ 'y' ][ 'max' ],
|
||||
border[ 'x' ][ 'min' ] : border[ 'x' ][ 'max' ]
|
||||
] )
|
||||
plt.savefig( 'asset/test.png' )
|
||||
|
|
Loading…
Reference in a new issue