Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switch auto cal to import from hexrd #1160

Merged
merged 4 commits into from
Feb 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions hexrd/ui/calibration/auto/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
from .instrument_calibrator import InstrumentCalibrator
from .powder_calibration_dialog import PowderCalibrationDialog
from .powder_calibrator import PowderCalibrator
from .powder_runner import PowderRunner

__all__ = [
'InstrumentCalibrator',
'PowderCalibrationDialog',
'PowderCalibrator',
'PowderRunner',
]
212 changes: 0 additions & 212 deletions hexrd/ui/calibration/auto/instrument_calibrator.py

This file was deleted.

94 changes: 87 additions & 7 deletions hexrd/ui/calibration/auto/powder_calibration_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,20 @@ def __init__(self, material, parent=None):

self.material = material

self.setup_combo_boxes()
self.update_gui()

def setup_combo_boxes(self):
self.ui.peak_fit_type.clear()
for t in peak_types:
label = peak_type_to_label(t)
self.ui.peak_fit_type.addItem(label, t)

self.ui.background_type.clear()
for t in background_types:
label = background_type_to_label(t)
self.ui.background_type.addItem(label, t)

def update_gui(self):
if self.tth_tol is None:
default = 0.125
Expand All @@ -28,21 +40,18 @@ def update_gui(self):
self.tth_tol = default

options = HexrdConfig().config['calibration']['powder']
pk_type = options['pk_type']

reformat = {
'pvoigt': 'PVoigt',
'gaussian': 'Gaussian',
}
self.ui.tth_tolerance.setValue(self.tth_tol)
self.ui.eta_tolerance.setValue(options['eta_tol'])
self.ui.fit_tth_tol.setValue(options['fit_tth_tol'])
self.ui.max_iter.setValue(options['max_iter'])
self.ui.int_cutoff.setValue(options['int_cutoff'])
self.ui.conv_tol.setValue(options['conv_tol'])
self.ui.peak_fit_type.setCurrentText(reformat.get(pk_type, pk_type))
self.ui.robust.setChecked(options['use_robust_optimization'])

self.peak_fit_type = options['pk_type']
self.background_type = options['bg_type']

def update_config(self):
options = HexrdConfig().config['calibration']['powder']
self.tth_tol = self.ui.tth_tolerance.value()
Expand All @@ -51,9 +60,11 @@ def update_config(self):
options['max_iter'] = self.ui.max_iter.value()
options['int_cutoff'] = self.ui.int_cutoff.value()
options['conv_tol'] = self.ui.conv_tol.value()
options['pk_type'] = self.ui.peak_fit_type.currentText().lower()
options['use_robust_optimization'] = self.ui.robust.isChecked()

options['pk_type'] = self.peak_fit_type
options['bg_type'] = self.background_type

def exec_(self):
if not self.ui.exec_():
return False
Expand All @@ -78,8 +89,77 @@ def tth_tol(self, v):
HexrdConfig().flag_overlay_updates_for_material(self.material.name)
HexrdConfig().overlay_config_changed.emit()

@property
def peak_fit_type(self):
return self.ui.peak_fit_type.currentData()

@peak_fit_type.setter
def peak_fit_type(self, v):
w = self.ui.peak_fit_type
found = False
for i in range(w.count()):
if w.itemData(i) == v:
found = True
w.setCurrentIndex(i)
break

if not found:
raise Exception(f'Unknown peak fit type: {v}')

@property
def background_type(self):
return self.ui.background_type.currentData()

@background_type.setter
def background_type(self, v):
w = self.ui.background_type
found = False
for i in range(w.count()):
if w.itemData(i) == v:
found = True
w.setCurrentIndex(i)
break

if not found:
raise Exception(f'Unknown background type: {v}')

def show_optimization_parameters(self, b=True):
self.ui.optimization_parameters_group.setVisible(b)

# Resize later so that the dialog is the correct size
QTimer.singleShot(0, lambda: self.ui.resize(self.ui.sizeHint()))


# If this gets added as a list to hexrd, we can import it from there
peak_types = [
'gaussian',
'pvoigt',
'split_pvoigt',
'pink_beam_dcs',
]

# If this gets added as a list to hexrd, we can import it from there
background_types = [
'linear',
'quadratic',
'cubic',
'quartic',
'quintic',
]

peak_type_to_label_map = {
'gaussian': 'Gaussian',
'pvoigt': 'PVoigt',
'split_pvoigt': 'SplPVoigt',
'pink_beam_dcs': 'DCS',
}

background_type_to_label_map = {}


def peak_type_to_label(t):
return peak_type_to_label_map.get(t, t.capitalize())


def background_type_to_label(t):
return background_type_to_label_map.get(t, t.capitalize())
Loading