Skip to content

Commit

Permalink
fixed issues in beamline tabs when parsing spec
Browse files Browse the repository at this point in the history
  • Loading branch information
Barbara Frosik committed Jun 5, 2023
1 parent 3350031 commit e25a460
Showing 1 changed file with 43 additions and 16 deletions.
59 changes: 43 additions & 16 deletions cohere-scripts/beamlines/aps_34idc/beam_tabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,10 @@ def set_data_dir(self):


def save_conf(self):
if not self.main_win.is_exp_exists():
msg_window('the experiment does not exist, cannot save the config_prep file')
return

conf_map = self.get_prep_config()
if len(conf_map) > 0:
er_msg = cohere.verify('config_prep', conf_map)
Expand Down Expand Up @@ -537,6 +541,10 @@ def run_tab(self):


def save_conf(self):
if not self.main_win.is_exp_exists():
msg_window('the experiment does not exist, cannot save the config_disp file')
return

conf_map = self.get_disp_config()
if len(conf_map) > 0:
er_msg = cohere.verify('config_disp', conf_map)
Expand Down Expand Up @@ -619,7 +627,7 @@ def __init__(self, parent=None):
super(SubInstrTab, self).__init__(parent)


def init(self, tabs, main_window):
def init(self, instr_tab, main_window):
"""
Creates and initializes the 'Instrument' tab.
Parameters
Expand All @@ -630,6 +638,7 @@ def init(self, tabs, main_window):
nothing
"""
self.main_window = main_window
self.instr_tab = instr_tab

self.spec_widget = QWidget()
spec_layout = QFormLayout()
Expand Down Expand Up @@ -667,7 +676,7 @@ def init(self, tabs, main_window):
self.detector.textChanged.connect(lambda: set_overriden(self.detector))


def load_tab(self, conf_map, specfile, diff):
def load_tab(self, conf_map):
"""
It verifies given configuration file, reads the parameters, and fills out the window.
Parameters
Expand All @@ -678,7 +687,7 @@ def load_tab(self, conf_map, specfile, diff):
-------
nothing
"""
self.parse_spec(specfile, diff)
self.parse_spec()

# if parameters are configured, override the readings from spec file
if 'energy' in conf_map:
Expand Down Expand Up @@ -762,7 +771,7 @@ def get_instr_config(self):
return conf_map


def parse_spec(self, specfile, diffractometer):
def parse_spec(self):
"""
Calls utility function to parse spec file. Displas the parsed parameters in the window with blue text.
Parameters
Expand All @@ -774,6 +783,17 @@ def parse_spec(self, specfile, diffractometer):
"""
scan = str(self.main_window.scan_widget.text())
if len(scan) == 0:
msg_window ('cannot parse spec, scan not defined')
return

diffractometer = self.instr_tab.diffractometer.text()
if len(diffractometer) == 0:
msg_window ('cannot parse spec, diffractometer not defined')
return

specfile = self.instr_tab.spec_file_button.text()
if len(specfile) == 0:
msg_window ('cannot parse spec, specfile not defined')
return

import beamlines.aps_34idc.diffractometers as diff
Expand All @@ -787,6 +807,8 @@ def parse_spec(self, specfile, diffractometer):

last_scan = int(scan.split('-')[-1].split(',')[-1])
spec_dict = instr.parse_spec(specfile, last_scan, diff_obj)
if spec_dict is None:
return
if 'energy' in spec_dict:
self.energy.setText(str(spec_dict['energy']))
self.energy.setStyleSheet('color: blue')
Expand Down Expand Up @@ -838,9 +860,9 @@ def toggle_config(self):
else:
self.add_config = True
self.extended.spec_widget.show()
self.extended.parse_spec(self.spec_file_button.text(), self.diffractometer.text())
if self.main_win.is_exp_exists():
self.save_conf()
self.extended.parse_spec()

self.save_conf()


def init(self, tabs, main_window):
Expand All @@ -861,7 +883,7 @@ def init(self, tabs, main_window):
else:
self.add_config = True
self.extended = SubInstrTab()
self.extended.init(tabs, main_window)
self.extended.init(self, main_window)

tab_layout = QVBoxLayout()
gen_layout = QFormLayout()
Expand Down Expand Up @@ -912,11 +934,12 @@ def load_tab(self, conf_map):
if os.path.isfile(specfile):
self.spec_file_button.setStyleSheet("Text-align:left")
self.spec_file_button.setText(specfile)
if self.add_config:
self.extended.load_tab(conf_map, specfile, diff)
else:
msg_window('The specfile file ' + specfile + ' in config file does not exist')

if self.add_config:
self.extended.load_tab(conf_map)


def set_spec_file(self):
"""
Expand All @@ -929,17 +952,17 @@ def set_spec_file(self):
-------
noting
"""
self.specfile = select_file(os.getcwd())
if self.specfile is not None:
specfile = select_file(os.getcwd())
if specfile is not None:
self.spec_file_button.setStyleSheet("Text-align:left")
self.spec_file_button.setText(self.specfile)
self.save_conf()
self.spec_file_button.setText(specfile)
if self.add_config:
self.extended.parse_spec(self.specfile, self.diffractometer.text())
self.extended.parse_spec()
else:
self.specfile = None
self.spec_file_button.setText('')

self.save_conf()


def clear_conf(self):
self.diffractometer.setText('')
Expand Down Expand Up @@ -1000,6 +1023,10 @@ def save_conf(self):
-------
nothing
"""
if not self.main_win.is_exp_exists():
msg_window('the experiment does not exist, cannot save the config_instr file')
return

conf_map = self.get_instr_config()
# verify that disp configuration is ok
er_msg = cohere.verify('config_instr', conf_map)
Expand Down

0 comments on commit e25a460

Please sign in to comment.