Skip to content

Commit

Permalink
fixed import issue
Browse files Browse the repository at this point in the history
  • Loading branch information
bfrosik committed Apr 12, 2021
1 parent bd6b5f8 commit 7f7d8da
Showing 1 changed file with 103 additions and 7 deletions.
110 changes: 103 additions & 7 deletions scripts/beamlines/aps_34idc/beam_tabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -468,16 +569,14 @@ 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():
# do not parse on initial assignment
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')

Expand Down Expand Up @@ -822,16 +921,14 @@ 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():
# do not parse on initial assignment
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')
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7f7d8da

Please sign in to comment.