Update version number

- Add --output option (WIP)
- Add output generated (only missing thing is now the wavelength axis)
This commit is contained in:
linarphy 2023-05-16 15:41:51 +02:00
parent 17531f2cea
commit 1f85197d07
No known key found for this signature in database
GPG key ID: 3D4AAAC3AD16E79C

97
ETA.py
View file

@ -8,7 +8,7 @@ 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 , filename = '' , None cache , filename , output = '' , None , None
if len( sys.argv ) < 2: if len( sys.argv ) < 2:
raise Exception( 'ETA.py: type \'ETA.py -h\' for more information' ) raise Exception( 'ETA.py: type \'ETA.py -h\' for more information' )
@ -27,7 +27,13 @@ for i in range( 1 , len( sys.argv ) ):
elif arg == '-c': elif arg == '-c':
if i == len( sys.argv ) - 1: if i == len( sys.argv ) - 1:
raise Exception( 'ETA.py: cache have to take a value' ) raise Exception( 'ETA.py: cache have to take a value' )
arg == '--cache=' + arg[ i + 1 ] arg[ i + 1 ] == '--cache=' + arg[ i + 1 ]
continue
elif arg == '-o':
if i == len( sys.argv ) - 1:
raise Exception( 'ETA.py: output have to take a value' )
arg[ i + 1 ] == '--output=' + arg[ i + 1 ]
continue
else: else:
raise Exception( 'ETA.py: unknown argument "' + arg + '", type \'ETA.py -h\' for more information' ) raise Exception( 'ETA.py: unknown argument "' + arg + '", type \'ETA.py -h\' for more information' )
if arg[1] == '-': # not elif because arg can change after last if if arg[1] == '-': # not elif because arg can change after last if
@ -37,16 +43,19 @@ for i in range( 1 , len( sys.argv ) ):
\n -v --version show version number and quit\ \n -v --version show version number and quit\
\n -n --no-cache do not use cache and rewrite it\ \n -n --no-cache do not use cache and rewrite it\
\n -c --cache use given cache\ \n -c --cache use given cache\
\n -o --output output file, default to standard output\
\n\ \n\
\nParse a naroo ETA fits' ) \nParse a naroo ETA fits' )
exit() exit()
elif arg == '--version': elif arg == '--version':
print( '0.1' ) print( '0.2' )
exit() exit()
elif arg == '--no-cache': elif arg == '--no-cache':
cache = '' # hack, empty string mean this dir, so not a file cache = '' # hack, empty string mean this dir, so not a file
elif len( arg ) > 8 and arg[ : 8 ] == '--cache=': elif len( arg ) > 8 and arg[ : 8 ] == '--cache=':
cache = arg[ 8 : ] cache = arg[ 8 : ]
elif len( arg ) > 9 and arg[ : 9 ] == '--output=':
output = arg[ 9 : ]
else: else:
raise Exception( 'ETA.py: unknown argument "' + arg + '", type \'ETA.py -h\' for more information' ) raise Exception( 'ETA.py: unknown argument "' + arg + '", type \'ETA.py -h\' for more information' )
else: else:
@ -68,6 +77,7 @@ if cache_file.is_file():
data = cache[ 'rotated_data' ] data = cache[ 'rotated_data' ]
border = cache[ 'border' ] border = cache[ 'border' ]
calibrations = cache[ 'calibrations' ] calibrations = cache[ 'calibrations' ]
stripes = cache[ 'stripes' ]
else: else:
""" """
find fill points find fill points
@ -327,34 +337,43 @@ else:
}, },
} }
"""
stripes curves detection
"""
list_ = data[
calibrations[ 'top' ][ 'y' ][ 'max' ] : calibrations[ 'down' ][ 'y' ][ 'min' ],
border[ 'x' ][ 'min' ] : border[ 'x' ][ 'max' ]
].copy()
list_min = np.min( list_ , axis = 0 )
list_ -= list_min
list_max = np.max( list_ , axis = 0 )
list_ /= list_max
size = list_.shape[1]
y_stripe = np.argmax( list_ , axis = 0 )
good_x = np.where( y_stripe < 2 * np.mean( y_stripe ) )[0]
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 )
]
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[ 'rotated_data' ] = data
cache[ 'border' ] = border cache[ 'border' ] = border
cache[ 'calibrations'] = calibrations cache[ 'calibrations'] = calibrations
cache[ 'stripes' ] = stripes
print( border )
print( calibrations )
exit()
# First deformation
"""
stripes curves detection
"""
list_ = data[ list_ = data[
calibrations[ 'top' ][ 'y' ][ 'max' ] : calibrations[ 'down' ][ 'y' ][ 'min' ], calibrations[ 'top' ][ 'y' ][ 'max' ] : calibrations[ 'down' ][ 'y' ][ 'min' ],
border[ 'x' ][ 'min' ] : border[ 'x' ][ 'max' ] border[ 'x' ][ 'min' ] : border[ 'x' ][ 'max' ]
].copy()
list_ -= np.min( list_ , axis = 0 )
list_ /= np.max( list_ , axis = 0 )
size = list_.shape[1]
y_stripe = np.argmax( list_ , axis = 0 )
good_x = np.where( y_stripe < 2 * np.mean( y_stripe ) )[0]
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 )
] ]
# First deformation
y_diff = ( np.polyval( stripes[0] , np.arange( 0 , size , 1 ) ) ).astype( int ) y_diff = ( np.polyval( stripes[0] , np.arange( 0 , size , 1 ) ) ).astype( int )
y_diff[ np.where( y_diff < 0 ) ] = 0 y_diff[ np.where( y_diff < 0 ) ] = 0
results = np.zeros( ( list_.shape[0] + np.max( y_diff ) , list_.shape[1] ) ) results = np.zeros( ( list_.shape[0] + np.max( y_diff ) , list_.shape[1] ) )
@ -369,7 +388,7 @@ list_results = np.convolve(
'same' , 'same' ,
) )
fall = utils.consecutive( np.where( list_results < - 0.02 )[0] ) fall = utils.consecutive( np.where( list_results < 0.03 * np.min( list_results ) )[0] )
fall = np.array( [ fall = np.array( [
np.argmax( list_results ) np.argmax( list_results )
] + [ ] + [
@ -378,30 +397,12 @@ fall = np.array( [
) for consecutive in fall ) for consecutive in fall
] ).astype( int ) ] ).astype( int )
mask = np.zeros_like( data ) stairs = np.zeros_like( results )
mask[ for x in range( size ):
calibrations[ 'top' ][ 'y' ][ 'min' ] : calibrations[ 'top' ][ 'y' ][ 'max' ], stairs[ : , x ] = results[ : , x ] # can be modified, but no used anymore so it's fine
calibrations[ 'top' ][ 'x' ][ 'min' ] : calibrations[ 'top' ][ 'x' ][ 'max' ] stairs[ : fall[0] , x ] = 0
] = -1 for i in range( len( fall ) - 1 ):
mask[ stairs[ fall[ i ] : fall[ i + 1 ] , x ] = np.mean( stairs[ fall[ i ] : fall[ i + 1 ] ] )
calibrations[ 'down' ][ 'y' ][ 'min' ] : calibrations[ 'down' ][ 'y' ][ 'max' ], stairs[ fall[ -1 ] : , x ] = 0
calibrations[ 'down' ][ 'x' ][ 'min' ] : calibrations[ 'down' ][ 'x' ][ 'max' ] plt.imshow( stairs )
] = -1
mask[
calibrations[ 'top' ][ 'y' ][ 'max' ] : calibrations[ 'down' ][ 'y' ][ 'min' ],
border[ 'x' ][ 'min' ] : border[ 'x' ][ 'max' ]
] = 1
plt.imshow( data )
plt.imshow( mask , alpha = 0.5 )
plt.show()
temp = results[ : , 10000 ].copy()
temp[ : fall[ 0 ] ] = 0
for i in range( len( fall ) - 1 ):
temp[ fall[ i ] : fall[ i + 1 ] ] = np.mean( temp[ fall[ i ] : fall[ i + 1 ] ] )
temp[ fall[ - 1 ] : ] = np.mean( temp[ fall[ -1 ] : ] )
plt.plot( results[ : , 10000 ] , label = 'raw' )
plt.plot( temp , label = 'flat' )
plt.legend()
plt.show() plt.show()