Ignore:
Timestamp:
Jul 24, 2017 8:27:05 AM (7 years ago)
Author:
krzywon
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, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
146c669
Parents:
b61bd57 (diff), bc04647 (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.
Message:

Merge branch 'master' into 4_1_issues

# Conflicts:
# docs/sphinx-docs/source/conf.py
# src/sas/sascalc/dataloader/readers/cansas_reader.py
# src/sas/sasgui/guiframe/documentation_window.py
# src/sas/sasgui/perspectives/fitting/models.py

Location:
src/sas/sasgui/perspectives/fitting
Files:
11 edited

Legend:

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

    rb301db9 r914c49d5  
    22Base Page for fitting 
    33""" 
     4from __future__ import print_function 
     5 
    46import sys 
    57import os 
    68import wx 
    7 import numpy 
     9import numpy as np 
    810import time 
    911import copy 
     
    3436from sas.sasgui.guiframe.documentation_window import DocumentationWindow 
    3537 
     38logger = logging.getLogger(__name__) 
    3639 
    3740(PageInfoEvent, EVT_PAGE_INFO) = wx.lib.newevent.NewEvent() 
     
    100103        self.graph_id = None 
    101104        # Q range for data set 
    102         self.qmin_data_set = numpy.inf 
     105        self.qmin_data_set = np.inf 
    103106        self.qmax_data_set = None 
    104107        self.npts_data_set = 0 
     
    251254        if not hasattr(self, "model_view"): 
    252255            return 
    253         toggle_mode_on = self.model_view.IsEnabled() 
     256        toggle_mode_on = self.model_view.IsEnabled() or self.data is None 
    254257        if toggle_mode_on: 
    255258            if self.enable2D and not check_data_validity(self.data): 
     
    278281 
    279282        """ 
    280         x = numpy.linspace(start=self.qmin_x, stop=self.qmax_x, 
     283        x = np.linspace(start=self.qmin_x, stop=self.qmax_x, 
    281284                           num=self.npts_x, endpoint=True) 
    282285        self.data = Data1D(x=x) 
     
    295298        """ 
    296299        if self.qmin_x >= 1.e-10: 
    297             qmin = numpy.log10(self.qmin_x) 
     300            qmin = np.log10(self.qmin_x) 
    298301        else: 
    299302            qmin = -10. 
    300303 
    301304        if self.qmax_x <= 1.e10: 
    302             qmax = numpy.log10(self.qmax_x) 
     305            qmax = np.log10(self.qmax_x) 
    303306        else: 
    304307            qmax = 10. 
    305308 
    306         x = numpy.logspace(start=qmin, stop=qmax, 
     309        x = np.logspace(start=qmin, stop=qmax, 
    307310                           num=self.npts_x, endpoint=True, base=10.0) 
    308311        self.data = Data1D(x=x) 
     
    341344        qstep = self.npts_x 
    342345 
    343         x = numpy.linspace(start=xmin, stop=xmax, num=qstep, endpoint=True) 
    344         y = numpy.linspace(start=ymin, stop=ymax, num=qstep, endpoint=True) 
     346        x = np.linspace(start=xmin, stop=xmax, num=qstep, endpoint=True) 
     347        y = np.linspace(start=ymin, stop=ymax, num=qstep, endpoint=True) 
    345348        # use data info instead 
    346         new_x = numpy.tile(x, (len(y), 1)) 
    347         new_y = numpy.tile(y, (len(x), 1)) 
     349        new_x = np.tile(x, (len(y), 1)) 
     350        new_y = np.tile(y, (len(x), 1)) 
    348351        new_y = new_y.swapaxes(0, 1) 
    349352        # all data reuire now in 1d array 
    350353        qx_data = new_x.flatten() 
    351354        qy_data = new_y.flatten() 
    352         q_data = numpy.sqrt(qx_data * qx_data + qy_data * qy_data) 
     355        q_data = np.sqrt(qx_data * qx_data + qy_data * qy_data) 
    353356        # set all True (standing for unmasked) as default 
    354         mask = numpy.ones(len(qx_data), dtype=bool) 
     357        mask = np.ones(len(qx_data), dtype=bool) 
    355358        # store x and y bin centers in q space 
    356359        x_bins = x 
     
    358361 
    359362        self.data.source = Source() 
    360         self.data.data = numpy.ones(len(mask)) 
    361         self.data.err_data = numpy.ones(len(mask)) 
     363        self.data.data = np.ones(len(mask)) 
     364        self.data.err_data = np.ones(len(mask)) 
    362365        self.data.qx_data = qx_data 
    363366        self.data.qy_data = qy_data 
     
    656659        # It seems MAC needs wxCallAfter 
    657660        if event.GetId() == GUIFRAME_ID.COPYEX_ID: 
    658             print "copy excel" 
     661            print("copy excel") 
    659662            wx.CallAfter(self.get_copy_excel) 
    660663        elif event.GetId() == GUIFRAME_ID.COPYLAT_ID: 
    661             print "copy latex" 
     664            print("copy latex") 
    662665            wx.CallAfter(self.get_copy_latex) 
    663666        else: 
     
    782785                except Exception: 
    783786                    # Skip non-data lines 
    784                     logging.error(traceback.format_exc()) 
    785             return numpy.array(angles), numpy.array(weights) 
     787                    logger.error(traceback.format_exc()) 
     788            return np.array(angles), np.array(weights) 
    786789        except: 
    787790            raise 
     
    13041307                    [state.values, state.weights] 
    13051308            except Exception: 
    1306                 logging.error(traceback.format_exc()) 
     1309                logger.error(traceback.format_exc()) 
    13071310            selection = self._find_polyfunc_selection(disp_model) 
    13081311            for list in self.fittable_param: 
     
    13211324                            list[6].Disable() 
    13221325                        except Exception: 
    1323                             logging.error(traceback.format_exc()) 
     1326                            logger.error(traceback.format_exc()) 
    13241327            # For array, disable all fixed params 
    13251328            if selection == 1: 
     
    13301333                            item[2].Disable() 
    13311334                        except Exception: 
    1332                             logging.error(traceback.format_exc()) 
     1335                            logger.error(traceback.format_exc()) 
    13331336 
    13341337    def _selectDlg(self): 
     
    14491452                self.state_change = True 
    14501453                self._draw_model() 
    1451                 # Time delay has been introduced to prevent _handle error 
    1452                 # on Windows 
    1453                 # This part of code is executed when model is selected and 
    1454                 # it's parameters are changed (with respect to previously 
    1455                 # selected model). There are two Iq evaluations occuring one 
    1456                 # after another and therefore there may be compilation error 
    1457                 # if model is calculated for the first time. 
    1458                 # This seems to be Windows only issue - haven't tested on Linux 
    1459                 # though.The proper solution (other than time delay) requires 
    1460                 # more fundemental code refatoring 
    1461                 # Wojtek P. Nov 7, 2016 
    1462                 if not ON_MAC: 
    1463                     time.sleep(0.1) 
    14641454                self.Refresh() 
    14651455 
    1466         # logging.info("is_modified flag set to %g",is_modified) 
     1456        # logger.info("is_modified flag set to %g",is_modified) 
    14671457        return is_modified 
    14681458 
     
    15691559            self.save_current_state() 
    15701560        except Exception: 
    1571             logging.error(traceback.format_exc()) 
     1561            logger.error(traceback.format_exc()) 
    15721562 
    15731563        return flag, is_modified 
     
    21202110        for data in self.data_list: 
    21212111            # q value from qx and qy 
    2122             radius = numpy.sqrt(data.qx_data * data.qx_data + 
     2112            radius = np.sqrt(data.qx_data * data.qx_data + 
    21232113                                data.qy_data * data.qy_data) 
    21242114            # get unmasked index 
     
    21262116                         (radius <= float(self.qmax.GetValue())) 
    21272117            index_data = (index_data) & (data.mask) 
    2128             index_data = (index_data) & (numpy.isfinite(data.data)) 
     2118            index_data = (index_data) & (np.isfinite(data.data)) 
    21292119 
    21302120            if len(index_data[index_data]) < 10: 
     
    21612151            index_data = (float(self.qmin.GetValue()) <= radius) & \ 
    21622152                         (radius <= float(self.qmax.GetValue())) 
    2163             index_data = (index_data) & (numpy.isfinite(data.y)) 
     2153            index_data = (index_data) & (np.isfinite(data.y)) 
    21642154 
    21652155            if len(index_data[index_data]) < 5: 
     
    22332223 
    22342224                # Check that min is less than max 
    2235                 low = -numpy.inf if min_str == "" else float(min_str) 
    2236                 high = numpy.inf if max_str == "" else float(max_str) 
     2225                low = -np.inf if min_str == "" else float(min_str) 
     2226                high = np.inf if max_str == "" else float(max_str) 
    22372227                if high < low: 
    22382228                    min_ctrl.SetBackgroundColour("pink") 
     
    23842374                    self.model.set_dispersion(p, disp_model) 
    23852375                except Exception: 
    2386                     logging.error(traceback.format_exc()) 
     2376                    logger.error(traceback.format_exc()) 
    23872377 
    23882378        # save state into 
     
    24992489            self.Refresh() 
    25002490        except Exception: 
    2501             logging.error(traceback.format_exc()) 
     2491            logger.error(traceback.format_exc()) 
    25022492            # Error msg 
    25032493            msg = "Error occurred:" 
     
    26002590                del self.state.model._persistency_dict[name.split('.')[0]] 
    26012591        except Exception: 
    2602             logging.error(traceback.format_exc()) 
     2592            logger.error(traceback.format_exc()) 
    26032593 
    26042594    def _lay_out(self): 
     
    26092599            Layout is called after fitting. 
    26102600        """ 
    2611         self._sleep4sec() 
    26122601        self.Layout() 
    26132602        return 
    2614  
    2615     def _sleep4sec(self): 
    2616         """ 
    2617             sleep for 1 sec only applied on Mac 
    2618             Note: This 1sec helps for Mac not to crash on self. 
    2619             Layout after self._draw_model 
    2620         """ 
    2621         if ON_MAC: 
    2622             time.sleep(1) 
    26232603 
    26242604    def _find_polyfunc_selection(self, disp_func=None): 
     
    26542634            self.qmin_x = data_min 
    26552635            self.qmax_x = math.sqrt(x * x + y * y) 
    2656             # self.data.mask = numpy.ones(len(self.data.data),dtype=bool) 
     2636            # self.data.mask = np.ones(len(self.data.data),dtype=bool) 
    26572637            # check smearing 
    26582638            if not self.disable_smearer.GetValue(): 
     
    27422722            except Exception: 
    27432723                # Not for control panels 
    2744                 logging.error(traceback.format_exc()) 
     2724                logger.error(traceback.format_exc()) 
    27452725        # Make sure the resduals plot goes to the last 
    27462726        if res_item is not None: 
     
    30753055                    disfunc = str(item[7].GetValue()) 
    30763056            except Exception: 
    3077                 logging.error(traceback.format_exc()) 
     3057                logger.error(traceback.format_exc()) 
    30783058 
    30793059            # 2D 
     
    31183098                        disfunc += ' ' + str(weight) 
    31193099            except Exception: 
    3120                 logging.error(traceback.format_exc()) 
     3100                logger.error(traceback.format_exc()) 
    31213101            content += name + ',' + str(check) + ',' + value + disfunc + ',' + \ 
    31223102                       bound_lo + ',' + bound_hi + ':' 
     
    33663346 
    33673347            if value[1] == 'array': 
    3368                 pd_vals = numpy.array(value[2]) 
    3369                 pd_weights = numpy.array(value[3]) 
     3348                pd_vals = np.array(value[2]) 
     3349                pd_weights = np.array(value[3]) 
    33703350                if len(pd_vals) == 0 or len(pd_vals) != len(pd_weights): 
    33713351                    msg = ("bad array distribution parameters for %s" 
     
    33893369 
    33903370        except Exception: 
    3391             logging.error(traceback.format_exc()) 
    3392             print "Error in BasePage._paste_poly_help: %s" % \ 
    3393                   sys.exc_info()[1] 
     3371            logger.error(traceback.format_exc()) 
     3372            print("Error in BasePage._paste_poly_help: %s" % \ 
     3373                  sys.exc_info()[1]) 
    33943374 
    33953375    def _set_disp_cb(self, isarray, item): 
     
    34203400            Moveit; This method doesn't belong here 
    34213401        """ 
    3422         print "BasicPage.update_pinhole_smear was called: skipping" 
     3402        print("BasicPage.update_pinhole_smear was called: skipping") 
    34233403        return 
    34243404 
     
    35963576        # check model type to show sizer 
    35973577        if self.model is not None: 
    3598             print "_set_model_sizer_selection: disabled." 
     3578            print("_set_model_sizer_selection: disabled.") 
    35993579            # self._set_model_sizer_selection(self.model) 
    36003580 
  • src/sas/sasgui/perspectives/fitting/batchfitpage.py

    ree4b3cb r7432acb  
    200200#         self.state.formfactorcombobox = self.formfactorbox.GetCurrentSelection() 
    201201#        
    202 #         if self.model != None: 
     202#         if self.model is not None: 
    203203#             self._set_copy_flag(True) 
    204204#             self._set_paste_flag(True) 
    205 #             if self.data != None: 
     205#             if self.data is not None: 
    206206#                 self._set_bookmark_flag(False) 
    207207#                 self._keep.Enable(False) 
     
    225225#  
    226226#              
    227 #         if event != None: 
     227#         if event is not None: 
    228228#             ## post state to fit panel 
    229229#             new_event = PageInfoEvent(page = self) 
     
    254254#         is_modified = False 
    255255#  
    256 #         if self.model != None:            
     256#         if self.model is not None: 
    257257#             ##Check the values 
    258258#             self._check_value_enter( self.fittable_param) 
     
    291291#         else: 
    292292#             #self.btFit.Enable(True) 
    293 #             if self._is_2D() and  self.data != None: 
     293#             if self._is_2D() and  self.data is not None: 
    294294#                 self.btEditMask.Enable(True) 
    295295#  
     
    335335#             self._set_save_flag(False) 
    336336#         else: 
    337 #             if self.model != None: 
     337#             if self.model is not None: 
    338338#                 self._set_bookmark_flag(False) 
    339339#                 self._keep.Enable(False) 
  • src/sas/sasgui/perspectives/fitting/fitpage.py

    r7143065 r6a455cd3  
    66import wx 
    77import wx.lib.newevent 
    8 import numpy 
     8import numpy as np 
    99import copy 
    1010import math 
     
    11151115            if item.GetValue(): 
    11161116                if button_list.index(item) == 0: 
    1117                     flag = 0  # dy = numpy.ones_like(dy_data) 
     1117                    flag = 0  # dy = np.ones_like(dy_data) 
    11181118                elif button_list.index(item) == 1: 
    11191119                    flag = 1  # dy = dy_data 
    11201120                elif button_list.index(item) == 2: 
    1121                     flag = 2  # dy = numpy.sqrt(numpy.abs(data)) 
     1121                    flag = 2  # dy = np.sqrt(np.abs(data)) 
    11221122                elif button_list.index(item) == 3: 
    1123                     flag = 3  # dy = numpy.abs(data) 
     1123                    flag = 3  # dy = np.abs(data) 
    11241124                break 
    11251125        return flag 
     
    14261426        key = event.GetKeyCode() 
    14271427        length = len(self.data.x) 
    1428         indx = (numpy.abs(self.data.x - x_data)).argmin() 
     1428        indx = (np.abs(self.data.x - x_data)).argmin() 
    14291429        # return array.flat[idx] 
    14301430        if key == wx.WXK_PAGEUP or key == wx.WXK_NUMPAD_PAGEUP: 
     
    14811481                    self.enable2D: 
    14821482                # set mask 
    1483                 radius = numpy.sqrt(self.data.qx_data * self.data.qx_data + 
     1483                radius = np.sqrt(self.data.qx_data * self.data.qx_data + 
    14841484                                    self.data.qy_data * self.data.qy_data) 
    14851485                index_data = ((self.qmin_x <= radius) & (radius <= self.qmax_x)) 
    14861486                index_data = (index_data) & (self.data.mask) 
    1487                 index_data = (index_data) & (numpy.isfinite(self.data.data)) 
     1487                index_data = (index_data) & (np.isfinite(self.data.data)) 
    14881488                if len(index_data[index_data]) < 10: 
    14891489                    msg = "Cannot Plot :No or too little npts in" 
     
    16021602                and data.dqx_data.any() != 0: 
    16031603                self.smear_type = "Pinhole2d" 
    1604                 self.dq_l = format_number(numpy.average(data.dqx_data)) 
    1605                 self.dq_r = format_number(numpy.average(data.dqy_data)) 
     1604                self.dq_l = format_number(np.average(data.dqx_data)) 
     1605                self.dq_r = format_number(np.average(data.dqy_data)) 
    16061606                return 
    16071607            else: 
    16081608                return 
    16091609        # check if it is pinhole smear and get min max if it is. 
    1610         if data.dx is not None and numpy.any(data.dx): 
     1610        if data.dx is not None and np.any(data.dx): 
    16111611            self.smear_type = "Pinhole" 
    16121612            self.dq_l = data.dx[0] 
     
    16161616        elif data.dxl is not None or data.dxw is not None: 
    16171617            self.smear_type = "Slit" 
    1618             if data.dxl is not None and numpy.all(data.dxl, 0): 
     1618            if data.dxl is not None and np.all(data.dxl, 0): 
    16191619                self.dq_l = data.dxl[0] 
    1620             if data.dxw is not None and numpy.all(data.dxw, 0): 
     1620            if data.dxw is not None and np.all(data.dxw, 0): 
    16211621                self.dq_r = data.dxw[0] 
    16221622        # return self.smear_type,self.dq_l,self.dq_r 
     
    18121812        if not flag: 
    18131813            self.onSmear(None) 
    1814  
    1815     def _mac_sleep(self, sec=0.2): 
    1816         """ 
    1817         Give sleep to MAC 
    1818         """ 
    1819         if self.is_mac: 
    1820             time.sleep(sec) 
    18211814 
    18221815    def get_view_mode(self): 
     
    19251918                self.default_mask = copy.deepcopy(self.data.mask) 
    19261919                if self.data.err_data is not None \ 
    1927                         and numpy.any(self.data.err_data): 
     1920                        and np.any(self.data.err_data): 
    19281921                    di_flag = True 
    19291922                if self.data.dqx_data is not None \ 
    1930                         and numpy.any(self.data.dqx_data): 
     1923                        and np.any(self.data.dqx_data): 
    19311924                    dq_flag = True 
    19321925            else: 
    19331926                self.slit_smearer.Enable(True) 
    19341927                self.pinhole_smearer.Enable(True) 
    1935                 if self.data.dy is not None and numpy.any(self.data.dy): 
     1928                if self.data.dy is not None and np.any(self.data.dy): 
    19361929                    di_flag = True 
    1937                 if self.data.dx is not None and numpy.any(self.data.dx): 
     1930                if self.data.dx is not None and np.any(self.data.dx): 
    19381931                    dq_flag = True 
    1939                 elif self.data.dxl is not None and numpy.any(self.data.dxl): 
     1932                elif self.data.dxl is not None and np.any(self.data.dxl): 
    19401933                    dq_flag = True 
    19411934 
     
    20712064        if self.data.__class__.__name__ == "Data2D" or \ 
    20722065                        self.enable2D: 
    2073             radius = numpy.sqrt(self.data.qx_data * self.data.qx_data + 
     2066            radius = np.sqrt(self.data.qx_data * self.data.qx_data + 
    20742067                                self.data.qy_data * self.data.qy_data) 
    20752068            index_data = (self.qmin_x <= radius) & (radius <= self.qmax_x) 
    20762069            index_data = (index_data) & (self.data.mask) 
    2077             index_data = (index_data) & (numpy.isfinite(self.data.data)) 
     2070            index_data = (index_data) & (np.isfinite(self.data.data)) 
    20782071            npts2fit = len(self.data.data[index_data]) 
    20792072        else: 
     
    21082101        # make sure stop button to fit button all the time 
    21092102        self._on_fit_complete() 
    2110         if out is None or not numpy.isfinite(chisqr): 
     2103        if out is None or not np.isfinite(chisqr): 
    21112104            raise ValueError, "Fit error occured..." 
    21122105 
     
    21192112 
    21202113        # Check if chi2 is finite 
    2121         if chisqr is not None and numpy.isfinite(chisqr): 
     2114        if chisqr is not None and np.isfinite(chisqr): 
    21222115            # format chi2 
    21232116            chi2 = format_number(chisqr, True) 
     
    21712164 
    21722165                        if cov[ind] is not None: 
    2173                             if numpy.isfinite(float(cov[ind])): 
     2166                            if np.isfinite(float(cov[ind])): 
    21742167                                val_err = format_number(cov[ind], True) 
    21752168                                item[4].SetForegroundColour(wx.BLACK) 
     
    21922185        self.save_current_state() 
    21932186 
    2194         if not self.is_mac: 
    2195             self.Layout() 
    2196             self.Refresh() 
    2197         self._mac_sleep(0.1) 
    21982187        # plot model ( when drawing, do not update chisqr value again) 
    21992188        self._draw_model(update_chisqr=False, source='fit') 
     
    22952284            self.smear_type = 'Pinhole2d' 
    22962285            len_data = len(data.data) 
    2297             data.dqx_data = numpy.zeros(len_data) 
    2298             data.dqy_data = numpy.zeros(len_data) 
     2286            data.dqx_data = np.zeros(len_data) 
     2287            data.dqy_data = np.zeros(len_data) 
    22992288        else: 
    23002289            self.smear_type = 'Pinhole' 
    23012290            len_data = len(data.x) 
    2302             data.dx = numpy.zeros(len_data) 
     2291            data.dx = np.zeros(len_data) 
    23032292            data.dxl = None 
    23042293            data.dxw = None 
     
    24732462        try: 
    24742463            self.dxl = float(self.smear_slit_height.GetValue()) 
    2475             data.dxl = self.dxl * numpy.ones(data_len) 
     2464            data.dxl = self.dxl * np.ones(data_len) 
    24762465            self.smear_slit_height.SetBackgroundColour(wx.WHITE) 
    24772466        except: 
    24782467            self.dxl = None 
    2479             data.dxl = numpy.zeros(data_len) 
     2468            data.dxl = np.zeros(data_len) 
    24802469            if self.smear_slit_height.GetValue().lstrip().rstrip() != "": 
    24812470                self.smear_slit_height.SetBackgroundColour("pink") 
     
    24862475            self.dxw = float(self.smear_slit_width.GetValue()) 
    24872476            self.smear_slit_width.SetBackgroundColour(wx.WHITE) 
    2488             data.dxw = self.dxw * numpy.ones(data_len) 
     2477            data.dxw = self.dxw * np.ones(data_len) 
    24892478        except: 
    24902479            self.dxw = None 
    2491             data.dxw = numpy.zeros(data_len) 
     2480            data.dxw = np.zeros(data_len) 
    24922481            if self.smear_slit_width.GetValue().lstrip().rstrip() != "": 
    24932482                self.smear_slit_width.SetBackgroundColour("pink") 
     
    26162605            if event is None: 
    26172606                output = "-" 
    2618             elif not numpy.isfinite(event.output): 
     2607            elif not np.isfinite(event.output): 
    26192608                output = "-" 
    26202609            else: 
  • src/sas/sasgui/perspectives/fitting/fitting.py

    r4c5098c ra534432  
    1111#copyright 2009, University of Tennessee 
    1212################################################################################ 
     13from __future__ import print_function 
     14 
    1315import re 
    1416import sys 
     
    1618import wx 
    1719import logging 
    18 import numpy 
     20import numpy as np 
    1921import time 
    2022from copy import deepcopy 
     
    4850 
    4951from . import models 
     52 
     53logger = logging.getLogger(__name__) 
    5054 
    5155MAX_NBR_DATA = 4 
     
    119123        self.page_finder = {} 
    120124        # Log startup 
    121         logging.info("Fitting plug-in started") 
     125        logger.info("Fitting plug-in started") 
    122126        self.batch_capable = self.get_batch_capable() 
    123127 
     
    300304        Make new model 
    301305        """ 
    302         if self.new_model_frame != None: 
     306        if self.new_model_frame is not None: 
    303307            self.new_model_frame.Show(False) 
    304308            self.new_model_frame.Show(True) 
     
    346350                                page.formfactorbox.SetLabel(current_val) 
    347351        except: 
    348             logging.error("update_custom_combo: %s", sys.exc_value) 
     352            logger.error("update_custom_combo: %s", sys.exc_value) 
    349353 
    350354    def set_edit_menu(self, owner): 
     
    384388        help for setting list of the edit model menu labels 
    385389        """ 
    386         if menu == None: 
     390        if menu is None: 
    387391            menu = self.edit_custom_model 
    388392        list_fnames = os.listdir(models.find_plugins_dir()) 
     
    439443            wx.PostEvent(self.parent, StatusEvent(status=msg)) 
    440444 
    441         if page != None: 
     445        if page is not None: 
    442446            return set_focus_page(page) 
    443447        if caption == "Const & Simul Fit": 
     
    586590                msg = "Fitting: cannot deal with the theory received" 
    587591                evt = StatusEvent(status=msg, info="error") 
    588                 logging.error("set_theory " + msg + "\n" + str(sys.exc_value)) 
     592                logger.error("set_theory " + msg + "\n" + str(sys.exc_value)) 
    589593                wx.PostEvent(self.parent, evt) 
    590594 
     
    632636            state = self.temp_state[self.state_index] 
    633637            #panel state should have model selection to set_state 
    634             if state.formfactorcombobox != None: 
     638            if state.formfactorcombobox is not None: 
    635639                #set state 
    636640                data = self.parent.create_gui_data(state.data) 
     
    875879                enable1D=enable1D, enable2D=enable2D, 
    876880                qmin=qmin, qmax=qmax, weight=weight) 
    877  
    878     def _mac_sleep(self, sec=0.2): 
    879         """ 
    880         Give sleep to MAC 
    881         """ 
    882         if ON_MAC: 
    883             time.sleep(sec) 
    884881 
    885882    def draw_model(self, model, page_id, data=None, smearer=None, 
     
    10211018                return False 
    10221019        ## If a thread is already started, stop it 
    1023         #if self.calc_fit!= None and self.calc_fit.isrunning(): 
     1020        #if self.calc_fitis not None and self.calc_fit.isrunning(): 
    10241021        #    self.calc_fit.stop() 
    10251022        msg = "Fitting is in progress..." 
     
    10301027                                manager=self, 
    10311028                                improvement_delta=0.1) 
    1032         self._mac_sleep(0.2) 
    10331029 
    10341030        # batch fit 
     
    11121108            page = self.fit_panel.add_empty_page() 
    11131109            # add data associated to the page created 
    1114             if page != None: 
     1110            if page is not None: 
    11151111                evt = StatusEvent(status="Page Created", info="info") 
    11161112                wx.PostEvent(self.parent, evt) 
     
    11311127        page = self.fit_panel.set_data(data) 
    11321128        # page could be None when loading state files 
    1133         if page == None: 
     1129        if page is None: 
    11341130            return page 
    11351131        #append Data1D to the panel containing its theory 
     
    11991195        """ 
    12001196        # case that uid is not specified 
    1201         if uid == None: 
     1197        if uid is None: 
    12021198            for page_id in self.page_finder.keys(): 
    12031199                self.page_finder[page_id].schedule_tofit(value) 
     
    12221218            for item in param: 
    12231219                ## check if constraint 
    1224                 if item[0] != None and item[1] != None: 
     1220                if item[0] is not None and item[1] is not None: 
    12251221                    listOfConstraint.append((item[0], item[1])) 
    12261222        new_model = model 
     
    12371233        """ 
    12381234        panel = self.plot_panel 
    1239         if panel == None: 
     1235        if panel is None: 
    12401236            raise ValueError, "Fitting:_onSelect: NonType panel" 
    12411237        Plugin.on_perspective(self, event=event) 
     
    12591255        """ 
    12601256        """ 
    1261         print "update_fit result", result 
     1257        print("update_fit result", result) 
    12621258 
    12631259    def _batch_fit_complete(self, result, pars, page_id, 
     
    12701266        :param elapsed: time spent at the fitting level 
    12711267        """ 
    1272         self._mac_sleep(0.2) 
    12731268        uid = page_id[0] 
    12741269        if uid in self.fit_thread_list.keys(): 
     
    13321327                    new_theory = copy_data.data 
    13331328                    new_theory[res.index] = res.theory 
    1334                     new_theory[res.index == False] = numpy.nan 
     1329                    new_theory[res.index == False] = np.nan 
    13351330                    correct_result = True 
    13361331                #get all fittable parameters of the current model 
     
    13411336                        param_list.remove(param) 
    13421337                if not correct_result or res.fitness is None or \ 
    1343                     not numpy.isfinite(res.fitness) or \ 
    1344                     numpy.any(res.pvec == None) or not \ 
    1345                     numpy.all(numpy.isfinite(res.pvec)): 
     1338                    not np.isfinite(res.fitness) or \ 
     1339                        np.any(res.pvec is None) or not \ 
     1340                        np.all(np.isfinite(res.pvec)): 
    13461341                    data_name = str(None) 
    13471342                    if data is not None: 
     
    13521347                    msg += "Data %s and Model %s did not fit.\n" % (data_name, 
    13531348                                                                    model_name) 
    1354                     ERROR = numpy.NAN 
     1349                    ERROR = np.NAN 
    13551350                    cell = BatchCell() 
    13561351                    cell.label = res.fitness 
     
    13661361                            batch_inputs["error on %s" % str(param)].append(ERROR) 
    13671362                else: 
    1368                     # TODO: Why sometimes res.pvec comes with numpy.float64? 
     1363                    # TODO: Why sometimes res.pvec comes with np.float64? 
    13691364                    # probably from scipy lmfit 
    1370                     if res.pvec.__class__ == numpy.float64: 
     1365                    if res.pvec.__class__ == np.float64: 
    13711366                        res.pvec = [res.pvec] 
    13721367 
     
    14641459        cell.value = index 
    14651460 
    1466         if theory_data != None: 
     1461        if theory_data is not None: 
    14671462            #Suucessful fit 
    14681463            theory_data.id = wx.NewId() 
     
    15201515            page_id = [] 
    15211516        ## fit more than 1 model at the same time 
    1522         self._mac_sleep(0.2) 
    15231517        try: 
    15241518            index = 0 
     
    15331527                fit_msg = res.mesg 
    15341528                if res.fitness is None or \ 
    1535                     not numpy.isfinite(res.fitness) or \ 
    1536                     numpy.any(res.pvec == None) or \ 
    1537                     not numpy.all(numpy.isfinite(res.pvec)): 
     1529                    not np.isfinite(res.fitness) or \ 
     1530                        np.any(res.pvec is None) or \ 
     1531                    not np.all(np.isfinite(res.pvec)): 
    15381532                    fit_msg += "\nFitting did not converge!!!" 
    15391533                    wx.CallAfter(self._update_fit_button, page_id) 
    15401534                else: 
    15411535                    #set the panel when fit result are float not list 
    1542                     if res.pvec.__class__ == numpy.float64: 
     1536                    if res.pvec.__class__ == np.float64: 
    15431537                        pvec = [res.pvec] 
    15441538                    else: 
    15451539                        pvec = res.pvec 
    1546                     if res.stderr.__class__ == numpy.float64: 
     1540                    if res.stderr.__class__ == np.float64: 
    15471541                        stderr = [res.stderr] 
    15481542                    else: 
     
    15521546                    #(CallAfter is important to MAC) 
    15531547                    try: 
    1554                         #if res != None: 
     1548                        #if res is not None: 
    15551549                        wx.CallAfter(cpage.onsetValues, res.fitness, 
    15561550                                     res.param_list, 
     
    15951589        """ 
    15961590        event.Skip() 
    1597         if self.menu1 == None: 
     1591        if self.menu1 is None: 
    15981592            return 
    15991593        menu_item = self.menu1.FindItemById(self.id_reset_flag) 
     
    16541648        caption = evt.caption 
    16551649        enable_smearer = evt.enable_smearer 
    1656         if model == None: 
     1650        if model is None: 
    16571651            return 
    16581652        if uid not in self.page_finder.keys(): 
     
    16921686        if dy is None: 
    16931687            new_plot.is_data = False 
    1694             new_plot.dy = numpy.zeros(len(y)) 
     1688            new_plot.dy = np.zeros(len(y)) 
    16951689            # If this is a theory curve, pick the proper symbol to make it a curve 
    16961690            new_plot.symbol = GUIFRAME_ID.CURVE_SYMBOL_NUM 
     
    17061700        new_plot.title = data.name 
    17071701        new_plot.group_id = data.group_id 
    1708         if new_plot.group_id == None: 
     1702        if new_plot.group_id is None: 
    17091703            new_plot.group_id = data.group_id 
    17101704        new_plot.id = data_id 
     
    17401734            @param unsmeared_error: data error, rescaled to unsmeared model 
    17411735        """ 
    1742         try: 
    1743             numpy.nan_to_num(y) 
    1744             new_plot = self.create_theory_1D(x, y, page_id, model, data, state, 
    1745                                              data_description=model.name, 
    1746                                              data_id=str(page_id) + " " + data.name) 
    1747             if unsmeared_model is not None: 
    1748                 self.create_theory_1D(x, unsmeared_model, page_id, model, data, state, 
    1749                                       data_description=model.name + " unsmeared", 
    1750                                       data_id=str(page_id) + " " + data.name + " unsmeared") 
    1751  
    1752                 if unsmeared_data is not None and unsmeared_error is not None: 
    1753                     self.create_theory_1D(x, unsmeared_data, page_id, model, data, state, 
    1754                                           data_description="Data unsmeared", 
    1755                                           data_id="Data  " + data.name + " unsmeared", 
    1756                                           dy=unsmeared_error) 
    1757             # Comment this out until we can get P*S models with correctly populated parameters 
    1758             #if sq_model is not None and pq_model is not None: 
    1759             #    self.create_theory_1D(x, sq_model, page_id, model, data, state, 
    1760             #                          data_description=model.name + " S(q)", 
    1761             #                          data_id=str(page_id) + " " + data.name + " S(q)") 
    1762             #    self.create_theory_1D(x, pq_model, page_id, model, data, state, 
    1763             #                          data_description=model.name + " P(q)", 
    1764             #                          data_id=str(page_id) + " " + data.name + " P(q)") 
    1765  
    1766             current_pg = self.fit_panel.get_page_by_id(page_id) 
    1767             title = new_plot.title 
    1768             batch_on = self.fit_panel.get_page_by_id(page_id).batch_on 
    1769             if not batch_on: 
    1770                 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, 
    1771                                             title=str(title))) 
    1772             elif plot_result: 
    1773                 top_data_id = self.fit_panel.get_page_by_id(page_id).data.id 
    1774                 if data.id == top_data_id: 
    1775                     wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, 
    1776                                             title=str(title))) 
    1777             caption = current_pg.window_caption 
    1778             self.page_finder[page_id].set_fit_tab_caption(caption=caption) 
    1779  
    1780             self.page_finder[page_id].set_theory_data(data=new_plot, 
     1736             
     1737        number_finite = np.count_nonzero(np.isfinite(y))  
     1738        np.nan_to_num(y) 
     1739        new_plot = self.create_theory_1D(x, y, page_id, model, data, state, 
     1740                                         data_description=model.name, 
     1741                                         data_id=str(page_id) + " " + data.name) 
     1742        if unsmeared_model is not None: 
     1743            self.create_theory_1D(x, unsmeared_model, page_id, model, data, state, 
     1744                                  data_description=model.name + " unsmeared", 
     1745                                  data_id=str(page_id) + " " + data.name + " unsmeared") 
     1746 
     1747            if unsmeared_data is not None and unsmeared_error is not None: 
     1748                self.create_theory_1D(x, unsmeared_data, page_id, model, data, state, 
     1749                                      data_description="Data unsmeared", 
     1750                                      data_id="Data  " + data.name + " unsmeared", 
     1751                                      dy=unsmeared_error) 
     1752        # Comment this out until we can get P*S models with correctly populated parameters 
     1753        #if sq_model is not None and pq_model is not None: 
     1754        #    self.create_theory_1D(x, sq_model, page_id, model, data, state, 
     1755        #                          data_description=model.name + " S(q)", 
     1756        #                          data_id=str(page_id) + " " + data.name + " S(q)") 
     1757        #    self.create_theory_1D(x, pq_model, page_id, model, data, state, 
     1758        #                          data_description=model.name + " P(q)", 
     1759        #                          data_id=str(page_id) + " " + data.name + " P(q)") 
     1760 
     1761        current_pg = self.fit_panel.get_page_by_id(page_id) 
     1762        title = new_plot.title 
     1763        batch_on = self.fit_panel.get_page_by_id(page_id).batch_on 
     1764        if not batch_on: 
     1765            wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title=str(title))) 
     1766        elif plot_result: 
     1767            top_data_id = self.fit_panel.get_page_by_id(page_id).data.id 
     1768            if data.id == top_data_id: 
     1769                wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title=str(title))) 
     1770        caption = current_pg.window_caption 
     1771        self.page_finder[page_id].set_fit_tab_caption(caption=caption) 
     1772 
     1773        self.page_finder[page_id].set_theory_data(data=new_plot, 
    17811774                                                      fid=data.id) 
    1782             if toggle_mode_on: 
    1783                 wx.PostEvent(self.parent, 
    1784                              NewPlotEvent(group_id=str(page_id) + " Model2D", 
     1775        if toggle_mode_on: 
     1776            wx.PostEvent(self.parent, 
     1777                         NewPlotEvent(group_id=str(page_id) + " Model2D", 
    17851778                                          action="Hide")) 
    1786             else: 
    1787                 if update_chisqr: 
    1788                     wx.PostEvent(current_pg, 
    1789                                  Chi2UpdateEvent(output=self._cal_chisqr( 
     1779        else: 
     1780            if update_chisqr: 
     1781                wx.PostEvent(current_pg, 
     1782                             Chi2UpdateEvent(output=self._cal_chisqr( 
    17901783                                                                data=data, 
    17911784                                                                fid=fid, 
    17921785                                                                weight=weight, 
    1793                                                             page_id=page_id, 
    1794                                                             index=index))) 
    1795                 else: 
    1796                     self._plot_residuals(page_id=page_id, data=data, fid=fid, 
    1797                                          index=index, weight=weight) 
    1798  
     1786                                                                page_id=page_id, 
     1787                                                                index=index))) 
     1788            else: 
     1789                self._plot_residuals(page_id=page_id, data=data, fid=fid, 
     1790                                     index=index, weight=weight) 
     1791 
     1792        if not number_finite: 
     1793            logger.error("Using the present parameters the model does not return any finite value. ") 
     1794            msg = "Computing Error: Model did not return any finite value." 
     1795            wx.PostEvent(self.parent, StatusEvent(status = msg, info="error")) 
     1796        else:                  
    17991797            msg = "Computation  completed!" 
     1798            if number_finite != y.size: 
     1799                msg += ' PROBLEM: For some Q values the model returns non finite intensities!' 
     1800                logger.error("For some Q values the model returns non finite intensities.") 
    18001801            wx.PostEvent(self.parent, StatusEvent(status=msg, type="stop")) 
    1801         except: 
    1802             raise 
    18031802 
    18041803    def _calc_exception(self, etype, value, tb): 
     
    18061805        Handle exception from calculator by posting it as an error. 
    18071806        """ 
    1808         logging.error("".join(traceback.format_exception(etype, value, tb))) 
     1807        logger.error("".join(traceback.format_exception(etype, value, tb))) 
    18091808        msg = traceback.format_exception(etype, value, tb, limit=1) 
    18101809        evt = StatusEvent(status="".join(msg), type="stop", info="error") 
     
    18251824        that can be plot. 
    18261825        """ 
    1827         numpy.nan_to_num(image) 
     1826        number_finite = np.count_nonzero(np.isfinite(image))  
     1827        np.nan_to_num(image) 
    18281828        new_plot = Data2D(image=image, err_image=data.err_data) 
    18291829        new_plot.name = model.name + '2d' 
     
    18831883                self._plot_residuals(page_id=page_id, data=data, fid=fid, 
    18841884                                      index=index, weight=weight) 
    1885         msg = "Computation  completed!" 
    1886         wx.PostEvent(self.parent, StatusEvent(status=msg, type="stop")) 
     1885 
     1886        if not number_finite: 
     1887            logger.error("Using the present parameters the model does not return any finite value. ") 
     1888            msg = "Computing Error: Model did not return any finite value." 
     1889            wx.PostEvent(self.parent, StatusEvent(status = msg, info="error")) 
     1890        else: 
     1891            msg = "Computation  completed!" 
     1892            if number_finite != image.size: 
     1893                msg += ' PROBLEM: For some Qx,Qy values the model returns non finite intensities!' 
     1894                logger.error("For some Qx,Qy values the model returns non finite intensities.") 
     1895            wx.PostEvent(self.parent, StatusEvent(status=msg, type="stop")) 
    18871896 
    18881897    def _draw_model2D(self, model, page_id, qmin, 
     
    20102019        chisqr = None 
    20112020        #to compute chisq make sure data has valid data 
    2012         # return None if data == None 
    2013         if not check_data_validity(data_copy) or data_copy == None: 
     2021        # return None if data is None 
     2022        if not check_data_validity(data_copy) or data_copy is None: 
    20142023            return chisqr 
    20152024 
    20162025        # Get data: data I, theory I, and data dI in order 
    20172026        if data_copy.__class__.__name__ == "Data2D": 
    2018             if index == None: 
    2019                 index = numpy.ones(len(data_copy.data), dtype=bool) 
    2020             if weight != None: 
     2027            if index is None: 
     2028                index = np.ones(len(data_copy.data), dtype=bool) 
     2029            if weight is not None: 
    20212030                data_copy.err_data = weight 
    20222031            # get rid of zero error points 
    20232032            index = index & (data_copy.err_data != 0) 
    2024             index = index & (numpy.isfinite(data_copy.data)) 
     2033            index = index & (np.isfinite(data_copy.data)) 
    20252034            fn = data_copy.data[index] 
    20262035            theory_data = self.page_finder[page_id].get_theory_data(fid=data_copy.id) 
    2027             if theory_data == None: 
     2036            if theory_data is None: 
    20282037                return chisqr 
    20292038            gn = theory_data.data[index] 
     
    20312040        else: 
    20322041            # 1 d theory from model_thread is only in the range of index 
    2033             if index == None: 
    2034                 index = numpy.ones(len(data_copy.y), dtype=bool) 
    2035             if weight != None: 
     2042            if index is None: 
     2043                index = np.ones(len(data_copy.y), dtype=bool) 
     2044            if weight is not None: 
    20362045                data_copy.dy = weight 
    2037             if data_copy.dy == None or data_copy.dy == []: 
    2038                 dy = numpy.ones(len(data_copy.y)) 
     2046            if data_copy.dy is None or data_copy.dy == []: 
     2047                dy = np.ones(len(data_copy.y)) 
    20392048            else: 
    20402049                ## Set consistently w/AbstractFitengine: 
     
    20452054 
    20462055            theory_data = self.page_finder[page_id].get_theory_data(fid=data_copy.id) 
    2047             if theory_data == None: 
     2056            if theory_data is None: 
    20482057                return chisqr 
    20492058            gn = theory_data.y 
     
    20542063            res = (fn - gn) / en 
    20552064        except ValueError: 
    2056             print "Unmatch lengths %s, %s, %s" % (len(fn), len(gn), len(en)) 
     2065            print("Unmatch lengths %s, %s, %s" % (len(fn), len(gn), len(en))) 
    20572066            return 
    20582067 
    2059         residuals = res[numpy.isfinite(res)] 
     2068        residuals = res[np.isfinite(res)] 
    20602069        # get chisqr only w/finite 
    2061         chisqr = numpy.average(residuals * residuals) 
     2070        chisqr = np.average(residuals * residuals) 
    20622071 
    20632072        self._plot_residuals(page_id=page_id, data=data_copy, 
     
    20882097            theory_data = self.page_finder[page_id].get_theory_data(fid=data_copy.id) 
    20892098            gn = theory_data.data 
    2090             if weight == None: 
     2099            if weight is None: 
    20912100                en = data_copy.err_data 
    20922101            else: 
     
    20962105            residuals.qy_data = data_copy.qy_data 
    20972106            residuals.q_data = data_copy.q_data 
    2098             residuals.err_data = numpy.ones(len(residuals.data)) 
     2107            residuals.err_data = np.ones(len(residuals.data)) 
    20992108            residuals.xmin = min(residuals.qx_data) 
    21002109            residuals.xmax = max(residuals.qx_data) 
     
    21092118        else: 
    21102119            # 1 d theory from model_thread is only in the range of index 
    2111             if data_copy.dy == None or data_copy.dy == []: 
    2112                 dy = numpy.ones(len(data_copy.y)) 
     2120            if data_copy.dy is None or data_copy.dy == []: 
     2121                dy = np.ones(len(data_copy.y)) 
    21132122            else: 
    2114                 if weight == None: 
    2115                     dy = numpy.ones(len(data_copy.y)) 
     2123                if weight is None: 
     2124                    dy = np.ones(len(data_copy.y)) 
    21162125                ## Set consitently w/AbstractFitengine: 
    21172126                ## But this should be corrected later. 
     
    21322141                residuals.y = (fn - gn[index]) / en 
    21332142            residuals.x = data_copy.x[index] 
    2134             residuals.dy = numpy.ones(len(residuals.y)) 
     2143            residuals.dy = np.ones(len(residuals.y)) 
    21352144            residuals.dx = None 
    21362145            residuals.dxl = None 
     
    21502159        ##group_id specify on which panel to plot this data 
    21512160        group_id = self.page_finder[page_id].get_graph_id() 
    2152         if group_id == None: 
     2161        if group_id is None: 
    21532162            group_id = data.group_id 
    21542163        new_plot.group_id = "res" + str(group_id) 
  • src/sas/sasgui/perspectives/fitting/media/plugin.rst

    r984f3fc r72100ee  
    538538    sin, cos, tan, asin, acos, atan: 
    539539        Trigonometry functions and inverses, operating on radians. 
    540     sinh, cos, tanh, asinh, acosh, atanh: 
     540    sinh, cosh, tanh, asinh, acosh, atanh: 
    541541        Hyperbolic trigonometry functions. 
    542542    atan2(y,x): 
  • src/sas/sasgui/perspectives/fitting/model_thread.py

    rc1c9929 r7432acb  
    44 
    55import time 
    6 import numpy 
     6import numpy as np 
    77import math 
    88from sas.sascalc.data_util.calcthread import CalcThread 
     
    5353        self.starttime = time.time() 
    5454        # Determine appropriate q range 
    55         if self.qmin == None: 
     55        if self.qmin is None: 
    5656            self.qmin = 0 
    57         if self.qmax == None: 
    58             if self.data != None: 
     57        if self.qmax is None: 
     58            if self.data is not None: 
    5959                newx = math.pow(max(math.fabs(self.data.xmax), 
    6060                                   math.fabs(self.data.xmin)), 2) 
     
    6868 
    6969        # Define matrix where data will be plotted 
    70         radius = numpy.sqrt((self.data.qx_data * self.data.qx_data) + \ 
     70        radius = np.sqrt((self.data.qx_data * self.data.qx_data) + \ 
    7171                    (self.data.qy_data * self.data.qy_data)) 
    7272 
     
    7575        index_model = (self.qmin <= radius) & (radius <= self.qmax) 
    7676        index_model = index_model & self.data.mask 
    77         index_model = index_model & numpy.isfinite(self.data.data) 
     77        index_model = index_model & np.isfinite(self.data.data) 
    7878 
    7979        if self.smearer is not None: 
     
    9191                self.data.qy_data[index_model] 
    9292            ]) 
    93         output = numpy.zeros(len(self.data.qx_data)) 
     93        output = np.zeros(len(self.data.qx_data)) 
    9494        # output default is None 
    9595        # This method is to distinguish between masked 
     
    163163        """ 
    164164        self.starttime = time.time() 
    165         output = numpy.zeros((len(self.data.x))) 
     165        output = np.zeros((len(self.data.x))) 
    166166        index = (self.qmin <= self.data.x) & (self.data.x <= self.qmax) 
    167167 
     
    175175                                                             self.qmax) 
    176176            mask = self.data.x[first_bin:last_bin+1] 
    177             unsmeared_output = numpy.zeros((len(self.data.x))) 
     177            unsmeared_output = np.zeros((len(self.data.x))) 
    178178            unsmeared_output[first_bin:last_bin+1] = self.model.evalDistribution(mask) 
    179179            self.smearer.model = self.model 
     
    183183            # Check that the arrays are compatible. If we only have a model but no data, 
    184184            # the length of data.y will be zero. 
    185             if isinstance(self.data.y, numpy.ndarray) and output.shape == self.data.y.shape: 
    186                 unsmeared_data = numpy.zeros((len(self.data.x))) 
    187                 unsmeared_error = numpy.zeros((len(self.data.x))) 
     185            if isinstance(self.data.y, np.ndarray) and output.shape == self.data.y.shape: 
     186                unsmeared_data = np.zeros((len(self.data.x))) 
     187                unsmeared_error = np.zeros((len(self.data.x))) 
    188188                unsmeared_data[first_bin:last_bin+1] = self.data.y[first_bin:last_bin+1]\ 
    189189                                                        * unsmeared_output[first_bin:last_bin+1]\ 
     
    209209 
    210210        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))) 
     211            sq_values = np.zeros((len(self.data.x))) 
     212            pq_values = np.zeros((len(self.data.x))) 
    213213            sq_values[index] = s_model.evalDistribution(self.data.x[index]) 
    214214            pq_values[index] = p_model.evalDistribution(self.data.x[index]) 
  • src/sas/sasgui/perspectives/fitting/models.py

    r05b8e01 r6a455cd3  
    22    Utilities to manage models 
    33""" 
     4from __future__ import print_function 
     5 
    46import traceback 
    57import os 
     
    1921from sasmodels.sasview_model import load_custom_model, load_standard_models 
    2022from sas.sasgui.perspectives.fitting.fitpage import CUSTOM_MODEL 
     23 
     24logger = logging.getLogger(__name__) 
    2125 
    2226 
     
    140144        type, value, tb = sys.exc_info() 
    141145        if type is not None and issubclass(type, py_compile.PyCompileError): 
    142             print "Problem with", repr(value) 
     146            print("Problem with", repr(value)) 
    143147            raise type, value, tb 
    144148        return 1 
     
    153157    try: 
    154158        import compileall 
    155         compileall.compile_dir(dir=dir, ddir=dir, force=1, 
     159        compileall.compile_dir(dir=dir, ddir=dir, force=0, 
    156160                               quiet=report_problem) 
    157161    except: 
     
    160164 
    161165 
    162 def _findModels(dir): 
     166def _find_models(): 
    163167    """ 
    164168    Find custom models 
    165169    """ 
    166170    # List of plugin objects 
    167     dir = find_plugins_dir() 
     171    directory = find_plugins_dir() 
    168172    # Go through files in plug-in directory 
    169     if not os.path.isdir(dir): 
    170         msg = "SasView couldn't locate Model plugin folder %r." % dir 
    171         logging.warning(msg) 
     173    if not os.path.isdir(directory): 
     174        msg = "SasView couldn't locate Model plugin folder %r." % directory 
     175        logger.warning(msg) 
    172176        return {} 
    173177 
    174     plugin_log("looking for models in: %s" % str(dir)) 
    175     #compile_file(dir)  #always recompile the folder plugin 
    176     logging.info("plugin model dir: %s" % str(dir)) 
     178    plugin_log("looking for models in: %s" % str(directory)) 
     179    # compile_file(directory)  #always recompile the folder plugin 
     180    logger.info("plugin model dir: %s" % str(directory)) 
    177181 
    178182    plugins = {} 
    179     for filename in os.listdir(dir): 
     183    for filename in os.listdir(directory): 
    180184        name, ext = os.path.splitext(filename) 
    181185        if ext == '.py' and not name == '__init__': 
    182             path = os.path.abspath(os.path.join(dir, filename)) 
     186            path = os.path.abspath(os.path.join(directory, filename)) 
    183187            try: 
    184188                model = load_custom_model(path) 
     
    189193                msg += "\nwhile accessing model in %r" % path 
    190194                plugin_log(msg) 
    191                 logging.warning("Failed to load plugin %r. See %s for details" 
    192                                 % (path, PLUGIN_LOG)) 
    193              
     195                logger.warning("Failed to load plugin %r. See %s for details" 
     196                               % (path, PLUGIN_LOG)) 
     197 
    194198    return plugins 
    195199 
     
    261265        temp = {} 
    262266        if self.is_changed(): 
    263             temp =  _findModels(dir) 
     267            temp =  _findModels() 
    264268            self.last_time_dir_modified = time.time() 
    265269            return temp 
    266         logging.info("plugin model : %s" % str(temp)) 
     270        logger.info("plugin model : %s" % str(temp)) 
    267271        return temp 
    268272 
     
    338342        """ 
    339343        self.plugins = [] 
    340         new_plugins = _findModels(dir) 
     344        new_plugins = _find_models() 
    341345        for name, plug in  new_plugins.iteritems(): 
    342346            for stored_name, stored_plug in self.stored_plugins.iteritems(): 
  • src/sas/sasgui/perspectives/fitting/pagestate.py

    r27109e5 r959eb01  
    1818import copy 
    1919import logging 
    20 import numpy 
     20import numpy as np 
    2121import traceback 
    2222 
     
    3333from sas.sascalc.dataloader.data_info import Data2D, Collimation, Detector 
    3434from sas.sascalc.dataloader.data_info import Process, Aperture 
     35 
     36logger = logging.getLogger(__name__) 
    3537 
    3638# Information to read/write state as xml 
     
    395397                    msg = "Save state does not have enough information to load" 
    396398                    msg += " the all of the data." 
    397                     logging.warning(msg=msg) 
     399                    logger.warning(msg=msg) 
    398400            else: 
    399401                self.formfactorcombobox = FIRST_FORM[self.categorycombobox] 
     
    410412        for fittable, name, value, _, uncert, lower, upper, units in params: 
    411413            if not value: 
    412                 value = numpy.nan 
     414                value = np.nan 
    413415            if not uncert or uncert[1] == '' or uncert[1] == 'None': 
    414416                uncert[0] = False 
    415                 uncert[1] = numpy.nan 
     417                uncert[1] = np.nan 
    416418            if not upper or upper[1] == '' or upper[1] == 'None': 
    417419                upper[0] = False 
    418                 upper[1] = numpy.nan 
     420                upper[1] = np.nan 
    419421            if not lower or lower[1] == '' or lower[1] == 'None': 
    420422                lower[0] = False 
    421                 lower[1] = numpy.nan 
     423                lower[1] = np.nan 
    422424            if is_string: 
    423425                p[name] = str(value) 
     
    449451                lower = params.get(name + ".lower", '-inf') 
    450452                units = params.get(name + ".units") 
    451                 if std is not None and std is not numpy.nan: 
     453                if std is not None and std is not np.nan: 
    452454                    std = [True, str(std)] 
    453455                else: 
    454456                    std = [False, ''] 
    455                 if lower is not None and lower is not numpy.nan: 
     457                if lower is not None and lower is not np.nan: 
    456458                    lower = [True, str(lower)] 
    457459                else: 
    458460                    lower = [True, '-inf'] 
    459                 if upper is not None and upper is not numpy.nan: 
     461                if upper is not None and upper is not np.nan: 
    460462                    upper = [True, str(upper)] 
    461463                else: 
     
    620622            except Exception: 
    621623                msg = "Report string expected 'name: value' but got %r" % line 
    622                 logging.error(msg) 
     624                logger.error(msg) 
    623625            if name.count("State created"): 
    624626                repo_time = "" + value 
     
    662664                except Exception: 
    663665                    msg = "While parsing 'data: ...'\n" 
    664                     logging.error(msg + traceback.format_exc()) 
     666                    logger.error(msg + traceback.format_exc()) 
    665667            if name == "model name ": 
    666668                try: 
     
    678680                except Exception: 
    679681                    msg = "While parsing 'Plotting Range: ...'\n" 
    680                     logging.error(msg + traceback.format_exc()) 
     682                    logger.error(msg + traceback.format_exc()) 
    681683        paramval = "" 
    682684        for lines in param_string.split(":"): 
     
    10371039                    msg = "PageState.fromXML: Could not" 
    10381040                    msg += " read timestamp\n %s" % sys.exc_value 
    1039                     logging.error(msg) 
     1041                    logger.error(msg) 
    10401042 
    10411043            if entry is not None: 
     
    10771079                            except Exception: 
    10781080                                base = "unable to load distribution %r for %s" 
    1079                                 logging.error(base % (value, parameter)) 
     1081                                logger.error(base % (value, parameter)) 
    10801082                                continue 
    10811083                        _disp_obj_dict = getattr(self, varname) 
     
    10991101                                msg = ("Error reading %r from %s %s\n" 
    11001102                                       % (line, tagname, name)) 
    1101                                 logging.error(msg + traceback.format_exc()) 
    1102                         dic[name] = numpy.array(value_list) 
     1103                                logger.error(msg + traceback.format_exc()) 
     1104                        dic[name] = np.array(value_list) 
    11031105                    setattr(self, varname, dic) 
    11041106 
     
    12071209 
    12081210        except: 
    1209             logging.info("XML document does not contain fitting information.\n" 
     1211            logger.info("XML document does not contain fitting information.\n" 
    12101212                         + traceback.format_exc()) 
    12111213 
  • src/sas/sasgui/perspectives/fitting/report_dialog.py

    rd85c194 r7432acb  
    3939        self.nimages = len(self.report_list[2]) 
    4040 
    41         if self.report_list[2] != None: 
     41        if self.report_list[2] is not None: 
    4242            # put image path in the report string 
    4343            if len(self.report_list[2]) == 1: 
  • src/sas/sasgui/perspectives/fitting/utils.py

    rd85c194 r959eb01  
    22Module contains functions frequently used in this package 
    33""" 
    4 import numpy 
     4import numpy as np 
    55 
    66 
     
    1919        data = data.y 
    2020    if flag == 0: 
    21         weight = numpy.ones_like(data) 
     21        weight = np.ones_like(data) 
    2222    elif flag == 1: 
    2323        weight = dy_data 
    2424    elif flag == 2: 
    25         weight = numpy.sqrt(numpy.abs(data)) 
     25        weight = np.sqrt(np.abs(data)) 
    2626    elif flag == 3: 
    27         weight = numpy.abs(data) 
     27        weight = np.abs(data) 
    2828    return weight 
  • src/sas/sasgui/perspectives/fitting/fitpanel.py

    r67b0a99 rd79feea  
    9292            # state must be cloned 
    9393            state = page.get_state().clone() 
    94             if data is not None or page.model is not None: 
     94            # data_list only populated with real data 
     95            # Fake object in data from page.get_data() if model is selected 
     96            if len(page.data_list) is not 0 and page.model is not None: 
    9597                new_doc = self._manager.state_reader.write_toXML(data, 
    9698                                                                 state, 
    9799                                                                 batch_state) 
     100                # Fit #2 through #n are append to first fit 
    98101                if doc is not None and hasattr(doc, "firstChild"): 
    99                     child = new_doc.firstChild.firstChild 
    100                     doc.firstChild.appendChild(child) 
     102                    # Only append if properly formed new_doc 
     103                    if new_doc is not None and hasattr(new_doc, "firstChild"): 
     104                        child = new_doc.firstChild.firstChild 
     105                        doc.firstChild.appendChild(child) 
     106                # First fit defines the main document 
    101107                else: 
    102108                    doc = new_doc 
     
    395401                temp_data = page.get_data() 
    396402                if temp_data is not None and temp_data.id in data: 
    397                     self.SetSelection(pos) 
    398                     self.on_close_page(event=None) 
    399                     temp = self.GetSelection() 
    400                     self.DeletePage(temp) 
     403                    self.close_page_with_data(temp_data) 
    401404            if self.sim_page is not None: 
    402405                if len(self.sim_page.model_list) == 0: 
     
    405408                    self.on_close_page(event=None) 
    406409                    temp = self.GetSelection() 
    407                     self.DeletePage(temp) 
     410                    self.DeletePage(pos) 
    408411                    self.sim_page = None 
    409412                    self.batch_on = False 
Note: See TracChangeset for help on using the changeset viewer.