Changes in / [5e0891b:d4ba565] in sasview
- Location:
- src/sas/qtgui/Perspectives/Fitting
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Perspectives/Fitting/FittingLogic.py
rdcabba7 rdcabba7 161 161 Create a new 1D data instance based on fitting results 162 162 """ 163 163 164 return self._create1DPlot(tab_id, return_data['x'], return_data['y'], 164 165 return_data['model'], return_data['data']) … … 211 212 (pq_plot, sq_plot). If either are unavailable, the corresponding plot is None. 212 213 """ 213 plots = [] 214 for name, result in return_data['intermediate_results'].items(): 215 plots.append(self._create1DPlot(tab_id, return_data['x'], result, 216 return_data['model'], return_data['data'], 217 component=name)) 218 return plots 214 215 pq_plot = None 216 sq_plot = None 217 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)") 226 227 return pq_plot, sq_plot 219 228 220 229 def computeDataRange(self): -
src/sas/qtgui/Perspectives/Fitting/FittingUtilities.py
r70f4458 r70f4458 167 167 return rows 168 168 169 def addSimpleParametersToModel(parameters, is2D, parameters_original=None, model=None, view=None , row_num=None):169 def addSimpleParametersToModel(parameters, is2D, parameters_original=None, model=None, view=None): 170 170 """ 171 171 Update local ModelModel with sasmodel parameters (non-dispersed, non-magnetic) … … 216 216 # Append to the model and use the combobox, if required 217 217 if None not in (model, view): 218 if row_num is None: 219 model.appendRow(row) 220 else: 221 model.insertRow(row_num, row) 222 row_num += 1 223 218 model.appendRow(row) 224 219 if cbox: 225 220 view.setIndexWidget(item2.index(), cbox) 226 227 221 rows.append(row) 228 222 -
src/sas/qtgui/Perspectives/Fitting/FittingWidget.py
rd4ba565 rd4ba565 2102 2102 return 2103 2103 2104 product_params = None2105 2106 2104 if self.kernel_module is None: 2107 2105 # Structure factor is the only selected model; build it and show all its params … … 2109 2107 s_params = self.kernel_module._model_info.parameters 2110 2108 s_params_orig = s_params 2109 2111 2110 else: 2112 2111 s_kernel = self.models[structure_factor]() … … 2125 2124 if "radius_effective_mode" in all_param_names: 2126 2125 # Show all parameters 2127 # In this case, radius_effective is NOT pruned by sasmodels.product2128 2126 s_params = modelinfo.ParameterTable(all_params[p_pars_len:p_pars_len+s_pars_len]) 2129 2127 s_params_orig = modelinfo.ParameterTable(s_kernel._model_info.parameters.kernel_parameters) 2130 product_params = modelinfo.ParameterTable(2131 self.kernel_module._model_info.parameters.kernel_parameters[p_pars_len+s_pars_len:])2132 2128 else: 2133 2129 # Ensure radius_effective is not displayed 2134 2130 s_params_orig = modelinfo.ParameterTable(s_kernel._model_info.parameters.kernel_parameters[1:]) 2135 2131 if "radius_effective" in all_param_names: 2136 # In this case, radius_effective is NOT pruned by sasmodels.product2137 2132 s_params = modelinfo.ParameterTable(all_params[p_pars_len+1:p_pars_len+s_pars_len]) 2138 product_params = modelinfo.ParameterTable(2139 self.kernel_module._model_info.parameters.kernel_parameters[p_pars_len+s_pars_len:])2140 2133 else: 2141 # In this case, radius_effective is pruned by sasmodels.product2142 2134 s_params = modelinfo.ParameterTable(all_params[p_pars_len:p_pars_len+s_pars_len-1]) 2143 product_params = modelinfo.ParameterTable(2144 self.kernel_module._model_info.parameters.kernel_parameters[p_pars_len+s_pars_len-1:])2145 2135 2146 2136 # Add heading row … … 2150 2140 # Any renamed parameters are stored as data in the relevant item, for later handling 2151 2141 FittingUtilities.addSimpleParametersToModel( 2152 parameters=s_params, 2153 is2D=self.is2D, 2154 parameters_original=s_params_orig, 2155 model=self._model_model, 2156 view=self.lstParams) 2157 2158 # Insert product-only params into QModel 2159 if product_params: 2160 prod_rows = FittingUtilities.addSimpleParametersToModel( 2161 parameters=product_params, 2162 is2D=self.is2D, 2163 parameters_original=None, 2164 model=self._model_model, 2165 view=self.lstParams, 2166 row_num=2) 2167 2168 # Since this all happens after shells are dealt with and we've inserted rows, fix this counter 2169 self._n_shells_row += len(prod_rows) 2142 s_params, 2143 self.is2D, 2144 s_params_orig, 2145 self._model_model, 2146 self.lstParams) 2170 2147 2171 2148 def haveParamsToFit(self): … … 2428 2405 2429 2406 # Create plots for intermediate product data 2430 plots = self.logic.new1DProductPlots(return_data, self.tab_id) 2431 for plot in plots: 2432 plot.symbol = "Line" 2433 self.createNewIndex(plot) 2434 new_plots.append(plot) 2407 pq_data, sq_data = self.logic.new1DProductPlots(return_data, self.tab_id) 2408 if pq_data is not None: 2409 pq_data.symbol = "Line" 2410 self.createNewIndex(pq_data) 2411 # self.communicate.plotUpdateSignal.emit([pq_data]) 2412 new_plots.append(pq_data) 2413 if sq_data is not None: 2414 sq_data.symbol = "Line" 2415 self.createNewIndex(sq_data) 2416 # self.communicate.plotUpdateSignal.emit([sq_data]) 2417 new_plots.append(sq_data) 2435 2418 2436 2419 for plot in new_plots: … … 2833 2816 self._num_shell_params = len(new_rows) 2834 2817 self.current_shell_displayed = index 2835 2836 # Change 'n' in the parameter model, thereby updating the underlying model2837 self._model_model.item(self._n_shells_row, 1).setText(str(index))2838 2818 2839 2819 # Update relevant models -
src/sas/qtgui/Perspectives/Fitting/ModelThread.py
r5181e9b rdcabba7 164 164 index = (self.qmin <= self.data.x) & (self.data.x <= self.qmax) 165 165 166 intermediate_results = None167 168 166 # If we use a smearer, also return the unsmeared model 169 167 unsmeared_output = None … … 176 174 mask = self.data.x[first_bin:last_bin+1] 177 175 unsmeared_output = numpy.zeros((len(self.data.x))) 178 179 return_data = self.model.calculate_Iq(mask) 180 if isinstance(return_data, tuple): 181 # see sasmodels beta_approx: SasviewModel.calculate_Iq 182 # TODO: implement intermediate results in smearers 183 return_data, _ = return_data 184 unsmeared_output[first_bin:last_bin+1] = return_data 176 unsmeared_output[first_bin:last_bin+1] = self.model.evalDistribution(mask) 185 177 output = self.smearer(unsmeared_output, first_bin, last_bin) 186 178 … … 201 193 unsmeared_error=unsmeared_error 202 194 else: 203 return_data = self.model.calculate_Iq(self.data.x[index]) 204 if isinstance(return_data, tuple): 205 # see sasmodels beta_approx: SasviewModel.calculate_Iq 206 return_data, intermediate_results = return_data 207 output[index] = return_data 208 209 if intermediate_results: 210 # the model returns a callable which is then used to retrieve the data 211 intermediate_results = intermediate_results() 212 else: 213 # TODO: this conditional branch needs refactoring 214 sq_values = None 215 pq_values = None 216 s_model = None 217 p_model = None 218 219 if isinstance(self.model, MultiplicationModel): 220 s_model = self.model.s_model 221 p_model = self.model.p_model 222 223 elif hasattr(self.model, "calc_composition_models"): 224 results = self.model.calc_composition_models(self.data.x[index]) 225 if results is not None: 226 pq_values, sq_values = results 227 228 if pq_values is None or sq_values is None: 229 if p_model is not None and s_model is not None: 230 sq_values = numpy.zeros((len(self.data.x))) 231 pq_values = numpy.zeros((len(self.data.x))) 232 sq_values[index] = s_model.evalDistribution(self.data.x[index]) 233 pq_values[index] = p_model.evalDistribution(self.data.x[index]) 234 235 if pq_values is not None and sq_values is not None: 236 intermediate_results = { 237 "P(Q)": pq_values, 238 "S(Q)": sq_values 239 } 240 else: 241 intermediate_results = {} 195 output[index] = self.model.evalDistribution(self.data.x[index]) 196 197 sq_values = None 198 pq_values = None 199 s_model = None 200 p_model = None 201 if isinstance(self.model, MultiplicationModel): 202 s_model = self.model.s_model 203 p_model = self.model.p_model 204 elif hasattr(self.model, "calc_composition_models"): 205 results = self.model.calc_composition_models(self.data.x[index]) 206 if results is not None: 207 pq_values, sq_values = results 208 209 if pq_values is None or sq_values is None: 210 if p_model is not None and s_model is not None: 211 sq_values = numpy.zeros((len(self.data.x))) 212 pq_values = numpy.zeros((len(self.data.x))) 213 sq_values[index] = s_model.evalDistribution(self.data.x[index]) 214 pq_values[index] = p_model.evalDistribution(self.data.x[index]) 242 215 243 216 elapsed = time.time() - self.starttime … … 250 223 source = self.source, unsmeared_output = unsmeared_output, 251 224 unsmeared_data = unsmeared_data, unsmeared_error = unsmeared_error, 252 intermediate_results = intermediate_results)225 pq_values = pq_values, sq_values = sq_values) 253 226 254 227 if LocalConfig.USING_TWISTED:
Note: See TracChangeset
for help on using the changeset viewer.