diff --git a/scripts/beamlines/aps_34idc/beam_tabs.py b/scripts/beamlines/aps_34idc/beam_tabs.py index 164cff9..ab78085 100644 --- a/scripts/beamlines/aps_34idc/beam_tabs.py +++ b/scripts/beamlines/aps_34idc/beam_tabs.py @@ -4,8 +4,109 @@ from PyQt5.QtWidgets import * import cohere.src_py.utilities.utils as ut import config_verifier as ver +from xrayutilities.io import spec as spec +def get_det_from_spec(specfile, scan): + """ + Reads detector area and detector name from spec file for given scan. + Parameters + ---------- + specfile : str + spec file name + + scan : int + scan number to use to recover the saved measurements + Returns + ------- + detector_name : str + detector name + det_area : list + detector area + """ + try: + # Scan numbers start at one but the list is 0 indexed + ss = spec.SPECFile(specfile)[scan - 1] + # Stuff from the header + detector_name = str(ss.getheader_element('UIMDET')) + det_area = [int(n) for n in ss.getheader_element('UIMR5').split()] + return detector_name, det_area + except Exception as ex: + print(str(ex)) + print ('Could not parse ' + specfile ) + return None, None + + +def parse_spec(specfile, scan): + """ + Reads parameters necessary to run visualization from spec file for given scan. + Parameters + ---------- + specfile : str + spec file name + + scan : int + scan number to use to recover the saved measurements + Returns + ------- + delta, gamma, theta, phi, chi, scanmot, scanmot_del, detdist, detector_name, energy + """ + # Scan numbers start at one but the list is 0 indexed + try: + ss = spec.SPECFile(specfile)[scan - 1] + except Exception as ex: + print(str(ex)) + print ('Could not parse ' + specfile ) + return None,None,None,None,None,None,None,None,None,None + + # Stuff from the header + try: + detector_name = str(ss.getheader_element('UIMDET')) + except: + detector_name = None + try: + command = ss.command.split() + scanmot = command[1] + scanmot_del = (float(command[3]) - float(command[2])) / int(command[4]) + except: + scanmot = None + scanmot_del = None + + # Motor stuff from the header + try: + delta = ss.init_motor_pos['INIT_MOPO_Delta'] + except: + delta = None + try: + gamma = ss.init_motor_pos['INIT_MOPO_Gamma'] + except: + gamma = None + try: + theta = ss.init_motor_pos['INIT_MOPO_Theta'] + except: + theta = None + try: + phi = ss.init_motor_pos['INIT_MOPO_Phi'] + except: + phi = None + try: + chi = ss.init_motor_pos['INIT_MOPO_Chi'] + except: + chi = None + try: + detdist = ss.init_motor_pos['INIT_MOPO_camdist'] + except: + detdist = None + try: + energy = ss.init_motor_pos['INIT_MOPO_Energy'] + except: + energy = None + + # returning the scan motor name as well. Sometimes we scan things + # other than theta. So we need to expand the capability of the display + # code. + return delta, gamma, theta, phi, chi, scanmot, scanmot_del, detdist, detector_name, energy + def msg_window(text): """ @@ -468,8 +569,6 @@ def parse_spec(self): ------- nothing """ - import cohere.src_py.beamlines.spec as spec - if self.main_win.specfile is None: return if not self.main_win.is_exp_exists(): @@ -477,7 +576,7 @@ def parse_spec(self): return try: last_scan = int(self.main_win.scan.split('-')[-1]) - detector_name, roi = spec.get_det_from_spec(self.main_win.specfile, last_scan) + detector_name, roi = get_det_from_spec(self.main_win.specfile, last_scan) self.roi.setText(str(roi)) self.roi.setStyleSheet('color: blue') @@ -822,8 +921,6 @@ def parse_spec(self): ------- nothing """ - import cohere.src_py.beamlines.spec as spec - if self.main_win.specfile is None: return if not self.main_win.is_exp_exists(): @@ -831,7 +928,7 @@ def parse_spec(self): return try: last_scan = int(self.main_win.scan.split('-')[-1]) - delta, gamma, theta, phi, chi, scanmot, scanmot_del, detdist, detector_name, energy = spec.parse_spec(self.main_win.specfile, last_scan) + delta, gamma, theta, phi, chi, scanmot, scanmot_del, detdist, detector_name, energy = parse_spec(self.main_win.specfile, last_scan) if energy is not None: self.energy.setText(str(energy)) self.energy.setStyleSheet('color: blue') @@ -915,7 +1012,6 @@ def update_tab(self, **args): self.result_dir_button.setText(self.results_dir) - def set_res_dir(self): """ Results directory is a parameter in display tab. It defines a directory tree that the display script will