Ignore:
Timestamp:
Jan 24, 2018 8:07:08 AM (6 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:
c6343a5
Parents:
eb1a386
Message:

Towards working C&S fits - SASVIEW-846

File:
1 edited

Legend:

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

    reb1a386 r116dd4c1  
    22import sys 
    33 
     4from twisted.internet import threads 
     5 
    46import sas.qtgui.Utilities.GuiUtils as GuiUtils 
    57from PyQt5 import QtGui, QtCore, QtWidgets 
    68 
     9from sas.sascalc.fit.BumpsFitting import BumpsFit as Fit 
     10 
    711import sas.qtgui.Utilities.ObjectLibrary as ObjectLibrary 
    8  
    912from sas.qtgui.Perspectives.Fitting.UI.ConstraintWidgetUI import Ui_ConstraintWidgetUI 
    1013from sas.qtgui.Perspectives.Fitting.FittingWidget import FittingWidget 
     14from sas.qtgui.Perspectives.Fitting.FitThread import FitThread 
     15from sas.qtgui.Perspectives.Fitting.ConsoleUpdate import ConsoleUpdate 
    1116from sas.qtgui.Perspectives.Fitting.ComplexConstraint import ComplexConstraint 
    1217from sas.qtgui.Perspectives.Fitting.Constraints import Constraint 
     
    1722    """ 
    1823 
    19     def __init__(self, parent=None): 
     24    def __init__(self, parent=None, tab_id=1): 
    2025        super(ConstraintWidget, self).__init__() 
    2126        self.parent = parent 
    2227        self.setupUi(self) 
    2328        self.currentType = "FitPage" 
     29        self.tab_id = tab_id 
     30        # Page id for fitting 
     31        # To keep with previous SasView values, use 300 as the start offset 
     32        self.page_id = 300 + self.tab_id 
    2433 
    2534        # Remember previous content of modified cell 
     
    114123        Perform the constrained/simultaneous fit 
    115124        """ 
    116         pass 
     125        # Find out all tabs to fit 
     126        tabs_to_fit = [tab for tab in self.tabs_for_fitting if self.tabs_for_fitting[tab]] 
     127 
     128        # Single fitter for the simultaneous run 
     129        sim_fitter = Fit() 
     130        sim_fitter.fitter_id = self.page_id 
     131 
     132        # prepare fitting problems for each tab 
     133        # 
     134        page_ids = [] 
     135        fitter_id = 0 
     136        sim_fitter=[sim_fitter] 
     137        for tab in tabs_to_fit: 
     138            tab_object = ObjectLibrary.getObject(tab) 
     139            sim_fitter, fitter_id = tab_object.prepareFitters(fitter=sim_fitter[0], fit_id=fitter_id) 
     140            page_ids.append([tab_object.page_id]) 
     141 
     142        # Create the fitting thread, based on the fitter 
     143        completefn = self.onBatchFitComplete if self.currentType=='BatchPage' else self.onFitComplete 
     144 
     145        #if USING_TWISTED: 
     146        handler = None 
     147        updater = None 
     148        #else: 
     149        #    handler = ConsoleUpdate(parent=self.parent, 
     150        #                            manager=self, 
     151        #                            improvement_delta=0.1) 
     152        #    updater = handler.update_fit 
     153 
     154        batch_inputs = {} 
     155        batch_outputs = {} 
     156 
     157        # new fit thread object 
     158        calc_fit = FitThread(handler=handler, 
     159                             fn=sim_fitter, 
     160                             batch_inputs=batch_inputs, 
     161                             batch_outputs=batch_outputs, 
     162                             page_id=page_ids, 
     163                             updatefn=updater, 
     164                             completefn=completefn) 
     165 
     166        #if USING_TWISTED: 
     167        # start the trhrhread with twisted 
     168        calc_thread = threads.deferToThread(calc_fit.compute) 
     169        calc_thread.addCallback(self.onFitComplete) 
     170        calc_thread.addErrback(self.onFitFailed) 
     171        #else: 
     172        #    # Use the old python threads + Queue 
     173        #    calc_fit.queue() 
     174        #    calc_fit.ready(2.5) 
     175 
     176 
     177        #disable the Fit button 
     178        self.cmdFit.setText('Running...') 
     179        self.parent.communicate.statusBarUpdateSignal.emit('Fitting started...') 
     180        self.cmdFit.setEnabled(False) 
    117181 
    118182    def onHelp(self): 
     
    172236    def onConstraintChange(self, row, column): 
    173237        """ 
    174         Modify the constraint in-place. 
     238        Modify the constraint's "active" instance variable. 
    175239        """ 
    176240        item = self.tblConstraints.item(row, column) 
     
    208272        pass 
    209273 
     274    def onFitComplete(self, result): 
     275        """ 
     276        Respond to the successful fit complete signal 
     277        """ 
     278        pass 
     279 
     280    def onBatchFitComplete(self, result): 
     281        """ 
     282        Respond to the successful batch fit complete signal 
     283        """ 
     284        pass 
     285 
     286    def onFitFailed(self, reason): 
     287        """ 
     288        """ 
     289        print("FIT FAILED: ", reason) 
     290        pass 
     291  
    210292    def isTabImportable(self, tab): 
    211293        """ 
Note: See TracChangeset for help on using the changeset viewer.