Add calibration (WIP)
- Fix command parser - Add --calibration option - Add calibration (WIP)
This commit is contained in:
parent
3a38b157d2
commit
bc493177bd
1 changed files with 48 additions and 11 deletions
55
ETA.py
55
ETA.py
|
@ -8,12 +8,13 @@ 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 , output = '' , None , None
|
cache , filename , output , calibration = '' , None , 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' )
|
||||||
|
|
||||||
for i in range( 1 , len( sys.argv ) ):
|
argv , i = sys.argv[ 1 : ] , 0
|
||||||
arg = sys.argv[ i ]
|
while i < len( argv ):
|
||||||
|
arg = argv[ i ]
|
||||||
if arg[0] == '-':
|
if arg[0] == '-':
|
||||||
if len( arg ) < 2:
|
if len( arg ) < 2:
|
||||||
raise Exception( 'ETA.py: unknown argument, type \'ETA.py -h\' for more information' )
|
raise Exception( 'ETA.py: unknown argument, type \'ETA.py -h\' for more information' )
|
||||||
|
@ -27,23 +28,33 @@ 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[ i + 1 ] == '--cache=' + arg[ i + 1 ]
|
argv[ i + 1 ] = '--cache=' + argv[ i + 1 ]
|
||||||
|
i += 1
|
||||||
continue
|
continue
|
||||||
elif arg == '-o':
|
elif arg == '-o':
|
||||||
if i == len( sys.argv ) - 1:
|
if i == len( sys.argv ) - 1:
|
||||||
raise Exception( 'ETA.py: output have to take a value' )
|
raise Exception( 'ETA.py: output have to take a value' )
|
||||||
arg[ i + 1 ] == '--output=' + arg[ i + 1 ]
|
argv[ i + 1 ] = '--output=' + argv[ i + 1 ]
|
||||||
|
i += 1
|
||||||
|
continue
|
||||||
|
elif arg == '-a':
|
||||||
|
if i == len( sys.argv ) - 1:
|
||||||
|
raise Exception( 'ETA.py: calibration have to take a value' )
|
||||||
|
argv[ i + 1 ] = '--calibration=' + argv[ i + 1 ]
|
||||||
|
i += 1
|
||||||
continue
|
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
|
||||||
if arg == '--help':
|
if arg == '--help':
|
||||||
print( 'ETA.py [options...] filename\
|
print( 'ETA.py [options...] filename\
|
||||||
\n -h --help show this help and quit\
|
\n -a --calibration calibration file, default to no calibration.\
|
||||||
\n -v --version show version number and quit\
|
\n No calibration means no wavelength interpolation\
|
||||||
\n -n --no-cache do not use cache and rewrite it\
|
|
||||||
\n -c --cache use given cache\
|
\n -c --cache use given cache\
|
||||||
|
\n -h --help show this help and quit\
|
||||||
|
\n -n --no-cache do not use cache and rewrite it\
|
||||||
\n -o --output output file, default to standard output\
|
\n -o --output output file, default to standard output\
|
||||||
|
\n -v --version show version number and quit\
|
||||||
\n\
|
\n\
|
||||||
\nParse a naroo ETA fits' )
|
\nParse a naroo ETA fits' )
|
||||||
exit()
|
exit()
|
||||||
|
@ -56,14 +67,18 @@ for i in range( 1 , len( sys.argv ) ):
|
||||||
cache = arg[ 8 : ]
|
cache = arg[ 8 : ]
|
||||||
elif len( arg ) > 9 and arg[ : 9 ] == '--output=':
|
elif len( arg ) > 9 and arg[ : 9 ] == '--output=':
|
||||||
output = arg[ 9 : ]
|
output = arg[ 9 : ]
|
||||||
|
elif len( arg ) > 14 and arg[ : 14 ] == '--calibration=':
|
||||||
|
calibration = arg[ 14 : ]
|
||||||
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:
|
||||||
raise Exception( 'ETA.py: this exception should never be raised' )
|
raise Exception( 'ETA.py: this exception should never be raised' )
|
||||||
else:
|
else:
|
||||||
filename = arg
|
filename = arg
|
||||||
|
i += 1
|
||||||
if filename == None:
|
if filename == None:
|
||||||
raise Exception( 'ETA.py: filename should be given' )
|
raise Exception( 'ETA.py: filename should be given' )
|
||||||
|
# TODO: check in advance file to check if exists or writeable
|
||||||
|
|
||||||
data = utils.load( filename )
|
data = utils.load( filename )
|
||||||
|
|
||||||
|
@ -366,6 +381,28 @@ else:
|
||||||
cache[ 'calibrations'] = calibrations
|
cache[ 'calibrations'] = calibrations
|
||||||
cache[ 'stripes' ] = stripes
|
cache[ 'stripes' ] = stripes
|
||||||
|
|
||||||
|
# Calibration
|
||||||
|
|
||||||
|
if calibration != None:
|
||||||
|
calib_peaks = np.loadtxt( calibration )
|
||||||
|
mean_calib_up = np.mean( data[
|
||||||
|
calibrations[ 'top' ][ 'y' ][ 'min' ] : calibrations[ 'top' ][ 'y' ][ 'max' ],
|
||||||
|
border[ 'x' ][ 'min' ] : border[ 'x' ][ 'max' ]
|
||||||
|
] , axis = 0 )
|
||||||
|
mean_calib_up -= np.min( mean_calib_up )
|
||||||
|
mean_calib_up /= np.max( mean_calib_up )
|
||||||
|
|
||||||
|
peaks_up = find_peaks( mean_calib_up , height = 0.6 )[0] + border[ 'x' ][ 'min' ]
|
||||||
|
|
||||||
|
if len( peaks_up ) != len( calib_peaks ):
|
||||||
|
print( calib_peaks , peaks_up )
|
||||||
|
print( len( calib_peaks ) , len( peaks_up ) )
|
||||||
|
plt.plot( mean_calib_up )
|
||||||
|
plt.show()
|
||||||
|
exit()
|
||||||
|
polyval = np.polyfit( peaks_up , calib_peaks , 1 )
|
||||||
|
print( polyval )
|
||||||
|
|
||||||
# First deformation
|
# First deformation
|
||||||
|
|
||||||
list_ = data[
|
list_ = data[
|
||||||
|
@ -398,7 +435,7 @@ fall = np.array( [
|
||||||
stairs = np.zeros_like( results )
|
stairs = np.zeros_like( results )
|
||||||
for x in range( size ):
|
for x in range( size ):
|
||||||
stairs[ : , x ] = results[ : , x ] # can be modified, but no used anymore so it's fine
|
stairs[ : , x ] = results[ : , x ] # can be modified, but no used anymore so it's fine
|
||||||
stairs[ : fall[0] , x ] = 0
|
stairs[ : fall[0] , x ] = 0 # TODO: put the mean
|
||||||
for i in range( len( fall ) - 1 ):
|
for i in range( len( fall ) - 1 ):
|
||||||
stairs[ fall[ i ] : fall[ i + 1 ] , x ] = np.mean( stairs[ fall[ i ] : fall[ i + 1 ] ] )
|
stairs[ fall[ i ] : fall[ i + 1 ] , x ] = np.mean( stairs[ fall[ i ] : fall[ i + 1 ] ] )
|
||||||
stairs[ fall[ -1 ] : , x ] = 0
|
stairs[ fall[ -1 ] : , x ] = 0
|
||||||
|
|
Loading…
Reference in a new issue