From 17531f2ceaafc35c18cd72ba3ef62b4535a15cc7 Mon Sep 17 00:00:00 2001 From: linarphy Date: Tue, 16 May 2023 14:08:26 +0200 Subject: [PATCH] Update cache use - Default strategy is now no cache - Cache name is not generated anymore - Add --cache option --- ETA.py | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/ETA.py b/ETA.py index 53f7862..00bf20d 100644 --- a/ETA.py +++ b/ETA.py @@ -8,11 +8,12 @@ from scipy.signal import convolve as sp_convolve from scipy.signal import find_peaks from scipy.ndimage import rotate -cache , filename = True , None +cache , filename = '' , None if len( sys.argv ) < 2: 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 len( arg ) < 2: 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': arg = '--version' 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: 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 @@ -31,6 +36,7 @@ for arg in sys.argv[ 1 : ]: \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\ \nParse a naroo ETA fits' ) exit() @@ -38,7 +44,9 @@ for arg in sys.argv[ 1 : ]: print( '0.1' ) exit() 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: raise Exception( 'ETA.py: unknown argument "' + arg + '", type \'ETA.py -h\' for more information' ) else: @@ -50,10 +58,13 @@ if filename == None: 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: + 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' ] border = cache[ 'border' ] calibrations = cache[ 'calibrations' ] @@ -316,10 +327,11 @@ else: }, } - with shelve.open( str( cache_file ) ) as cache: - cache[ 'rotated_data' ] = data - cache[ 'border' ] = border - cache[ 'calibrations'] = calibrations + if not cache_file.exists(): + with shelve.open( str( cache_file ) ) as cache: + cache[ 'rotated_data' ] = data + cache[ 'border' ] = border + cache[ 'calibrations'] = calibrations """ stripes curves detection @@ -384,8 +396,10 @@ 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' )