Ignore:
File:
1 edited

Legend:

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

    r463e7ffc r7432acb  
    1616import wx 
    1717import logging 
    18 import numpy 
     18import numpy as np 
    1919import time 
    2020from copy import deepcopy 
     
    302302        Make new model 
    303303        """ 
    304         if self.new_model_frame != None: 
     304        if self.new_model_frame is not None: 
    305305            self.new_model_frame.Show(False) 
    306306            self.new_model_frame.Show(True) 
     
    386386        help for setting list of the edit model menu labels 
    387387        """ 
    388         if menu == None: 
     388        if menu is None: 
    389389            menu = self.edit_custom_model 
    390390        list_fnames = os.listdir(models.find_plugins_dir()) 
     
    441441            wx.PostEvent(self.parent, StatusEvent(status=msg)) 
    442442 
    443         if page != None: 
     443        if page is not None: 
    444444            return set_focus_page(page) 
    445445        if caption == "Const & Simul Fit": 
     
    634634            state = self.temp_state[self.state_index] 
    635635            #panel state should have model selection to set_state 
    636             if state.formfactorcombobox != None: 
     636            if state.formfactorcombobox is not None: 
    637637                #set state 
    638638                data = self.parent.create_gui_data(state.data) 
     
    877877                enable1D=enable1D, enable2D=enable2D, 
    878878                qmin=qmin, qmax=qmax, weight=weight) 
    879  
    880     def _mac_sleep(self, sec=0.2): 
    881         """ 
    882         Give sleep to MAC 
    883         """ 
    884         if ON_MAC: 
    885             time.sleep(sec) 
    886879 
    887880    def draw_model(self, model, page_id, data=None, smearer=None, 
     
    10231016                return False 
    10241017        ## If a thread is already started, stop it 
    1025         #if self.calc_fit!= None and self.calc_fit.isrunning(): 
     1018        #if self.calc_fitis not None and self.calc_fit.isrunning(): 
    10261019        #    self.calc_fit.stop() 
    10271020        msg = "Fitting is in progress..." 
     
    10321025                                manager=self, 
    10331026                                improvement_delta=0.1) 
    1034         self._mac_sleep(0.2) 
    10351027 
    10361028        # batch fit 
     
    11141106            page = self.fit_panel.add_empty_page() 
    11151107            # add data associated to the page created 
    1116             if page != None: 
     1108            if page is not None: 
    11171109                evt = StatusEvent(status="Page Created", info="info") 
    11181110                wx.PostEvent(self.parent, evt) 
     
    11331125        page = self.fit_panel.set_data(data) 
    11341126        # page could be None when loading state files 
    1135         if page == None: 
     1127        if page is None: 
    11361128            return page 
    11371129        #append Data1D to the panel containing its theory 
     
    12011193        """ 
    12021194        # case that uid is not specified 
    1203         if uid == None: 
     1195        if uid is None: 
    12041196            for page_id in self.page_finder.keys(): 
    12051197                self.page_finder[page_id].schedule_tofit(value) 
     
    12241216            for item in param: 
    12251217                ## check if constraint 
    1226                 if item[0] != None and item[1] != None: 
     1218                if item[0] is not None and item[1] is not None: 
    12271219                    listOfConstraint.append((item[0], item[1])) 
    12281220        new_model = model 
     
    12391231        """ 
    12401232        panel = self.plot_panel 
    1241         if panel == None: 
     1233        if panel is None: 
    12421234            raise ValueError, "Fitting:_onSelect: NonType panel" 
    12431235        Plugin.on_perspective(self, event=event) 
     
    12721264        :param elapsed: time spent at the fitting level 
    12731265        """ 
    1274         self._mac_sleep(0.2) 
    12751266        uid = page_id[0] 
    12761267        if uid in self.fit_thread_list.keys(): 
     
    13341325                    new_theory = copy_data.data 
    13351326                    new_theory[res.index] = res.theory 
    1336                     new_theory[res.index == False] = numpy.nan 
     1327                    new_theory[res.index == False] = np.nan 
    13371328                    correct_result = True 
    13381329                #get all fittable parameters of the current model 
     
    13431334                        param_list.remove(param) 
    13441335                if not correct_result or res.fitness is None or \ 
    1345                     not numpy.isfinite(res.fitness) or \ 
    1346                     numpy.any(res.pvec == None) or not \ 
    1347                     numpy.all(numpy.isfinite(res.pvec)): 
     1336                    not np.isfinite(res.fitness) or \ 
     1337                        np.any(res.pvec is None) or not \ 
     1338                        np.all(np.isfinite(res.pvec)): 
    13481339                    data_name = str(None) 
    13491340                    if data is not None: 
     
    13541345                    msg += "Data %s and Model %s did not fit.\n" % (data_name, 
    13551346                                                                    model_name) 
    1356                     ERROR = numpy.NAN 
     1347                    ERROR = np.NAN 
    13571348                    cell = BatchCell() 
    13581349                    cell.label = res.fitness 
     
    13681359                            batch_inputs["error on %s" % str(param)].append(ERROR) 
    13691360                else: 
    1370                     # TODO: Why sometimes res.pvec comes with numpy.float64? 
     1361                    # TODO: Why sometimes res.pvec comes with np.float64? 
    13711362                    # probably from scipy lmfit 
    1372                     if res.pvec.__class__ == numpy.float64: 
     1363                    if res.pvec.__class__ == np.float64: 
    13731364                        res.pvec = [res.pvec] 
    13741365 
     
    14661457        cell.value = index 
    14671458 
    1468         if theory_data != None: 
     1459        if theory_data is not None: 
    14691460            #Suucessful fit 
    14701461            theory_data.id = wx.NewId() 
     
    15221513            page_id = [] 
    15231514        ## fit more than 1 model at the same time 
    1524         self._mac_sleep(0.2) 
    15251515        try: 
    15261516            index = 0 
     
    15351525                fit_msg = res.mesg 
    15361526                if res.fitness is None or \ 
    1537                     not numpy.isfinite(res.fitness) or \ 
    1538                     numpy.any(res.pvec == None) or \ 
    1539                     not numpy.all(numpy.isfinite(res.pvec)): 
     1527                    not np.isfinite(res.fitness) or \ 
     1528                        np.any(res.pvec is None) or \ 
     1529                    not np.all(np.isfinite(res.pvec)): 
    15401530                    fit_msg += "\nFitting did not converge!!!" 
    15411531                    wx.CallAfter(self._update_fit_button, page_id) 
    15421532                else: 
    15431533                    #set the panel when fit result are float not list 
    1544                     if res.pvec.__class__ == numpy.float64: 
     1534                    if res.pvec.__class__ == np.float64: 
    15451535                        pvec = [res.pvec] 
    15461536                    else: 
    15471537                        pvec = res.pvec 
    1548                     if res.stderr.__class__ == numpy.float64: 
     1538                    if res.stderr.__class__ == np.float64: 
    15491539                        stderr = [res.stderr] 
    15501540                    else: 
     
    15541544                    #(CallAfter is important to MAC) 
    15551545                    try: 
    1556                         #if res != None: 
     1546                        #if res is not None: 
    15571547                        wx.CallAfter(cpage.onsetValues, res.fitness, 
    15581548                                     res.param_list, 
     
    15971587        """ 
    15981588        event.Skip() 
    1599         if self.menu1 == None: 
     1589        if self.menu1 is None: 
    16001590            return 
    16011591        menu_item = self.menu1.FindItemById(self.id_reset_flag) 
     
    16561646        caption = evt.caption 
    16571647        enable_smearer = evt.enable_smearer 
    1658         if model == None: 
     1648        if model is None: 
    16591649            return 
    16601650        if uid not in self.page_finder.keys(): 
     
    16941684        if dy is None: 
    16951685            new_plot.is_data = False 
    1696             new_plot.dy = numpy.zeros(len(y)) 
     1686            new_plot.dy = np.zeros(len(y)) 
    16971687            # If this is a theory curve, pick the proper symbol to make it a curve 
    16981688            new_plot.symbol = GUIFRAME_ID.CURVE_SYMBOL_NUM 
     
    17081698        new_plot.title = data.name 
    17091699        new_plot.group_id = data.group_id 
    1710         if new_plot.group_id == None: 
     1700        if new_plot.group_id is None: 
    17111701            new_plot.group_id = data.group_id 
    17121702        new_plot.id = data_id 
     
    17431733        """ 
    17441734        try: 
    1745             numpy.nan_to_num(y) 
     1735            np.nan_to_num(y) 
    17461736            new_plot = self.create_theory_1D(x, y, page_id, model, data, state, 
    17471737                                             data_description=model.name, 
     
    18271817        that can be plot. 
    18281818        """ 
    1829         numpy.nan_to_num(image) 
     1819        np.nan_to_num(image) 
    18301820        new_plot = Data2D(image=image, err_image=data.err_data) 
    18311821        new_plot.name = model.name + '2d' 
     
    20122002        chisqr = None 
    20132003        #to compute chisq make sure data has valid data 
    2014         # return None if data == None 
    2015         if not check_data_validity(data_copy) or data_copy == None: 
     2004        # return None if data is None 
     2005        if not check_data_validity(data_copy) or data_copy is None: 
    20162006            return chisqr 
    20172007 
    20182008        # Get data: data I, theory I, and data dI in order 
    20192009        if data_copy.__class__.__name__ == "Data2D": 
    2020             if index == None: 
    2021                 index = numpy.ones(len(data_copy.data), dtype=bool) 
    2022             if weight != None: 
     2010            if index is None: 
     2011                index = np.ones(len(data_copy.data), dtype=bool) 
     2012            if weight is not None: 
    20232013                data_copy.err_data = weight 
    20242014            # get rid of zero error points 
    20252015            index = index & (data_copy.err_data != 0) 
    2026             index = index & (numpy.isfinite(data_copy.data)) 
     2016            index = index & (np.isfinite(data_copy.data)) 
    20272017            fn = data_copy.data[index] 
    20282018            theory_data = self.page_finder[page_id].get_theory_data(fid=data_copy.id) 
    2029             if theory_data == None: 
     2019            if theory_data is None: 
    20302020                return chisqr 
    20312021            gn = theory_data.data[index] 
     
    20332023        else: 
    20342024            # 1 d theory from model_thread is only in the range of index 
    2035             if index == None: 
    2036                 index = numpy.ones(len(data_copy.y), dtype=bool) 
    2037             if weight != None: 
     2025            if index is None: 
     2026                index = np.ones(len(data_copy.y), dtype=bool) 
     2027            if weight is not None: 
    20382028                data_copy.dy = weight 
    2039             if data_copy.dy == None or data_copy.dy == []: 
    2040                 dy = numpy.ones(len(data_copy.y)) 
     2029            if data_copy.dy is None or data_copy.dy == []: 
     2030                dy = np.ones(len(data_copy.y)) 
    20412031            else: 
    20422032                ## Set consistently w/AbstractFitengine: 
     
    20472037 
    20482038            theory_data = self.page_finder[page_id].get_theory_data(fid=data_copy.id) 
    2049             if theory_data == None: 
     2039            if theory_data is None: 
    20502040                return chisqr 
    20512041            gn = theory_data.y 
     
    20592049            return 
    20602050 
    2061         residuals = res[numpy.isfinite(res)] 
     2051        residuals = res[np.isfinite(res)] 
    20622052        # get chisqr only w/finite 
    2063         chisqr = numpy.average(residuals * residuals) 
     2053        chisqr = np.average(residuals * residuals) 
    20642054 
    20652055        self._plot_residuals(page_id=page_id, data=data_copy, 
     
    20902080            theory_data = self.page_finder[page_id].get_theory_data(fid=data_copy.id) 
    20912081            gn = theory_data.data 
    2092             if weight == None: 
     2082            if weight is None: 
    20932083                en = data_copy.err_data 
    20942084            else: 
     
    20982088            residuals.qy_data = data_copy.qy_data 
    20992089            residuals.q_data = data_copy.q_data 
    2100             residuals.err_data = numpy.ones(len(residuals.data)) 
     2090            residuals.err_data = np.ones(len(residuals.data)) 
    21012091            residuals.xmin = min(residuals.qx_data) 
    21022092            residuals.xmax = max(residuals.qx_data) 
     
    21112101        else: 
    21122102            # 1 d theory from model_thread is only in the range of index 
    2113             if data_copy.dy == None or data_copy.dy == []: 
    2114                 dy = numpy.ones(len(data_copy.y)) 
     2103            if data_copy.dy is None or data_copy.dy == []: 
     2104                dy = np.ones(len(data_copy.y)) 
    21152105            else: 
    2116                 if weight == None: 
    2117                     dy = numpy.ones(len(data_copy.y)) 
     2106                if weight is None: 
     2107                    dy = np.ones(len(data_copy.y)) 
    21182108                ## Set consitently w/AbstractFitengine: 
    21192109                ## But this should be corrected later. 
     
    21342124                residuals.y = (fn - gn[index]) / en 
    21352125            residuals.x = data_copy.x[index] 
    2136             residuals.dy = numpy.ones(len(residuals.y)) 
     2126            residuals.dy = np.ones(len(residuals.y)) 
    21372127            residuals.dx = None 
    21382128            residuals.dxl = None 
     
    21522142        ##group_id specify on which panel to plot this data 
    21532143        group_id = self.page_finder[page_id].get_graph_id() 
    2154         if group_id == None: 
     2144        if group_id is None: 
    21552145            group_id = data.group_id 
    21562146        new_plot.group_id = "res" + str(group_id) 
Note: See TracChangeset for help on using the changeset viewer.