Update processing order & fix

This commit is contained in:
linarphy 2023-05-26 13:53:16 +02:00
parent 3c0ece6688
commit d1b02301aa
No known key found for this signature in database
GPG key ID: 3D4AAAC3AD16E79C

88
ETA.py
View file

@ -89,10 +89,9 @@ if cache_file.is_file():
for key in [ 'rotated_data' , 'border' , 'calibrations' ]: for key in [ 'rotated_data' , 'border' , 'calibrations' ]:
if key not in cache: if key not in cache:
raise Exception( 'ETA.py: missing data in cache_file' ) raise Exception( 'ETA.py: missing data in cache_file' )
data = cache[ 'rotated_data' ] data = cache[ 'data' ]
border = cache[ 'border' ] border = cache[ 'border' ]
calibrations = cache[ 'calibrations' ] calibrations = cache[ 'calibrations' ]
stripes = cache[ 'stripes' ]
else: else:
""" """
find fill points find fill points
@ -370,20 +369,42 @@ else:
x_stripe = np.arange( 0 , size , 1 ).astype( int )[ good_x ] x_stripe = np.arange( 0 , size , 1 ).astype( int )[ good_x ]
y_stripe = y_stripe[ good_x ] y_stripe = y_stripe[ good_x ]
stripes = [ # list of polyval result for each stripe stripe = np.polyfit( x_stripe , y_stripe , 3 )
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(): if not cache_file.exists():
with shelve.open( str( cache_file ) ) as cache: with shelve.open( str( cache_file ) ) as cache:
cache[ 'rotated_data' ] = data cache[ 'data' ] = data
cache[ 'border' ] = border cache[ 'border' ] = border
cache[ 'calibrations'] = calibrations cache[ 'calibrations'] = calibrations
cache[ 'stripes' ] = stripes
size = border[ 'x' ][ 'max' ] - border[ 'x' ][ 'min' ] size_x = border[ 'x' ][ 'max' ] - border[ 'x' ][ 'min' ]
size_x = size size_y = calibrations[ 'down' ][ 'y' ][ 'min' ] - calibrations[ 'top' ][ 'y' ][ 'max' ]
size_y = calibrations[ 'down' ][ 'y' ][ 'min' ] - calibrations[ 'top' ][ 'y' ][ 'max' ]
# Calibration # Calibration
@ -461,17 +482,21 @@ if calibration != None:
return ( a * list_y + b ).astype( int ) 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 ) 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 ) diff = diff_calc( x , list_y )
cons_diff , i = utils.same_value( diff ) , 0 cons_diff , i = utils.same_value( diff ) , 0
for list_same in cons_diff: 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' ][ 'y' ][ 'max' ] + i : calibrations[ 'top' ][ 'y' ][ 'max' ] + i + len( list_same ),
calibrations[ 'top' ][ 'x' ][ 'min' ] + list_same[0] calibrations[ 'top' ][ 'x' ][ 'min' ] + list_same[0]
] ]
i += len( list_same ) 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 polyval_wavelength = np.polyfit( # x = 0 begins at the start of
peaks_up , # calibrations[ 'top' ][ 'x' ][ 'min' ] peaks_up , # calibrations[ 'top' ][ 'x' ][ 'min' ]
@ -486,44 +511,37 @@ if calibration != None:
1 , 1 ,
) )
) )
else:
padding = 0
wavelength = np.arange( size_y )
# First deformation list_ = np.convolve(
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(
np.gradient( np.gradient(
np.mean( results , axis = 1 ), np.mean( data , axis = 1 ),
) , ) ,
np.ones( 50 ), np.ones( 50 ),
'same' , '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( [ fall = np.array( [
np.argmax( list_results ) np.argmax( list_ )
] + [ ] + [
consecutive[0] + np.argmin( consecutive[0] + np.argmin(
list_results[ consecutive[0] : consecutive[-1] ] list_[ consecutive[0] : consecutive[-1] ]
) for consecutive in fall ) for consecutive in fall
] ).astype( int ) ] ).astype( int )
stairs = np.zeros_like( results ) stairs = np.zeros( ( size_y , size_x ) )
for x in range( size ): for x in range( size_x ):
stairs[ : , x ] = results[ : , x ] # can be modified, but no used anymore so it's fine
stairs[ : fall[0] , x ] = 0 # TODO: put the mean stairs[ : fall[0] , x ] = 0 # TODO: put the mean
for i in range( len( fall ) - 1 ): 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 stairs[ fall[ -1 ] : , x ] = 0
np.imshow( stairs , aspect = 'auto' )
np.show()
if output == None: if output == None:
print( stairs ) print( stairs )
else: else: