From 6eb7b1d0b46bdd7117d3367b6ede7ce843098315 Mon Sep 17 00:00:00 2001 From: Daniel Ching Date: Thu, 7 Mar 2024 12:15:57 -0600 Subject: [PATCH] NEW: Add update magnitude limit parameter to Position Options Co-authored-by: stevehenke <91344068+stevehenke@users.noreply.github.com> --- ptychodus/controller/tike/positionCorrection.py | 2 ++ ptychodus/model/tike/positionCorrection.py | 8 ++++++++ ptychodus/model/tike/reconstructor.py | 1 + ptychodus/view/tike.py | 5 +++++ setup.cfg | 2 +- 5 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ptychodus/controller/tike/positionCorrection.py b/ptychodus/controller/tike/positionCorrection.py index c8c89920..879ac739 100644 --- a/ptychodus/controller/tike/positionCorrection.py +++ b/ptychodus/controller/tike/positionCorrection.py @@ -27,6 +27,7 @@ def createInstance(cls, presenter: TikePositionCorrectionPresenter, view.positionRegularizationCheckBox.toggled.connect( presenter.setPositionRegularizationEnabled) + view.updateMagnitudeLimitLineEdit.valueChanged.connect(presenter.setUpdateMagnitudeLimit) controller._syncModelToView() @@ -37,6 +38,7 @@ def _syncModelToView(self) -> None: self._view.positionRegularizationCheckBox.setChecked( self._presenter.isPositionRegularizationEnabled()) + self._view.updateMagnitudeLimitLineEdit.setValue(self._presenter.getUpdateMagnitudeLimit()) def update(self, observable: Observable) -> None: if observable is self._presenter: diff --git a/ptychodus/model/tike/positionCorrection.py b/ptychodus/model/tike/positionCorrection.py index 8d236d1a..2bc4a1ba 100644 --- a/ptychodus/model/tike/positionCorrection.py +++ b/ptychodus/model/tike/positionCorrection.py @@ -1,4 +1,5 @@ from __future__ import annotations +from decimal import Decimal from ...api.settings import SettingsGroup, SettingsRegistry from .adaptiveMoment import TikeAdaptiveMomentPresenter, TikeAdaptiveMomentSettings @@ -12,6 +13,7 @@ def __init__(self, settingsGroup: SettingsGroup) -> None: 'UsePositionCorrection', False) self.usePositionRegularization = settingsGroup.createBooleanEntry( 'UsePositionRegularization', False) + self.updateMagnitudeLimit = settingsGroup.createRealEntry('Update Magnitude Limit', '0.0') # TODO transform: Global transform of positions. # TODO origin: The rotation center of the transformation. @@ -42,3 +44,9 @@ def isPositionRegularizationEnabled(self) -> bool: def setPositionRegularizationEnabled(self, enabled: bool) -> None: self._settings.usePositionRegularization.value = enabled + + def getUpdateMagnitudeLimit(self) -> Decimal: + return self._settings.updateMagnitudeLimit.value + + def setUpdateMagnitudeLimit(self, value: Decimal) -> None: + self._settings.updateMagnitudeLimit.value = value diff --git a/ptychodus/model/tike/reconstructor.py b/ptychodus/model/tike/reconstructor.py index 1a9f2d51..89919088 100644 --- a/ptychodus/model/tike/reconstructor.py +++ b/ptychodus/model/tike/reconstructor.py @@ -67,6 +67,7 @@ def getPositionOptions(self, vdecay=float(settings.vdecay.value), mdecay=float(settings.mdecay.value), use_position_regularization=settings.usePositionRegularization.value, + update_magnitude_limit=float(settings.updateMagnitudeLimit.value), ) return options diff --git a/ptychodus/view/tike.py b/ptychodus/view/tike.py index 2d864fe1..f5f25ca1 100644 --- a/ptychodus/view/tike.py +++ b/ptychodus/view/tike.py @@ -115,6 +115,7 @@ def __init__(self, parent: Optional[QWidget]) -> None: super().__init__('Position Correction', parent) self.positionRegularizationCheckBox = QCheckBox('Use Regularization') self.adaptiveMomentView = TikeAdaptiveMomentView.createInstance() + self.updateMagnitudeLimitLineEdit = DecimalLineEdit.createInstance() @classmethod def createInstance(cls, parent: Optional[QWidget] = None) -> TikePositionCorrectionView: @@ -122,10 +123,14 @@ def createInstance(cls, parent: Optional[QWidget] = None) -> TikePositionCorrect view.positionRegularizationCheckBox.setToolTip( 'Whether the positions are constrained to fit a random error plus affine error model.') + view.updateMagnitudeLimitLineEdit.setToolTip( + 'When set to a positive number, x and y update magnitudes are clipped (limited) ' + 'to this value.') layout = QFormLayout() layout.addRow(view.positionRegularizationCheckBox) layout.addRow(view.adaptiveMomentView) + layout.addRow('Update Magnitude Limit:', view.updateMagnitudeLimitLineEdit) view.setLayout(layout) return view diff --git a/setup.cfg b/setup.cfg index a2d3985b..6443708a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -22,7 +22,7 @@ install_requires = [options.extras_require] ptychonn = ptychonn ==0.2.* -tike = tike ==0.25.* +tike = tike ==0.25.*,>=0.25.3 gui = pyqt5 ==5.* globus = gladier >=0.9