Update processing order & fix
This commit is contained in:
parent
3c0ece6688
commit
d1b02301aa
1 changed files with 53 additions and 35 deletions
88
ETA.py
88
ETA.py
|
@ -89,10 +89,9 @@ if cache_file.is_file():
|
|||
for key in [ 'rotated_data' , 'border' , 'calibrations' ]:
|
||||
if key not in cache:
|
||||
raise Exception( 'ETA.py: missing data in cache_file' )
|
||||
data = cache[ 'rotated_data' ]
|
||||
data = cache[ 'data' ]
|
||||
border = cache[ 'border' ]
|
||||
calibrations = cache[ 'calibrations' ]
|
||||
stripes = cache[ 'stripes' ]
|
||||
else:
|
||||
"""
|
||||
find fill points
|
||||
|
@ -370,20 +369,42 @@ else:
|
|||
x_stripe = np.arange( 0 , size , 1 ).astype( int )[ good_x ]
|
||||
y_stripe = y_stripe[ good_x ]
|
||||
|
||||
stripes = [ # list of polyval result for each stripe
|
||||
np.polyfit( x_stripe , y_stripe , 3 )
|
||||
stripe = np.polyfit( x_stripe , y_stripe , 3 )
|
||||
|
||||
# First deformation
|
||||
|
||||
list_ = data[
|
||||
calibrations[ 'top' ][ 'y' ][ 'max' ] : calibrations[ 'down' ][ 'y' ][ 'min' ],
|
||||
border[ 'x' ][ 'min' ] : border[ 'x' ][ 'max' ]
|
||||
]
|
||||
y_diff = ( np.polyval(
|
||||
stripe,
|
||||
np.arange( 0 , border[ 'x' ][ 'max' ] - border[ 'x' ][ 'min' ] , 1 )
|
||||
) ).astype( int )
|
||||
y_diff[ np.where( y_diff < 0 ) ] = 0
|
||||
results = np.zeros( ( list_.shape[0] + np.max( y_diff ) , list_.shape[1] ) )
|
||||
for i in range( list_.shape[1] ):
|
||||
results[ : , i ] = np.concatenate( (
|
||||
np.zeros(
|
||||
np.max( y_diff ) - y_diff[ i ]
|
||||
) ,
|
||||
list_[ : , i ] ,
|
||||
np.zeros( y_diff[i] ),
|
||||
) )
|
||||
|
||||
data[
|
||||
calibrations[ 'top' ][ 'y' ][ 'max' ] : calibrations[ 'down' ][ 'y' ][ 'min' ] + np.max( y_diff ),
|
||||
border[ 'x' ][ 'min' ] : border[ 'x' ][ 'max' ]
|
||||
] = results
|
||||
|
||||
if not cache_file.exists():
|
||||
with shelve.open( str( cache_file ) ) as cache:
|
||||
cache[ 'rotated_data' ] = data
|
||||
cache[ 'border' ] = border
|
||||
cache[ 'calibrations'] = calibrations
|
||||
cache[ 'stripes' ] = stripes
|
||||
cache[ 'data' ] = data
|
||||
cache[ 'border' ] = border
|
||||
cache[ 'calibrations'] = calibrations
|
||||
|
||||
size = border[ 'x' ][ 'max' ] - border[ 'x' ][ 'min' ]
|
||||
size_x = size
|
||||
size_y = calibrations[ 'down' ][ 'y' ][ 'min' ] - calibrations[ 'top' ][ 'y' ][ 'max' ]
|
||||
size_x = border[ 'x' ][ 'max' ] - border[ 'x' ][ 'min' ]
|
||||
size_y = calibrations[ 'down' ][ 'y' ][ 'min' ] - calibrations[ 'top' ][ 'y' ][ 'max' ]
|
||||
|
||||
# Calibration
|
||||
|
||||
|
@ -461,17 +482,21 @@ if calibration != None:
|
|||
|
||||
return ( a * list_y + b ).astype( int )
|
||||
|
||||
new_data = np.zeros( ( size_y , size_x - 199 ) )
|
||||
padding = diff_calc( size_x , size_y ) - size_x
|
||||
new_data = np.zeros( ( size_y , size_x - padding ) )
|
||||
list_y = np.arange( 0 , size_y , 1 )
|
||||
for x in range( 100 , size_x - 100 ):
|
||||
for x in range( size_x - padding ):
|
||||
diff = diff_calc( x , list_y )
|
||||
cons_diff , i = utils.same_value( diff ) , 0
|
||||
for list_same in cons_diff:
|
||||
new_data[ i : i + len( list_same ) , x - 100 ] = data[
|
||||
new_data[ i : i + len( list_same ) , x ] = data[
|
||||
calibrations[ 'top' ][ 'y' ][ 'max' ] + i : calibrations[ 'top' ][ 'y' ][ 'max' ] + i + len( list_same ),
|
||||
calibrations[ 'top' ][ 'x' ][ 'min' ] + list_same[0]
|
||||
]
|
||||
i += len( list_same )
|
||||
calibrations[ 'top' ][ 'x' ][ 'max' ] -= padding
|
||||
calibrations[ 'down' ][ 'x' ][ 'max' ] -= padding
|
||||
border[ 'x' ][ 'max' ] -= padding
|
||||
|
||||
polyval_wavelength = np.polyfit( # x = 0 begins at the start of
|
||||
peaks_up , # calibrations[ 'top' ][ 'x' ][ 'min' ]
|
||||
|
@ -486,44 +511,37 @@ if calibration != None:
|
|||
1 ,
|
||||
)
|
||||
)
|
||||
else:
|
||||
padding = 0
|
||||
wavelength = np.arange( size_y )
|
||||
|
||||
# First deformation
|
||||
|
||||
list_ = data[
|
||||
calibrations[ 'top' ][ 'y' ][ 'max' ] : calibrations[ 'down' ][ 'y' ][ 'min' ],
|
||||
border[ 'x' ][ 'min' ] : border[ 'x' ][ 'max' ]
|
||||
]
|
||||
y_diff = ( np.polyval( stripes[0] , np.arange( 0 , size , 1 ) ) ).astype( int )
|
||||
y_diff[ np.where( y_diff < 0 ) ] = 0
|
||||
results = np.zeros( ( list_.shape[0] + np.max( y_diff ) , list_.shape[1] ) )
|
||||
for i in range( list_.shape[1] ):
|
||||
results[ : , i ] = np.concatenate( ( np.zeros( np.max( y_diff ) - y_diff[ i ] ) , list_[ : , i ] , np.zeros( y_diff[i] ) ) )
|
||||
|
||||
list_results = np.convolve(
|
||||
list_ = np.convolve(
|
||||
np.gradient(
|
||||
np.mean( results , axis = 1 ),
|
||||
np.mean( data , axis = 1 ),
|
||||
) ,
|
||||
np.ones( 50 ),
|
||||
'same' ,
|
||||
)
|
||||
|
||||
fall = utils.consecutive( np.where( list_results < 0.03 * np.min( list_results ) )[0] )
|
||||
fall = utils.consecutive( np.where( list_ < 0.03 * np.min( list_ ) )[0] )
|
||||
fall = np.array( [
|
||||
np.argmax( list_results )
|
||||
np.argmax( list_ )
|
||||
] + [
|
||||
consecutive[0] + np.argmin(
|
||||
list_results[ consecutive[0] : consecutive[-1] ]
|
||||
list_[ consecutive[0] : consecutive[-1] ]
|
||||
) for consecutive in fall
|
||||
] ).astype( int )
|
||||
|
||||
stairs = np.zeros_like( results )
|
||||
for x in range( size ):
|
||||
stairs[ : , x ] = results[ : , x ] # can be modified, but no used anymore so it's fine
|
||||
stairs = np.zeros( ( size_y , size_x ) )
|
||||
for x in range( size_x ):
|
||||
stairs[ : fall[0] , x ] = 0 # TODO: put the mean
|
||||
for i in range( len( fall ) - 1 ):
|
||||
stairs[ fall[ i ] : fall[ i + 1 ] , x ] = np.mean( stairs[ fall[ i ] : fall[ i + 1 ] ] )
|
||||
stairs[ fall[ i ] : fall[ i + 1 ] , x ] = np.mean( data[ fall[ i ] : fall[ i + 1 ] , x ] )
|
||||
stairs[ fall[ -1 ] : , x ] = 0
|
||||
|
||||
np.imshow( stairs , aspect = 'auto' )
|
||||
np.show()
|
||||
|
||||
if output == None:
|
||||
print( stairs )
|
||||
else:
|
||||
|
|
Loading…
Reference in a new issue