Skip to content

Commit

Permalink
Merge pull request #1725 from HEXRD/calibration-mirror-first-detector
Browse files Browse the repository at this point in the history
Add button to mirror "Vary" from first detector in Calibration Dialog
  • Loading branch information
psavery committed Aug 20, 2024
2 parents 4c54a1b + f27848d commit ba5848e
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 17 deletions.
28 changes: 28 additions & 0 deletions hexrdgui/calibration/calibration_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ def setup_connections(self):
self.on_engineering_constraints_changed)
self.ui.delta_boundaries.toggled.connect(
self.on_delta_boundaries_toggled)
self.ui.mirror_vary_from_first_detector.clicked.connect(
self.mirror_vary_from_first_detector)
self.ui.edit_picks_button.clicked.connect(self.on_edit_picks_clicked)
self.ui.save_picks_button.clicked.connect(self.on_save_picks_clicked)
self.ui.load_picks_button.clicked.connect(self.on_load_picks_clicked)
Expand Down Expand Up @@ -315,6 +317,32 @@ def on_delta_boundaries_toggled(self, b):
# The columns have changed, so we need to reinitialize the tree view
self.reinitialize_tree_view()

def mirror_vary_from_first_detector(self):
config = self.tree_view.model().config
detector_iterator = iter(config['detectors'])
first_detector_name = next(detector_iterator)
first_detector = config['detectors'][first_detector_name]
tilts = first_detector['transform']['tilt']
translations = first_detector['transform']['translation']

statuses = {
'tilt': {k: v['_param'].vary for k, v in tilts.items()},
'translation': {
k: v['_param'].vary for k, v in translations.items()
},
}

# Now loop through all other detectors and update them
for det_name in detector_iterator:
detector = config['detectors'][det_name]
for transform, transform_vary in statuses.items():
det_transform = detector['transform'][transform]
for k, v in transform_vary.items():
det_transform[k]['_param'].vary = v
det_transform[k]['_vary'] = v

self.tree_view.reset_gui()

def update_from_calibrator(self, calibrator):
self.engineering_constraints = calibrator.engineering_constraints
self.tth_distortion = calibrator.tth_distortion
Expand Down
33 changes: 22 additions & 11 deletions hexrdgui/resources/ui/calibration_dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,23 @@
<string>Constraints</string>
</property>
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0">
<widget class="QLabel" name="engineering_constraints_label">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Add engineering constraints for certain instrument types. This may add extra parameters to the table.&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;For example, for TARDIS, the distance between IMAGE-PLATE-2 and IMAGE-PLATE-4 must be within a certain range. If TARDIS is selected, a new parameter is added with default values for this distance.&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;If the instrument type can be guessed, it will be selected automatically when the dialog first appears. For example, TARDIS is automatically selected if any of the detector names are IMAGE-PLATE-2, IMAGE-PLATE-3, or IMAGE-PLATE-4.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Add engineering constraints for:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="delta_boundaries">
<property name="text">
<string>Use delta for boundaries</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="engineering_constraints">
<property name="toolTip">
Expand All @@ -37,20 +54,13 @@
</item>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="engineering_constraints_label">
<item row="2" column="0" colspan="2">
<widget class="QPushButton" name="mirror_vary_from_first_detector">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Add engineering constraints for certain instrument types. This may add extra parameters to the table.&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;For example, for TARDIS, the distance between IMAGE-PLATE-2 and IMAGE-PLATE-4 must be within a certain range. If TARDIS is selected, a new parameter is added with default values for this distance.&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;If the instrument type can be guessed, it will be selected automatically when the dialog first appears. For example, TARDIS is automatically selected if any of the detector names are IMAGE-PLATE-2, IMAGE-PLATE-3, or IMAGE-PLATE-4.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Add engineering constraints for:</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;If clicked, the &amp;quot;Vary&amp;quot; statuses of the first detector's tilt/translation parameters will be copied to all other detectors' tilt/translation parameters.&lt;/p&gt;&lt;p&gt;This is helpful if you have many detectors and want to modify all of their &amp;quot;Vary&amp;quot; settings in a similar way.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="delta_boundaries">
<property name="text">
<string>Use delta for boundaries</string>
<string>Mirror &quot;Vary&quot; from First Detector</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -439,6 +449,7 @@ See scipy.optimize.least_squares for more details.</string>
<tabstop>draw_picks</tabstop>
<tabstop>engineering_constraints</tabstop>
<tabstop>delta_boundaries</tabstop>
<tabstop>mirror_vary_from_first_detector</tabstop>
<tabstop>edit_picks_button</tabstop>
<tabstop>save_picks_button</tabstop>
<tabstop>load_picks_button</tabstop>
Expand Down
16 changes: 10 additions & 6 deletions hexrdgui/tree_views/base_dict_tree_item_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,20 +241,24 @@ def rebuild_tree(self):
self.model().rebuild_tree()

def expand_rows(self, parent=QModelIndex(), rows=None):
row_count = self.model().rowCount(parent)

if rows is None:
# Default to all rows
rows = list(range(row_count))
# Perform expandRecursively(), as it is *significantly* faster.
self.expandRecursively(parent)
return

# If there are certain rows selected for expansion, we have to do
# it ourselves.

# Recursively expands rows
row_count = self.model().rowCount(parent)
for i in rows:
if i >= row_count:
continue

index = self.model().index(i, KEY_COL, parent)
self.expand(index)
self.expand_rows(index)
if self.model().hasChildren(index):
self.expand(index)
self.expand_rows(index)

@property
def lists_resizable(self):
Expand Down

0 comments on commit ba5848e

Please sign in to comment.