Changeset 4ea8020 in sasview for src/sas/qtgui
- Timestamp:
- Sep 7, 2018 9:40:56 AM (6 years ago)
- Branches:
- ESS_GUI, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
- Children:
- c0de493
- Parents:
- 0109f2a (diff), dcabba7 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - git-author:
- Torin Cooper-Bennun <40573959+tcbennun@…> (09/07/18 09:40:56)
- git-committer:
- GitHub <noreply@…> (09/07/18 09:40:56)
- Location:
- src/sas/qtgui
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Calculators/SldPanel.py
raed0532 r5c0e717 6 6 7 7 from periodictable import formula as Formula 8 from periodictable.xsf import xray_energy, xray_sld _from_atoms8 from periodictable.xsf import xray_energy, xray_sld 9 9 from periodictable.nsf import neutron_scattering 10 10 … … 21 21 'MOLECULAR_FORMULA', 22 22 'MASS_DENSITY', 23 ' WAVELENGTH',23 'NEUTRON_WAVELENGTH', 24 24 'NEUTRON_SLD_REAL', 25 25 'NEUTRON_SLD_IMAG', 26 'CU_KA_SLD_REAL', 27 'CU_KA_SLD_IMAG', 28 'MO_KA_SLD_REAL', 29 'MO_KA_SLD_IMAG', 26 'XRAY_WAVELENGTH', 27 'XRAY_SLD_REAL', 28 'XRAY_SLD_IMAG', 30 29 'NEUTRON_INC_XS', 31 30 'NEUTRON_ABS_XS', … … 34 33 35 34 class SldResult(object): 36 def __init__(self, molecular_formula, mass_density, wavelength, 37 neutron_sld_real, neutron_sld_imag, 38 cu_ka_sld_real, cu_ka_sld_imag, 39 mo_ka_sld_real, mo_ka_sld_imag, 35 def __init__(self, molecular_formula, mass_density, 36 neutron_wavelength, neutron_sld_real, neutron_sld_imag, 37 xray_wavelength, xray_sld_real, xray_sld_imag, 40 38 neutron_inc_xs, neutron_abs_xs, neutron_length): 41 39 42 40 self.molecular_formula = molecular_formula 43 41 self.mass_density = mass_density 44 self. wavelength =wavelength42 self.neutron_wavelength = neutron_wavelength 45 43 self.neutron_sld_real = neutron_sld_real 46 44 self.neutron_sld_imag = neutron_sld_imag 47 self.cu_ka_sld_real = cu_ka_sld_real 48 self.cu_ka_sld_imag = cu_ka_sld_imag 49 self.mo_ka_sld_real = mo_ka_sld_real 50 self.mo_ka_sld_imag = mo_ka_sld_imag 45 self.xray_wavelength = xray_wavelength 46 self.xray_sld_real = xray_sld_real 47 self.xray_sld_imag = xray_sld_imag 51 48 self.neutron_inc_xs = neutron_inc_xs 52 49 self.neutron_abs_xs = neutron_abs_xs 53 50 self.neutron_length = neutron_length 54 51 55 def sldAlgorithm(molecular_formula, mass_density, wavelength): 56 57 sld_formula = Formula(molecular_formula, density=mass_density) 58 59 def calculate_sld(formula): 60 if len(formula.atoms) != 1: 61 raise NotImplementedError() 62 energy = xray_energy(list(formula.atoms.keys())[0].K_alpha) 63 return xray_sld_from_atoms( 64 sld_formula.atoms, 52 def sldAlgorithm(molecular_formula, mass_density, neutron_wavelength, xray_wavelength): 53 54 xray_sld_real, xray_sld_imag = xray_sld( 55 compound=molecular_formula, 65 56 density=mass_density, 66 energy=energy) 67 68 cu_real, cu_imag = calculate_sld(Formula("Cu")) 69 mo_real, mo_imag = calculate_sld(Formula("Mo")) 70 71 (sld_real, sld_imag, _), (_, neutron_abs_xs, neutron_inc_xs), neutron_length = \ 57 wavelength=xray_wavelength) 58 59 (neutron_sld_real, neutron_sld_imag, _), (_, neutron_abs_xs, neutron_inc_xs), neutron_length = \ 72 60 neutron_scattering( 73 61 compound=molecular_formula, 74 62 density=mass_density, 75 wavelength= wavelength)63 wavelength=neutron_wavelength) 76 64 77 65 SCALE = 1e-6 78 66 79 67 # neutron sld 80 neutron_sld_real = SCALE * sld_real 81 neutron_sld_imag = SCALE * abs(sld_imag) 82 83 # Cu sld 84 cu_ka_sld_real = SCALE * cu_real 85 cu_ka_sld_imag = SCALE * abs(cu_imag) 86 87 # Mo sld 88 mo_ka_sld_real = SCALE * mo_real 89 mo_ka_sld_imag = SCALE * abs(mo_imag) 68 scaled_neutron_sld_real = SCALE * neutron_sld_real 69 scaled_neutron_sld_imag = SCALE * abs(neutron_sld_imag) 70 71 # xray sld 72 scaled_xray_sld_real = SCALE * xray_sld_real 73 scaled_xray_sld_imag = SCALE * abs(xray_sld_imag) 74 90 75 91 76 return SldResult( 92 molecular_formula, mass_density, wavelength, 93 neutron_sld_real, neutron_sld_imag, 94 cu_ka_sld_real, cu_ka_sld_imag, 95 mo_ka_sld_real, mo_ka_sld_imag, 77 molecular_formula, mass_density, 78 neutron_wavelength, scaled_neutron_sld_real, scaled_neutron_sld_imag, 79 xray_wavelength, scaled_xray_sld_real, scaled_xray_sld_imag, 96 80 neutron_inc_xs, neutron_abs_xs, neutron_length) 97 81 … … 112 96 MODEL.NEUTRON_SLD_REAL: self.ui.editNeutronSldReal, 113 97 MODEL.NEUTRON_SLD_IMAG: self.ui.editNeutronSldImag, 114 MODEL.CU_KA_SLD_REAL: self.ui.editCuKaSldReal, 115 MODEL.CU_KA_SLD_IMAG: self.ui.editCuKaSldImag, 116 MODEL.MO_KA_SLD_REAL: self.ui.editMoKaSldReal, 117 MODEL.MO_KA_SLD_IMAG: self.ui.editMoKaSldImag, 98 MODEL.XRAY_SLD_REAL: self.ui.editXraySldReal, 99 MODEL.XRAY_SLD_IMAG: self.ui.editXraySldImag, 118 100 MODEL.NEUTRON_INC_XS: self.ui.editNeutronIncXs, 119 101 MODEL.NEUTRON_ABS_XS: self.ui.editNeutronAbsXs, … … 131 113 rx = QtCore.QRegExp("[+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?") 132 114 self.ui.editMassDensity.setValidator(QtGui.QRegExpValidator(rx, self.ui.editMassDensity)) 133 self.ui.editWavelength.setValidator(QtGui.QRegExpValidator(rx, self.ui.editWavelength)) 115 self.ui.editNeutronWavelength.setValidator(QtGui.QRegExpValidator(rx, self.ui.editNeutronWavelength)) 116 self.ui.editXrayWavelength.setValidator(QtGui.QRegExpValidator(rx, self.ui.editXrayWavelength)) 134 117 135 118 # signals 136 self.ui.buttonBox.button(QtWidgets.QDialogButtonBox.Reset).clicked.connect(self.modelReset) 137 self.ui.buttonBox.button(QtWidgets.QDialogButtonBox.Help).clicked.connect(self.displayHelp) 119 self.ui.helpButton.clicked.connect(self.displayHelp) 120 self.ui.closeButton.clicked.connect(self.closePanel) 121 self.ui.recalculateButton.clicked.connect(self.calculateSLD) 122 123 def calculateSLD(self): 124 self.recalculateSLD() 138 125 139 126 def setupModel(self): 140 127 self.model = QtGui.QStandardItemModel(self) 141 self.model.setItem(MODEL.MOLECULAR_FORMULA, QtGui.QStandardItem()) 142 self.model.setItem(MODEL.MASS_DENSITY , QtGui.QStandardItem()) 143 self.model.setItem(MODEL.WAVELENGTH , QtGui.QStandardItem()) 128 self.model.setItem(MODEL.MOLECULAR_FORMULA , QtGui.QStandardItem()) 129 self.model.setItem(MODEL.MASS_DENSITY , QtGui.QStandardItem()) 130 self.model.setItem(MODEL.NEUTRON_WAVELENGTH, QtGui.QStandardItem()) 131 self.model.setItem(MODEL.XRAY_WAVELENGTH , QtGui.QStandardItem()) 144 132 145 133 for key in list(self._getOutputs().keys()): … … 147 135 148 136 self.model.dataChanged.connect(self.dataChanged) 137 138 self.ui.editMassDensity.textEdited.connect(self.recalculateSLD) 139 self.ui.editMolecularFormula.textEdited.connect(self.recalculateSLD) 140 self.ui.editNeutronWavelength.textEdited.connect(self.recalculateSLD) 141 self.ui.editXrayWavelength.textEdited.connect(self.recalculateSLD) 149 142 150 143 self.modelReset() … … 154 147 self.mapper.setModel(self.model) 155 148 self.mapper.setOrientation(QtCore.Qt.Vertical) 156 self.mapper.addMapping(self.ui.editMolecularFormula, MODEL.MOLECULAR_FORMULA) 157 self.mapper.addMapping(self.ui.editMassDensity , MODEL.MASS_DENSITY) 158 self.mapper.addMapping(self.ui.editWavelength , MODEL.WAVELENGTH) 149 self.mapper.addMapping(self.ui.editMolecularFormula , MODEL.MOLECULAR_FORMULA) 150 self.mapper.addMapping(self.ui.editMassDensity , MODEL.MASS_DENSITY) 151 self.mapper.addMapping(self.ui.editNeutronWavelength, MODEL.NEUTRON_WAVELENGTH) 152 self.mapper.addMapping(self.ui.editXrayWavelength , MODEL.XRAY_WAVELENGTH) 159 153 160 154 for key, edit in self._getOutputs().items(): … … 166 160 update = False 167 161 for index in range(top.row(), bottom.row() + 1): 168 if (index == MODEL.MOLECULAR_FORMULA) or (index == MODEL.MASS_DENSITY) or (index == MODEL. WAVELENGTH):162 if (index == MODEL.MOLECULAR_FORMULA) or (index == MODEL.MASS_DENSITY) or (index == MODEL.NEUTRON_WAVELENGTH) or (index == MODEL.XRAY_WAVELENGTH): 169 163 update = True 170 164 171 # calcu altion165 # calculation 172 166 if update: 173 formula = self.model.item(MODEL.MOLECULAR_FORMULA).text() 174 density = self.model.item(MODEL.MASS_DENSITY).text() 175 wavelength = self.model.item(MODEL.WAVELENGTH).text() 176 if len(formula) > 0 and len(density) > 0 and len(wavelength) > 0: 177 try: 178 results = sldAlgorithm(str(formula), float(density), float(wavelength)) 179 180 def format(value): 181 return ("%-5.3g" % value).strip() 182 183 self.model.item(MODEL.NEUTRON_SLD_REAL).setText(format(results.neutron_sld_real)) 184 self.model.item(MODEL.NEUTRON_SLD_IMAG).setText(format(results.neutron_sld_imag)) 185 186 self.model.item(MODEL.CU_KA_SLD_REAL).setText(format(results.cu_ka_sld_real)) 187 self.model.item(MODEL.CU_KA_SLD_IMAG).setText(format(results.cu_ka_sld_imag)) 188 189 self.model.item(MODEL.MO_KA_SLD_REAL).setText(format(results.mo_ka_sld_real)) 190 self.model.item(MODEL.MO_KA_SLD_IMAG).setText(format(results.mo_ka_sld_imag)) 191 192 self.model.item(MODEL.NEUTRON_INC_XS).setText(format(results.neutron_inc_xs)) 193 self.model.item(MODEL.NEUTRON_ABS_XS).setText(format(results.neutron_abs_xs)) 194 self.model.item(MODEL.NEUTRON_LENGTH).setText(format(results.neutron_length)) 195 196 return 197 198 except Exception as e: 199 pass 200 201 for key in list(self._getOutputs().keys()): 202 self.model.item(key).setText("") 167 self.recalculateSLD() 168 169 def recalculateSLD(self): 170 formula = self.ui.editMolecularFormula.text() 171 density = self.ui.editMassDensity.text() 172 neutronWavelength = self.ui.editNeutronWavelength.text() 173 xrayWavelength = self.ui.editXrayWavelength.text() 174 175 if len(formula) > 0 and len(density) > 0 and len(neutronWavelength) > 0 and len(xrayWavelength) > 0: 176 try: 177 results = sldAlgorithm(str(formula), float(density), float(neutronWavelength), float(xrayWavelength)) 178 179 def format(value): 180 return ("%-5.3g" % value).strip() 181 182 self.model.item(MODEL.NEUTRON_SLD_REAL).setText(format(results.neutron_sld_real)) 183 self.model.item(MODEL.NEUTRON_SLD_IMAG).setText(format(results.neutron_sld_imag)) 184 185 self.model.item(MODEL.XRAY_SLD_REAL).setText(format(results.xray_sld_real)) 186 self.model.item(MODEL.XRAY_SLD_IMAG).setText(format(results.xray_sld_imag)) 187 188 self.model.item(MODEL.NEUTRON_INC_XS).setText(format(results.neutron_inc_xs)) 189 self.model.item(MODEL.NEUTRON_ABS_XS).setText(format(results.neutron_abs_xs)) 190 self.model.item(MODEL.NEUTRON_LENGTH).setText(format(results.neutron_length)) 191 192 return 193 194 except Exception as e: 195 pass 196 197 for key in list(self._getOutputs().keys()): 198 self.model.item(key).setText("") 203 199 204 200 def modelReset(self): 205 201 #self.model.beginResetModel() 206 202 try: 207 self.model.item(MODEL.MOLECULAR_FORMULA).setText("H2O") 208 self.model.item(MODEL.MASS_DENSITY ).setText("1") 209 self.model.item(MODEL.WAVELENGTH ).setText("6") 203 self.model.item(MODEL.MOLECULAR_FORMULA ).setText("H2O") 204 self.model.item(MODEL.MASS_DENSITY ).setText("1.0") 205 self.model.item(MODEL.NEUTRON_WAVELENGTH).setText("6.0") 206 self.model.item(MODEL.XRAY_WAVELENGTH ).setText("1.0") 207 self.recalculateSLD() 210 208 finally: 211 209 pass … … 217 215 218 216 217 def closePanel(self): 218 """ 219 close the window containing this panel 220 """ 221 self.close() 222 -
src/sas/qtgui/Calculators/UI/SldPanel.ui
rcd2cc745 r5c0e717 7 7 <x>0</x> 8 8 <y>0</y> 9 <width>4 47</width>10 <height>4 03</height>9 <width>490</width> 10 <height>490</height> 11 11 </rect> 12 12 </property> … … 25 25 </property> 26 26 <layout class="QGridLayout" name="gridLayout_2"> 27 <item row="3" column="0"> 28 <spacer name="verticalSpacer"> 29 <property name="orientation"> 30 <enum>Qt::Vertical</enum> 31 </property> 32 <property name="sizeHint" stdset="0"> 33 <size> 34 <width>20</width> 35 <height>40</height> 36 </size> 37 </property> 38 </spacer> 39 </item> 40 <item row="4" column="0"> 41 <widget class="QWidget" name="widget" native="true"> 42 <property name="minimumSize"> 43 <size> 44 <width>466</width> 45 <height>32</height> 46 </size> 47 </property> 48 <widget class="QPushButton" name="recalculateButton"> 49 <property name="geometry"> 50 <rect> 51 <x>0</x> 52 <y>0</y> 53 <width>114</width> 54 <height>32</height> 55 </rect> 56 </property> 57 <property name="text"> 58 <string>Recalculate</string> 59 </property> 60 </widget> 61 <widget class="QPushButton" name="helpButton"> 62 <property name="geometry"> 63 <rect> 64 <x>176</x> 65 <y>0</y> 66 <width>114</width> 67 <height>32</height> 68 </rect> 69 </property> 70 <property name="text"> 71 <string>Help</string> 72 </property> 73 </widget> 74 <widget class="QPushButton" name="closeButton"> 75 <property name="geometry"> 76 <rect> 77 <x>352</x> 78 <y>0</y> 79 <width>114</width> 80 <height>32</height> 81 </rect> 82 </property> 83 <property name="text"> 84 <string>Close</string> 85 </property> 86 </widget> 87 </widget> 88 </item> 27 89 <item row="0" column="0"> 28 90 <widget class="QGroupBox" name="groupBoxInput"> … … 58 120 <widget class="QLineEdit" name="editMassDensity"/> 59 121 </item> 122 <item row="2" column="2"> 123 <widget class="QLabel" name="label_12"> 124 <property name="text"> 125 <string>à 126 </string> 127 </property> 128 </widget> 129 </item> 130 <item row="0" column="0"> 131 <widget class="QLabel" name="label_9"> 132 <property name="text"> 133 <string>Molecular Formula</string> 134 </property> 135 </widget> 136 </item> 137 <item row="2" column="0"> 138 <widget class="QLabel" name="label_11"> 139 <property name="text"> 140 <string>Neutron Wavelength</string> 141 </property> 142 </widget> 143 </item> 60 144 <item row="2" column="1"> 61 <widget class="QLineEdit" name="edit Wavelength">145 <widget class="QLineEdit" name="editNeutronWavelength"> 62 146 <property name="styleSheet"> 63 147 <string notr="true"/> … … 68 152 </widget> 69 153 </item> 70 <item row="2" column="2"> 71 <widget class="QLabel" name="label_12"> 154 <item row="3" column="1"> 155 <widget class="QLineEdit" name="editXrayWavelength"/> 156 </item> 157 <item row="3" column="0"> 158 <widget class="QLabel" name="label_13"> 159 <property name="text"> 160 <string>X-Ray Wavelength</string> 161 </property> 162 </widget> 163 </item> 164 <item row="3" column="2"> 165 <widget class="QLabel" name="label"> 72 166 <property name="text"> 73 167 <string>à 74 168 </string> 75 </property>76 </widget>77 </item>78 <item row="0" column="0">79 <widget class="QLabel" name="label_9">80 <property name="text">81 <string>Molecular Formula</string>82 </property>83 </widget>84 </item>85 <item row="2" column="0">86 <widget class="QLabel" name="label_11">87 <property name="text">88 <string>Wavelength</string>89 169 </property> 90 170 </widget> … … 99 179 </property> 100 180 <layout class="QGridLayout" name="gridLayoutOutput"> 181 <item row="0" column="1"> 182 <widget class="QLineEdit" name="editNeutronSldReal"> 183 <property name="enabled"> 184 <bool>false</bool> 185 </property> 186 <property name="readOnly"> 187 <bool>true</bool> 188 </property> 189 </widget> 190 </item> 101 191 <item row="0" column="0"> 102 192 <widget class="QLabel" name="label_17"> … … 106 196 </widget> 107 197 </item> 108 <item row="0" column="1"> 109 <widget class="QLineEdit" name="editNeutronSldReal"> 110 <property name="readOnly"> 111 <bool>true</bool> 198 <item row="5" column="0"> 199 <widget class="QLabel" name="label_3"> 200 <property name="text"> 201 <string>Neutron 1/e length</string> 202 </property> 203 </widget> 204 </item> 205 <item row="3" column="1"> 206 <widget class="QLineEdit" name="editNeutronIncXs"> 207 <property name="enabled"> 208 <bool>false</bool> 209 </property> 210 <property name="readOnly"> 211 <bool>true</bool> 212 </property> 213 </widget> 214 </item> 215 <item row="3" column="0"> 216 <widget class="QLabel" name="label_21"> 217 <property name="text"> 218 <string>Neutron Inc. Xs</string> 112 219 </property> 113 220 </widget> … … 120 227 </widget> 121 228 </item> 229 <item row="1" column="2"> 230 <widget class="QLabel" name="label_20"> 231 <property name="text"> 232 <string>-i</string> 233 </property> 234 </widget> 235 </item> 122 236 <item row="0" column="3"> 123 237 <widget class="QLineEdit" name="editNeutronSldImag"> 124 <property name="readOnly"> 125 <bool>true</bool> 238 <property name="enabled"> 239 <bool>false</bool> 240 </property> 241 <property name="readOnly"> 242 <bool>true</bool> 243 </property> 244 </widget> 245 </item> 246 <item row="5" column="2" colspan="2"> 247 <widget class="QLabel" name="label_4"> 248 <property name="text"> 249 <string>cm</string> 250 </property> 251 </widget> 252 </item> 253 <item row="5" column="1"> 254 <widget class="QLineEdit" name="editNeutronLength"> 255 <property name="enabled"> 256 <bool>false</bool> 257 </property> 258 <property name="readOnly"> 259 <bool>true</bool> 260 </property> 261 </widget> 262 </item> 263 <item row="4" column="2" colspan="2"> 264 <widget class="QLabel" name="label_24"> 265 <property name="text"> 266 <string>1/cm</string> 267 </property> 268 </widget> 269 </item> 270 <item row="4" column="1"> 271 <widget class="QLineEdit" name="editNeutronAbsXs"> 272 <property name="enabled"> 273 <bool>false</bool> 274 </property> 275 <property name="readOnly"> 276 <bool>true</bool> 277 </property> 278 </widget> 279 </item> 280 <item row="4" column="0"> 281 <widget class="QLabel" name="label_23"> 282 <property name="text"> 283 <string>Neutron Abs. Xs</string> 284 </property> 285 </widget> 286 </item> 287 <item row="3" column="2" colspan="2"> 288 <widget class="QLabel" name="label_22"> 289 <property name="text"> 290 <string>1/cm</string> 291 </property> 292 </widget> 293 </item> 294 <item row="1" column="4"> 295 <widget class="QLabel" name="label_6"> 296 <property name="text"> 297 <string>1/à 298 ²</string> 299 </property> 300 </widget> 301 </item> 302 <item row="1" column="0"> 303 <widget class="QLabel" name="label_19"> 304 <property name="text"> 305 <string>X-Ray SLD</string> 126 306 </property> 127 307 </widget> … … 135 315 </widget> 136 316 </item> 137 <item row="1" column="0"> 138 <widget class="QLabel" name="label_19"> 139 <property name="text"> 140 <string>Cu Ka SLD</string> 141 </property> 142 </widget> 143 </item> 144 <item row="1" column="1"> 145 <widget class="QLineEdit" name="editCuKaSldReal"> 146 <property name="styleSheet"> 147 <string notr="true"/> 148 </property> 149 <property name="readOnly"> 150 <bool>true</bool> 151 </property> 152 </widget> 153 </item> 154 <item row="1" column="2"> 155 <widget class="QLabel" name="label_20"> 156 <property name="text"> 157 <string>-i</string> 158 </property> 159 </widget> 160 </item> 161 <item row="1" column="3"> 162 <widget class="QLineEdit" name="editCuKaSldImag"> 163 <property name="readOnly"> 164 <bool>true</bool> 165 </property> 166 </widget> 167 </item> 168 <item row="1" column="4"> 169 <widget class="QLabel" name="label_6"> 170 <property name="text"> 171 <string>1/à 172 ²</string> 173 </property> 174 </widget> 175 </item> 176 <item row="2" column="0"> 177 <widget class="QLabel" name="label"> 178 <property name="text"> 179 <string>Mo Ka SLD</string> 180 </property> 181 </widget> 182 </item> 183 <item row="2" column="1"> 184 <widget class="QLineEdit" name="editMoKaSldReal"> 185 <property name="readOnly"> 186 <bool>true</bool> 187 </property> 188 </widget> 189 </item> 190 <item row="2" column="2"> 191 <widget class="QLabel" name="label_2"> 192 <property name="text"> 193 <string>-i</string> 194 </property> 195 </widget> 196 </item> 197 <item row="2" column="3"> 198 <widget class="QLineEdit" name="editMoKaSldImag"> 199 <property name="readOnly"> 200 <bool>true</bool> 201 </property> 202 </widget> 203 </item> 204 <item row="2" column="4"> 205 <widget class="QLabel" name="label_7"> 206 <property name="text"> 207 <string>1/à 208 ²</string> 209 </property> 210 </widget> 211 </item> 212 <item row="3" column="0" colspan="5"> 317 <item row="2" column="0" colspan="5"> 213 318 <widget class="QFrame" name="frame"> 214 319 <property name="minimumSize"> … … 232 337 </widget> 233 338 </item> 234 <item row="4" column="0"> 235 <widget class="QLabel" name="label_21"> 236 <property name="text"> 237 <string>Neutron Inc. Xs</string> 238 </property> 239 </widget> 240 </item> 241 <item row="4" column="1"> 242 <widget class="QLineEdit" name="editNeutronIncXs"> 243 <property name="readOnly"> 244 <bool>true</bool> 245 </property> 246 </widget> 247 </item> 248 <item row="4" column="2" colspan="2"> 249 <widget class="QLabel" name="label_22"> 250 <property name="text"> 251 <string>1/cm</string> 252 </property> 253 </widget> 254 </item> 255 <item row="5" column="0"> 256 <widget class="QLabel" name="label_23"> 257 <property name="text"> 258 <string>Neutron Abs. Xs</string> 259 </property> 260 </widget> 261 </item> 262 <item row="5" column="1"> 263 <widget class="QLineEdit" name="editNeutronAbsXs"> 264 <property name="readOnly"> 265 <bool>true</bool> 266 </property> 267 </widget> 268 </item> 269 <item row="5" column="2" colspan="2"> 270 <widget class="QLabel" name="label_24"> 271 <property name="text"> 272 <string>1/cm</string> 273 </property> 274 </widget> 275 </item> 276 <item row="6" column="0"> 277 <widget class="QLabel" name="label_3"> 278 <property name="text"> 279 <string>Neutron 1/e length</string> 280 </property> 281 </widget> 282 </item> 283 <item row="6" column="1"> 284 <widget class="QLineEdit" name="editNeutronLength"> 285 <property name="readOnly"> 286 <bool>true</bool> 287 </property> 288 </widget> 289 </item> 290 <item row="6" column="2" colspan="2"> 291 <widget class="QLabel" name="label_4"> 292 <property name="text"> 293 <string>cm</string> 339 <item row="1" column="1"> 340 <widget class="QLineEdit" name="editXraySldReal"> 341 <property name="enabled"> 342 <bool>false</bool> 343 </property> 344 <property name="readOnly"> 345 <bool>true</bool> 346 </property> 347 </widget> 348 </item> 349 <item row="1" column="3"> 350 <widget class="QLineEdit" name="editXraySldImag"> 351 <property name="enabled"> 352 <bool>false</bool> 353 </property> 354 <property name="readOnly"> 355 <bool>true</bool> 294 356 </property> 295 357 </widget> 296 358 </item> 297 359 </layout> 298 </widget>299 </item>300 <item row="2" column="0">301 <spacer name="verticalSpacer">302 <property name="orientation">303 <enum>Qt::Vertical</enum>304 </property>305 <property name="sizeHint" stdset="0">306 <size>307 <width>20</width>308 <height>40</height>309 </size>310 </property>311 </spacer>312 </item>313 <item row="3" column="0">314 <widget class="QDialogButtonBox" name="buttonBox">315 <property name="orientation">316 <enum>Qt::Horizontal</enum>317 </property>318 <property name="standardButtons">319 <set>QDialogButtonBox::Close|QDialogButtonBox::Help|QDialogButtonBox::Reset</set>320 </property>321 <property name="centerButtons">322 <bool>true</bool>323 </property>324 360 </widget> 325 361 </item> … … 329 365 <tabstop>editMolecularFormula</tabstop> 330 366 <tabstop>editMassDensity</tabstop> 331 <tabstop>edit Wavelength</tabstop>367 <tabstop>editNeutronWavelength</tabstop> 332 368 <tabstop>editNeutronSldReal</tabstop> 333 369 <tabstop>editNeutronSldImag</tabstop> 334 <tabstop>editCuKaSldReal</tabstop>335 <tabstop>editCuKaSldImag</tabstop>336 <tabstop>editMoKaSldReal</tabstop>337 <tabstop>editMoKaSldImag</tabstop>338 370 <tabstop>editNeutronIncXs</tabstop> 339 371 <tabstop>editNeutronAbsXs</tabstop> 340 372 <tabstop>editNeutronLength</tabstop> 341 <tabstop>buttonBox</tabstop>342 373 </tabstops> 343 374 <resources/> 344 <connections> 345 <connection> 346 <sender>buttonBox</sender> 347 <signal>accepted()</signal> 348 <receiver>SldPanel</receiver> 349 <slot>accept()</slot> 350 <hints> 351 <hint type="sourcelabel"> 352 <x>248</x> 353 <y>254</y> 354 </hint> 355 <hint type="destinationlabel"> 356 <x>157</x> 357 <y>274</y> 358 </hint> 359 </hints> 360 </connection> 361 <connection> 362 <sender>buttonBox</sender> 363 <signal>rejected()</signal> 364 <receiver>SldPanel</receiver> 365 <slot>reject()</slot> 366 <hints> 367 <hint type="sourcelabel"> 368 <x>316</x> 369 <y>260</y> 370 </hint> 371 <hint type="destinationlabel"> 372 <x>286</x> 373 <y>274</y> 374 </hint> 375 </hints> 376 </connection> 377 </connections> 375 <connections/> 378 376 </ui> -
src/sas/qtgui/MainWindow/DataExplorer.py
ra24eacf r60d55a7 4 4 import time 5 5 import logging 6 import re7 6 8 7 from PyQt5 import QtCore … … 37 36 # The controller which is responsible for managing signal slots connections 38 37 # for the gui and providing an interface to the data model. 39 40 # This matches the ID of a plot created using FittingLogic._create1DPlot, e.g.41 # "5 [P(Q)] modelname"42 # or43 # "4 modelname".44 # Useful for determining whether the plot in question is for an intermediate result, such as P(Q) or S(Q) in the45 # case of a product model; the identifier for this is held in square brackets, as in the example above.46 theory_plot_ID_pattern = re.compile(r"^([0-9]+)\s+(\[(.*)\]\s+)?(.*)$")47 38 48 39 def __init__(self, parent=None, guimanager=None, manager=None): … … 394 385 # Notify the GuiManager about the send request 395 386 self._perspective().setData(data_item=selected_items, is_batch=self.chkBatch.isChecked()) 387 388 def freezeCheckedData(self): 389 """ 390 Convert checked results (fitted model, residuals) into separate dataset. 391 """ 392 outer_index = -1 393 theories_copied = 0 394 orig_model_size = self.model.rowCount() 395 while outer_index < orig_model_size: 396 outer_index += 1 397 outer_item = self.model.item(outer_index) 398 if not outer_item: 399 continue 400 if not outer_item.isCheckable(): 401 continue 402 # Look for checked inner items 403 inner_index = -1 404 while inner_index < outer_item.rowCount(): 405 inner_item = outer_item.child(inner_index) 406 inner_index += 1 407 if not inner_item: 408 continue 409 if not inner_item.isCheckable(): 410 continue 411 if inner_item.checkState() != QtCore.Qt.Checked: 412 continue 413 self.model.beginResetModel() 414 theories_copied += 1 415 new_item = self.cloneTheory(inner_item) 416 self.model.appendRow(new_item) 417 self.model.endResetModel() 418 419 freeze_msg = "" 420 if theories_copied == 0: 421 return 422 elif theories_copied == 1: 423 freeze_msg = "1 theory copied to a separate data set" 424 elif theories_copied > 1: 425 freeze_msg = "%i theories copied to separate data sets" % theories_copied 426 else: 427 freeze_msg = "Unexpected number of theories copied: %i" % theories_copied 428 raise AttributeError(freeze_msg) 429 self.communicator.statusBarUpdateSignal.emit(freeze_msg) 396 430 397 431 def freezeTheory(self, event): … … 526 560 # Now query the model item for available plots 527 561 plots = GuiUtils.plotsFromFilename(filename, model) 528 ids_keys = list(self.active_plots.keys())529 ids_vals = [val.data.id for val in self.active_plots.values()]530 562 531 563 new_plots = [] 532 564 for item, plot in plots.items(): 533 plot_id = plot.id 534 if plot_id in ids_keys: 535 self.active_plots[plot_id].replacePlot(plot_id, plot) 536 elif plot_id in ids_vals: 537 list(self.active_plots.values())[ids_vals.index(plot_id)].replacePlot(plot_id, plot) 538 else: 565 if not self.updatePlot(plot): 539 566 # Don't plot intermediate results, e.g. P(Q), S(Q) 540 match = self.theory_plot_ID_pattern.match(plot_id)567 match = GuiUtils.theory_plot_ID_pattern.match(plot.id) 541 568 # 2nd match group contains the identifier for the intermediate result, if present (e.g. "[P(Q)]") 542 569 if match and match.groups()[1] != None: … … 672 699 self.active_plots[plot_set.id] = old_plot 673 700 674 def updatePlot(self, new_data): 675 """ 676 Modify existing plot for immediate response 677 """ 678 data = new_data[0] 701 def updatePlot(self, data): 702 """ 703 Modify existing plot for immediate response and returns True. 704 Returns false, if the plot does not exist already. 705 """ 706 try: # there might be a list or a single value being passed 707 data = data[0] 708 except TypeError: 709 pass 679 710 assert type(data).__name__ in ['Data1D', 'Data2D'] 680 711 … … 685 716 if data_id in ids_keys: 686 717 self.active_plots[data_id].replacePlot(data_id, data) 718 return True 687 719 elif data_id in ids_vals: 688 720 list(self.active_plots.values())[ids_vals.index(data_id)].replacePlot(data_id, data) 721 return True 722 return False 689 723 690 724 def chooseFiles(self): … … 1247 1281 self.theory_model.appendRow(model_item) 1248 1282 1283 def deleteIntermediateTheoryPlotsByModelID(self, model_id): 1284 """Given a model's ID, deletes all items in the theory item model which reference the same ID. Useful in the 1285 case of intermediate results disappearing when changing calculations (in which case you don't want them to be 1286 retained in the list).""" 1287 items_to_delete = [] 1288 for r in range(self.theory_model.rowCount()): 1289 item = self.theory_model.item(r, 0) 1290 data = item.child(0).data() 1291 if not hasattr(data, "id"): 1292 return 1293 match = GuiUtils.theory_plot_ID_pattern.match(data.id) 1294 if match: 1295 item_model_id = match.groups()[-1] 1296 if item_model_id == model_id: 1297 # Only delete those identified as an intermediate plot 1298 if match.groups()[2] not in (None, ""): 1299 items_to_delete.append(item) 1300 1301 for item in items_to_delete: 1302 self.theory_model.removeRow(item.row()) -
src/sas/qtgui/MainWindow/GuiManager.py
raa1db44 rf84d793 123 123 #self._workspace.workspace.addDockWidget(Qt.LeftDockWidgetArea, self.dockedFilesWidget) 124 124 self._workspace.addDockWidget(Qt.LeftDockWidgetArea, self.dockedFilesWidget) 125 self._workspace.resizeDocks([self.dockedFilesWidget], [305], Qt.Horizontal) 125 126 126 127 # Add the console window as another docked widget … … 395 396 self.communicate.perspectiveChangedSignal.connect(self.perspectiveChanged) 396 397 self.communicate.updateTheoryFromPerspectiveSignal.connect(self.updateTheoryFromPerspective) 398 self.communicate.deleteIntermediateTheoryPlotsSignal.connect(self.deleteIntermediateTheoryPlotsByModelID) 397 399 self.communicate.plotRequestedSignal.connect(self.showPlot) 398 400 self.communicate.plotFromFilenameSignal.connect(self.showPlotFromFilename) … … 438 440 self._workspace.actionImage_Viewer.triggered.connect(self.actionImage_Viewer) 439 441 self._workspace.actionOrientation_Viewer.triggered.connect(self.actionOrientation_Viewer) 442 self._workspace.actionFreeze_Theory.triggered.connect(self.actionFreeze_Theory) 440 443 # Fitting 441 444 self._workspace.actionNew_Fit_Page.triggered.connect(self.actionNew_Fit_Page) … … 531 534 """ 532 535 self.communicate.copyFitParamsSignal.emit("") 536 self._workspace.actionPaste.setEnabled(True) 533 537 pass 534 538 … … 683 687 self._workspace.addDockWidget(Qt.RightDockWidgetArea, self.ipDockWidget) 684 688 689 def actionFreeze_Theory(self): 690 """ 691 Convert a child index with data into a separate top level dataset 692 """ 693 self.filesWidget.freezeCheckedData() 694 685 695 def actionOrientation_Viewer(self): 686 696 """ … … 878 888 """ 879 889 self.filesWidget.updateTheoryFromPerspective(index) 890 891 def deleteIntermediateTheoryPlotsByModelID(self, model_id): 892 """ 893 Catch the signal to delete items in the Theory item model which correspond to a model ID. 894 Send the request to the DataExplorer for updating the theory model. 895 """ 896 self.filesWidget.deleteIntermediateTheoryPlotsByModelID(model_id) 880 897 881 898 def updateModelFromDataOperationPanel(self, new_item, new_datalist_item): … … 945 962 self._workspace.menubar.addAction(self._workspace.menuWindow.menuAction()) 946 963 self._workspace.menubar.addAction(self._workspace.menuHelp.menuAction()) 964 947 965 elif isinstance(perspective, Perspectives.PERSPECTIVES["Invariant"]): 948 966 self.checkAnalysisOption(self._workspace.actionInvariant) -
src/sas/qtgui/MainWindow/UI/MainWindowUI.ui
raa1db44 rdda8f16 64 64 <addaction name="actionReport"/> 65 65 <addaction name="actionReset"/> 66 <addaction name="separator"/> 67 <addaction name="actionFreeze_Theory"/> 66 68 </widget> 67 69 <widget class="QMenu" name="menuView"> … … 252 254 </action> 253 255 <action name="actionPaste"> 256 <property name="enabled"> 257 <bool>false</bool> 258 </property> 254 259 <property name="icon"> 255 260 <iconset> … … 533 538 <property name="text"> 534 539 <string>Orientation Viewer</string> 540 </property> 541 </action> 542 <action name="actionFreeze_Theory"> 543 <property name="text"> 544 <string>Freeze Theory</string> 535 545 </property> 536 546 </action> -
src/sas/qtgui/Perspectives/Fitting/FittingLogic.py
rb4d05bd rdcabba7 161 161 Create a new 1D data instance based on fitting results 162 162 """ 163 # Unpack return data from Calc1D 164 x, y, page_id, state, weight,\ 165 fid, toggle_mode_on, \ 166 elapsed, index, model, \ 167 data, update_chisqr, source, \ 168 unsmeared_output, unsmeared_data, unsmeared_error, \ 169 pq_values, sq_values = return_data 170 171 return self._create1DPlot(tab_id, x, y, model, data) 163 164 return self._create1DPlot(tab_id, return_data['x'], return_data['y'], 165 return_data['model'], return_data['data']) 172 166 173 167 def new2DPlot(self, return_data): … … 175 169 Create a new 2D data instance based on fitting results 176 170 """ 177 image , data, page_id, model, state, toggle_mode_on,\178 elapsed, index, fid, qmin, qmax, weight, \179 update_chisqr, source = return_data171 image = return_data['image'] 172 data = return_data['data'] 173 model = return_data['model'] 180 174 181 175 np.nan_to_num(image) … … 183 177 new_plot.name = model.name + '2d' 184 178 new_plot.title = "Analytical model 2D " 185 new_plot.id = str( page_id) + " " + data.name186 new_plot.group_id = str( page_id) + " Model2D"179 new_plot.id = str(return_data['page_id']) + " " + data.name 180 new_plot.group_id = str(return_data['page_id']) + " Model2D" 187 181 new_plot.detector = data.detector 188 182 new_plot.source = data.source … … 218 212 (pq_plot, sq_plot). If either are unavailable, the corresponding plot is None. 219 213 """ 220 # Unpack return data from Calc1D221 x, y, page_id, state, weight, \222 fid, toggle_mode_on, \223 elapsed, index, model, \224 data, update_chisqr, source, \225 unsmeared_output, unsmeared_data, unsmeared_error, \226 pq_values, sq_values = return_data227 214 228 215 pq_plot = None 229 216 sq_plot = None 230 217 231 if pq_values is not None: 232 pq_plot = self._create1DPlot(tab_id, x, pq_values, model, data, component="P(Q)") 233 if sq_values is not None: 234 sq_plot = self._create1DPlot(tab_id, x, sq_values, model, data, component="S(Q)") 218 if return_data.get('pq_values', None) is not None: 219 pq_plot = self._create1DPlot(tab_id, return_data['x'], 220 return_data['pq_values'], return_data['model'], 221 return_data['data'], component="P(Q)") 222 if return_data.get('sq_values', None) is not None: 223 sq_plot = self._create1DPlot(tab_id, return_data['x'], 224 return_data['sq_values'], return_data['model'], 225 return_data['data'], component="S(Q)") 235 226 236 227 return pq_plot, sq_plot -
src/sas/qtgui/Perspectives/Fitting/FittingUtilities.py
r70f4458 r4ea8020 474 474 475 475 theory_name = str(current_data.name.split()[0]) 476 res iduals.name = "Residuals for " + str(theory_name) + "[" + \477 str(reference_data.filename)+ "]"476 res_name = reference_data.filename if reference_data.filename else reference_data.name 477 residuals.name = "Residuals for " + str(theory_name) + "[" + res_name + "]" 478 478 residuals.title = residuals.name 479 479 residuals.ytransform = 'y' … … 501 501 """ 502 502 weight = None 503 if data is None: 504 return [] 503 505 if is2d: 506 if not hasattr(data, 'err_data'): 507 return [] 504 508 dy_data = data.err_data 505 509 data = data.data 506 510 else: 511 if not hasattr(data, 'dy'): 512 return [] 507 513 dy_data = data.dy 508 514 data = data.y -
src/sas/qtgui/Perspectives/Fitting/FittingWidget.py
r0109f2a r4ea8020 49 49 50 50 51 52 51 TAB_MAGNETISM = 4 53 52 TAB_POLY = 3 … … 61 60 62 61 logger = logging.getLogger(__name__) 63 64 62 65 63 class ToolTippedItemModel(QtGui.QStandardItemModel): … … 93 91 fittingFinishedSignal = QtCore.pyqtSignal(tuple) 94 92 batchFittingFinishedSignal = QtCore.pyqtSignal(tuple) 95 Calc1DFinishedSignal = QtCore.pyqtSignal( tuple)96 Calc2DFinishedSignal = QtCore.pyqtSignal( tuple)93 Calc1DFinishedSignal = QtCore.pyqtSignal(dict) 94 Calc2DFinishedSignal = QtCore.pyqtSignal(dict) 97 95 98 96 def __init__(self, parent=None, data=None, tab_id=1): … … 251 249 self.kernel_module_copy = None 252 250 251 # dictionaries of current params 252 self.poly_params = {} 253 self.magnet_params = {} 254 253 255 # Page id for fitting 254 256 # To keep with previous SasView values, use 200 as the start offset … … 267 269 self.has_poly_error_column = False 268 270 self.has_magnet_error_column = False 271 272 # If the widget generated theory item, save it 273 self.theory_item = None 269 274 270 275 # signal communicator … … 390 395 # Tag along functionality 391 396 self.label.setText("Data loaded from: ") 392 self.lblFilename.setText(self.logic.data.filename) 397 if self.logic.data.filename: 398 self.lblFilename.setText(self.logic.data.filename) 399 else: 400 self.lblFilename.setText(self.logic.data.name) 393 401 self.updateQRange() 394 402 # Switch off Data2D control … … 522 530 523 531 # Signals from separate tabs asking for replot 524 self.options_widget.plot_signal.connect(self.onOptionsUpdate)525 532 self.options_widget.plot_signal.connect(self.onOptionsUpdate) 526 533 … … 964 971 model = self.cbModel.currentText() 965 972 966 # empty combobox forced to be read 973 # Assure the control is active 974 if not self.cbModel.isEnabled(): 975 return 976 # Empty combobox forced to be read 967 977 if not model: 968 978 return 969 # Reset structure factor970 self.cbStructureFactor.setCurrentIndex(0)971 979 972 980 # Reset parameters to fit … … 975 983 self.has_poly_error_column = False 976 984 977 self.respondToModelStructure(model=model, structure_factor=None) 985 structure = None 986 if self.cbStructureFactor.isEnabled(): 987 structure = str(self.cbStructureFactor.currentText()) 988 self.respondToModelStructure(model=model, structure_factor=structure) 978 989 979 990 def onSelectBatchFilename(self, data_index): … … 1118 1129 self.disableModelCombo() 1119 1130 self.enableStructureCombo() 1131 # set the index to 0 1132 self.cbStructureFactor.setCurrentIndex(0) 1133 self.model_parameters = None 1120 1134 self._model_model.clear() 1121 1135 return … … 1142 1156 model_row = item.row() 1143 1157 name_index = self._poly_model.index(model_row, 0) 1144 parameter_name = str(name_index.data()) .lower()# "distribution of sld" etc.1145 if " distribution of" in parameter_name:1158 parameter_name = str(name_index.data()) # "distribution of sld" etc. 1159 if "istribution of" in parameter_name: 1146 1160 # just the last word 1147 1161 parameter_name = parameter_name.rsplit()[-1] … … 1188 1202 # Update the sasmodel 1189 1203 # PD[ratio] -> width, npts -> npts, nsigs -> nsigmas 1190 self.kernel_module.setParam(parameter_name + '.' + delegate.columnDict()[model_column], value) 1204 #self.kernel_module.setParam(parameter_name + '.' + delegate.columnDict()[model_column], value) 1205 key = parameter_name + '.' + delegate.columnDict()[model_column] 1206 self.poly_params[key] = value 1191 1207 1192 1208 # Update plot … … 1197 1213 row = self.getRowFromName(parameter_name) 1198 1214 param_item = self._model_model.item(row) 1215 self._model_model.blockSignals(True) 1199 1216 param_item.child(0).child(0, model_column).setText(item.text()) 1217 self._model_model.blockSignals(False) 1200 1218 1201 1219 def onMagnetModelChange(self, item): … … 1226 1244 # Unparsable field 1227 1245 return 1228 1229 property_index = self._magnet_model.headerData(1, model_column)-1 # Value, min, max, etc. 1230 1231 # Update the parameter value - note: this supports +/-inf as well 1232 self.kernel_module.params[parameter_name] = value 1233 1234 # min/max to be changed in self.kernel_module.details[parameter_name] = ['Ang', 0.0, inf] 1235 self.kernel_module.details[parameter_name][property_index] = value 1236 1237 # Force the chart update when actual parameters changed 1238 if model_column == 1: 1246 delegate = self.lstMagnetic.itemDelegate() 1247 1248 if model_column > 1: 1249 if model_column == delegate.mag_min: 1250 pos = 1 1251 elif model_column == delegate.mag_max: 1252 pos = 2 1253 elif model_column == delegate.mag_unit: 1254 pos = 0 1255 else: 1256 raise AttributeError("Wrong column in magnetism table.") 1257 # min/max to be changed in self.kernel_module.details[parameter_name] = ['Ang', 0.0, inf] 1258 self.kernel_module.details[parameter_name][pos] = value 1259 else: 1260 self.magnet_params[parameter_name] = value 1261 #self.kernel_module.setParam(parameter_name) = value 1262 # Force the chart update when actual parameters changed 1239 1263 self.recalculatePlotData() 1240 1264 … … 1497 1521 # Data going in 1498 1522 data = self.logic.data 1499 model = self.kernel_module1523 model = copy.deepcopy(self.kernel_module) 1500 1524 qmin = self.q_range_min 1501 1525 qmax = self.q_range_max 1526 # add polydisperse/magnet parameters if asked 1527 self.updateKernelModelWithExtraParams(model) 1502 1528 1503 1529 params_to_fit = self.main_params_to_fit … … 1509 1535 raise ValueError('Fitting requires at least one parameter to optimize.') 1510 1536 1511 # Potential smearing added1512 # Remember that smearing_min/max can be None ->1513 # deal with it until Python gets discriminated unions1514 self.addWeightingToData(data)1515 1516 1537 # Get the constraints. 1517 1538 constraints = self.getComplexConstraintsForModel() … … 1530 1551 data = GuiUtils.dataFromItem(fit_index) 1531 1552 # Potential weights added directly to data 1532 self.addWeightingToData(data)1553 weighted_data = self.addWeightingToData(data) 1533 1554 try: 1534 fitter_single.set_model(model, fit_id, params_to_fit, data= data,1555 fitter_single.set_model(model, fit_id, params_to_fit, data=weighted_data, 1535 1556 constraints=constraints) 1536 1557 except ValueError as ex: 1537 1558 raise ValueError("Setting model parameters failed with: %s" % ex) 1538 1559 1539 qmin, qmax, _ = self.logic.computeRangeFromData( data)1540 fitter_single.set_data(data= data, id=fit_id, smearer=smearer, qmin=qmin,1560 qmin, qmax, _ = self.logic.computeRangeFromData(weighted_data) 1561 fitter_single.set_data(data=weighted_data, id=fit_id, smearer=smearer, qmin=qmin, 1541 1562 qmax=qmax) 1542 1563 fitter_single.select_problem_for_fit(id=fit_id, value=1) … … 1929 1950 Adds weighting contribution to fitting data 1930 1951 """ 1952 new_data = copy.deepcopy(data) 1931 1953 # Send original data for weighting 1932 1954 weight = FittingUtilities.getWeight(data=data, is2d=self.is2D, flag=self.weighting) 1933 1955 if self.is2D: 1934 data.err_data = weight1956 new_data.err_data = weight 1935 1957 else: 1936 data.dy = weight 1937 pass 1958 new_data.dy = weight 1959 1960 return new_data 1938 1961 1939 1962 def updateQRange(self): … … 1970 1993 self.addExtraShells() 1971 1994 1972 if structure_factor not in (None, "None"): 1973 # add S(Q) 1995 # Allow the SF combobox visibility for the given sasmodel 1996 self.enableStructureFactorControl(structure_factor) 1997 1998 # Add S(Q) 1999 if self.cbStructureFactor.isEnabled(): 2000 structure_factor = self.cbStructureFactor.currentText() 1974 2001 self.fromStructureFactorToQModel(structure_factor) 1975 else:1976 # enable selection of S(Q)1977 self.enableStructureFactorControl(structure_factor)1978 2002 1979 2003 # Add polydispersity to the model 2004 self.poly_params = {} 1980 2005 self.setPolyModel() 1981 2006 # Add magnetic parameters to the model 2007 self.magnet_params = {} 1982 2008 self.setMagneticModel() 1983 2009 … … 2005 2031 """ 2006 2032 name = model_name 2033 kernel_module = None 2007 2034 if self.cbCategory.currentText() == CATEGORY_CUSTOM: 2008 2035 # custom kernel load requires full path … … 2010 2037 try: 2011 2038 kernel_module = generate.load_kernel_module(name) 2012 except ModuleNotFoundError: 2013 # maybe it's a recategorised custom model? 2014 name = os.path.join(ModelUtilities.find_plugins_dir(), model_name+".py") 2015 # If this rises, it's a valid problem. 2016 kernel_module = generate.load_kernel_module(name) 2039 except ModuleNotFoundError as ex: 2040 pass 2041 2042 if kernel_module is None: 2043 # mismatch between "name" attribute and actual filename. 2044 curr_model = self.models[model_name] 2045 name, _ = os.path.splitext(os.path.basename(curr_model.filename)) 2046 try: 2047 kernel_module = generate.load_kernel_module(name) 2048 except ModuleNotFoundError as ex: 2049 logging.error("Can't find the model "+ str(ex)) 2050 return 2017 2051 2018 2052 if hasattr(kernel_module, 'parameters'): … … 2059 2093 Setting model parameters into QStandardItemModel based on selected _structure factor_ 2060 2094 """ 2095 if structure_factor is None or structure_factor=="None": 2096 return 2097 2061 2098 s_kernel = self.models[structure_factor]() 2062 2099 p_kernel = self.kernel_module … … 2257 2294 name = self.nameFromData(fitted_data) 2258 2295 # Notify the GUI manager so it can create the theory model in DataExplorer 2259 new_item = GuiUtils.createModelItemWithPlot(fitted_data, name=name)2260 self.communicate.updateTheoryFromPerspectiveSignal.emit( new_item)2296 self.theory_item = GuiUtils.createModelItemWithPlot(fitted_data, name=name) 2297 self.communicate.updateTheoryFromPerspectiveSignal.emit(self.theory_item) 2261 2298 2262 2299 def nameFromData(self, fitted_data): … … 2281 2318 return self.completed1D if isinstance(self.data, Data1D) else self.completed2D 2282 2319 2320 def updateKernelModelWithExtraParams(self, model=None): 2321 """ 2322 Updates kernel model 'model' with extra parameters from 2323 the polydisp and magnetism tab, if the tabs are enabled 2324 """ 2325 if model is None: return 2326 if not hasattr(model, 'setParam'): return 2327 2328 # add polydisperse parameters if asked 2329 if self.chkPolydispersity.isChecked(): 2330 for key, value in self.poly_params.items(): 2331 model.setParam(key, value) 2332 # add magnetic params if asked 2333 if self.chkMagnetism.isChecked(): 2334 for key, value in self.magnet_params.items(): 2335 model.setParam(key, value) 2336 2283 2337 def calculateQGridForModelExt(self, data=None, model=None, completefn=None, use_threads=True): 2284 2338 """ … … 2288 2342 data = self.data 2289 2343 if model is None: 2290 model = self.kernel_module 2344 model = copy.deepcopy(self.kernel_module) 2345 self.updateKernelModelWithExtraParams(model) 2346 2291 2347 if completefn is None: 2292 2348 completefn = self.methodCompleteForData() 2293 2349 smearer = self.smearing_widget.smearer() 2350 weight = FittingUtilities.getWeight(data=data, is2d=self.is2D, flag=self.weighting) 2351 2294 2352 # Awful API to a backend method. 2295 2353 calc_thread = self.methodCalculateForData()(data=data, … … 2300 2358 smearer=smearer, 2301 2359 state=None, 2302 weight= None,2360 weight=weight, 2303 2361 fid=None, 2304 2362 toggle_mode_on=False, … … 2348 2406 residuals = self.calculateResiduals(fitted_data) 2349 2407 self.model_data = fitted_data 2350 2351 new_plots = [fitted_data, residuals] 2408 new_plots = [fitted_data] 2409 if residuals is not None: 2410 new_plots.append(residuals) 2411 2412 if self.data_is_loaded: 2413 GuiUtils.deleteRedundantPlots(self.all_data[self.data_index], new_plots) 2414 else: 2415 # delete theory items for the model, in order to get rid of any redundant items, e.g. beta(Q), S_eff(Q) 2416 self.communicate.deleteIntermediateTheoryPlotsSignal.emit(self.kernel_module.id) 2352 2417 2353 2418 # Create plots for intermediate product data … … 2364 2429 new_plots.append(sq_data) 2365 2430 2366 if self.data_is_loaded:2367 GuiUtils.deleteRedundantPlots(self.all_data[self.data_index], new_plots)2368 2369 # TODO: merge rest of beta approx implementation in2370 # TODO: refactor2371 # deal with constrained radius_effective2372 # for row in range(self._model_model.rowCount()):2373 # if self._model_model.item(row, 0).text() == "radius_effective_mode":2374 # if GuiUtils.toDouble(self._model_model.item(row, 1).text()) == 0:2375 # return2376 # radius_effective = intermediate_ER()2377 # if radius_effective:2378 # for row in range(self._model_model.rowCount()):2379 # if self._model_model.item(row, 0).text() == "radius_effective":2380 # self._model_model.item(row, 1).setText(str(radius_effective))2381 # break2382 2383 2431 for plot in new_plots: 2384 if hasattr(plot, "id") and "esidual" in plot.id: 2385 # TODO: fix updates to residuals plot 2386 pass 2387 elif plot is not None: 2388 self.communicate.plotUpdateSignal.emit([plot]) 2432 self.communicate.plotUpdateSignal.emit([plot]) 2389 2433 2390 2434 def complete2D(self, return_data): … … 2393 2437 """ 2394 2438 fitted_data = self.logic.new2DPlot(return_data) 2395 self.calculateResiduals(fitted_data)2439 residuals = self.calculateResiduals(fitted_data) 2396 2440 self.model_data = fitted_data 2441 new_plots = [fitted_data] 2442 if residuals is not None: 2443 new_plots.append(residuals) 2444 2445 # Update/generate plots 2446 for plot in new_plots: 2447 self.communicate.plotUpdateSignal.emit([plot]) 2397 2448 2398 2449 def calculateResiduals(self, fitted_data): … … 2404 2455 2405 2456 # Modify fitted_data with weighting 2406 self.addWeightingToData(fitted_data)2407 2408 self.createNewIndex( fitted_data)2457 weighted_data = self.addWeightingToData(fitted_data) 2458 2459 self.createNewIndex(weighted_data) 2409 2460 # Calculate difference between return_data and logic.data 2410 self.chi2 = FittingUtilities.calculateChi2( fitted_data, self.logic.data)2461 self.chi2 = FittingUtilities.calculateChi2(weighted_data, self.logic.data) 2411 2462 # Update the control 2412 2463 chi2_repr = "---" if self.chi2 is None else GuiUtils.formatNumber(self.chi2, high=True) 2413 2464 self.lblChi2Value.setText(chi2_repr) 2414 2465 2415 # self.communicate.plotUpdateSignal.emit([fitted_data])2416 2417 2466 # Plot residuals if actual data 2418 2467 if not self.data_is_loaded: 2419 2468 return 2420 2469 2421 residuals_plot = FittingUtilities.plotResiduals(self.data, fitted_data)2470 residuals_plot = FittingUtilities.plotResiduals(self.data, weighted_data) 2422 2471 residuals_plot.id = "Residual " + residuals_plot.id 2423 2472 self.createNewIndex(residuals_plot) … … 2488 2537 self._poly_model.clear() 2489 2538 2539 parameters = self.model_parameters.form_volume_parameters 2540 if self.is2D: 2541 parameters += self.model_parameters.orientation_parameters 2542 2490 2543 [self.setPolyModelParameters(i, param) for i, param in \ 2491 enumerate(self.model_parameters.form_volume_parameters) if param.polydisperse] 2544 enumerate(parameters) if param.polydisperse] 2545 2492 2546 FittingUtilities.addPolyHeadersToModel(self._poly_model) 2493 2547 … … 2522 2576 _, min, max = self.kernel_module.details[param_name] 2523 2577 2578 # Update local param dict 2579 self.poly_params[param_name + '.width'] = width 2580 self.poly_params[param_name + '.npts'] = npts 2581 self.poly_params[param_name + '.nsigmas'] = nsigs 2582 2524 2583 # Construct a row with polydisp. related variable. 2525 2584 # This will get added to the polydisp. model … … 2571 2630 if not self.isCheckable(row): 2572 2631 return 2632 self._model_model.blockSignals(True) 2573 2633 param_name = str(self._model_model.item(row, 0).text()) 2634 self._model_model.blockSignals(False) 2574 2635 if param_name != param.name: 2575 2636 return 2576 2637 # Modify the param value 2638 self._model_model.blockSignals(True) 2577 2639 if self.has_error_column: 2578 2640 # err column changes the indexing … … 2580 2642 else: 2581 2643 self._model_model.item(row, 0).child(0).child(0,4).setText(combo_string) 2644 self._model_model.blockSignals(False) 2582 2645 2583 2646 if combo_string == 'array': … … 2698 2761 param.units] 2699 2762 2763 self.magnet_params[param.name] = param.default 2764 2700 2765 FittingUtilities.addCheckedListToModel(model, checked_list) 2701 2766 … … 2876 2941 # TODO: add polidyspersity and magnetism 2877 2942 2878 2879 2943 def updateUndo(self): 2880 2944 """ … … 2913 2977 if self.all_data: 2914 2978 index = self.all_data[self.data_index] 2979 else: 2980 index = self.theory_item 2915 2981 report_logic = ReportPageLogic(self, 2916 2982 kernel_module=self.kernel_module, … … 3036 3102 # first - regular params 3037 3103 param_list = [] 3104 3105 param_list.append(['model_name', str(self.cbModel.currentText())]) 3038 3106 def gatherParams(row): 3039 3107 """ … … 3122 3190 if lines[0] != 'sasview_parameter_values': 3123 3191 return False 3124 for line in lines[1:-1]: 3192 3193 model = lines[1].split(',') 3194 3195 if model[0] != 'model_name': 3196 return False 3197 3198 context['model_name'] = [model[1]] 3199 for line in lines[2:-1]: 3125 3200 if len(line) != 0: 3126 3201 item = line.split(',') … … 3148 3223 except IndexError: 3149 3224 pass 3225 3226 if str(self.cbModel.currentText()) != str(context['model_name'][0]): 3227 msg = QtWidgets.QMessageBox() 3228 msg.setIcon(QtWidgets.QMessageBox.Information) 3229 msg.setText("The model in the clipboard is not the same as the currently loaded model. \ 3230 Not all parameters saved may paste correctly.") 3231 msg.setStandardButtons(QtWidgets.QMessageBox.Ok | QtWidgets.QMessageBox.Cancel) 3232 result = msg.exec_() 3233 if result == QtWidgets.QMessageBox.Ok: 3234 pass 3235 else: 3236 return 3150 3237 3151 3238 self.updateFullModel(context) … … 3186 3273 param_repr = GuiUtils.formatNumber(param_dict[param_name][3+ioffset], high=True) 3187 3274 self._model_model.item(row, 3+ioffset).setText(param_repr) 3275 self.setFocus() 3276 3188 3277 3189 3278 # block signals temporarily, so we don't end up … … 3192 3281 self.iterateOverModel(updateFittedValues) 3193 3282 self._model_model.blockSignals(False) 3283 3194 3284 3195 3285 def updateFullPolyModel(self, param_dict): … … 3236 3326 param_repr = GuiUtils.formatNumber(param_dict[param_name][5+ioffset], high=True) 3237 3327 self._poly_model.item(row, 5+ioffset).setText(param_repr) 3328 self.setFocus() 3238 3329 3239 3330 # block signals temporarily, so we don't end up … … 3243 3334 self._poly_model.blockSignals(False) 3244 3335 3245 -
src/sas/qtgui/Perspectives/Fitting/ModelThread.py
r3ae9179 rdcabba7 101 101 elapsed = time.time() - self.starttime 102 102 103 res = dict(image = output, data = self.data, page_id = self.page_id, 104 model = self.model, state = self.state, 105 toggle_mode_on = self.toggle_mode_on, elapsed = elapsed, 106 index = index_model, fid = self.fid, 107 qmin = self.qmin, qmax = self.qmax, 108 weight = self.weight, update_chisqr = self.update_chisqr, 109 source = self.source) 110 103 111 if LocalConfig.USING_TWISTED: 104 return (output, 105 self.data, 106 self.page_id, 107 self.model, 108 self.state, 109 self.toggle_mode_on, 110 elapsed, 111 index_model, 112 self.fid, 113 self.qmin, 114 self.qmax, 115 self.weight, 116 self.update_chisqr, 117 self.source) 118 else: 119 self.complete(image=output, 120 data=self.data, 121 page_id=self.page_id, 122 model=self.model, 123 state=self.state, 124 toggle_mode_on=self.toggle_mode_on, 125 elapsed=elapsed, 126 index=index_model, 127 fid=self.fid, 128 qmin=self.qmin, 129 qmax=self.qmax, 130 weight=self.weight, 131 #qstep=self.qstep, 132 update_chisqr=self.update_chisqr, 133 source=self.source) 134 112 return res 113 else: 114 self.completefn(res) 135 115 136 116 class Calc1D(CalcThread): … … 236 216 elapsed = time.time() - self.starttime 237 217 218 res = dict(x = self.data.x[index], y = output[index], 219 page_id = self.page_id, state = self.state, weight = self.weight, 220 fid = self.fid, toggle_mode_on = self.toggle_mode_on, 221 elapsed = elapsed, index = index, model = self.model, 222 data = self.data, update_chisqr = self.update_chisqr, 223 source = self.source, unsmeared_output = unsmeared_output, 224 unsmeared_data = unsmeared_data, unsmeared_error = unsmeared_error, 225 pq_values = pq_values, sq_values = sq_values) 226 238 227 if LocalConfig.USING_TWISTED: 239 return (self.data.x[index], output[index], 240 self.page_id, 241 self.state, 242 self.weight, 243 self.fid, 244 self.toggle_mode_on, 245 elapsed, index, self.model, 246 self.data, 247 self.update_chisqr, 248 self.source, 249 unsmeared_output, unsmeared_data, unsmeared_error, 250 pq_values, sq_values) 251 else: 252 self.complete(x=self.data.x[index], y=output[index], 253 page_id=self.page_id, 254 state=self.state, 255 weight=self.weight, 256 fid=self.fid, 257 toggle_mode_on=self.toggle_mode_on, 258 elapsed=elapsed, index=index, model=self.model, 259 data=self.data, 260 update_chisqr=self.update_chisqr, 261 source=self.source, 262 unsmeared_model=unsmeared_output, 263 unsmeared_data=unsmeared_data, 264 unsmeared_error=unsmeared_error, 265 pq_model=pq_values, 266 sq_model=sq_values) 228 return res 229 else: 230 self.completefn(res) 267 231 268 232 def results(self): -
src/sas/qtgui/Perspectives/Fitting/OptionsWidget.py
rc0a3b22e rb764ae5 79 79 self.weightingGroup.buttonClicked.connect(self.onWeightingChoice) 80 80 81 self.qmin = QMIN_DEFAULT 82 self.qmax = QMAX_DEFAULT 83 self.npts = NPTS_DEFAULT 84 if self.logic.data_is_loaded: 85 self.qmin, self.qmax, self.npts = self.logic.computeDataRange() 81 86 self.initModel() 82 87 self.initMapper() 83 88 self.model.blockSignals(True) 84 self.updateQRange( QMIN_DEFAULT, QMAX_DEFAULT, NPTS_DEFAULT)85 self.txtMaxRange.setText(str( QMAX_DEFAULT))86 self.txtMinRange.setText(str( QMIN_DEFAULT))87 self.txtNpts.setText(str( NPTS_DEFAULT))88 self.txtNptsFit.setText(str( NPTS_DEFAULT))89 self.updateQRange(self.qmin, self.qmax, self.npts) 90 self.txtMaxRange.setText(str(self.qmax)) 91 self.txtMinRange.setText(str(self.qmin)) 92 self.txtNpts.setText(str(self.npts)) 93 self.txtNptsFit.setText(str(self.npts)) 89 94 self.model.blockSignals(False) 90 95 … … 134 139 Callback for resetting qmin/qmax 135 140 """ 136 self.updateQRange( QMIN_DEFAULT, QMAX_DEFAULT, NPTS_DEFAULT)141 self.updateQRange(self.qmin, self.qmax, self.npts) 137 142 138 143 def onWeightingChoice(self, button): … … 179 184 self.model.item(MODEL.index('MAX_RANGE')).setText(str(q_range_max)) 180 185 self.model.item(MODEL.index('NPTS')).setText(str(npts)) 186 self.qmin, self.qmax, self.npts = q_range_min, q_range_max, npts 181 187 182 188 def state(self): -
src/sas/qtgui/Perspectives/Fitting/UnitTesting/FittingWidgetTest.py
r3fbd77b r4ea8020 18 18 from sas.qtgui.Perspectives.Fitting.FittingWidget import * 19 19 from sas.qtgui.Perspectives.Fitting.Constraint import Constraint 20 20 import sas.qtgui.Utilities.LocalConfig 21 21 from sas.qtgui.UnitTesting.TestUtils import QtSignalSpy 22 from sas.qtgui.Perspectives.Fitting.ModelThread import Calc1D 23 from sas.qtgui.Perspectives.Fitting.ModelThread import Calc2D 22 24 23 25 from sas.qtgui.Plotting.PlotterData import Data1D … … 260 262 self.widget.cbModel.setCurrentIndex(0) 261 263 262 # Observe factor reset to None263 self.assertEqual(self.widget.cbStructureFactor.currentText(), STRUCTURE_DEFAULT)264 # Observe factor doesn't reset to None 265 self.assertEqual(self.widget.cbStructureFactor.currentText(), 'squarewell') 264 266 265 267 # Switch category to structure factor … … 319 321 Check that the fitting 1D data object is ready 320 322 """ 321 # Mock the thread creation 322 threads.deferToThread = MagicMock() 323 # Model for theory 324 self.widget.SASModelToQModel("cylinder") 325 # Call the tested method 326 self.widget.calculateQGridForModel() 327 time.sleep(1) 328 # Test the mock 329 self.assertTrue(threads.deferToThread.called) 330 self.assertEqual(threads.deferToThread.call_args_list[0][0][0].__name__, "compute") 323 324 if LocalConfig.USING_TWISTED: 325 # Mock the thread creation 326 threads.deferToThread = MagicMock() 327 # Model for theory 328 self.widget.SASModelToQModel("cylinder") 329 # Call the tested method 330 self.widget.calculateQGridForModel() 331 time.sleep(1) 332 # Test the mock 333 self.assertTrue(threads.deferToThread.called) 334 self.assertEqual(threads.deferToThread.call_args_list[0][0][0].__name__, "compute") 335 else: 336 Calc2D.queue = MagicMock() 337 # Model for theory 338 self.widget.SASModelToQModel("cylinder") 339 # Call the tested method 340 self.widget.calculateQGridForModel() 341 time.sleep(1) 342 # Test the mock 343 self.assertTrue(Calc2D.queue.called) 331 344 332 345 def testCalculateResiduals(self): … … 417 430 index = self.widget._poly_model.index(0,0) 418 431 419 #self.widget.show()420 #QtWidgets.QApplication(sys.argv).exec_()421 422 432 # Set the checbox 423 433 self.widget._poly_model.item(0,0).setCheckState(2) … … 435 445 self.assertEqual(self.widget.kernel_module.details['radius_bell'][1], 1.0) 436 446 447 #self.widget.show() 448 #QtWidgets.QApplication.exec_() 449 437 450 # Change the number of points 438 self.assertEqual(self.widget. kernel_module.getParam('radius_bell.npts'), 35)451 self.assertEqual(self.widget.poly_params['radius_bell.npts'], 35) 439 452 self.widget._poly_model.item(0,4).setText("22") 440 self.assertEqual(self.widget. kernel_module.getParam('radius_bell.npts'), 22)453 self.assertEqual(self.widget.poly_params['radius_bell.npts'], 22) 441 454 # try something stupid 442 455 self.widget._poly_model.item(0,4).setText("butt") 443 456 # see that this didn't annoy the control at all 444 self.assertEqual(self.widget. kernel_module.getParam('radius_bell.npts'), 22)457 self.assertEqual(self.widget.poly_params['radius_bell.npts'], 22) 445 458 446 459 # Change the number of sigmas 447 self.assertEqual(self.widget. kernel_module.getParam('radius_bell.nsigmas'), 3)460 self.assertEqual(self.widget.poly_params['radius_bell.nsigmas'], 3) 448 461 self.widget._poly_model.item(0,5).setText("222") 449 self.assertEqual(self.widget. kernel_module.getParam('radius_bell.nsigmas'), 222)462 self.assertEqual(self.widget.poly_params['radius_bell.nsigmas'], 222) 450 463 # try something stupid again 451 464 self.widget._poly_model.item(0,4).setText("beer") 452 465 # no efect 453 self.assertEqual(self.widget. kernel_module.getParam('radius_bell.nsigmas'), 222)466 self.assertEqual(self.widget.poly_params['radius_bell.nsigmas'], 222) 454 467 455 468 def testOnPolyComboIndexChange(self): … … 472 485 self.widget.onPolyComboIndexChange('rectangle', 0) 473 486 # check values 474 self.assertEqual(self.widget. kernel_module.getParam('radius_bell.npts'), 35)475 self.assertAlmostEqual(self.widget. kernel_module.getParam('radius_bell.nsigmas'), 1.73205, 5)487 self.assertEqual(self.widget.poly_params['radius_bell.npts'], 35) 488 self.assertAlmostEqual(self.widget.poly_params['radius_bell.nsigmas'], 1.73205, 5) 476 489 # Change the index 477 490 self.widget.onPolyComboIndexChange('lognormal', 0) 478 491 # check values 479 self.assertEqual(self.widget. kernel_module.getParam('radius_bell.npts'), 80)480 self.assertEqual(self.widget. kernel_module.getParam('radius_bell.nsigmas'), 8)492 self.assertEqual(self.widget.poly_params['radius_bell.npts'], 80) 493 self.assertEqual(self.widget.poly_params['radius_bell.nsigmas'], 8) 481 494 # Change the index 482 495 self.widget.onPolyComboIndexChange('schulz', 0) 483 496 # check values 484 self.assertEqual(self.widget. kernel_module.getParam('radius_bell.npts'), 80)485 self.assertEqual(self.widget. kernel_module.getParam('radius_bell.nsigmas'), 8)497 self.assertEqual(self.widget.poly_params['radius_bell.npts'], 80) 498 self.assertEqual(self.widget.poly_params['radius_bell.nsigmas'], 8) 486 499 487 500 # mock up file load … … 651 664 self.assertEqual(self.widget.cmdPlot.text(), 'Show Plot') 652 665 653 self.widget.show()654 655 666 # Set data 656 667 test_data = Data1D(x=[1,2], y=[1,2]) 657 668 item = QtGui.QStandardItem() 669 updateModelItem(item, test_data, "test") 658 670 # Force same data into logic 659 self.widget.logic.data = test_data 660 self.widget.data_is_loaded = True 671 self.widget.data = item 661 672 662 673 # Change the category index so we have a model available … … 704 715 self.widget.close() 705 716 717 def testOnEmptyFit2(self): 706 718 test_data = Data2D(image=[1.0, 2.0, 3.0], 707 719 err_image=[0.01, 0.02, 0.03], … … 714 726 item = QtGui.QStandardItem() 715 727 updateModelItem(item, test_data, "test") 728 716 729 # Force same data into logic 717 730 self.widget.data = item … … 731 744 self.widget.close() 732 745 733 734 def testOnFit1D(self): 746 def notestOnFit1D(self): 735 747 """ 736 748 Test the threaded fitting call … … 770 782 self.widget.close() 771 783 772 def testOnFit2D(self):784 def notestOnFit2D(self): 773 785 """ 774 786 Test the threaded fitting call … … 865 877 # Set data 866 878 test_data = Data1D(x=[1,2], y=[1,2]) 867 879 item = QtGui.QStandardItem() 880 updateModelItem(item, test_data, "test") 868 881 # Force same data into logic 869 self.widget.logic.data = test_data 870 self.widget.data_is_loaded = True 882 self.widget.data = item 883 884 # Force same data into logic 871 885 category_index = self.widget.cbCategory.findText('Sphere') 886 872 887 self.widget.cbCategory.setCurrentIndex(category_index) 873 888 self.widget.main_params_to_fit = ['scale'] … … 951 966 # Set data 952 967 test_data = Data1D(x=[1,2], y=[1,2]) 953 968 item = QtGui.QStandardItem() 969 updateModelItem(item, test_data, "test") 954 970 # Force same data into logic 955 self.widget.logic.data = test_data 956 self.widget.data_is_loaded = True 971 self.widget.data = item 957 972 category_index = self.widget.cbCategory.findText("Sphere") 958 973 self.widget.cbCategory.setCurrentIndex(category_index) … … 976 991 # Set data 977 992 test_data = Data1D(x=[1,2], y=[1,2]) 978 993 item = QtGui.QStandardItem() 994 updateModelItem(item, test_data, "test") 979 995 # Force same data into logic 980 self.widget.logic.data = test_data 981 self.widget.data_is_loaded = True 996 self.widget.data = item 982 997 category_index = self.widget.cbCategory.findText("Sphere") 983 998 -
src/sas/qtgui/Plotting/Plotter.py
rae43f3b rb764ae5 195 195 ax.set_xlabel(self.x_label) 196 196 197 # define the ranges198 #self.setRange = SetGraphRange(parent=self,199 # x_range=self.ax.get_xlim(), y_range=self.ax.get_ylim())200 201 197 # refresh canvas 202 198 self.canvas.draw_idle() 199 # This is an important processEvent. 200 # This allows charts to be properly updated in order 201 # of plots being applied. 202 QtWidgets.QApplication.processEvents() 203 203 204 204 def createContextMenu(self): -
src/sas/qtgui/Utilities/AddMultEditor.py
raed0532 r287d356 15 15 import re 16 16 import logging 17 import traceback 18 17 19 import sas.qtgui.Utilities.GuiUtils as GuiUtils 18 20 from sasmodels.sasview_model import load_standard_models … … 202 204 self.cbOperator.currentText()) 203 205 204 success = GuiUtils.checkModel(self.plugin_filename) 206 try: 207 success = GuiUtils.checkModel(self.plugin_filename) 208 except Exception as ex: 209 # broad exception from sasmodels 210 msg = "Error building model: "+ str(ex) 211 logging.error(msg) 212 #print three last lines of the stack trace 213 # this will point out the exact line failing 214 last_lines = traceback.format_exc().split('\n')[-4:] 215 traceback_to_show = '\n'.join(last_lines) 216 logging.error(traceback_to_show) 217 218 # Set the status bar message 219 self.parent.communicate.statusBarUpdateSignal.emit("Model check failed") 220 return 205 221 206 222 if not success: -
src/sas/qtgui/Utilities/GuiUtils.py
r9463ca2 r6da3e3d 35 35 HELP_DIRECTORY_LOCATION = "docs/sphinx-docs/build/html" 36 36 IMAGES_DIRECTORY_LOCATION = HELP_DIRECTORY_LOCATION + "/_images" 37 38 # This matches the ID of a plot created using FittingLogic._create1DPlot, e.g. 39 # "5 [P(Q)] modelname" 40 # or 41 # "4 modelname". 42 # Useful for determining whether the plot in question is for an intermediate result, such as P(Q) or S(Q) in the 43 # case of a product model; the identifier for this is held in square brackets, as in the example above. 44 theory_plot_ID_pattern = re.compile(r"^([0-9]+)\s+(\[(.*)\]\s+)?(.*)$") 37 45 38 46 def get_app_dir(): … … 212 220 updateTheoryFromPerspectiveSignal = QtCore.pyqtSignal(QtGui.QStandardItem) 213 221 222 # Request to delete plots (in the theory view) related to a given model ID 223 deleteIntermediateTheoryPlotsSignal = QtCore.pyqtSignal(str) 224 214 225 # New plot requested from the GUI manager 215 226 # Old "NewPlotEvent" … … 260 271 # Fitting parameter paste from clipboard 261 272 pasteFitParamsSignal = QtCore.pyqtSignal() 273 262 274 # Notify about new categories/models from category manager 263 275 updateModelCategoriesSignal = QtCore.pyqtSignal() -
src/sas/qtgui/Utilities/LocalConfig.py
re4335ae rb764ae5 134 134 135 135 # Default threading model 136 USING_TWISTED = True136 USING_TWISTED = False 137 137 138 138 # Time out for updating sasview -
src/sas/qtgui/Utilities/ReportDialog.py
rce30949 rcb90b65 73 73 # Use a sensible filename default 74 74 default_name = os.path.join(location, 'fit_report.pdf') 75 75 76 kwargs = { 76 77 'parent' : self, 77 78 'caption' : 'Save Report', 78 'directory': default_name, 79 # don't use 'directory' in order to remember the previous user choice 80 #'directory': default_name, 79 81 'filter' : 'PDF file (*.pdf);;HTML file (*.html);;Text file (*.txt)', 80 82 'options' : QtWidgets.QFileDialog.DontUseNativeDialog} … … 99 101 100 102 # Create files with charts 101 pictures = self.getPictures(basename) 103 pictures = [] 104 if self.data_images is not None: 105 pictures = self.getPictures(basename) 102 106 103 107 # self.data_html contains all images at the end of the report, in base64 form; -
src/sas/qtgui/Utilities/UnitTesting/ReportDialogTest.py
r144fe21 rcb90b65 158 158 159 159 self.assertTrue(logging.error.called) 160 logging.error.assert_called_with("Error creating pdf: Failed")160 #logging.error.assert_called_with("Error creating pdf") 161 161
Note: See TracChangeset
for help on using the changeset viewer.