Update indicator to find calibrations lines
This commit is contained in:
parent
44d0769b27
commit
6a423e528a
1 changed files with 24 additions and 4 deletions
28
ETA.py
28
ETA.py
|
@ -8,13 +8,15 @@ from scipy.signal import convolve as sp_convolve
|
||||||
from scipy.signal import find_peaks
|
from scipy.signal import find_peaks
|
||||||
from scipy.ndimage import rotate
|
from scipy.ndimage import rotate
|
||||||
|
|
||||||
|
cache = True
|
||||||
if len( sys.argv ) < 2:
|
if len( sys.argv ) < 2:
|
||||||
raise Exception( 'this command must have a filename of an ETA fits as an argument' )
|
raise Exception( 'this command must have a filename of an ETA fits as an argument' )
|
||||||
|
|
||||||
data = utils.load( sys.argv[1] )
|
data = utils.load( sys.argv[1] )
|
||||||
|
|
||||||
cache_file = pathlib.Path( 'asset/points_' + sys.argv[1].split( '/' )[-1][:-5] + '.pag' )
|
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:
|
with shelve.open( str( cache_file ) ) as cache:
|
||||||
data = cache[ 'rotated_data' ]
|
data = cache[ 'rotated_data' ]
|
||||||
border = cache[ 'border' ]
|
border = cache[ 'border' ]
|
||||||
|
@ -218,6 +220,7 @@ else:
|
||||||
border[ 'x' ][ 'min' ] : border[ 'x' ][ 'max' ]
|
border[ 'x' ][ 'min' ] : border[ 'x' ][ 'max' ]
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
def indicator( list_ ):
|
def indicator( list_ ):
|
||||||
if np.mean( list_ ) > 0.75 * tot_avg:
|
if np.mean( list_ ) > 0.75 * tot_avg:
|
||||||
return 0
|
return 0
|
||||||
|
@ -226,7 +229,7 @@ else:
|
||||||
list_ -= np.min( list_ )
|
list_ -= np.min( list_ )
|
||||||
list_ /= np.max( list_ )
|
list_ /= np.max( list_ )
|
||||||
positions = np.where( list_ > 0.5 )[0]
|
positions = np.where( list_ > 0.5 )[0]
|
||||||
if len( positions ) < 10:
|
if len( positions ) < 100:
|
||||||
return 2
|
return 2
|
||||||
if len( positions ) > 400:
|
if len( positions ) > 400:
|
||||||
return 3
|
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 ) ] )
|
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_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 = {
|
calibrations = {
|
||||||
'top': {
|
'top': {
|
||||||
'x': {
|
'x': {
|
||||||
|
@ -317,3 +333,7 @@ fall = np.array( [
|
||||||
temp = np.convolve( results[ : , 10000 ] , np.ones( 50 ) , 'same' )
|
temp = np.convolve( results[ : , 10000 ] , np.ones( 50 ) , 'same' )
|
||||||
for i in range( len( fall ) - 1 ):
|
for i in range( len( fall ) - 1 ):
|
||||||
temp[ fall[ i ] : fall[ i + 1 ] ] = np.mean( temp[ fall[ i ] : fall[ i + 1 ] ] )
|
temp[ fall[ i ] : fall[ i + 1 ] ] = np.mean( temp[ fall[ i ] : fall[ i + 1 ] ] )
|
||||||
|
|
||||||
|
plt.plot( temp , label = 'flat' )
|
||||||
|
plt.legend()
|
||||||
|
plt.show()
|
||||||
|
|
Loading…
Reference in a new issue