Commit 4c2139c3 authored by myron's avatar myron
Browse files

this modification should make sure that lists of keys made of strings are...

this modification should make sure that lists of keys made of strings are always properly sorted according to their numerical part
parent 3d107ee8
...@@ -151,7 +151,7 @@ class Plot2D(MyMplCanvas): ...@@ -151,7 +151,7 @@ class Plot2D(MyMplCanvas):
def compute_initial_figure(self): def compute_initial_figure(self):
file_list = glob.glob("scan_*.txt") file_list = glob.glob("scan_*.txt")
file_list.sort() file_list.sort( key = lambda x: int(''.join(filter(str.isdigit, str(x) ))) )
img=[] img=[]
error = [] error = []
......
...@@ -302,7 +302,7 @@ class imageset: ...@@ -302,7 +302,7 @@ class imageset:
def loadkimberlite(self,matfilename): def loadkimberlite(self,matfilename):
data_dict = io.loadmat(matfilename) data_dict = io.loadmat(matfilename)
sorted_keys = sorted(data_dict.keys()) sorted_keys = sorted(data_dict.keys(), key = lambda x: int(''.join(filter(str.isdigit, str(x) ))) )
sy = data_dict['sy'][0] sy = data_dict['sy'][0]
allsx = [] allsx = []
for key in sorted_keys[3:12]: for key in sorted_keys[3:12]:
......
...@@ -313,7 +313,7 @@ class offDiagonal: ...@@ -313,7 +313,7 @@ class offDiagonal:
ds_group = h5group[ "offDiaDataSets" ] ds_group = h5group[ "offDiaDataSets" ]
keys = [nm for nm in ds_group] keys = [nm for nm in ds_group]
keys.sort() keys.sort(key = lambda x: int(''.join(filter(str.isdigit, str(x) ))) )
for k in keys: for k in keys:
......
...@@ -884,7 +884,7 @@ class mainwindow(Qt.QMainWindow): ...@@ -884,7 +884,7 @@ class mainwindow(Qt.QMainWindow):
print( x,y, cx, cy) print( x,y, cx, cy)
newspots.append((y,x,i, int((cy*4+cx)+1) ) ) newspots.append((y,x,i, int((cy*4+cx)+1) ) )
else: else:
spots.sort() spots.sort(key = lambda x: int(''.join(filter(str.isdigit, str(x) ))) )
newspots = [] newspots = []
for k,(y,x,i) in enumerate( spots): for k,(y,x,i) in enumerate( spots):
newspots.append((y,x,i,k+1) ) newspots.append((y,x,i,k+1) )
......
...@@ -767,7 +767,7 @@ class roi_finder: ...@@ -767,7 +767,7 @@ class roi_finder:
counter = 0 counter = 0
new_rois = {} new_rois = {}
for data, key in zip(pw_data, sorted(roi_obj.red_rois)): # go through each matrix (one per ROI) for data, key in zip(pw_data, sorted(roi_obj.red_rois , key = lambda x: int(''.join(filter(str.isdigit, str(x) ))) )): # go through each matrix (one per ROI)
# decompose data, choose method # decompose data, choose method
if method == 'nnma': # non negative matrix factorisation if method == 'nnma': # non negative matrix factorisation
...@@ -883,7 +883,7 @@ class roi_finder: ...@@ -883,7 +883,7 @@ class roi_finder:
counter = 0 counter = 0
new_rois = {} new_rois = {}
for data, key in zip(pw_data, sorted(self.roi_obj.red_rois)): # go through each matrix (one per ROI) for data, key in zip(pw_data, sorted(self.roi_obj.red_rois, key = lambda x: int(''.join(filter(str.isdigit, str(x) ))) )): # go through each matrix (one per ROI)
# decompose data, choose method # decompose data, choose method
if method == 'nnma': # non negative matrix factorisation if method == 'nnma': # non negative matrix factorisation
...@@ -1123,7 +1123,7 @@ class roi_finder: ...@@ -1123,7 +1123,7 @@ class roi_finder:
plt.ioff() plt.ioff()
counter = 0 counter = 0
for data, key in zip(cw_data, sorted(self.roi_obj.red_rois)): for data, key in zip(cw_data, sorted(self.roi_obj.red_rois, key = lambda x: int(''.join(filter(str.isdigit, str(x) ))) )):
for ii in range(data.shape[1]): for ii in range(data.shape[1]):
if save_dataset: if save_dataset:
the_shelve = shelve.open(save_dataset) the_shelve = shelve.open(save_dataset)
...@@ -1254,7 +1254,7 @@ class roi_finder: ...@@ -1254,7 +1254,7 @@ class roi_finder:
plt.cla() plt.cla()
counter = 0 counter = 0
for data, key in zip(cw_data, sorted(self.roi_obj.red_rois)): for data, key in zip(cw_data, sorted(self.roi_obj.red_rois, key = lambda x: int(''.join(filter(str.isdigit, str(x) ))) )):
print('Processing: ', key) print('Processing: ', key)
for ii in range(data.shape[1]): for ii in range(data.shape[1]):
print('>>>>>>>>> ', ii) print('>>>>>>>>> ', ii)
...@@ -1375,11 +1375,11 @@ class roi_finder: ...@@ -1375,11 +1375,11 @@ class roi_finder:
cw_data[key] = np.sum( data_dict_norm[key], axis=1 ) cw_data[key] = np.sum( data_dict_norm[key], axis=1 )
# fetch all red_roi keys # fetch all red_roi keys
roi_keys = [key for key in sorted(self.roi_obj.red_rois)] roi_keys = [key for key in sorted(self.roi_obj.red_rois , key = lambda x: int(''.join(filter(str.isdigit, str(x) ))) )]
# deep copy all ROIs, set all to zero # deep copy all ROIs, set all to zero
red_rois_copy = {} red_rois_copy = {}
for key in sorted( self.roi_obj.red_rois ): for key in sorted( self.roi_obj.red_rois , key = lambda x: int(''.join(filter(str.isdigit, str(x) ))) ):
red_rois_copy[key] = copy.deepcopy( self.roi_obj.red_rois[key] ) red_rois_copy[key] = copy.deepcopy( self.roi_obj.red_rois[key] )
red_rois_copy[key][1] = np.zeros_like( self.roi_obj.red_rois[key][1] ) red_rois_copy[key][1] = np.zeros_like( self.roi_obj.red_rois[key][1] )
...@@ -1492,7 +1492,7 @@ class roi_finder: ...@@ -1492,7 +1492,7 @@ class roi_finder:
self.column_ind -= 0 self.column_ind -= 0
def finish( self, event ): def finish( self, event ):
for key in sorted(red_rois_copy): for key in sorted(red_rois_copy, key = lambda x: int(''.join(filter(str.isdigit, str(x) ))) ):
red_rois_copy[key][1] = self.red_rois[key][1] red_rois_copy[key][1] = self.red_rois[key][1]
plt.close() plt.close()
...@@ -1602,7 +1602,7 @@ class roi_finder: ...@@ -1602,7 +1602,7 @@ class roi_finder:
plt.ioff() plt.ioff()
counter = 0 counter = 0
for data, key in zip(cw_data, sorted(self.roi_obj.red_rois)): for data, key in zip(cw_data, sorted(self.roi_obj.red_rois, key = lambda x: int(''.join(filter(str.isdigit, str(x) ))) )):
print('Processing: ', key) print('Processing: ', key)
for ii in range(data.shape[1]): for ii in range(data.shape[1]):
plt.cla() plt.cla()
...@@ -1955,11 +1955,11 @@ class roi_finder: ...@@ -1955,11 +1955,11 @@ class roi_finder:
rw_data[key] = np.sum( data_dict_norm[key], axis=2 ) rw_data[key] = np.sum( data_dict_norm[key], axis=2 )
# fetch all red_roi keys # fetch all red_roi keys
roi_keys = [key for key in sorted(self.roi_obj.red_rois)] roi_keys = [key for key in sorted(self.roi_obj.red_rois, key = lambda x: int(''.join(filter(str.isdigit, str(x) ))) )]
# deep copy all ROIs, set all to zero # deep copy all ROIs, set all to zero
red_rois_copy = {} red_rois_copy = {}
for key in sorted( self.roi_obj.red_rois ): for key in sorted( self.roi_obj.red_rois, key = lambda x: int(''.join(filter(str.isdigit, str(x) ))) ):
red_rois_copy[key] = copy.deepcopy( self.roi_obj.red_rois[key] ) red_rois_copy[key] = copy.deepcopy( self.roi_obj.red_rois[key] )
red_rois_copy[key][1] = np.zeros_like( self.roi_obj.red_rois[key][1] ) red_rois_copy[key][1] = np.zeros_like( self.roi_obj.red_rois[key][1] )
...@@ -2073,7 +2073,7 @@ class roi_finder: ...@@ -2073,7 +2073,7 @@ class roi_finder:
self.row_ind -= 0 self.row_ind -= 0
def finish( self, event ): def finish( self, event ):
for key in sorted(red_rois_copy): for key in sorted(red_rois_copy, key = lambda x: int(''.join(filter(str.isdigit, str(x) ))) ):
red_rois_copy[key][1] = self.red_rois[key][1] red_rois_copy[key][1] = self.red_rois[key][1]
plt.close() plt.close()
...@@ -2247,11 +2247,11 @@ class roi_finder: ...@@ -2247,11 +2247,11 @@ class roi_finder:
data_dict_norm[key] = scans[0].raw_signals[key] data_dict_norm[key] = scans[0].raw_signals[key]
# fetch all red_roi keys # fetch all red_roi keys
roi_keys = [key for key in sorted(self.roi_obj.red_rois)] roi_keys = [key for key in sorted(self.roi_obj.red_rois, key = lambda x: int(''.join(filter(str.isdigit, str(x) ))) )]
# deep copy all ROIs, set all to zero # deep copy all ROIs, set all to zero
red_rois_copy = {} red_rois_copy = {}
for key in sorted( self.roi_obj.red_rois ): for key in sorted( self.roi_obj.red_rois, key = lambda x: int(''.join(filter(str.isdigit, str(x) ))) ):
red_rois_copy[key] = copy.deepcopy( self.roi_obj.red_rois[key] ) red_rois_copy[key] = copy.deepcopy( self.roi_obj.red_rois[key] )
red_rois_copy[key][1] = np.zeros_like( self.roi_obj.red_rois[key][1] ) red_rois_copy[key][1] = np.zeros_like( self.roi_obj.red_rois[key][1] )
...@@ -2267,7 +2267,7 @@ class roi_finder: ...@@ -2267,7 +2267,7 @@ class roi_finder:
ax0 = plt.subplot2grid( (16, 16), (0, 0), colspan=16, rowspan=16 ) ax0 = plt.subplot2grid( (16, 16), (0, 0), colspan=16, rowspan=16 )
new_rois = {} new_rois = {}
for counter, key in enumerate(sorted(pw_data)): # go through each matrix (one per ROI) for counter, key in enumerate(sorted(pw_data, key = lambda x: int(''.join(filter(str.isdigit, str(x) ))) ) ): # go through each matrix (one per ROI)
# decompose data, choose method # decompose data, choose method
if method == 'nnma': # non negative matrix factorisation if method == 'nnma': # non negative matrix factorisation
......
...@@ -181,7 +181,7 @@ class imageset: ...@@ -181,7 +181,7 @@ class imageset:
def loadkimberlite(self,matfilename): def loadkimberlite(self,matfilename):
data_dict = io.loadmat(matfilename) data_dict = io.loadmat(matfilename)
sorted_keys = sorted(data_dict.keys()) sorted_keys = sorted(data_dict.keys(), key = lambda x: int(''.join(filter(str.isdigit, str(x) ))) )
sy = data_dict['sy'][0] sy = data_dict['sy'][0]
allsx = [] allsx = []
for key in sorted_keys[3:12]: for key in sorted_keys[3:12]:
......
...@@ -83,7 +83,7 @@ def optimize_analyzer_focus(path, SPECfname, EDFprefix, EDFname, EDFpostfix, roi ...@@ -83,7 +83,7 @@ def optimize_analyzer_focus(path, SPECfname, EDFprefix, EDFname, EDFpostfix, roi
scan72.get_raw_signals( roi_obj, method='pixel') scan72.get_raw_signals( roi_obj, method='pixel')
# measure the FWHM for each ROI # measure the FWHM for each ROI
for ii,key in enumerate(sorted(scan72.raw_signals)): for ii,key in enumerate(sorted(scan72.raw_signals , key = lambda x: int(''.join(filter(str.isdigit, str(x) ))) )):
motor_scale = scan72.counters[scan72_motornames[ii]] motor_scale = scan72.counters[scan72_motornames[ii]]
points = [] points = []
heights = [] # index 1 heights = [] # index 1
......
...@@ -551,7 +551,8 @@ class imageset: ...@@ -551,7 +551,8 @@ class imageset:
def loadkimberlite(self,matfilename): def loadkimberlite(self,matfilename):
data_dict = io.loadmat(matfilename) data_dict = io.loadmat(matfilename)
sorted_keys = sorted(data_dict.keys()) sorted_keys = sorted(data_dict.keys() , key = lambda x: int(''.join(filter(str.isdigit, str(x) ))) )
sy = data_dict['sy'][0] sy = data_dict['sy'][0]
allsx = [] allsx = []
for key in sorted_keys[3:12]: for key in sorted_keys[3:12]:
......
...@@ -514,7 +514,7 @@ class Hydra: ...@@ -514,7 +514,7 @@ class Hydra:
self.errors = np.zeros((len(self.energy),len(self.cenom_dict))) self.errors = np.zeros((len(self.energy),len(self.cenom_dict)))
master_eloss = (self.energy - np.median([self.cenom_dict[key] for key in self.cenom_dict]))*1.0e3 master_eloss = (self.energy - np.median([self.cenom_dict[key] for key in self.cenom_dict]))*1.0e3
self.E0 = np.median([self.cenom_dict[key] for key in self.cenom_dict]) self.E0 = np.median([self.cenom_dict[key] for key in self.cenom_dict])
for key,ii in zip(sorted(self.cenom_dict), range(len(self.cenom_dict))): for key,ii in zip(sorted(self.cenom_dict, key = lambda x: int(''.join(filter(str.isdigit, str(x) ))) ), range(len(self.cenom_dict))):
# signals # signals
x = ( self.energy - self.cenom_dict[key] )*1.0e3 x = ( self.energy - self.cenom_dict[key] )*1.0e3
y = self.raw_signals[key][:] y = self.raw_signals[key][:]
...@@ -539,7 +539,7 @@ class Hydra: ...@@ -539,7 +539,7 @@ class Hydra:
self.errors = np.zeros((len(self.energy),len(self.cenom_dict))) self.errors = np.zeros((len(self.energy),len(self.cenom_dict)))
master_eloss = ( self.energy - np.median(self.cenom_dict[first_key][self.cenom_dict[first_key] > 0.0]) )*1.0e3 master_eloss = ( self.energy - np.median(self.cenom_dict[first_key][self.cenom_dict[first_key] > 0.0]) )*1.0e3
self.E0 = np.median(self.cenom_dict[first_key][self.cenom_dict[first_key] > 0.0]) self.E0 = np.median(self.cenom_dict[first_key][self.cenom_dict[first_key] > 0.0])
for key,ii in zip(sorted(self.cenom_dict), range(len(self.cenom_dict))): for key,ii in zip(sorted(self.cenom_dict, key = lambda x: int(''.join(filter(str.isdigit, str(x) ))) ), range(len(self.cenom_dict))):
print ('Pixel-by-pixel compensation for ' + key +'.') print ('Pixel-by-pixel compensation for ' + key +'.')
signal = np.zeros(len(master_eloss)) signal = np.zeros(len(master_eloss))
error = np.zeros(len(master_eloss)) error = np.zeros(len(master_eloss))
...@@ -570,7 +570,7 @@ class Hydra: ...@@ -570,7 +570,7 @@ class Hydra:
self.errors = np.zeros((len(self.energy),len(self.roi_obj.red_rois))) self.errors = np.zeros((len(self.energy),len(self.roi_obj.red_rois)))
energy = self.energy * 1e3 # energy in eV energy = self.energy * 1e3 # energy in eV
for key,ii in zip(sorted(self.raw_signals), range(len(self.raw_signals))): for key,ii in zip(sorted(self.raw_signals, key = lambda x: int(''.join(filter(str.isdigit, str(x) ))) ), range(len(self.raw_signals))):
y = self.raw_signals[key] y = self.raw_signals[key]
meanii = len(range(y.shape[1]))/2 meanii = len(range(y.shape[1]))/2
yc = np.zeros_like(y) yc = np.zeros_like(y)
...@@ -1074,7 +1074,7 @@ class Hydra: ...@@ -1074,7 +1074,7 @@ class Hydra:
# normalize data # normalize data
pw_matrices_norm = [] pw_matrices_norm = []
for key in sorted(raw_signals): for key in sorted(raw_signals, key = lambda x: int(''.join(filter(str.isdigit, str(x) ))) ):
if method == 'pixel': if method == 'pixel':
unrav_mat = np.zeros((raw_signals[key].shape[0], raw_signals[key].shape[1]*raw_signals[key].shape[2])) unrav_mat = np.zeros((raw_signals[key].shape[0], raw_signals[key].shape[1]*raw_signals[key].shape[2]))
elif method in [ 'column' , 'row']: elif method in [ 'column' , 'row']:
...@@ -1098,7 +1098,7 @@ class Hydra: ...@@ -1098,7 +1098,7 @@ class Hydra:
# normalize data (first scan) # normalize data (first scan)
pw_matrices_norm = [] pw_matrices_norm = []
for key in sorted(raw_signals): for key in sorted(raw_signals, key = lambda x: int(''.join(filter(str.isdigit, str(x) ))) ):
if method == 'pixel': if method == 'pixel':
unrav_mat = np.zeros((raw_signals[key].shape[0], raw_signals[key].shape[1]*raw_signals[key].shape[2])) unrav_mat = np.zeros((raw_signals[key].shape[0], raw_signals[key].shape[1]*raw_signals[key].shape[2]))
elif method in [ 'column' , 'row' ]: elif method in [ 'column' , 'row' ]:
...@@ -1119,7 +1119,7 @@ class Hydra: ...@@ -1119,7 +1119,7 @@ class Hydra:
raw_signals = self.scans[scanname].raw_signals # dict with raw_signals raw_signals = self.scans[scanname].raw_signals # dict with raw_signals
monitor = self.scans[scanname].monitor monitor = self.scans[scanname].monitor
for key,jj in zip(sorted(raw_signals), range(len(raw_signals))): for key,jj in zip(sorted(raw_signals, key = lambda x: int(''.join(filter(str.isdigit, str(x) ))) ), range(len(raw_signals))):
if method == 'pixel': if method == 'pixel':
unrav_mat = np.zeros((raw_signals[key].shape[0], raw_signals[key].shape[1]*raw_signals[key].shape[2])) unrav_mat = np.zeros((raw_signals[key].shape[0], raw_signals[key].shape[1]*raw_signals[key].shape[2]))
elif method in [ 'column' , 'row']: elif method in [ 'column' , 'row']:
...@@ -1173,7 +1173,7 @@ class Hydra: ...@@ -1173,7 +1173,7 @@ class Hydra:
self.scans[scan_name].get_raw_signals( self.roi_obj, method='sum' ) self.scans[scan_name].get_raw_signals( self.roi_obj, method='sum' )
# find CENOM of each ROI # find CENOM of each ROI
for key in sorted(self.scans[scan_name].raw_signals): for key in sorted(self.scans[scan_name].raw_signals, key = lambda x: int(''.join(filter(str.isdigit, str(x) ))) ):
cofm = xrs_utilities.find_center_of_mass(self.scans[scan_name].energy,self.scans[scan_name].raw_signals[key]) cofm = xrs_utilities.find_center_of_mass(self.scans[scan_name].energy,self.scans[scan_name].raw_signals[key])
self.cenom_dict[key] = cofm self.cenom_dict[key] = cofm
...@@ -1192,7 +1192,7 @@ class Hydra: ...@@ -1192,7 +1192,7 @@ class Hydra:
self.scans[scan_name].get_raw_signals( self.roi_obj, method='pixel' ) self.scans[scan_name].get_raw_signals( self.roi_obj, method='pixel' )
# find CENOM for each pixel of each ROI # find CENOM for each pixel of each ROI
for key in sorted(self.scans[scan_name].raw_signals): for key in sorted(self.scans[scan_name].raw_signals, key = lambda x: int(''.join(filter(str.isdigit, str(x) ))) ):
self.cenom_dict[key] = np.zeros_like(self.roi_obj.red_rois[key][1],dtype='float') self.cenom_dict[key] = np.zeros_like(self.roi_obj.red_rois[key][1],dtype='float')
for ii in range(self.cenom_dict[key].shape[0]): for ii in range(self.cenom_dict[key].shape[0]):
for jj in range(self.cenom_dict[key].shape[1]): for jj in range(self.cenom_dict[key].shape[1]):
...@@ -1393,7 +1393,7 @@ class Hydra_imaging(Hydra): ...@@ -1393,7 +1393,7 @@ class Hydra_imaging(Hydra):
# parse energy scale # parse energy scale
energy = np.array([]) energy = np.array([])
for scan_key in sorted(self.scans): for scan_key in sorted(self.scans, key = lambda x: int(''.join(filter(str.isdigit, str(x) ))) ):
energy = np.append(energy, self.scans[scan_key].motors['energy']) energy = np.append(energy, self.scans[scan_key].motors['energy'])
energy = np.array(list(set(energy))) energy = np.array(list(set(energy)))
...@@ -1402,7 +1402,7 @@ class Hydra_imaging(Hydra): ...@@ -1402,7 +1402,7 @@ class Hydra_imaging(Hydra):
for roi_key, (pos,M) in sorted(self.roi_obj.red_rois.items()): for roi_key, (pos,M) in sorted(self.roi_obj.red_rois.items()):
signals[roi_key] = np.zeros( (len(energy), ) ) signals[roi_key] = np.zeros( (len(energy), ) )
for en,estep in zip(energy, range(len(energy))): for en,estep in zip(energy, range(len(energy))):
for scan_key in sorted(self.scans): for scan_key in sorted(self.scans, key = lambda x: int(''.join(filter(str.isdigit, str(x) ))) ):
if self.scans[scan_key].motors['energy'] == en: if self.scans[scan_key].motors['energy'] == en:
signals[roi_key][estep] += np.sum(self.scans[scan_key].raw_signals[roi_key]) signals[roi_key][estep] += np.sum(self.scans[scan_key].raw_signals[roi_key])
...@@ -1430,7 +1430,7 @@ class Hydra_imaging(Hydra): ...@@ -1430,7 +1430,7 @@ class Hydra_imaging(Hydra):
""" """
# define master energy-loss scale # define master energy-loss scale
energy = np.array([]) energy = np.array([])
for scan_key in sorted(self.scans): for scan_key in sorted(self.scans, key = lambda x: int(''.join(filter(str.isdigit, str(x) ))) ):
energy = np.append(energy, self.scans[scan_key].motors['energy']) energy = np.append(energy, self.scans[scan_key].motors['energy'])
energy = np.sort(np.array(list(set(energy)))) energy = np.sort(np.array(list(set(energy))))
...@@ -1451,7 +1451,7 @@ class Hydra_imaging(Hydra): ...@@ -1451,7 +1451,7 @@ class Hydra_imaging(Hydra):
for roi_key, (pos,M) in sorted(self.roi_obj.red_rois.items()): for roi_key, (pos,M) in sorted(self.roi_obj.red_rois.items()):
self.raw_signals[roi_key] = np.zeros( (len(energy), len(scan_scale_1), M.shape[1], len(scan_scale_2)) ) self.raw_signals[roi_key] = np.zeros( (len(energy), len(scan_scale_1), M.shape[1], len(scan_scale_2)) )
for en,estep in zip(energy, range(len(energy))): for en,estep in zip(energy, range(len(energy))):
for scan_key in sorted(self.scans): for scan_key in sorted(self.scans, key = lambda x: int(''.join(filter(str.isdigit, str(x) ))) ):
if self.scans[scan_key].motors['energy'] == en: if self.scans[scan_key].motors['energy'] == en:
for zstep in range(len(scan_scale_2)): for zstep in range(len(scan_scale_2)):
if self.scans[scan_key].motors[step_motor] == scan_scale_2[zstep]: if self.scans[scan_key].motors[step_motor] == scan_scale_2[zstep]:
...@@ -1459,7 +1459,7 @@ class Hydra_imaging(Hydra): ...@@ -1459,7 +1459,7 @@ class Hydra_imaging(Hydra):
# interpolate everything onto master energy-loss scale # interpolate everything onto master energy-loss scale
self.raw_signals_int = {} self.raw_signals_int = {}
for roi_key in sorted(self.raw_signals): for roi_key in sorted(self.raw_signals, key = lambda x: int(''.join(filter(str.isdigit, str(x) ))) ):
x = (energy - self.cenom_dict[roi_key])*1.0e3 x = (energy - self.cenom_dict[roi_key])*1.0e3
y = self.raw_signals[roi_key] y = self.raw_signals[roi_key]
f = interp1d(x, y, kind='linear', axis=0, bounds_error=False, fill_value=0.0) f = interp1d(x, y, kind='linear', axis=0, bounds_error=False, fill_value=0.0)
...@@ -1722,7 +1722,7 @@ class Fourc: ...@@ -1722,7 +1722,7 @@ class Fourc:
elastic_scan.get_raw_signals( self.roi_obj, method='pixel' ) elastic_scan.get_raw_signals( self.roi_obj, method='pixel' )
# find CENOM for each pixel of each ROI # find CENOM for each pixel of each ROI
for key in sorted(elastic_scan.raw_signals): for key in sorted(elastic_scan.raw_signals, key = lambda x: int(''.join(filter(str.isdigit, str(x) ))) ):
self.cenom_dict[key] = np.zeros_like(self.roi_obj.red_rois[key][1]) self.cenom_dict[key] = np.zeros_like(self.roi_obj.red_rois[key][1])
for ii in range(self.cenom_dict[key].shape[0]): for ii in range(self.cenom_dict[key].shape[0]):
for jj in range(self.cenom_dict[key].shape[1]): for jj in range(self.cenom_dict[key].shape[1]):
...@@ -2087,7 +2087,7 @@ class Fourc: ...@@ -2087,7 +2087,7 @@ class Fourc:
# normalize data # normalize data
pw_matrices_norm = [] pw_matrices_norm = []
for key in sorted(raw_signals): for key in sorted(raw_signals, key = lambda x: int(''.join(filter(str.isdigit, str(x) ))) ):
if method == 'pixel': if method == 'pixel':
unrav_mat = np.zeros((raw_signals[key].shape[0], raw_signals[key].shape[1]*raw_signals[key].shape[2])) unrav_mat = np.zeros((raw_signals[key].shape[0], raw_signals[key].shape[1]*raw_signals[key].shape[2]))
elif method in [ 'column' , 'row']: elif method in [ 'column' , 'row']:
...@@ -2111,7 +2111,7 @@ class Fourc: ...@@ -2111,7 +2111,7 @@ class Fourc:
# normalize data (first scan) # normalize data (first scan)
pw_matrices_norm = [] pw_matrices_norm = []
for key in sorted(raw_signals): for key in sorted(raw_signals, key = lambda x: int(''.join(filter(str.isdigit, str(x) ))) ):
if method == 'pixel': if method == 'pixel':
unrav_mat = np.zeros((raw_signals[key].shape[0], raw_signals[key].shape[1]*raw_signals[key].shape[2])) unrav_mat = np.zeros((raw_signals[key].shape[0], raw_signals[key].shape[1]*raw_signals[key].shape[2]))
elif method in [ 'column' , 'row']: elif method in [ 'column' , 'row']:
...@@ -2132,7 +2132,7 @@ class Fourc: ...@@ -2132,7 +2132,7 @@ class Fourc:
raw_signals = self.scans[scanname].raw_signals # dict with raw_signals raw_signals = self.scans[scanname].raw_signals # dict with raw_signals
monitor = self.scans[scanname].monitor monitor = self.scans[scanname].monitor
for key,jj in zip(sorted(raw_signals), range(len(raw_signals))): for key,jj in zip(sorted(raw_signals, key = lambda x: int(''.join(filter(str.isdigit, str(x) ))) ), range(len(raw_signals))):
if method == 'pixel': if method == 'pixel':
unrav_mat = np.zeros((raw_signals[key].shape[0], raw_signals[key].shape[1]*raw_signals[key].shape[2])) unrav_mat = np.zeros((raw_signals[key].shape[0], raw_signals[key].shape[1]*raw_signals[key].shape[2]))
elif method in [ 'column' ,'row'] : elif method in [ 'column' ,'row'] :
......
...@@ -202,7 +202,7 @@ class roi_object: ...@@ -202,7 +202,7 @@ class roi_object:
# append the other ROIs # append the other ROIs
self_len = len( new_obj.red_rois ) self_len = len( new_obj.red_rois )
for ii,key in enumerate( sorted( roi_obj.red_rois ) ): for ii,key in enumerate( sorted( roi_obj.red_rois, key = lambda x: int(''.join(filter(str.isdigit, str(x) ))) ) ):
new_key = 'ROI%02d'%( ii+self_len ) new_key = 'ROI%02d'%( ii+self_len )
if not new_key in list( new_obj.red_rois.keys() ): if not new_key in list( new_obj.red_rois.keys() ):
new_obj.red_rois[new_key] = roi_obj.red_rois[key] new_obj.red_rois[new_key] = roi_obj.red_rois[key]
...@@ -328,7 +328,7 @@ class roi_object: ...@@ -328,7 +328,7 @@ class roi_object:
orig_length = len( self.red_rois ) orig_length = len( self.red_rois )
for ii,key in enumerate(sorted(roi_object.red_rois)): for ii,key in enumerate(sorted(roi_object.red_rois, key = lambda x: int(''.join(filter(str.isdigit, str(x) ))) )):
new_key = 'ROI%02d'%(ii+orig_length) new_key = 'ROI%02d'%(ii+orig_length)
self.red_rois[new_key] = roi_object.red_rois[key] self.red_rois[new_key] = roi_object.red_rois[key]
self.red_rois[new_key][1][ self.red_rois[new_key][1]>0 ] += orig_length self.red_rois[new_key][1][ self.red_rois[new_key][1]>0 ] += orig_length
...@@ -457,7 +457,7 @@ class roi_object: ...@@ -457,7 +457,7 @@ class roi_object:
# delete last ROI if no key is specified # delete last ROI if no key is specified
if not roi_key: if not roi_key:
roi_key = sorted(list( self.red_rois.keys()))[-1] roi_key = sorted(list( self.red_rois.keys()) , key = lambda x: int(''.join(filter(str.isdigit, str(x) ))) )[-1]