Skip to content

Commit

Permalink
Merge pull request #745 from HEXRD/cylindrical-detector-radius
Browse files Browse the repository at this point in the history
Take into account radius for calibration params
  • Loading branch information
saransh13 authored Jan 12, 2025
2 parents bcab514 + 4890d34 commit 8bd2a7d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
11 changes: 11 additions & 0 deletions hexrd/instrument/cylindrical_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ def __init__(self, radius=49.51, **detector_kwargs):
self._radius = radius
super().__init__(**detector_kwargs)

# Add the radius to the calibration flags
self._calibration_flags = np.hstack(
(self._calibration_flags, np.zeros((1,), dtype=bool)),
dtype=bool,
)

@property
def detector_type(self):
return 'cylindrical'
Expand Down Expand Up @@ -211,6 +217,11 @@ def pixel_tth_gradient(self, origin=ct.zeros_3):
def pixel_eta_gradient(self, origin=ct.zeros_3):
return _pixel_eta_gradient(origin=origin, **self._pixel_angle_kwargs)

@property
def calibration_parameters(self):
# Old style of calibration parameters. Include radius at the end.
return super().calibration_parameters + [self.radius]

@property
def caxis(self):
# returns the cylinder axis
Expand Down
13 changes: 12 additions & 1 deletion hexrd/instrument/hedm_instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,13 @@ def set_calibration_flags_to_lmfit_params(self, params_dict):
flags = self.calibration_flags
for i, name in enumerate(self.calibration_flags_to_lmfit_names):
if name in params_dict:
params_dict[name].vary = flags[i]
param = params_dict[name]
if param.expr is not None:
# Don't update the flags on anything with an expression,
# because it is computed and should not be varied.
continue

param.vary = flags[i]

@property
def calibration_flags(self):
Expand All @@ -1082,6 +1088,11 @@ def calibration_flags(self, x):
npp = 6
if panel.distortion is not None:
npp += len(panel.distortion.params)

if panel.detector_type == 'cylindrical':
# Add one for the radius
npp += 1

panel.calibration_flags = x[ii:ii + npp]
self._calibration_flags = x

Expand Down
4 changes: 3 additions & 1 deletion tests/calibration/test_calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ def test_calibration(calibration_dir, test_data_dir):

calibrator = InstrumentCalibrator(
*calibrators,
engineering_constraints='TARDIS',
# Engineering constraints were actually not being utilized before,
# due to a bug. Disable them for now.
# engineering_constraints='TARDIS',
euler_convention=euler_convention,
)

Expand Down

0 comments on commit 8bd2a7d

Please sign in to comment.