Commit 0adaae67 authored by bliss administrator's avatar bliss administrator
Browse files

xes def order_multiple_xes_vars and fixes

parent c2e048b4
Pipeline #65763 failed
......@@ -175,7 +175,55 @@ def xes_regions_simple(xes_energies, ene_steps , acq_times, *counter_args):
print('going to run: ascan(xes_en, {:f}, {:f}, {:d}, {:f})'.format(one_ene, xes_energies[idx+1], int(_npts[idx]), acq_times[idx]))
setup_globals.ascan(XES_EN, one_ene, xes_energies[idx+1], int(_npts[idx]), acq_times[idx], *counter_args)
def order_multiple_xes_vars(start_xes_en, end_xes_en, step_xes_en, acq_time, hutch):
# check length of arrays and validity of multiple_xes_vars entries. Re-order if necessary.
# valid is something like this:
# start_xes_en: list of n elements, ascending/descending
# end_xes_en: single float
# step_xes_en: list of n elements
# acq_time: list of n elements
if general_len(end_xes_en) > 1:
print('end_xes_en must be a single value (float)')
multiple_xes_en_scan = None
if (general_len(start_xes_en) == 1 and general_len(step_xes_en) == 1 and general_len(acq_time) == 1): #single scan
multiple_xes_en_scan = False # single xes_en scan
if hutch == 'eh1':
if start_xes_en < end_xes_en:
(start_xes_en, end_xes_en) = (end_xes_en, start_xes_en)
elif (general_len(end_xes_en) == 1 and general_len(start_xes_en) == general_len(step_xes_en) and general_len(start_xes_en) == general_len(acq_time) ):
multiple_xes_en_scan = True # correct length of lists/arrays
xes_energies = np.append(start_xes_en,end_xes_en)
if hutch == 'eh1':
if np.all(np.sort(xes_energies) == xes_energies):
print("The energies are in ascending order, must re-order")
xes_energies = xes_energies [::-1]
start_xes_en = xes_energies[:-1]
end_xes_en = xes_energies[-1]
step_xes_en = step_xes_en [::-1]
acq_time = acq_time [::-1]
elif np.all(np.sort(xes_energies) == xes_energies[::-1]):
print("The energies are in descending order, perfect for TEXS")
else:
print('ATTENTION: the energies are not ordered, descending order imposed, steps and acq times retained, this may be wrong!')
xes_enegies = np.sort(xes_energies)[::-1]
start_xes_en = xes_energies[:-1]
end_xes_en = xes_energies[-1]
elif hutch == 'eh2':
if np.all(np.sort(xes_energies) == xes_energies):
print("The energies are in ascending order, perfect for EH2")
elif np.all(np.sort(xes_energies) == xes_energies[::-1]):
print("The energies are in descending order, must re-order")
xes_energies = xes_energies [::-1]
start_xes_en = xes_energies[:-1]
end_xes_en = xes_energies[-1]
step_xes_en = step_xes_en [::-1]
acq_time = acq_time [::-1]
else:
print('ATTENTION: the energies are not ordered, ascending order imposed. Steps and acq times retained, this may be wrong!')
xes_enegies = np.sort(xes_energies)
start_xes_en = xes_energies[:-1]
end_xes_en = xes_energies[-1]
return (start_xes_en, end_xes_en, step_xes_en, acq_time, multiple_xes_en_scan)
class Xes(ID26Measurement):
......@@ -256,17 +304,18 @@ class Xes(ID26Measurement):
if acq_time is None:
raise ValueError('Acq time not defined')
# find out whether this is a single or multi xes_en scan
if general_len(start_xes_en) == 1: # single xes_en scan as in Xes main
multiple_xes_en_scan = False
elif (general_len(end_xes_en) == 1 and general_len(start_xes_en) == general_len(step_xes_en) and general_len(start_xes_en) == general_len(acq_time) ):
multiple_xes_en_scan = True
else:
# find out whether this is a single or multi xes_en scan and if multi, check order of params and re-order if necessary
if setup_globals.current_session.name in ['optics', 'eh2']:
hutch = 'eh2'
elif setup_globals.current_session.name in ['texs']:
hutch = 'eh1'
(start_xes_en, end_xes_en, step_xes_en, acq_time, multiple_xes_en_scan) = order_multiple_xes_vars(start_xes_en, end_xes_en, step_xes_en, acq_time, hutch)
if multiple_xes_en_scan is None: # something went wrong:
print('len([\'start_xes_en\'] = ',general_len(self['start_xes_en']))
print('len([\'step_xes_en\'] = ',general_len(self['step_xes_en']))
print('len([\'acq_time\'] = ',general_len(self['acq_time']))
print('Xes object key value lists/arrays [\'start_xes_en\'], [\'step_xes_en\'] and [\'acq_time\'] do not have the same length. Check and try again.')
print('Xes object key value lists/arrays [\'start_xes_en\'], [\'step_xes_en\'] and [\'acq_time\'] do not have the same length or are not in the correct order. Check and try again.')
raise ValueError
if self._move_scan_mode == 'in':
......@@ -288,10 +337,9 @@ class Xes(ID26Measurement):
for i in range(_number_of_scans):
print("NOT IMPLEMENTED YET check gauges 5 and open valve 4")
# first a single xes_en scan:
if multiple_xes_en_scan == False:
no_intervals = np.ceil((end_xes_en-start_xes_en)/step_xes_en)
no_intervals = np.abs(np.ceil((end_xes_en-start_xes_en)/step_xes_en)) # make sure positive number
if self._move_scan_mode == 'in':
self._first_correction_index = self.get_current_index()
my_xes_scan = setup_globals.ascan(XES_EN,start_xes_en, end_xes_en,int(no_intervals),acq_time, run = False)
......@@ -757,4 +805,5 @@ class CorrectionScan(ID26Measurement):
correction_scan.acq_chain.add_preset(self._main_scan._radiation_damage)
correction_scan.run() # run the correction scan
return correction_scan
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment