Ignore:
Timestamp:
Mar 17, 2017 8:58:33 AM (7 years ago)
Author:
Piotr Rozyczko <rozyczko@…>
Branches:
ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
Children:
7248d75d
Parents:
811bec1
Message:

Minor refactoring in the fitting widget

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/qtgui/Perspectives/Fitting/FittingWidget.py

    r811bec1 r4d457df  
    2020from sas.sasgui.guiframe.dataFitting import Data2D 
    2121import sas.qtgui.GuiUtils as GuiUtils 
    22 from sas.sascalc.dataloader.data_info import Detector 
    23 from sas.sascalc.dataloader.data_info import Source 
    2422from sas.sasgui.perspectives.fitting.model_thread import Calc1D 
    2523from sas.sasgui.perspectives.fitting.model_thread import Calc2D 
    2624 
    2725from UI.FittingWidgetUI import Ui_FittingWidgetUI 
     26from sas.qtgui.Perspectives.Fitting.FittingLogic import FittingLogic 
     27from sas.qtgui.Perspectives.Fitting import FittingUtilities 
    2828 
    2929TAB_MAGNETISM = 4 
    3030TAB_POLY = 3 
    3131CATEGORY_DEFAULT = "Choose category..." 
     32CATEGORY_STRUCTURE = "Structure Factor" 
    3233QMIN_DEFAULT = 0.0005 
    3334QMAX_DEFAULT = 0.5 
     
    7071 
    7172        # Main Data[12]D holder 
    72         self._data = None 
     73        self.logic = FittingLogic(data=data) 
    7374 
    7475        # Main GUI setup up 
     
    111112        self.cbCategory.addItem(CATEGORY_DEFAULT) 
    112113        self.cbCategory.addItems(category_list) 
    113         self.cbCategory.addItem("Structure Factor") 
     114        self.cbCategory.addItem(CATEGORY_STRUCTURE) 
    114115        self.cbCategory.setCurrentIndex(0) 
    115116 
     
    126127    @property 
    127128    def data(self): 
    128         return self._data 
     129        return self.logic.data 
    129130 
    130131    @data.setter 
    131132    def data(self, value): 
    132133        """ data setter """ 
     134        assert isinstance(value[0], QtGui.QStandardItem) 
    133135        # _index contains the QIndex with data 
    134136        self._index = value 
    135         # _data contains the actual Data[12]D 
    136         self._data = GuiUtils.dataFromItem(value[0]) 
     137        # Update logics with data items 
     138        self.logic.data = GuiUtils.dataFromItem(value[0]) 
     139 
    137140        self.data_is_loaded = True 
    138141        # Tag along functionality 
     
    169172        """ 
    170173        if self.data_is_loaded: 
    171             self.q_range_min, self.q_range_max, self.npts = self.computeDataRange(self.data) 
     174            self.q_range_min, self.q_range_max, self.npts = self.logic.computeDataRange() 
    172175        # set Q range labels on the main tab 
    173176        self.lblMinRangeDef.setText(str(self.q_range_min)) 
     
    227230        Fill in the structure factors combo box with defaults 
    228231        """ 
    229         structure_factor_list = self.master_category_dict.pop('Structure Factor') 
     232        structure_factor_list = self.master_category_dict.pop(CATEGORY_STRUCTURE) 
    230233        structure_factors = ["None"] 
    231234        self.cbStructureFactor.clear() 
     
    237240        Select Category from list 
    238241        """ 
    239         category = self.cbCategory.currentText() 
     242        category = str(self.cbCategory.currentText()) 
    240243        # Check if the user chose "Choose category entry" 
    241         if str(category) == CATEGORY_DEFAULT: 
     244        if category == CATEGORY_DEFAULT: 
    242245            # if the previous category was not the default, keep it. 
    243246            # Otherwise, just return 
     
    246249            return 
    247250 
    248         if category == "Structure Factor": 
     251        if category == CATEGORY_STRUCTURE: 
    249252            self.disableModelCombo() 
    250253            self.enableStructureCombo() 
     
    260263        self._previous_category_index = self.cbCategory.currentIndex() 
    261264        # Retrieve the list of models 
    262         model_list = self.master_category_dict[str(category)] 
     265        model_list = self.master_category_dict[category] 
    263266        models = [] 
    264267        # Populate the models combobox 
    265         for (model, _) in model_list: 
    266             models.append(model) 
    267         self.cbModel.addItems(sorted(models)) 
     268        self.cbModel.addItems(sorted([model for (model,_) in model_list])) 
     269 
     270    def createDefaultDataset(self): 
     271        """ 
     272        Generate default Dataset 1D/2D for the given model 
     273        """ 
     274        # Create default datasets if no data passed 
     275        if self.is2D: 
     276            qmax = self.q_range_max/numpy.sqrt(2) 
     277            qstep = self.npts 
     278            self.logic.createDefault2dData(qmax, qstep, self.tab_id) 
     279        else: 
     280            interval = numpy.linspace(start=self.q_range_min, stop=self.q_range_max, 
     281                        num=self.npts, endpoint=True) 
     282            self.logic.createDefault1dData(interval, self.tab_id) 
    268283 
    269284    def onSelectModel(self): 
     
    274289 
    275290        # SasModel -> QModel 
    276         self.setModelModel(model) 
     291        self.SASModelToQModel(model) 
    277292 
    278293        if self._index is None: 
    279294            # Create default datasets if no data passed 
    280             if self.is2D: 
    281                 self.createDefault2dData() 
    282             else: 
    283                 self.createDefault1dData() 
    284             # DESIGN: create the theory now or on Plot event? 
    285             #self.createTheoryIndex() 
     295            self.createDefaultDataset() 
    286296        else: 
    287             # Create datasets and errorbars for current data 
    288             if self.is2D: 
    289                 self.calculate2DForModel() 
    290             else: 
    291                 self.calculate1DForModel() 
    292             # TODO: attach the chart to index 
     297            self.calculateDataForModel() 
    293298 
    294299    def onSelectStructureFactor(self): 
     
    298303        model = str(self.cbModel.currentText()) 
    299304        structure = str(self.cbStructureFactor.currentText()) 
    300         self.setModelModel(model, structure_factor=structure) 
     305        self.SASModelToQModel(model, structure_factor=structure) 
    301306 
    302307    def readCategoryInfo(self): 
     
    332337                self.model_enabled_dict[model] = enabled 
    333338 
    334     def getIterParams(self, model): 
    335         """ 
    336         Returns a list of all multi-shell parameters in 'model' 
    337         """ 
    338         return list(filter(lambda par: "[" in par.name, model.iq_parameters)) 
    339  
    340     def getMultiplicity(self, model): 
    341         """ 
    342         Finds out if 'model' has multishell parameters. 
    343         If so, returns the name of the counter parameter and the number of shells 
    344         """ 
    345         iter_params = self.getIterParams(model) 
    346         # return the iterator parameter name and length 
    347         return (iter_params[0].length_control if iter_params else "", 
    348                 iter_params[0].length if iter_params else 0) 
    349  
    350339    def addBackgroundToModel(self, model): 
    351340        """ 
     
    354343        assert isinstance(model, QtGui.QStandardItemModel) 
    355344        checked_list = ['background', '0.001', '-inf', 'inf', '1/cm'] 
    356         self.addCheckedListToModel(model, checked_list) 
     345        FittingUtilities.addCheckedListToModel(model, checked_list) 
    357346 
    358347    def addScaleToModel(self, model): 
     
    362351        assert isinstance(model, QtGui.QStandardItemModel) 
    363352        checked_list = ['scale', '1.0', '0.0', 'inf', ''] 
    364         self.addCheckedListToModel(model, checked_list) 
    365  
    366     def addCheckedListToModel(self, model, param_list): 
    367         """ 
    368         Add a QItem to model. Makes the QItem checkable 
    369         """ 
    370         assert isinstance(model, QtGui.QStandardItemModel) 
    371         item_list = [QtGui.QStandardItem(item) for item in param_list] 
    372         item_list[0].setCheckable(True) 
    373         model.appendRow(item_list) 
    374  
    375     def addHeadersToModel(self, model): 
    376         """ 
    377         Adds predefined headers to the model 
    378         """ 
    379         model.setHeaderData(0, QtCore.Qt.Horizontal, QtCore.QVariant("Parameter")) 
    380         model.setHeaderData(1, QtCore.Qt.Horizontal, QtCore.QVariant("Value")) 
    381         model.setHeaderData(2, QtCore.Qt.Horizontal, QtCore.QVariant("Min")) 
    382         model.setHeaderData(3, QtCore.Qt.Horizontal, QtCore.QVariant("Max")) 
    383         model.setHeaderData(4, QtCore.Qt.Horizontal, QtCore.QVariant("[Units]")) 
    384  
    385     def addPolyHeadersToModel(self, model): 
    386         """ 
    387         Adds predefined headers to the model 
    388         """ 
    389         model.setHeaderData(0, QtCore.Qt.Horizontal, QtCore.QVariant("Parameter")) 
    390         model.setHeaderData(1, QtCore.Qt.Horizontal, QtCore.QVariant("PD[ratio]")) 
    391         model.setHeaderData(2, QtCore.Qt.Horizontal, QtCore.QVariant("Min")) 
    392         model.setHeaderData(3, QtCore.Qt.Horizontal, QtCore.QVariant("Max")) 
    393         model.setHeaderData(4, QtCore.Qt.Horizontal, QtCore.QVariant("Npts")) 
    394         model.setHeaderData(5, QtCore.Qt.Horizontal, QtCore.QVariant("Nsigs")) 
    395         model.setHeaderData(6, QtCore.Qt.Horizontal, QtCore.QVariant("Function")) 
    396  
    397     def setModelModel(self, model_name, structure_factor=None): 
     353        FittingUtilities.addCheckedListToModel(model, checked_list) 
     354 
     355    def SASModelToQModel(self, model_name, structure_factor=None): 
    398356        """ 
    399357        Setting model parameters into table based on selected category 
     
    413371 
    414372        # Update the QModel 
    415         self.addParametersToModel(self.model_parameters, self._model_model) 
    416         self.addHeadersToModel(self._model_model) 
     373        FittingUtilities.addParametersToModel(self.model_parameters, self._model_model) 
     374        # Update the counter used for multishell display 
     375        self._last_model_row = self._model_model.rowCount() 
     376 
     377        FittingUtilities.addHeadersToModel(self._model_model) 
    417378 
    418379        # Add structure factor 
     
    420381            structure_module = generate.load_kernel_module(structure_factor) 
    421382            structure_parameters = modelinfo.make_parameter_table(getattr(structure_module, 'parameters', [])) 
    422             self.addSimpleParametersToModel(structure_parameters, self._model_model) 
     383            FittingUtilities.addSimpleParametersToModel(structure_parameters, self._model_model) 
     384            # Update the counter used for multishell display 
     385            self._last_model_row = self._model_model.rowCount() 
    423386        else: 
    424387            self.addStructureFactor() 
     
    459422        # Reload the main model - may not be required if no variable is shown in main view 
    460423        #model = str(self.cbModel.currentText()) 
    461         #self.setModelModel(model) 
     424        #self.SASModelToQModel(model) 
    462425 
    463426        pass # debug anchor 
     
    499462        # multishell params in self.kernel_module.details[??] = value 
    500463 
    501     def computeDataRange(self, data): 
    502         """ 
    503         Compute the minimum and the maximum range of the data 
    504         return the npts contains in data 
    505         """ 
    506         assert data is not None 
    507         assert (isinstance(data, Data1D) or isinstance(data, Data2D)) 
    508         qmin, qmax, npts = None, None, None 
    509         if isinstance(data, Data1D): 
    510             try: 
    511                 qmin = min(data.x) 
    512                 qmax = max(data.x) 
    513                 npts = len(data.x) 
    514             except (ValueError, TypeError): 
    515                 msg = "Unable to find min/max/length of \n data named %s" % \ 
    516                             data.filename 
    517                 raise ValueError, msg 
    518  
    519         else: 
    520             qmin = 0 
    521             try: 
    522                 x = max(numpy.fabs(data.xmin), numpy.fabs(data.xmax)) 
    523                 y = max(numpy.fabs(data.ymin), numpy.fabs(data.ymax)) 
    524             except (ValueError, TypeError): 
    525                 msg = "Unable to find min/max of \n data named %s" % \ 
    526                             data.filename 
    527                 raise ValueError, msg 
    528             qmax = numpy.sqrt(x * x + y * y) 
    529             npts = len(data.data) 
    530         return qmin, qmax, npts 
    531  
    532     def addParametersToModel(self, parameters, model): 
    533         """ 
    534         Update local ModelModel with sasmodel parameters 
    535         """ 
    536         multishell_parameters = self.getIterParams(parameters) 
    537         multishell_param_name, _ = self.getMultiplicity(parameters) 
    538  
    539         for param in parameters.iq_parameters: 
    540             # don't include shell parameters 
    541             if param.name == multishell_param_name: 
    542                 continue 
    543             # Modify parameter name from <param>[n] to <param>1 
    544             item_name = param.name 
    545             if param in multishell_parameters: 
    546                 item_name = self.replaceShellName(param.name, 1) 
    547  
    548             item1 = QtGui.QStandardItem(item_name) 
    549             item1.setCheckable(True) 
    550             # check for polydisp params 
    551             if param.polydisperse: 
    552                 poly_item = QtGui.QStandardItem("Polydispersity") 
    553                 item1_1 = QtGui.QStandardItem("Distribution") 
    554                 # Find param in volume_params 
    555                 for p in parameters.form_volume_parameters: 
    556                     if p.name != param.name: 
    557                         continue 
    558                     item1_2 = QtGui.QStandardItem(str(p.default)) 
    559                     item1_3 = QtGui.QStandardItem(str(p.limits[0])) 
    560                     item1_4 = QtGui.QStandardItem(str(p.limits[1])) 
    561                     item1_5 = QtGui.QStandardItem(p.units) 
    562                     poly_item.appendRow([item1_1, item1_2, item1_3, item1_4, item1_5]) 
    563                     break 
    564                 # Add the polydisp item as a child 
    565                 item1.appendRow([poly_item]) 
    566             # Param values 
    567             item2 = QtGui.QStandardItem(str(param.default)) 
    568             # TODO: the error column. 
    569             # Either add a proxy model or a custom view delegate 
    570             #item_err = QtGui.QStandardItem() 
    571             item3 = QtGui.QStandardItem(str(param.limits[0])) 
    572             item4 = QtGui.QStandardItem(str(param.limits[1])) 
    573             item5 = QtGui.QStandardItem(param.units) 
    574             model.appendRow([item1, item2, item3, item4, item5]) 
    575  
    576         # Update the counter used for multishell display 
    577         self._last_model_row = self._model_model.rowCount() 
    578  
    579     def addSimpleParametersToModel(self, parameters, model): 
    580         """ 
    581         Update local ModelModel with sasmodel parameters 
    582         """ 
    583         for param in parameters.iq_parameters: 
    584             # Modify parameter name from <param>[n] to <param>1 
    585             item_name = param.name 
    586             item1 = QtGui.QStandardItem(item_name) 
    587             item1.setCheckable(True) 
    588             # Param values 
    589             item2 = QtGui.QStandardItem(str(param.default)) 
    590             # TODO: the error column. 
    591             # Either add a proxy model or a custom view delegate 
    592             #item_err = QtGui.QStandardItem() 
    593             item3 = QtGui.QStandardItem(str(param.limits[0])) 
    594             item4 = QtGui.QStandardItem(str(param.limits[1])) 
    595             item5 = QtGui.QStandardItem(param.units) 
    596             model.appendRow([item1, item2, item3, item4, item5]) 
    597  
    598         # Update the counter used for multishell display 
    599         self._last_model_row = self._model_model.rowCount() 
    600  
    601     def createDefault1dData(self): 
    602         """ 
    603         Create default data for fitting perspective 
    604         Only when the page is on theory mode. 
    605         """ 
    606         x = numpy.linspace(start=self.q_range_min, stop=self.q_range_max, 
    607                            num=self.npts, endpoint=True) 
    608         self._data = Data1D(x=x) 
    609         self._data.xaxis('\\rm{Q}', "A^{-1}") 
    610         self._data.yaxis('\\rm{Intensity}', "cm^{-1}") 
    611         self._data.is_data = False 
    612         self._data.id = str(self.tab_id) + " data" 
    613         self._data.group_id = str(self.tab_id) + " Model1D" 
    614  
    615     def createDefault2dData(self): 
    616         """ 
    617         Create 2D data by default 
    618         Only when the page is on theory mode. 
    619         """ 
    620         self._data = Data2D() 
    621         qmax = self.q_range_max / numpy.sqrt(2) 
    622         self._data.xaxis('\\rm{Q_{x}}', 'A^{-1}') 
    623         self._data.yaxis('\\rm{Q_{y}}', 'A^{-1}') 
    624         self._data.is_data = False 
    625         self._data.id = str(self.tab_id) + " data" 
    626         self._data.group_id = str(self.tab_id) + " Model2D" 
    627  
    628         # Default detector 
    629         self._data.detector.append(Detector()) 
    630         index = len(self._data.detector) - 1 
    631         self._data.detector[index].distance = 8000   # mm 
    632         self._data.source.wavelength = 6             # A 
    633         self._data.detector[index].pixel_size.x = 5  # mm 
    634         self._data.detector[index].pixel_size.y = 5  # mm 
    635         self._data.detector[index].beam_center.x = qmax 
    636         self._data.detector[index].beam_center.y = qmax 
    637         # theory default: assume the beam 
    638         #center is located at the center of sqr detector 
    639         xmax = qmax 
    640         xmin = -qmax 
    641         ymax = qmax 
    642         ymin = -qmax 
    643         qstep = self.npts 
    644  
    645         x = numpy.linspace(start=xmin, stop=xmax, num=qstep, endpoint=True) 
    646         y = numpy.linspace(start=ymin, stop=ymax, num=qstep, endpoint=True) 
    647         # Use data info instead 
    648         new_x = numpy.tile(x, (len(y), 1)) 
    649         new_y = numpy.tile(y, (len(x), 1)) 
    650         new_y = new_y.swapaxes(0, 1) 
    651  
    652         # all data required in 1d array 
    653         qx_data = new_x.flatten() 
    654         qy_data = new_y.flatten() 
    655         q_data = numpy.sqrt(qx_data * qx_data + qy_data * qy_data) 
    656  
    657         # set all True (standing for unmasked) as default 
    658         mask = numpy.ones(len(qx_data), dtype=bool) 
    659         # calculate the range of qx and qy: this way, 
    660         # it is a little more independent 
    661         # store x and y bin centers in q space 
    662         x_bins = x 
    663         y_bins = y 
    664  
    665         self._data.source = Source() 
    666         self._data.data = numpy.ones(len(mask)) 
    667         self._data.err_data = numpy.ones(len(mask)) 
    668         self._data.qx_data = qx_data 
    669         self._data.qy_data = qy_data 
    670         self._data.q_data = q_data 
    671         self._data.mask = mask 
    672         self._data.x_bins = x_bins 
    673         self._data.y_bins = y_bins 
    674         # max and min taking account of the bin sizes 
    675         self._data.xmin = xmin 
    676         self._data.xmax = xmax 
    677         self._data.ymin = ymin 
    678         self._data.ymax = ymax 
    679464 
    680465    def createTheoryIndex(self): 
     
    702487        """ 
    703488        # TODO: reimplement basepage.py/_update_paramv_on_fit 
    704         if self.data is None or not self._data.is_data: 
    705             self.createDefault2dData() if self.is2D else self.createDefault1dData() 
    706         self.calculate2DForModel() if self.is2D else self.calculate1DForModel() 
     489        if self.data is None or not self.data.is_data: 
     490            self.createDefaultDataset() 
     491        self.calculateDataForModel() 
    707492 
    708493    def onNpts(self, text): 
     
    740525        self.lblMaxRangeDef.setText(str(self.q_range_max)) 
    741526 
    742     def calculate1DForModel(self): 
     527    def methodCalculateForData(self): 
     528        '''return the method for data calculation''' 
     529        return Calc1D if isinstance(self.data, Data1D) else Calc2D 
     530 
     531    def methodCompleteForData(self): 
     532        '''return the method for result parsin on calc complete ''' 
     533        return self.complete1D if isinstance(self.data, Data1D) else self.complete2D 
     534 
     535    def calculateDataForModel(self): 
    743536        """ 
    744537        Prepare the fitting data object, based on current ModelModel 
    745538        """ 
    746         self.calc_1D = Calc1D(data=self.data, 
     539        # Awful API to a backend method. 
     540        method = self.methodCalculateForData()(data=self.data, 
    747541                              model=self.kernel_module, 
    748542                              page_id=0, 
     
    754548                              fid=None, 
    755549                              toggle_mode_on=False, 
    756                               completefn=self.complete1D, 
     550                              completefn=None, 
    757551                              update_chisqr=True, 
    758552                              exception_handler=self.calcException, 
    759553                              source=None) 
    760         # Instead of starting the thread with 
    761         #   self.calc_1D.queue() 
    762         # let's try running the async request 
    763         calc_thread = threads.deferToThread(self.calc_1D.compute) 
    764         calc_thread.addCallback(self.complete1D) 
     554 
     555        calc_thread = threads.deferToThread(method.compute) 
     556        calc_thread.addCallback(self.methodCompleteForData()) 
    765557 
    766558    def complete1D(self, return_data): 
    767559        """ 
    768         Plot the current data 
    769         """ 
    770         # Unpack return data from Calc1D 
    771         x, y, page_id, state, weight,\ 
    772         fid, toggle_mode_on, \ 
    773         elapsed, index, model,\ 
    774         data, update_chisqr, source = return_data 
    775  
    776         # Create the new plot 
    777         new_plot = Data1D(x=x, y=y) 
    778         new_plot.is_data = False 
    779         new_plot.dy = numpy.zeros(len(y)) 
    780         _yaxis, _yunit = data.get_yaxis() 
    781         _xaxis, _xunit = data.get_xaxis() 
    782         new_plot.title = data.name 
    783  
    784         new_plot.group_id = data.group_id 
    785         if new_plot.group_id == None: 
    786             new_plot.group_id = data.group_id 
    787         new_plot.id = str(self.tab_id) + " " + data.name 
    788         new_plot.name = model.name + " [" + data.name + "]" 
    789         new_plot.xaxis(_xaxis, _xunit) 
    790         new_plot.yaxis(_yaxis, _yunit) 
    791  
    792         # Assign the new Data1D object-wide 
    793         self._data = new_plot 
     560        Plot the current 1D data 
     561        """ 
     562        self.logic.new1DPlot(return_data) 
    794563        self.createTheoryIndex() 
    795564 
     
    800569        #                        index=index) 
    801570 
    802     def calculate2DForModel(self): 
    803         """ 
    804         Prepare the fitting data object, based on current ModelModel 
    805         """ 
    806         self.calc_2D = Calc2D(data=self.data, 
    807                               model=self.kernel_module, 
    808                               page_id=0, 
    809                               qmin=self.q_range_min, 
    810                               qmax=self.q_range_max, 
    811                               smearer=None, 
    812                               state=None, 
    813                               weight=None, 
    814                               fid=None, 
    815                               toggle_mode_on=False, 
    816                               completefn=self.complete2D, 
    817                               update_chisqr=True, 
    818                               exception_handler=self.calcException, 
    819                               source=None) 
    820  
    821         # Instead of starting the thread with 
    822         #    self.calc_2D.queue() 
    823         # let's try running the async request 
    824         calc_thread = threads.deferToThread(self.calc_2D.compute) 
    825         calc_thread.addCallback(self.complete2D) 
    826  
    827571    def complete2D(self, return_data): 
    828572        """ 
    829         Plot the current data 
    830         Should be a rewrite of fitting.py/_complete2D 
    831         """ 
    832         image, data, page_id, model, state, toggle_mode_on,\ 
    833         elapsed, index, fid, qmin, qmax, weight, \ 
    834         update_chisqr, source = return_data 
    835  
    836         numpy.nan_to_num(image) 
    837         new_plot = Data2D(image=image, err_image=data.err_data) 
    838         new_plot.name = model.name + '2d' 
    839         new_plot.title = "Analytical model 2D " 
    840         new_plot.id = str(page_id) + " " + data.name 
    841         new_plot.group_id = str(page_id) + " Model2D" 
    842         new_plot.detector = data.detector 
    843         new_plot.source = data.source 
    844         new_plot.is_data = False 
    845         new_plot.qx_data = data.qx_data 
    846         new_plot.qy_data = data.qy_data 
    847         new_plot.q_data = data.q_data 
    848         new_plot.mask = data.mask 
    849         ## plot boundaries 
    850         new_plot.ymin = data.ymin 
    851         new_plot.ymax = data.ymax 
    852         new_plot.xmin = data.xmin 
    853         new_plot.xmax = data.xmax 
    854  
    855         title = data.title 
    856  
    857         new_plot.is_data = False 
    858         if data.is_data: 
    859             data_name = str(data.name) 
    860         else: 
    861             data_name = str(model.__class__.__name__) + '2d' 
    862  
    863         if len(title) > 1: 
    864             new_plot.title = "Model2D for %s " % model.name + data_name 
    865         new_plot.name = model.name + " [" + \ 
    866                                     data_name + "]" 
    867  
    868         # Assign the new Data2D object-wide 
    869         self._data = new_plot 
     573        Plot the current 2D data 
     574        """ 
     575        self.logic.new2DPlot(return_data) 
    870576        self.createTheoryIndex() 
    871577 
     
    885591        msg = traceback.format_exception(etype, value, tb, limit=1) 
    886592 
    887     def replaceShellName(self, param_name, value): 
    888         """ 
    889         Updates parameter name from <param_name>[n_shell] to <param_name>value 
    890         """ 
    891         assert '[' in param_name 
    892         return param_name[:param_name.index('[')]+str(value) 
    893  
    894593    def setTableProperties(self, table): 
    895594        """ 
     
    927626                            str(param.limits[0]), str(param.limits[1]), 
    928627                            "35", "3", ""] 
    929             self.addCheckedListToModel(self._poly_model, checked_list) 
     628            FittingUtilities.addCheckedListToModel(self._poly_model, checked_list) 
    930629 
    931630            #TODO: Need to find cleaner way to input functions 
     
    935634            self.lstPoly.setIndexWidget(func_index, func) 
    936635 
    937         self.addPolyHeadersToModel(self._poly_model) 
     636        FittingUtilities.addPolyHeadersToModel(self._poly_model) 
    938637 
    939638    def setMagneticModel(self): 
     
    952651                            str(param.limits[1]), 
    953652                            param.units] 
    954             self.addCheckedListToModel(self._magnet_model, checked_list) 
    955  
    956         self.addHeadersToModel(self._magnet_model) 
     653            FittingUtilities.addCheckedListToModel(self._magnet_model, checked_list) 
     654 
     655        FittingUtilities.addHeadersToModel(self._magnet_model) 
    957656 
    958657    def addStructureFactor(self): 
     
    969668        Add a combobox for multiple shell display 
    970669        """ 
    971         param_name, param_length = self.getMultiplicity(self.model_parameters) 
     670        param_name, param_length = FittingUtilities.getMultiplicity(self.model_parameters) 
    972671 
    973672        if param_length == 0: 
     
    988687        shell_row = self._model_model.rowCount() 
    989688        shell_index = self._model_model.index(shell_row-1, 1) 
     689 
    990690        self.lstParams.setIndexWidget(shell_index, func) 
    991  
    992691        self._last_model_row = self._model_model.rowCount() 
    993692 
     
    1004703            self._model_model.removeRows(last_row, remove_rows) 
    1005704 
    1006         multishell_parameters = self.getIterParams(self.model_parameters) 
    1007  
    1008         for i in xrange(index): 
    1009             for par in multishell_parameters: 
    1010                 param_name = self.replaceShellName(par.name, i+2) 
    1011                 #param_name = str(p.name) + str(i+2) 
    1012                 item1 = QtGui.QStandardItem(param_name) 
    1013                 item1.setCheckable(True) 
    1014                 # check for polydisp params 
    1015                 if par.polydisperse: 
    1016                     poly_item = QtGui.QStandardItem("Polydispersity") 
    1017                     item1_1 = QtGui.QStandardItem("Distribution") 
    1018                     # Find param in volume_params 
    1019                     for p in self.model_parameters.form_volume_parameters: 
    1020                         if p.name != par.name: 
    1021                             continue 
    1022                         item1_2 = QtGui.QStandardItem(str(p.default)) 
    1023                         item1_3 = QtGui.QStandardItem(str(p.limits[0])) 
    1024                         item1_4 = QtGui.QStandardItem(str(p.limits[1])) 
    1025                         item1_5 = QtGui.QStandardItem(p.units) 
    1026                         poly_item.appendRow([item1_1, item1_2, item1_3, item1_4, item1_5]) 
    1027                         break 
    1028                     item1.appendRow([poly_item]) 
    1029  
    1030                 item2 = QtGui.QStandardItem(str(par.default)) 
    1031                 item3 = QtGui.QStandardItem(str(par.limits[0])) 
    1032                 item4 = QtGui.QStandardItem(str(par.limits[1])) 
    1033                 item5 = QtGui.QStandardItem(par.units) 
    1034                 self._model_model.appendRow([item1, item2, item3, item4, item5]) 
     705        FittingUtilities.addShellsToModel(self.model_parameters, self._model_model, index) 
    1035706 
    1036707    def togglePoly(self, isChecked): 
Note: See TracChangeset for help on using the changeset viewer.