Changeset 4cac8a47 in sasview for src/sas


Ignore:
Timestamp:
Oct 31, 2017 12:45:50 PM (6 years ago)
Author:
GitHub <noreply@…>
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:
7f5196e
Parents:
570a2f73 (diff), cd4f421 (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:
Jeff Krzywon <krzywon@…> (10/31/17 12:45:50)
git-committer:
GitHub <noreply@…> (10/31/17 12:45:50)
Message:

Merge pull request #115 from rprospero/ESS_DMAX

Dmax window for the P(r) perspective.

Location:
src/sas/qtgui
Files:
4 added
4 edited

Legend:

Unmodified
Added
Removed
  • src/sas/qtgui/Plotting/Plottables.py

    rdc5ef15 rbed08e7  
    227227            if p.hidden == True: 
    228228                continue 
    229             if not p.x == None: 
     229            if not p.x is None: 
    230230                for x_i in p.x: 
    231                     if min_value == None or x_i < min_value: 
     231                    if min_value is None or x_i < min_value: 
    232232                        min_value = x_i 
    233                     if max_value == None or x_i > max_value: 
     233                    if max_value is None or x_i > max_value: 
    234234                        max_value = x_i 
    235235        return min_value, max_value 
     
    560560        Returns True if there is no data stored in the plottable 
    561561        """ 
    562         if not self.x == None and len(self.x) == 0 \ 
    563             and not self.y == None and len(self.y) == 0: 
     562        if not self.x is None and len(self.x) == 0 \ 
     563            and not self.y is None and len(self.y) == 0: 
    564564            return True 
    565565        return False 
     
    795795        tempy = [] 
    796796        tempdy = [] 
    797         if self.dx == None: 
     797        if self.dx is None: 
    798798            self.dx = numpy.zeros(len(self.x)) 
    799         if self.dy == None: 
     799        if self.dy is None: 
    800800            self.dy = numpy.zeros(len(self.y)) 
    801801        if self.xLabel == "log10(x)": 
     
    825825        tempy = [] 
    826826        tempdy = [] 
    827         if self.dx == None: 
     827        if self.dx is None: 
    828828            self.dx = numpy.zeros(len(self.x)) 
    829         if self.dy == None: 
     829        if self.dy is None: 
    830830            self.dy = numpy.zeros(len(self.y)) 
    831831        if self.yLabel == "log10(y)": 
     
    858858        tempy = [] 
    859859        tempdy = [] 
    860         if self.dx == None: 
     860        if self.dx is None: 
    861861            self.dx = numpy.zeros(len(self.x)) 
    862         if self.dy == None: 
     862        if self.dy is None: 
    863863            self.dy = numpy.zeros(len(self.y)) 
    864864        if xmin != None and xmax != None: 
     
    12021202        """ 
    12031203        """ 
    1204         if  self._chisq == None: 
     1204        if  self._chisq is None: 
    12051205            chisqTxt = r'$\chi^2=$' 
    12061206        else: 
  • src/sas/qtgui/Perspectives/Inversion/InversionPerspective.py

    rd132f33 r570a2f73  
    2121 
    2222def is_float(value): 
     23    """Converts text input values to floats. Empty strings throw ValueError""" 
    2324    try: 
    2425        return float(value) 
     
    2627        return 0.0 
    2728 
     29 
     30# TODO: Remove data 
     31# TODO: Modify plot references, don't just send new 
     32# TODO: Explorer button - link to PR from AW 
     33# TODO: Update help with batch capabilities 
     34# TODO: Window should not be fixed size 
     35# TODO: Easy way to scroll through results - no tabs in window(?) - 'spreadsheet' 
     36# TODO: Method to export results in some meaningful way 
    2837class InversionWindow(QtGui.QTabWidget, Ui_PrInversion): 
    2938    """ 
     
    7180                self._data_list[datum] = self._calculator.clone() 
    7281 
    73         # plots 
     82        # plots for current data 
    7483        self.pr_plot = None 
    7584        self.data_plot = None 
     85        # plot references for all data in perspective 
     86        self.pr_plot_list = {} 
     87        self.data_plot_list = {} 
    7688 
    7789        self.model = QtGui.QStandardItemModel(self) 
     
    8395        # Set up the Widget Map 
    8496        self.setupMapper() 
     97        # Set base window state 
     98        self.setupWindow() 
    8599 
    86100    ###################################################################### 
     
    118132    def setupLinks(self): 
    119133        """Connect the use controls to their appropriate methods""" 
    120         self.enableButtons() 
    121134        self.dataList.currentIndexChanged.connect(self.displayChange) 
    122         self.calculateButton.clicked.connect(self._calculation) 
     135        self.calculateAllButton.clicked.connect(self.startThreadAll) 
     136        self.calculateThisButton.clicked.connect(self.startThread) 
    123137        self.helpButton.clicked.connect(self.help) 
    124138        self.estimateBgd.toggled.connect(self.toggleBgd) 
     
    149163                str(self.slitHeightInput.text())))) 
    150164        self.model.itemChanged.connect(self.model_changed) 
    151         self.estimateBgd.setChecked(True) 
    152165 
    153166    def setupMapper(self): 
     
    194207 
    195208        # Main Buttons 
    196         self.mapper.addMapping(self.calculateButton, WIDGETS.W_CALCULATE) 
     209        self.mapper.addMapping(self.calculateAllButton, WIDGETS.W_CALCULATE_ALL) 
     210        self.mapper.addMapping(self.calculateThisButton, 
     211                               WIDGETS.W_CALCULATE_VISIBLE) 
    197212        self.mapper.addMapping(self.helpButton, WIDGETS.W_HELP) 
    198213 
     
    238253        self.model.setItem(WIDGETS.W_SIGMA_POS_FRACTION, item) 
    239254 
     255    def setupWindow(self): 
     256        """Initialize base window state on init""" 
     257        self.setTabPosition(0) 
     258        self.enableButtons() 
     259        self.estimateBgd.setChecked(True) 
     260 
    240261    ###################################################################### 
    241262    # Methods for updating GUI 
     
    245266        Enable buttons when data is present, else disable them 
    246267        """ 
    247         if self.logic.data_is_loaded: 
    248             self.explorerButton.setEnabled(True) 
    249             self.calculateButton.setEnabled(True) 
    250         else: 
    251             self.calculateButton.setEnabled(False) 
    252             self.explorerButton.setEnabled(False) 
    253  
    254     def populateDataComboBox(self, filename): 
     268        self.explorerButton.setEnabled(self.logic.data_is_loaded) 
     269        self.calculateAllButton.setEnabled(self.logic.data_is_loaded) 
     270        self.calculateThisButton.setEnabled(self.logic.data_is_loaded) 
     271 
     272    def populateDataComboBox(self, filename, data_ref): 
    255273        """ 
    256274        Append a new file name to the data combobox 
     
    258276        """ 
    259277        qt_item = QtCore.QString.fromUtf8(filename) 
    260         self.dataList.addItem(qt_item) 
     278        ref = QtCore.QVariant(data_ref) 
     279        self.dataList.addItem(qt_item, ref) 
    261280 
    262281    def acceptNoTerms(self): 
     
    271290 
    272291    def displayChange(self): 
    273         data_name = str(self.dataList.currentText()) 
    274         # TODO: Find data ref based on file name 
    275         # TODO: Find way to link standardmodelitem with combobox entry 
     292        variant_ref = self.dataList.itemData(self.dataList.currentIndex()) 
     293        self.setCurrentData(variant_ref.toPyObject()) 
    276294 
    277295    ###################################################################### 
     
    284302        self._calculator.set_err(self._data_set.dy) 
    285303 
    286     def _calculation(self): 
    287         """ 
    288         Calculate the P(r) for every data set in the data list 
    289         """ 
    290         for data_ref, pr in self._data_list.items(): 
    291             self._data_set = GuiUtils.dataFromItem(data_ref) 
    292             self._calculator = pr 
    293             # Set data before running the calculations 
    294             self.update_calculator() 
    295             # Run 
    296             self.startThread() 
    297  
    298304    def model_changed(self): 
    299305        """Update the values when user makes changes""" 
    300306        if not self.mapper: 
    301             return 
     307            msg = "Unable to update P{r}. The connection between the main GUI " 
     308            msg += "and P(r) was severed. Attempting to restart P(r)." 
     309            logging.warning(msg) 
     310            self.setClosable(True) 
     311            self.close() 
     312            InversionWindow.__init__(self.parent(), self._data_list.keys()) 
     313            exit(0) 
     314        # TODO: Only send plot first time - otherwise, update in complete 
    302315        if self.pr_plot is not None: 
    303316            title = self.pr_plot.name 
     
    326339        """ 
    327340        Toggle the background between manual and estimated 
    328         :param item: gui item that was triggered 
    329341        """ 
    330342        sender = self.sender() 
     
    338350        Open the Explorer window to see correlations between params and results 
    339351        """ 
    340         # TODO: This depends on SVCC-45 
     352        # TODO: Look at PR from AW - Is there anything else I need to do? 
    341353        pass 
    342354 
     
    346358    def setData(self, data_item=None, is_batch=False): 
    347359        """ 
    348         Assign new data set or sets to the P(r) perspective 
    349         Obtain a QStandardItem object and dissect it to get Data1D/2D 
     360        Assign new data set(s) to the P(r) perspective 
     361        Obtain a QStandardItem object and parse it to get Data1D/2D 
    350362        Pass it over to the calculator 
    351363        """ 
     
    356368            raise AttributeError, msg 
    357369 
    358         if not isinstance(data_item[0], QtGui.QStandardItem): 
    359             msg = "Incorrect type passed to the P(r) Perspective" 
    360             raise AttributeError, msg 
    361  
    362370        for data in data_item: 
    363             # Data references 
    364             self._data = data 
     371            # Create initial internal mappings 
     372            self._data_list[data] = self._calculator.clone() 
    365373            self._data_set = GuiUtils.dataFromItem(data) 
    366             self.populateDataComboBox(self._data_set.filename) 
    367             self._data_list[self._data] = self._calculator 
     374            self.data_plot_list[data] = self.data_plot 
     375            self.pr_plot_list[data] = self.pr_plot 
     376            ref_var = QtCore.QVariant(data) 
     377            self.populateDataComboBox(self._data_set.filename, ref_var) 
     378            self.setCurrentData(data) 
    368379 
    369380            # Estimate initial values from data 
     
    378389                "{:.4g}".format(qmax))) 
    379390 
    380             self.enableButtons() 
     391        self.enableButtons() 
     392 
     393    def setCurrentData(self, data_ref): 
     394        """Get the current data and display as necessary""" 
     395 
     396        if not isinstance(data_ref, QtGui.QStandardItem): 
     397            msg = "Incorrect type passed to the P(r) Perspective" 
     398            raise AttributeError, msg 
     399 
     400        # Data references 
     401        self._data = data_ref 
     402        self._data_set = GuiUtils.dataFromItem(data_ref) 
     403        self._calculator = self._data_list[data_ref] 
     404        self.pr_plot = self.pr_plot_list[data_ref] 
     405        self.data_plot = self.data_plot_list[data_ref] 
    381406 
    382407    ###################################################################### 
    383408    # Thread Creators 
    384409 
     410    # TODO: Move to individual class(?) 
     411 
     412    def startThreadAll(self): 
     413        for data_ref, pr in self._data_list.items(): 
     414            self._data_set = GuiUtils.dataFromItem(data_ref) 
     415            self._calculator = pr 
     416            self.startThread() 
     417 
    385418    def startThread(self): 
    386419        """ 
     
    388421        """ 
    389422        from Thread import CalcPr 
     423 
     424        # Set data before running the calculations 
     425        self.update_calculator() 
    390426 
    391427        # If a thread is already started, stop it 
     
    431467        from Thread import EstimatePr 
    432468 
    433         self._calculation() 
     469        self.startThread() 
    434470 
    435471        # If a thread is already started, stop it 
     
    508544        # Show result on control panel 
    509545 
    510         # TODO: Connect self._calculator to GUI 
     546        # TODO: Connect self._calculator to GUI - two-to-one connection possible? 
    511547        self.model.setItem(WIDGETS.W_RG, QtGui.QStandardItem(str(pr.rg(out)))) 
    512548        self.model.setItem(WIDGETS.W_I_ZERO, 
     
    534570        self._data_list[self._data] = self._calculator.clone() 
    535571 
     572        # Create new P(r) and fit plots 
    536573        if self.pr_plot is None: 
    537574            self.pr_plot = self.logic.newPRPlot(out, self._calculator, cov) 
     575            self.pr_plot_list[self._data] = self.pr_plot 
     576        else: 
     577            # FIXME: this should update the existing plot, not create a new one 
     578            self.pr_plot = self.logic.newPRPlot(out, self._calculator, cov) 
     579            self.pr_plot_list[self._data] = self.pr_plot 
    538580        if self.data_plot is None: 
    539581            self.data_plot = self.logic.new1DPlot(out, self._calculator) 
     582            self.data_plot_list[self._data] = self.data_plot 
     583        else: 
     584            # FIXME: this should update the existing plot, not create a new one 
     585            self.data_plot = self.logic.new1DPlot(out, self._calculator) 
     586            self.data_plot_list[self._data] = self.data_plot 
    540587 
    541588    def _threadError(self, error): 
  • src/sas/qtgui/Perspectives/Inversion/InversionUtils.py

    re7651ff rc00a28ff  
    2727                'W_SIGMA_POS_FRACTION', 
    2828                # bottom buttons 
    29                 'W_CALCULATE', 
     29                'W_CALCULATE_ALL', 
     30                'W_CALCULATE_VISIBLE', 
    3031                'W_HELP' 
    3132) 
  • src/sas/qtgui/Perspectives/Inversion/UI/TabbedInversionUI.ui

    r57ad773 rc00a28ff  
    3939     </property> 
    4040     <item> 
    41       <widget class="QPushButton" name="calculateButton"> 
     41      <widget class="QPushButton" name="calculateThisButton"> 
     42       <property name="text"> 
     43        <string>Calculate</string> 
     44       </property> 
     45      </widget> 
     46     </item> 
     47     <item> 
     48      <widget class="QPushButton" name="calculateAllButton"> 
    4249       <property name="sizePolicy"> 
    4350        <sizepolicy hsizetype="Minimum" vsizetype="Fixed"> 
     
    4754       </property> 
    4855       <property name="text"> 
    49         <string>Calculate</string> 
     56        <string>Calculate All</string> 
    5057       </property> 
    5158      </widget> 
Note: See TracChangeset for help on using the changeset viewer.