Update version number
- Add --output option (WIP) - Add output generated (only missing thing is now the wavelength axis)
This commit is contained in:
parent
17531f2cea
commit
1f85197d07
1 changed files with 50 additions and 49 deletions
99
ETA.py
99
ETA.py
|
@ -8,7 +8,7 @@ from scipy.signal import convolve as sp_convolve
|
|||
from scipy.signal import find_peaks
|
||||
from scipy.ndimage import rotate
|
||||
|
||||
cache , filename = '' , None
|
||||
cache , filename , output = '' , None , None
|
||||
if len( sys.argv ) < 2:
|
||||
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':
|
||||
if i == len( sys.argv ) - 1:
|
||||
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:
|
||||
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
|
||||
|
@ -37,16 +43,19 @@ for i in range( 1 , len( sys.argv ) ):
|
|||
\n -v --version show version number and quit\
|
||||
\n -n --no-cache do not use cache and rewrite it\
|
||||
\n -c --cache use given cache\
|
||||
\n -o --output output file, default to standard output\
|
||||
\n\
|
||||
\nParse a naroo ETA fits' )
|
||||
exit()
|
||||
elif arg == '--version':
|
||||
print( '0.1' )
|
||||
print( '0.2' )
|
||||
exit()
|
||||
elif arg == '--no-cache':
|
||||
cache = '' # hack, empty string mean this dir, so not a file
|
||||
elif len( arg ) > 8 and arg[ : 8 ] == '--cache=':
|
||||
cache = arg[ 8 : ]
|
||||
elif len( arg ) > 9 and arg[ : 9 ] == '--output=':
|
||||
output = arg[ 9 : ]
|
||||
else:
|
||||
raise Exception( 'ETA.py: unknown argument "' + arg + '", type \'ETA.py -h\' for more information' )
|
||||
else:
|
||||
|
@ -66,8 +75,9 @@ if cache_file.is_file():
|
|||
if key not in cache:
|
||||
raise Exception( 'ETA.py: missing data in cache_file' )
|
||||
data = cache[ 'rotated_data' ]
|
||||
border = cache[ 'border' ]
|
||||
border = cache[ 'border' ]
|
||||
calibrations = cache[ 'calibrations' ]
|
||||
stripes = cache[ 'stripes' ]
|
||||
else:
|
||||
"""
|
||||
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():
|
||||
with shelve.open( str( cache_file ) ) as cache:
|
||||
cache[ 'rotated_data' ] = data
|
||||
cache[ 'border' ] = border
|
||||
cache[ 'calibrations'] = calibrations
|
||||
cache[ 'stripes' ] = stripes
|
||||
print( border )
|
||||
print( calibrations )
|
||||
exit()
|
||||
# First deformation
|
||||
|
||||
"""
|
||||
stripes curves detection
|
||||
"""
|
||||
list_ = data[
|
||||
calibrations[ 'top' ][ 'y' ][ 'max' ] : calibrations[ 'down' ][ 'y' ][ 'min' ],
|
||||
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.where( y_diff < 0 ) ] = 0
|
||||
results = np.zeros( ( list_.shape[0] + np.max( y_diff ) , list_.shape[1] ) )
|
||||
|
@ -369,7 +388,7 @@ list_results = np.convolve(
|
|||
'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( [
|
||||
np.argmax( list_results )
|
||||
] + [
|
||||
|
@ -378,30 +397,12 @@ fall = np.array( [
|
|||
) for consecutive in fall
|
||||
] ).astype( int )
|
||||
|
||||
mask = np.zeros_like( data )
|
||||
mask[
|
||||
calibrations[ 'top' ][ 'y' ][ 'min' ] : calibrations[ 'top' ][ 'y' ][ 'max' ],
|
||||
calibrations[ 'top' ][ 'x' ][ 'min' ] : calibrations[ 'top' ][ 'x' ][ 'max' ]
|
||||
] = -1
|
||||
mask[
|
||||
calibrations[ 'down' ][ 'y' ][ 'min' ] : calibrations[ 'down' ][ 'y' ][ 'max' ],
|
||||
calibrations[ 'down' ][ 'x' ][ 'min' ] : calibrations[ 'down' ][ 'x' ][ 'max' ]
|
||||
] = -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()
|
||||
stairs = np.zeros_like( results )
|
||||
for x in range( size ):
|
||||
stairs[ : , x ] = results[ : , x ] # can be modified, but no used anymore so it's fine
|
||||
stairs[ : fall[0] , x ] = 0
|
||||
for i in range( len( fall ) - 1 ):
|
||||
stairs[ fall[ i ] : fall[ i + 1 ] , x ] = np.mean( stairs[ fall[ i ] : fall[ i + 1 ] ] )
|
||||
stairs[ fall[ -1 ] : , x ] = 0
|
||||
plt.imshow( stairs )
|
||||
plt.show()
|
||||
|
|
Loading…
Reference in a new issue