Skip to content

Commit ba0b426

Browse files
authored
Merge pull request #1811 from HEXRD/calibration-distortion-fixes
Calibration distortion fixes
2 parents 07b8fbd + 19f53ae commit ba0b426

File tree

4 files changed

+53
-5
lines changed

4 files changed

+53
-5
lines changed

hexrdgui/calibration/calibration_dialog.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import copy
2+
import traceback
23

34
import yaml
45

@@ -296,6 +297,7 @@ def on_run_button_clicked(self):
296297
try:
297298
self.validate_parameters()
298299
except Exception as e:
300+
traceback.print_exc()
299301
msg = 'Parameter settings are invalid!\n\n' + str(e)
300302
print(msg)
301303
QMessageBox.critical(self.parent(), 'Invalid Parameters', msg)
@@ -531,12 +533,18 @@ def on_delta_boundaries_toggled(self, b):
531533
self.reinitialize_tree_view()
532534

533535
def mirror_constraints_from_first_detector(self):
536+
instr = self.instr
534537
config = self.tree_view.model().config
535538
detector_iterator = iter(config['detectors'])
536539
first_detector_name = next(detector_iterator)
537540
first_detector = config['detectors'][first_detector_name]
538541
tilts = first_detector['transform']['tilt']
539542
translations = first_detector['transform']['translation']
543+
first_distortion = first_detector.get('distortion parameters')
544+
first_distortion_obj = instr.detectors[first_detector_name].distortion
545+
first_distortion_type = (
546+
first_distortion_obj.maptype if first_distortion else None
547+
)
540548

541549
statuses = {
542550
'tilt': {k: v['_param'].vary for k, v in tilts.items()},
@@ -577,6 +585,31 @@ def mirror_constraints_from_first_detector(self):
577585
param.delta = v
578586
det_transform[k]['_delta'] = v
579587

588+
# Check if we should copy distortion parameters too
589+
distortion = detector.get('distortion parameters')
590+
distortion_obj = instr.detectors[det_name].distortion
591+
distortion_type = (
592+
distortion_obj.maptype if distortion else None
593+
)
594+
copy_distortion = (
595+
distortion_type and
596+
distortion_type == first_distortion_type
597+
)
598+
if copy_distortion:
599+
# Copy all parameters if the distortion function matches
600+
for k, v in first_distortion.items():
601+
first_param = v['_param']
602+
param = distortion[k]['_param']
603+
if param.expr is None:
604+
# Only copy "vary" for non expression parameters
605+
param.vary = first_param.vary
606+
distortion[k]['_vary'] = first_param.vary
607+
608+
if self.delta_boundaries:
609+
# Copy the deltas too
610+
param.delta = v['_delta']
611+
distortion[k]['_delta'] = v['_delta']
612+
580613
self.tree_view.reset_gui()
581614

582615
def update_from_calibrator(self, calibrator):

hexrdgui/calibration/hedm/calibration_dialog.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from hexrd import rotations
77
import hexrd.constants as cnst
8+
from hexrd.fitting.calibration.calibrator import Calibrator
89
from hexrd.fitting.calibration.lmfit_param_handling import fix_detector_y
910
from hexrd.transforms import xfcapi
1011

@@ -554,13 +555,22 @@ def load_picks_from_file(self, selected_file):
554555
raise NotImplementedError
555556

556557

557-
def compute_xyo(calibrators) -> dict[str, list]:
558+
def compute_xyo(calibrators: list[Calibrator]) -> dict[str, list]:
559+
instr = calibrators[0].instr
558560
xyo = {}
559561
for calibrator in calibrators:
560562
results = calibrator.model()
561563
for det_key, values in results.items():
564+
panel = instr.detectors[det_key]
562565
xyo.setdefault(det_key, [])
563-
xyo[det_key].append(values[0])
566+
567+
values = values[0]
568+
if panel.distortion is not None:
569+
# The model results are not distorted
570+
# Apply the distortion for the visualization
571+
values[:, :2] = panel.distortion.apply_inverse(values[:, :2])
572+
573+
xyo[det_key].append(values)
564574

565575
return xyo
566576

hexrdgui/instrument_form_view_widget.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ def set_beam_vector_is_finite(self, b):
585585
# Update the config
586586
v = self.beam_vector_magnitude
587587
beam_config = self.active_beam
588-
if beam_config['source_distance'] != v:
588+
if beam_config.get('source_distance', np.inf) != v:
589589
beam_config['source_distance'] = v
590590
HexrdConfig().beam_vector_changed.emit()
591591

@@ -618,7 +618,7 @@ def beam_vector_magnitude_value_changed(self, v):
618618

619619
# Update the config
620620
beam_config = self.active_beam
621-
if beam_config['source_distance'] != v:
621+
if beam_config.get('source_distance', np.inf) != v:
622622
beam_config['source_distance'] = v
623623
HexrdConfig().beam_vector_changed.emit()
624624

@@ -627,7 +627,9 @@ def beam_vector_magnitude_value_changed(self, v):
627627

628628
def update_beam_vector_magnitude_from_config(self):
629629
beam_config = self.active_beam
630-
self.beam_vector_magnitude = beam_config['source_distance']
630+
dist = beam_config.get('source_distance', np.inf)
631+
if self.beam_vector_magnitude != dist:
632+
self.beam_vector_magnitude = dist
631633

632634
@property
633635
def cartesian_beam_vector_convention(self):

hexrdgui/resources/ui/rotation_series_overlay_editor.ui

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,9 @@
240240
<property name="alignment">
241241
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
242242
</property>
243+
<property name="keyboardTracking">
244+
<bool>false</bool>
245+
</property>
243246
<property name="suffix">
244247
<string>°</string>
245248
</property>

0 commit comments

Comments
 (0)