Skip to content

Commit

Permalink
update IS code
Browse files Browse the repository at this point in the history
  • Loading branch information
mdoucet committed Sep 2, 2024
1 parent 9816528 commit cffb3fc
Show file tree
Hide file tree
Showing 8 changed files with 431 additions and 98 deletions.
58 changes: 50 additions & 8 deletions launcher/apps/reduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@ def __init__(self):
layout.addWidget(self.choose_template, 1, 1)

self.template_path = QLabel(self)
layout.addWidget(self.template_path, 1, 2)
layout.addWidget(self.template_path, 1, 3)

# First run to process
self.first_run_number_ledit = QtWidgets.QLineEdit()
self.first_run_number_ledit.setValidator(QtGui.QIntValidator())
layout.addWidget(self.first_run_number_ledit, 3, 1)
self.first_run_number_label = QLabel(self)
self.first_run_number_label.setText("First run to process")
layout.addWidget(self.first_run_number_label, 3, 2)
layout.addWidget(self.first_run_number_label, 3, 3)

# Last run to process
self.last_run_number_ledit = QtWidgets.QLineEdit()
self.last_run_number_ledit.setValidator(QtGui.QIntValidator())
layout.addWidget(self.last_run_number_ledit, 4, 1)
self.last_run_number_label = QLabel(self)
self.last_run_number_label.setText("Last run to process")
layout.addWidget(self.last_run_number_label, 4, 2)
layout.addWidget(self.last_run_number_label, 4, 3)

# Select version
self.select_version_label = QLabel(self)
Expand All @@ -48,7 +48,7 @@ def __init__(self):
layout.addWidget(self.select_version_label, 5, 1)
self.select_version_check = QtWidgets.QCheckBox()
self.select_version_check.setChecked(False)
layout.addWidget(self.select_version_check, 5, 2)
layout.addWidget(self.select_version_check, 5, 3)

# Select const-q binning
self.const_q_label = QLabel(self)
Expand All @@ -57,7 +57,7 @@ def __init__(self):
layout.addWidget(self.const_q_label, 6, 1)
self.const_q_check = QtWidgets.QCheckBox()
self.const_q_check.setChecked(False)
layout.addWidget(self.const_q_check, 6, 2)
layout.addWidget(self.const_q_check, 6, 3)

# Select how to treat overlap
self.average_overlapp_label = QLabel(self)
Expand All @@ -66,11 +66,33 @@ def __init__(self):
layout.addWidget(self.average_overlapp_label, 7, 1)
self.average_overlapp_check = QtWidgets.QCheckBox()
self.average_overlapp_check.setChecked(True)
layout.addWidget(self.average_overlapp_check, 7, 2)
layout.addWidget(self.average_overlapp_check, 7, 3)

# Fit first peak to compute offset
self.first_peak_label = QLabel(self)
self.first_peak_label.setText("Offset from first peak")
self.first_peak_label.setAlignment(QtCore.Qt.AlignRight)
layout.addWidget(self.first_peak_label, 8, 1)
self.first_peak_check = QtWidgets.QCheckBox()
self.first_peak_check.setChecked(True)
layout.addWidget(self.first_peak_check, 8, 3)

# Theta offset
self.fix_offset_label = QLabel(self)
self.fix_offset_label.setText("Use fixed theta offset")
self.fix_offset_label.setAlignment(QtCore.Qt.AlignRight)
layout.addWidget(self.fix_offset_label, 9, 1)
self.fix_offset_check = QtWidgets.QCheckBox()
self.fix_offset_check.setChecked(False)
layout.addWidget(self.fix_offset_check, 9, 2)

self.fix_offset_ledit = QtWidgets.QLineEdit()
self.fix_offset_ledit.setValidator(QtGui.QDoubleValidator())
layout.addWidget(self.fix_offset_ledit, 9, 3)

# Process button
self.perform_reduction = QPushButton('Reduce')
layout.addWidget(self.perform_reduction, 8, 1)
layout.addWidget(self.perform_reduction, 10, 1)

# connections
self.choose_template.clicked.connect(self.template_selection)
Expand All @@ -87,7 +109,12 @@ def select_version(self):
self.average_overlapp_label.setEnabled(not use_old)
self.const_q_check.setEnabled(not use_old)
self.const_q_label.setEnabled(not use_old)

self.fix_offset_check.setEnabled(not use_old)
self.fix_offset_label.setEnabled(not use_old)
self.fix_offset_ledit.setEnabled(not use_old)
self.first_peak_label.setEnabled(not use_old)
self.first_peak_check.setEnabled(not use_old)

def template_selection(self):
_template_file, _ = QFileDialog.getOpenFileName(self, 'Open file',
self.template_path.text(),
Expand All @@ -114,6 +141,14 @@ def read_settings(self):
_const_q = self.settings.value("reduction_const_q", "false")
self.const_q_check.setChecked(_const_q=='true')

_first_peak = self.settings.value("fit_first_peak", "false")
self.first_peak_check.setChecked(_first_peak=='true')
_fix_offset = self.settings.value("reduction_fix_use_offset", "false")
self.fix_offset_check.setChecked(_fix_offset=='true')
_fix_offset = self.settings.value("reduction_fix_offset", "0")
self.fix_offset_ledit.setText(_fix_offset)


def save_settings(self):
self.settings.setValue('reduction_template', self.template_path.text())
self.settings.setValue('reduction_first_run_number', self.first_run_number_ledit.text())
Expand All @@ -122,6 +157,10 @@ def save_settings(self):
self.settings.setValue('reduction_avg_overlap', self.average_overlapp_check.isChecked())
self.settings.setValue('reduction_const_q', self.const_q_check.isChecked())

self.settings.setValue('fit_first_peak', self.first_peak_check.isChecked())
self.settings.setValue('reduction_fix_use_offset', self.fix_offset_check.isChecked())
self.settings.setValue('reduction_fix_offset', self.fix_offset_ledit.text())

def check_inputs(self):
error = None
# Check files and output directory
Expand Down Expand Up @@ -167,6 +206,9 @@ def reduce(self):
options.append(self.template_path.text())
options.append(str(self.average_overlapp_check.isChecked()))
options.append(str(self.const_q_check.isChecked()))
options.append(str(self.first_peak_check.isChecked()))
if self.fix_offset_check.isChecked():
options.append(str(self.fix_offset_ledit.text()))
else:
options.append('old')
options.append(self.template_path.text())
Expand Down
8 changes: 4 additions & 4 deletions launcher/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ def __init__(self):
# 60Hz time-resolved
tab_id += 1
self.time_60Hz_tab = Dynamic60Hz()
self.addTab(self.time_60Hz_tab, "Time-resolved 60Hz")
self.setTabText(tab_id, "Time-resolved 60Hz")
self.addTab(self.time_60Hz_tab, "Time-resolved")
self.setTabText(tab_id, "Time-resolved")

# 30 Hz time-resolved
tab_id += 1
self.time_30Hz_tab = Dynamic30Hz()
self.addTab(self.time_30Hz_tab, "Time-resolved 30Hz")
self.setTabText(tab_id, "Time-resolved 30Hz")
self.addTab(self.time_30Hz_tab, "Time-resolved (D2O ref)")
self.setTabText(tab_id, "Time-resolved (D2O ref)")

# Off-specular data
tab_id += 1
Expand Down
15 changes: 12 additions & 3 deletions miniDAS/db_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ def scan_centers(self, charge: float = None):
s1_width = self.positions[1]['s1:X:Gap']
self.lr.move({'si:X:Gap': si_width/self.grid_size[0], 's1:X:Gap': s1_width/self.grid_size[1]})

# Set scale multiplier
multiplier = self.grid_size[0] * self.grid_size[1]
instrument.ScaleMultiplier.put(multiplier)

# The starting center should half a step from the left-most position
si_start = si_width * (-1 + 1 / self.grid_size[0]) / 2
s1_start = s1_width * (-1 + 1 / self.grid_size[1]) / 2
Expand All @@ -110,10 +114,13 @@ def scan_centers(self, charge: float = None):
print("Charge to acquire per configuration:", charge_to_acquire_per_point)

# Iterate over Si
counter = 0
for si in si_positions:
# Iterate over S1
for s1 in s1_positions:
print(f"Si X center: {si}\tS1 X center: {s1}")
counter += 1
t0 = time.time()
print(f"{counter} -> Si X center: {si}\tS1 X center: {s1}")
# Move motors to the specified positions
self.lr.move({'si:X:Center': si, 's1:X:Center': s1})
time.sleep(1.)
Expand All @@ -124,13 +131,15 @@ def scan_centers(self, charge: float = None):
self.lr.pause()

rate = self.lr.get_rate()
print(f" Rate: {rate}")
elapsed = time.time() - t0
print(f" Rate: {rate} Elapsed: {elapsed} sec\n\n")

time.sleep(1.)
self.lr.stop()

# Move centers back to zero
self.lr.move({'si:X:Center': 0, 's1:X:Center': 0})

instrument.ScaleMultiplier.put(multiplier)
time.sleep(2)

# Example usage
Expand Down
3 changes: 2 additions & 1 deletion miniDAS/instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def get(self):
Lcen = PV('BL4B:Det:TH:BL:Lambda')
Lset = PV('BL4B:Chop:Gbl:WavelengthReq')
ChopStat = PV('BL4B:Chop:Gbl:Busy:Stat')
ScaleMultiplier = PV('BL4B:CS:Autoreduce:ScaleMultiplier')

BL4B_MOT_PREFIX = 'BL4B:Mot:'

Expand Down Expand Up @@ -155,7 +156,7 @@ def start_or_resume(self, counts: int = 0, seconds: int = 0, charge: float = 200



time.sleep(1)
time.sleep(2)
# Wait for the neutron count to reach the desired value
if counts > 0:
while neutrons.get() < counts:
Expand Down
Loading

0 comments on commit cffb3fc

Please sign in to comment.