diff --git a/ETA.py b/ETA.py index 234b21c..3274a10 100644 --- a/ETA.py +++ b/ETA.py @@ -381,45 +381,103 @@ else: cache[ 'calibrations'] = calibrations cache[ 'stripes' ] = stripes +size = border[ 'x' ][ 'max' ] - border[ 'x' ][ 'min' ] +size_x = size +size_y = calibrations[ 'down' ][ 'y' ][ 'min' ] - calibrations[ 'top' ][ 'y' ][ 'max' ] + # Calibration if calibration != None: import wavelength_calibration as wave_calib - peaks_calib = np.loadtxt( calibration ) # sorted list + peaks_calib = np.loadtxt( calibration ) # sorted list peaks_calib = np.sort( peaks_calib ) - mean_up = np.mean( data[ + mean_up = np.mean( data[ calibrations[ 'top' ][ 'y' ][ 'min' ] : calibrations[ 'top' ][ 'y' ][ 'max' ], calibrations[ 'top' ][ 'x' ][ 'min' ] : calibrations[ 'top' ][ 'x' ][ 'max' ] ] , axis = 0 ) - peaks_up = np.array( + mean_down = np.mean( data[ + calibrations[ 'down' ][ 'y' ][ 'min' ] : calibrations[ 'down' ][ 'y' ][ 'max' ], + calibrations[ 'down' ][ 'x' ][ 'min' ] : calibrations[ 'down' ][ 'x' ][ 'max' ] + ] , axis = 0 ) + peaks_up = np.array( utils.retrieve_peaks( mean_up , window_size = 1 , max_window_size = 1, ) ).astype( int ) + peaks_down = np.array( + utils.retrieve_peaks( + mean_down , + window_size = 1 , + max_window_size = 1, + ) + ).astype( int ) - peakless_up = wave_calib.remove_peaks( mean_up , peaks_up ) + peakless_up = wave_calib.remove_peaks( mean_up , peaks_up ) + peakless_down = wave_calib.remove_peaks( mean_down , peaks_down ) calib = { # hard-coded for now 'first': 3 , - 'last': 20, + 'last' : 20, } first , last = wave_calib.get_extremities( peakless_up , peaks_up ) up = { 'first': first, 'last' : last , } + first , last = wave_calib.get_extremities( peakless_down , peaks_down ) + down = { + 'first': first, + 'last' : last , + } peaks_up = peaks_up[ up[ 'first' ] : up[ 'last' ] + 1 ] + peaks_down = peaks_down[ down[ 'first' ] : down[ 'last' ] + 1 ] peaks_calib = peaks_calib[ calib[ 'first' ] : calib[ 'last' ] + 1 ] - peaks_up = wave_calib.only_keep_calib( peaks_up , peaks_calib ) + peaks_up = wave_calib.only_keep_calib( peaks_up , peaks_calib ) + peaks_down = wave_calib.only_keep_calib( peaks_down , peaks_calib ) + + diff = peaks_up - peaks_down + polyval_vert = np.polyfit( # give diff by horizontal pixel + peaks_up, + diff , + 3 , + ) + + def diff_calc( x , list_y ): + """ + give "good" x list for a given x and y + x = 0 start from border[ 'x' ][ 'min' ] + y = 0 start from calibrations[ 'top' ][ 'y' ][ 'max' ] + """ + y_top = 0 + y_bot = size_y + + x_top = x + x_bot = x + np.polyval( polyval_vert , x ) + + a = ( x_top - x_bot ) / ( y_top - y_bot ) + b = ( 1 / 2 ) * ( x_top + x_bot - a * ( y_top + y_bot ) ) + + return ( a * list_y + b ).astype( int ) + + new_data = np.zeros( ( size_y , size_x - 199 ) ) + list_y = np.arange( 0 , size_y , 1 ) + for x in range( 100 , size_x - 100 ): + diff = diff_calc( x , list_y ) + cons_diff , i = utils.same_value( diff ) , 0 + for list_same in cons_diff: + new_data[ i : i + len( list_same ) , x - 100 ] = data[ + calibrations[ 'top' ][ 'y' ][ 'max' ] + i : calibrations[ 'top' ][ 'y' ][ 'max' ] + i + len( list_same ), + calibrations[ 'top' ][ 'x' ][ 'min' ] + list_same[0] + ] + i += len( list_same ) polyval_wavelength = np.polyfit( # x = 0 begins at the start of - peaks_up , # calibartions[ 'top' ][ 'x' ][ 'min' ] + peaks_up , # calibrations[ 'top' ][ 'x' ][ 'min' ] peaks_calib, 1 , ) - wavelength = np.polyval( polyval_wavelength, np.arange( @@ -429,16 +487,6 @@ if calibration != None: ) ) - plt.plot( - peaks_up, - peaks_calib - np.polyval( - polyval_wavelength, - peaks_up , - ) , - ) - plt.show() - exit() - # First deformation list_ = data[