Ignore:
Timestamp:
Aug 30, 2016 1:05:36 PM (8 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, 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, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
b61bd57
Parents:
86eb046
Message:

fix 'invalid Q range' when parameter value is min or max. Fixes #636

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sasgui/perspectives/fitting/basepage.py

    re4c897b ree4b3cb  
    15041504            is_2Ddata = True 
    15051505        if self.model != None: 
    1506             try: 
    1507                 is_modified = self._check_value_enter(self.fittable_param, 
    1508                                                       is_modified) 
    1509                 is_modified = self._check_value_enter(self.fixed_param, 
    1510                                                       is_modified) 
    1511                 is_modified = self._check_value_enter(self.parameters, 
    1512                                                       is_modified) 
    1513             except Exception: 
    1514                 logging.error(traceback.format_exc()) 
     1506            is_modified = (self._check_value_enter(self.fittable_param) 
     1507                           or self._check_value_enter(self.fixed_param) 
     1508                           or self._check_value_enter(self.parameters)) 
    15151509 
    15161510            # Here we should check whether the boundaries have been modified. 
     
    15611555        flag = True 
    15621556        self.fitrange = True 
    1563         is_modified = False 
    15641557 
    15651558        #wx.PostEvent(self._manager.parent, StatusEvent(status=" \ 
     
    15741567                                                                [self.data]) 
    15751568            ##Check the values 
    1576             self._check_value_enter(self.fittable_param, is_modified) 
    1577             self._check_value_enter(self.fixed_param, is_modified) 
    1578             self._check_value_enter(self.parameters, is_modified) 
     1569            self._check_value_enter(self.fittable_param) 
     1570            self._check_value_enter(self.fixed_param) 
     1571            self._check_value_enter(self.parameters) 
    15791572 
    15801573            # If qmin and qmax have been modified, update qmin and qmax and 
     
    16601653        return flag 
    16611654 
    1662     def _is_modified(self, is_modified): 
    1663         """ 
    1664         return to self._is_modified 
    1665         """ 
    1666         return is_modified 
    1667  
    16681655    def _reset_parameters_state(self, listtorestore, statelist): 
    16691656        """ 
     
    19641951        wx.PostEvent(self.parent, StatusEvent(status=msg)) 
    19651952        # Flag to register when a parameter has changed. 
    1966         #is_modified = False 
    19671953        if tcrtl.GetValue().lstrip().rstrip() != "": 
    19681954            try: 
     
    19941980                    if temp_npts != self.num_points: 
    19951981                        self.num_points = temp_npts 
    1996                         #is_modified = True 
    19971982                else: 
    19981983                    msg = "Cannot plot: No points in Q range!!!  " 
     
    21702155        self.Layout() 
    21712156 
     2157 
    21722158    def _validate_qrange(self, qmin_ctrl, qmax_ctrl): 
    21732159        """ 
     
    22762262        return flag 
    22772263 
    2278     def _check_value_enter(self, list, modified): 
     2264    def _check_value_enter(self, list): 
    22792265        """ 
    22802266        :param list: model parameter and panel info 
     
    22862272                parameter's maximum value , 
    22872273                parameter's units] 
    2288         """ 
    2289         is_modified = modified 
    2290         if len(list) == 0: 
    2291             return is_modified 
     2274 
     2275        Returns True if the model parameters have changed. 
     2276        """ 
     2277        is_modified = False 
    22922278        for item in list: 
    22932279            #skip angle parameters for 1D 
    2294             if not self.enable2D: 
    2295                 if item in self.orientation_params: 
    2296                     continue 
    2297             #try: 
     2280            if not self.enable2D and item in self.orientation_params: 
     2281                continue 
     2282 
    22982283            name = str(item[1]) 
    2299  
    2300             if string.find(name, ".npts") == -1 and \ 
    2301                                         string.find(name, ".nsigmas") == -1: 
    2302                 ## check model parameters range 
    2303                 param_min = None 
    2304                 param_max = None 
    2305  
    2306                 ## check minimun value 
    2307                 if item[5] != None and item[5] != "": 
    2308                     if item[5].GetValue().lstrip().rstrip() != "": 
    2309                         try: 
    2310                             param_min = float(item[5].GetValue()) 
    2311                             if not self._validate_qrange(item[5], item[2]): 
    2312                                 if numpy.isfinite(param_min): 
    2313                                     item[2].SetValue(format_number(param_min)) 
    2314  
    2315                             item[5].SetBackgroundColour(wx.WHITE) 
    2316                             item[2].SetBackgroundColour(wx.WHITE) 
    2317  
    2318                         except: 
    2319                             msg = "Wrong fit parameter range entered" 
    2320                             wx.PostEvent(self._manager.parent, 
    2321                                          StatusEvent(status=msg)) 
    2322                             raise ValueError, msg 
    2323                         is_modified = True 
    2324                 ## check maximum value 
    2325                 if item[6] != None and item[6] != "": 
    2326                     if item[6].GetValue().lstrip().rstrip() != "": 
    2327                         try: 
    2328                             param_max = float(item[6].GetValue()) 
    2329                             if not self._validate_qrange(item[2], item[6]): 
    2330                                 if numpy.isfinite(param_max): 
    2331                                     item[2].SetValue(format_number(param_max)) 
    2332  
    2333                             item[6].SetBackgroundColour(wx.WHITE) 
    2334                             item[2].SetBackgroundColour(wx.WHITE) 
    2335                         except: 
    2336                             msg = "Wrong Fit parameter range entered " 
    2337                             wx.PostEvent(self._manager.parent, 
    2338                                          StatusEvent(status=msg)) 
    2339                             raise ValueError, msg 
    2340                         is_modified = True 
    2341  
    2342                 if param_min != None and param_max != None: 
    2343                     if not self._validate_qrange(item[5], item[6]): 
    2344                         msg = "Wrong Fit range entered for parameter " 
    2345                         msg += "name %s of model %s " % (name, self.model.name) 
    2346                         wx.PostEvent(self._manager.parent, 
    2347                                      StatusEvent(status=msg)) 
    2348  
    2349                 if name in self.model.details.keys(): 
    2350                     self.model.details[name][1:3] = param_min, param_max 
    2351                     is_modified = True 
    2352                 else: 
    2353                     self.model.details[name] = ["", param_min, param_max] 
    2354                     is_modified = True 
    2355             try: 
    2356                 # Check if the textctr is enabled 
    2357                 if item[2].IsEnabled(): 
    2358                     value = float(item[2].GetValue()) 
    2359                     item[2].SetBackgroundColour("white") 
    2360                     # If the value of the parameter has changed, 
    2361                     # +update the model and set the is_modified flag 
    2362                     if value != self.model.getParam(name) and \ 
    2363                                                 numpy.isfinite(value): 
    2364                         self.model.setParam(name, value) 
    2365             except: 
    2366                 item[2].SetBackgroundColour("pink") 
    2367                 msg = "Wrong Fit parameter value entered " 
    2368                 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 
     2284            if name.endswith(".npts") or name.endswith(".nsigmas"): 
     2285                continue 
     2286 
     2287            # Check that min, max and value are floats 
     2288            value_ctrl, min_ctrl, max_ctrl = item[2], item[5], item[6] 
     2289            min_str = min_ctrl.GetValue().strip() 
     2290            max_str = max_ctrl.GetValue().strip() 
     2291            value_str = value_ctrl.GetValue().strip() 
     2292            validity = check_float(value_ctrl) 
     2293            if min_str != "": 
     2294                validity = validity and check_float(min_ctrl) 
     2295            if max_str != "": 
     2296                validity = validity and check_float(max_ctrl) 
     2297            if not validity: 
     2298                continue 
     2299 
     2300            # Check that min is less than max 
     2301            low = -numpy.inf if min_str == "" else float(min_str) 
     2302            high = numpy.inf if max_str == "" else float(max_str) 
     2303            if high < low: 
     2304                min_ctrl.SetBackgroundColour("pink") 
     2305                min_ctrl.Refresh() 
     2306                max_ctrl.SetBackgroundColour("pink") 
     2307                max_ctrl.Refresh() 
     2308                #msg = "Invalid fit range for %s: min must be smaller than max"%name 
     2309                #wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 
     2310                continue 
     2311 
     2312            # Force value between min and max 
     2313            value = float(value_str) 
     2314            if value < low: 
     2315                value = low 
     2316                value_ctrl.SetValue(format_number(value)) 
     2317            elif value > high: 
     2318                value = high 
     2319                value_ctrl.SetValue(format_number(value)) 
     2320 
     2321            # Update value in model if it has changed 
     2322            if value != self.model.getParam(name): 
     2323                self.model.setParam(name, value) 
     2324                is_modified = True 
     2325 
     2326            if name not in self.model.details.keys(): 
     2327                self.model.details[name] = ["", None, None] 
     2328            old_low, old_high = self.model.details[name][1:3] 
     2329            if old_low != low or old_high != high: 
     2330                # The configuration has changed but it won't change the 
     2331                # computed curve so no need to set is_modified to True 
     2332                #is_modified = True 
     2333                self.model.details[name][1:3] = low, high 
    23692334 
    23702335        return is_modified 
Note: See TracChangeset for help on using the changeset viewer.