Update indicator to find calibrations lines

This commit is contained in:
linarphy 2023-05-16 11:13:30 +02:00
parent 44d0769b27
commit 6a423e528a
No known key found for this signature in database
GPG key ID: 3D4AAAC3AD16E79C

28
ETA.py
View file

@ -8,13 +8,15 @@ from scipy.signal import convolve as sp_convolve
from scipy.signal import find_peaks
from scipy.ndimage import rotate
cache = True
if len( sys.argv ) < 2:
raise Exception( 'this command must have a filename of an ETA fits as an argument' )
data = utils.load( sys.argv[1] )
cache_file = pathlib.Path( 'asset/points_' + sys.argv[1].split( '/' )[-1][:-5] + '.pag' )
if cache_file.is_file():
if cache_file.is_file() and cache:
with shelve.open( str( cache_file ) ) as cache:
data = cache[ 'rotated_data' ]
border = cache[ 'border' ]
@ -218,6 +220,7 @@ else:
border[ 'x' ][ 'min' ] : border[ 'x' ][ 'max' ]
]
)
def indicator( list_ ):
if np.mean( list_ ) > 0.75 * tot_avg:
return 0
@ -226,7 +229,7 @@ else:
list_ -= np.min( list_ )
list_ /= np.max( list_ )
positions = np.where( list_ > 0.5 )[0]
if len( positions ) < 10:
if len( positions ) < 100:
return 2
if len( positions ) > 400:
return 3
@ -238,9 +241,22 @@ else:
indicators = np.array( [ indicator( data[ i , border[ 'x' ][ 'min' ] : border[ 'x' ][ 'max' ] ].copy() ) for i in range( border[ 'y' ][ 'min' ] , border[ 'y' ][ 'max' ] , 1 ) ] )
calibration_areas = utils.consecutive( np.where( indicators == 10 )[0] )
calibration_sizes = [ len( calibration_area ) for calibration_area in calibration_areas ]
y_calibrations = [ calibration_areas[ i ] for i in np.argsort( calibration_sizes ) ][ -2 : ]
calibration_areas = [
[ calibration_area for calibration_area in calibration_areas if calibration_area[-1] < ( border[ 'y' ][ 'max' ] - border[ 'y' ][ 'min' ] ) / 2 ],
[ calibration_area for calibration_area in calibration_areas if calibration_area[ 0] > ( border[ 'y' ][ 'max' ] - border[ 'y' ][ 'min' ] ) / 2 ],
]
calibration_sizes = [
[ len( calibration_area ) for calibration_area in calibration_areas[0] ],
[ len( calibration_area ) for calibration_area in calibration_areas[1] ],
]
y_calibrations = [
calibration_areas[0][ np.argmax( calibration_sizes[0] ) ],
calibration_areas[1][ np.argmax( calibration_sizes[1] ) ],
]
calibrations = {
'top': {
'x': {
@ -317,3 +333,7 @@ fall = np.array( [
temp = np.convolve( results[ : , 10000 ] , np.ones( 50 ) , 'same' )
for i in range( len( fall ) - 1 ):
temp[ fall[ i ] : fall[ i + 1 ] ] = np.mean( temp[ fall[ i ] : fall[ i + 1 ] ] )
plt.plot( temp , label = 'flat' )
plt.legend()
plt.show()