From 6a423e528a3f80acad5dce3c10ae1c460f792af4 Mon Sep 17 00:00:00 2001 From: linarphy Date: Tue, 16 May 2023 11:13:30 +0200 Subject: [PATCH] Update indicator to find calibrations lines --- ETA.py | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/ETA.py b/ETA.py index 1528701..2489dff 100644 --- a/ETA.py +++ b/ETA.py @@ -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()