Fix & Clean up

This commit is contained in:
linarphy 2023-07-27 14:59:34 +02:00
parent c70be8a74f
commit 4c25cf6ac5
No known key found for this signature in database
GPG key ID: 3D4AAAC3AD16E79C

88
ETA.py
View file

@ -211,12 +211,12 @@ else:
border = { border = {
'x': { 'x': {
'min': points[0][1] + extremum[0][1] + 1, 'min': points[0][1] + extremum[0][1] + 25,
'max': points[0][1] + extremum[1][0] , 'max': points[0][1] + extremum[1][0] - 25,
}, },
'y': { 'y': {
'min': points[2][0] + extremum[2][3] + 1, 'min': points[2][0] + extremum[2][3] + 25,
'max': points[2][0] + extremum[3][2] , 'max': points[2][0] + extremum[3][2] - 25,
}, },
} }
@ -264,11 +264,11 @@ else:
if label_x[ 'max' ] < data.shape[1] // 2: if label_x[ 'max' ] < data.shape[1] // 2:
border[ 'x' ][ 'min' ] = label_x[ 'max' ] border[ 'x' ][ 'min' ] = label_x[ 'max' ]
else: else:
raise Exception( 'the label seems to be in the middle of the picture' ) raise Exception( 'ETA.py: the label seems to be in the middle of the picture' )
elif label_x[ 'max' ] > data.shape[1] // 2: elif label_x[ 'max' ] > data.shape[1] // 2:
border[ 'x' ][ 'max' ] = label_x[ 'min' ] border[ 'x' ][ 'max' ] = label_x[ 'min' ]
else: else:
raise Exception( 'for an unkown reason, label_x[ \'min\' ] > label_x[ \'max\' ]' ) raise Exception( 'ETA.py: for an unkown reason, label_x[ \'min\' ] > label_x[ \'max\' ]' )
if verbose: if verbose:
print( 'label section deleted' ) print( 'label section deleted' )
@ -490,20 +490,44 @@ if calibration != None:
calibrations[ 'down' ][ 'x' ][ 'min' ]: calibrations[ 'down' ][ 'x' ][ 'min' ]:
calibrations[ 'down' ][ 'x' ][ 'max' ] calibrations[ 'down' ][ 'x' ][ 'max' ]
] , axis = 0 ) ] , axis = 0 )
peaks_up = np.array(
utils.retrieve_peaks( percent = 0.4
mean_up ,
window_size = 1 , peaks_up = np.array( [
max_window_size = 1, np.mean( consecutive )
for consecutive in
utils.consecutive(
np.where(
mean_up > np.min(
mean_up
) + (
np.max(
mean_up
) - np.min(
mean_up
)
) * percent
)[0]
) )
).astype( int ) ] , dtype = int )
peaks_down = np.array(
utils.retrieve_peaks( peaks_down = np.array( [
mean_down , np.mean( consecutive )
window_size = 1 , for consecutive in
max_window_size = 1, utils.consecutive(
np.where(
mean_down > np.min(
mean_down
) + (
np.max(
mean_down
) - np.min(
mean_down
)
) * percent
)[0]
) )
).astype( int ) ] , dtype = 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 ) peakless_down = wave_calib.remove_peaks( mean_down , peaks_down )
@ -521,6 +545,7 @@ if calibration != None:
'first': first, 'first': first,
'last' : last , 'last' : last ,
} }
peaks_up = peaks_up[ up[ 'first' ] : up[ 'last' ] + 1 ] peaks_up = peaks_up[ up[ 'first' ] : up[ 'last' ] + 1 ]
peaks_down = peaks_down[ down[ 'first' ] : down[ 'last' ] + 1 ] peaks_down = peaks_down[ down[ 'first' ] : down[ 'last' ] + 1 ]
peaks_calib = peaks_calib[ calib[ 'first' ] : calib[ 'last' ] + 1 ] peaks_calib = peaks_calib[ calib[ 'first' ] : calib[ 'last' ] + 1 ]
@ -680,7 +705,7 @@ for line in range_:
points_taken, points_taken,
values_taken, values_taken,
) )
wrong_points = np.where( wrong_points = np.where(
np.abs( np.abs(
interpolation( interpolation(
abciss, abciss,
@ -691,18 +716,10 @@ for line in range_:
abciss[ wrong_points ], abciss[ wrong_points ],
) )
import matplotlib.pyplot as plt data[
plt.plot( line ,
abciss, border[ 'x' ][ 'min' ] : border[ 'x' ][ 'max' ]
list_ , ] = list_
)
plt.plot(
abciss,
interpolation(
abciss,
) ,
)
plt.show()
if verbose: if verbose:
print( 'artefact removed from intensity curve' ) print( 'artefact removed from intensity curve' )
@ -736,12 +753,12 @@ mean_bias = sp_convolve(
bias[ 'down' ], bias[ 'down' ],
] , ] ,
axis = 0, axis = 0,
) , ) ,
np.ones( np.ones(
50, 50,
) , ) ,
'same' , 'same',
) / 50 ) / 50 * 0
data[ data[
: , : ,
@ -804,7 +821,6 @@ if verbose:
if output == None: if output == None:
print( stairs , wavelength ) print( stairs , wavelength )
else: else:
output_file = pathlib.Path( output ) output_file = pathlib.Path( output )
with shelve.open( str( output_file ) ) as output: with shelve.open( str( output_file ) ) as output:
output[ 'data' ] = stairs output[ 'data' ] = stairs