Update cache use
- Default strategy is now no cache - Cache name is not generated anymore - Add --cache option
This commit is contained in:
parent
20be3e07ad
commit
17531f2cea
1 changed files with 24 additions and 10 deletions
34
ETA.py
34
ETA.py
|
@ -8,11 +8,12 @@ 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 = True , None
|
cache , filename = '' , 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 arg in sys.argv[ 1 : ]:
|
for i in range( 1 , len( sys.argv ) ):
|
||||||
|
arg = sys.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' )
|
||||||
|
@ -22,7 +23,11 @@ for arg in sys.argv[ 1 : ]:
|
||||||
elif arg == '-v':
|
elif arg == '-v':
|
||||||
arg = '--version'
|
arg = '--version'
|
||||||
elif arg == '-n':
|
elif arg == '-n':
|
||||||
arg == '--no-cachge'
|
arg == '--no-cache'
|
||||||
|
elif arg == '-c':
|
||||||
|
if i == len( sys.argv ) - 1:
|
||||||
|
raise Exception( 'ETA.py: cache have to take a value' )
|
||||||
|
arg == '--cache=' + arg[ i + 1 ]
|
||||||
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
|
||||||
|
@ -31,6 +36,7 @@ for arg in sys.argv[ 1 : ]:
|
||||||
\n -h --help show this help and quit\
|
\n -h --help show this help and quit\
|
||||||
\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\
|
\n\
|
||||||
\nParse a naroo ETA fits' )
|
\nParse a naroo ETA fits' )
|
||||||
exit()
|
exit()
|
||||||
|
@ -38,7 +44,9 @@ for arg in sys.argv[ 1 : ]:
|
||||||
print( '0.1' )
|
print( '0.1' )
|
||||||
exit()
|
exit()
|
||||||
elif arg == '--no-cache':
|
elif arg == '--no-cache':
|
||||||
cache = False
|
cache = '' # hack, empty string mean this dir, so not a file
|
||||||
|
elif len( arg ) > 8 and arg[ : 8 ] == '--cache=':
|
||||||
|
cache = arg[ 8 : ]
|
||||||
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:
|
||||||
|
@ -50,10 +58,13 @@ if filename == None:
|
||||||
|
|
||||||
data = utils.load( filename )
|
data = utils.load( filename )
|
||||||
|
|
||||||
cache_file = pathlib.Path( 'asset/points_' + sys.argv[1].split( '/' )[-1][:-5] + '.pag' )
|
cache_file = pathlib.Path( cache )
|
||||||
|
|
||||||
if cache_file.is_file() and cache:
|
if cache_file.is_file():
|
||||||
with shelve.open( str( cache_file ) ) as cache:
|
with shelve.open( str( cache_file ) ) as cache:
|
||||||
|
for key in [ 'rotated_data' , 'border' , 'calibrations' ]:
|
||||||
|
if key not in cache:
|
||||||
|
raise Exception( 'ETA.py: missing data in cache_file' )
|
||||||
data = cache[ 'rotated_data' ]
|
data = cache[ 'rotated_data' ]
|
||||||
border = cache[ 'border' ]
|
border = cache[ 'border' ]
|
||||||
calibrations = cache[ 'calibrations' ]
|
calibrations = cache[ 'calibrations' ]
|
||||||
|
@ -316,10 +327,11 @@ else:
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
with shelve.open( str( cache_file ) ) as cache:
|
if not cache_file.exists():
|
||||||
cache[ 'rotated_data' ] = data
|
with shelve.open( str( cache_file ) ) as cache:
|
||||||
cache[ 'border' ] = border
|
cache[ 'rotated_data' ] = data
|
||||||
cache[ 'calibrations'] = calibrations
|
cache[ 'border' ] = border
|
||||||
|
cache[ 'calibrations'] = calibrations
|
||||||
|
|
||||||
"""
|
"""
|
||||||
stripes curves detection
|
stripes curves detection
|
||||||
|
@ -384,8 +396,10 @@ plt.imshow( mask , alpha = 0.5 )
|
||||||
plt.show()
|
plt.show()
|
||||||
|
|
||||||
temp = results[ : , 10000 ].copy()
|
temp = results[ : , 10000 ].copy()
|
||||||
|
temp[ : fall[ 0 ] ] = 0
|
||||||
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 ] ] )
|
||||||
|
temp[ fall[ - 1 ] : ] = np.mean( temp[ fall[ -1 ] : ] )
|
||||||
|
|
||||||
plt.plot( results[ : , 10000 ] , label = 'raw' )
|
plt.plot( results[ : , 10000 ] , label = 'raw' )
|
||||||
plt.plot( temp , label = 'flat' )
|
plt.plot( temp , label = 'flat' )
|
||||||
|
|
Loading…
Reference in a new issue