Skip to content

Commit

Permalink
Merge pull request #2744 from SasView/1932-fitting-details-panel-not-…
Browse files Browse the repository at this point in the history
…displaying-correct-information-when-sesans-data-loaded

Made changes to fitting perspective for sesans data
  • Loading branch information
caitwolf authored Jan 21, 2024
2 parents d303d6d + a49550a commit 4f84dcb
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 17 deletions.
48 changes: 47 additions & 1 deletion src/sas/qtgui/Perspectives/Fitting/FittingWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
import sys
from collections import defaultdict
from typing import Any, Tuple
from typing import Any, Tuple, Optional

import copy
import logging
Expand Down Expand Up @@ -221,6 +221,9 @@ def data(self, value):
self.data_is_loaded = True
# Reset the smearer
self.smearing_widget.resetSmearer()
if self.data.isSesans:
self.onSesansData()

# Enable/disable UI components
self.setEnablementOnDataLoad()
# Reinitialize model list for constrained/simult fitting
Expand Down Expand Up @@ -528,6 +531,22 @@ def disableStructureCombo(self):
self.lblStructure.setEnabled(False)
self.enabled_sfmodel = False

def enableBackgroundParameter(self, set_value: Optional[float] = None):
""" Enable the background parameter. Optionally set at a specified value. """
background_row = self.getRowFromName("background")
if background_row is not None:
self.setParamEditableByRow(background_row, True)
if set_value is not None:
self._model_model.item(background_row, 1).setText(GuiUtils.formatNumber(set_value, high=True))

def disableBackgroundParameter(self, set_value: Optional[float] = None):
""" Disable the background parameter. Optionally set at a specified value. """
background_row = self.getRowFromName("background")
if background_row is not None:
self.setParamEditableByRow(background_row, False)
if set_value is not None:
self._model_model.item(background_row, 1).setText(GuiUtils.formatNumber(set_value, high=True))

def enableStructureCombo(self):
""" Enable the combobox """
self.cbStructureFactor.setEnabled(True)
Expand Down Expand Up @@ -1577,6 +1596,27 @@ def onSelectionChanged(self):
return
self.communicate.statusBarUpdateSignal.emit(update_text)

def onSesansData(self):
"""
Updates the fitting widget format when SESANS data is loaded.
"""
# update the units in the 'Fitting details' box of the Model tab on the Fit Panel
self.label_17.setText("Å")
self.label_19.setText("Å")
# disable the background parameter and set at 0 for sesans
self.disableBackgroundParameter(set_value=0.0)
# update options defaults and settings for SESANS data
self.options_widget.updateQRange(1, 100000, self.options_widget.NPTS_DEFAULT)
# update the units in the 'Fitting details' box of the Fit Options tab on the Fit Panel
self.options_widget.label_13.setText("Å")
self.options_widget.label_15.setText("Å")
# update the smearing drop down box to indicate a Hankel Transform is being used instead of resolution
self.smearing_widget.onIndexChange(1)
# update the Weighting box of the Fit Options tab on the Fit Panel
self.options_widget.rbWeighting2.setText("Use dP Data")
self.options_widget.rbWeighting3.setText("Use |sqrt(P Data)|")
self.options_widget.rbWeighting4.setText("Use |P Data|")

def replaceConstraintName(self, old_name, new_name=""):
"""
Replace names of models in defined constraints
Expand Down Expand Up @@ -1629,6 +1669,12 @@ def respondToModelStructure(self, model=None, structure_factor=None):
for column, width in self.lstParamHeaderSizes.items():
self.lstParams.setColumnWidth(column, width)

# disable background for SESANS data
# this should be forced to 0 in sasmodels but this tells the user it is enforced to 0 and disables the box
if self.data_is_loaded:
if self.data.isSesans:
self.disableBackgroundParameter(set_value=0)

# Update plot
self.updateData()

Expand Down
19 changes: 15 additions & 4 deletions src/sas/qtgui/Perspectives/Fitting/SmearingWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ def addMapping(self, widget, section, propertyName=None):

SMEARING_1D = ["Custom Pinhole Smear", "Custom Slit Smear"]
SMEARING_2D = ["Custom Pinhole Smear"]
SMEARING_SESANS = "Hankel Transform"
SMEARING_QD = "Use dQ Data"

MODEL = [
'SMEARING',
'PINHOLE_MIN',
Expand Down Expand Up @@ -150,10 +150,13 @@ def updateKernelModel(self, kernel_model=None, keep_order=False, old_index=None)
if self.data is None:
self.setElementsVisibility(False)
return
# Find out if data has dQ
# Find out if data has dQ or is SESANS
self.current_smearer = smear_selection(self.data, self.kernel_model)
self.setSmearInfo()
if self.smear_type is not None:
if self.smear_type == "Hankel Transform":
self.cbSmearing.addItem(SMEARING_SESANS)
index_to_show = 1
elif self.smear_type is not None:
self.cbSmearing.addItem(SMEARING_QD)
index_to_show = 1 if keep_order else index_to_show

Expand Down Expand Up @@ -195,6 +198,9 @@ def onIndexChange(self, index):
self.setElementsVisibility(True)
self.setSlitLabels()
self.onSlitSmear()
elif text == "Hankel Transform":
self.setElementsVisibility(False)
self.cbSmearing.setEnabled(False) # turn off ability to change smearing; no other options for sesans
self.smearingChangedSignal.emit()

def onModelChange(self):
Expand Down Expand Up @@ -471,9 +477,14 @@ def setSmearInfo(self):
self.smear_type = "Pinhole2d"
self.dq_l = GuiUtils.formatNumber(np.average(data.dqx_data/np.abs(data.qx_data))*100., high=True)
self.dq_r = GuiUtils.formatNumber(np.average(data.dqy_data/np.abs(data.qy_data))*100., high=True)
# Check for SESANS data - currently no resolution functions are available for SESANS data
# The Hankel transform is treated like other resolution functions.
elif (isinstance(self.smearer(), PySmear)
and isinstance(self.smearer().resolution, SesansTransform)):
self.smear_type = "Hankel Transform"
# Check for pinhole smearing and get min max if it is.
elif (isinstance(self.smearer(), PySmear)
and isinstance(self.smearer().resolution, (Pinhole1D, SesansTransform))):
and isinstance(self.smearer().resolution, Pinhole1D)):
self.smear_type = "Pinhole"
self.dq_r = GuiUtils.formatNumber(data.dx[0]/data.x[0] *100., high=True)
self.dq_l = GuiUtils.formatNumber(data.dx[-1]/data.x[-1] *100., high=True)
Expand Down
5 changes: 5 additions & 0 deletions src/sas/qtgui/Perspectives/Fitting/UI/SmearingWidgetUI.ui
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@
<string>Custom Slit Smear</string>
</property>
</item>
<item>
<property name="text">
<string>Hankel Transform</string>
</property>
</item>
</widget>
</item>
<item row="0" column="1" rowspan="2">
Expand Down
16 changes: 4 additions & 12 deletions src/sas/sascalc/fit/qsmearing.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,7 @@ def smear_selection(data, model = None):
# Look for resolution smearing data
# This is the code that checks for SESANS data; it looks for the file loader
# TODO: change other sanity checks to check for file loader instead of data structure?
_found_sesans = False
#if data.dx is not None and data.meta_data['loader']=='SESANS':
if data.dx is not None and data.isSesans:
#if data.dx[0] > 0.0:
if np.size(data.dx[data.dx <= 0]) == 0:
_found_sesans = True
# if data.dx[0] <= 0.0:
if np.size(data.dx[data.dx <= 0]) > 0:
raise ValueError('one or more of your dx values are negative, please check the data file!')

if _found_sesans:
if data.isSesans: # data.dx data is not required in the Hankel transform for SESANS data
# Pre-compute the Hankel matrix (H)
SElength = Converter(data._xunit)(data.x, "A")

Expand All @@ -84,7 +74,9 @@ def smear_selection(data, model = None):
if data.dx is not None and len(data.dx) == len(data.x):

# Check that we have non-zero data
if data.dx[0] > 0.0:
if np.min(data.dx) < 0:
raise ValueError('one or more of your dx values are negative, please check the data file!')
else:
_found_resolution = True
#print "_found_resolution",_found_resolution
#print "data1D.dx[0]",data1D.dx[0],data1D.dxl[0]
Expand Down

0 comments on commit 4f84dcb

Please sign in to comment.