Add calibration (WIP)

- Fix command parser
- Add --calibration option
- Add calibration (WIP)
This commit is contained in:
linarphy 2023-05-16 16:46:19 +02:00
parent 3a38b157d2
commit bc493177bd
No known key found for this signature in database
GPG key ID: 3D4AAAC3AD16E79C

59
ETA.py
View file

@ -8,12 +8,13 @@ from scipy.signal import convolve as sp_convolve
from scipy.signal import find_peaks
from scipy.ndimage import rotate
cache , filename , output = '' , None , None
cache , filename , output , calibration = '' , None , None , None
if len( sys.argv ) < 2:
raise Exception( 'ETA.py: type \'ETA.py -h\' for more information' )
for i in range( 1 , len( sys.argv ) ):
arg = sys.argv[ i ]
argv , i = sys.argv[ 1 : ] , 0
while i < len( argv ):
arg = argv[ i ]
if arg[0] == '-':
if len( arg ) < 2:
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':
if i == len( sys.argv ) - 1:
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
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 ]
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
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
if arg == '--help':
print( 'ETA.py [options...] filename\
\n -h --help show this help and quit\
\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 -a --calibration calibration file, default to no calibration.\
\n No calibration means no wavelength interpolation\
\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 -v --version show version number and quit\
\n\
\nParse a naroo ETA fits' )
exit()
@ -56,14 +67,18 @@ for i in range( 1 , len( sys.argv ) ):
cache = arg[ 8 : ]
elif len( arg ) > 9 and arg[ : 9 ] == '--output=':
output = arg[ 9 : ]
elif len( arg ) > 14 and arg[ : 14 ] == '--calibration=':
calibration = arg[ 14 : ]
else:
raise Exception( 'ETA.py: unknown argument "' + arg + '", type \'ETA.py -h\' for more information' )
else:
raise Exception( 'ETA.py: this exception should never be raised' )
else:
filename = arg
i += 1
if filename == None:
raise Exception( 'ETA.py: filename should be given' )
# TODO: check in advance file to check if exists or writeable
data = utils.load( filename )
@ -366,6 +381,28 @@ else:
cache[ 'calibrations'] = calibrations
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
list_ = data[
@ -398,7 +435,7 @@ fall = np.array( [
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
stairs[ : fall[0] , x ] = 0 # TODO: put the mean
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