Changeset bfe4644 in sasview for sansview


Ignore:
Timestamp:
Sep 17, 2009 6:21:56 AM (15 years ago)
Author:
Gervaise Alina <gervyh@…>
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:
104f3da
Parents:
c5cd3b9
Message:

add check for plugin model

Location:
sansview/perspectives/fitting
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • sansview/perspectives/fitting/fitting.py

    r7ad6ff5 rbfe4644  
    277277            @param return  
    278278        """ 
    279         detector=None 
    280         source=None 
     279        
    281280        info = None 
    282281        id=None 
    283         dxl=None 
    284         dxw=None 
    285         dx=None 
    286         if hasattr(item, "dxl"): 
    287             dxl = copy.deepcopy(item.dxl) 
    288         if hasattr(item, "dxw"): 
    289             dxw = copy.deepcopy(item.dxw) 
    290         if hasattr(item, "detector"): 
    291             detector = copy.deepcopy(item.detector) 
    292         if hasattr(item, "source"): 
    293             source = copy.deepcopy(item.source) 
     282     
    294283        if hasattr(item ,"info"): 
    295284            info= copy.deepcopy(item.info) 
    296285        if hasattr(item,"id"): 
    297286            id = copy.deepcopy(item.id) 
    298         if hasattr(item, "dx"): 
    299             dx= item.dx 
    300              
    301          
    302         data= Data1D(x=item.x, y=item.y,dx=dx, dy=dy) 
    303         data.dxl = dxl 
    304         data.dxw = dxw 
    305          
     287        
     288        data= Data1D(x=item.x, y=item.y,dx=None, dy=None) 
     289        data.copy_from_datainfo(item)  
     290        item.clone_without_data(clone=data)       
     291        data.dy= dy 
    306292        data.name = item.name 
    307         data.detector = detector 
    308         data.source = source 
     293       
    309294        ## allow to highlight data when plotted 
    310295        data.interactive = copy.deepcopy(item.interactive) 
     
    314299        ## to save  data 1D as cansas xml file 
    315300        data.info= info 
    316         ## If the data file does not tell us what the axes are, just assume... 
    317         data.xaxis(copy.deepcopy(item._xaxis),copy.deepcopy(item._xunit)) 
    318         data.yaxis(copy.deepcopy(item._yaxis),copy.deepcopy(item._yunit)) 
    319         ##group_id specify on which panel to plot this data 
    320301        data.group_id = item.group_id 
    321302        return data 
    322  
     303     
    323304    def set_fit_range(self, page, qmin, qmax): 
    324305        """ 
     
    409390         
    410391        smear =self.page_finder[current_pg].get_smearer() 
    411         self.draw_model( model=model, data= data, smearer= smear, 
     392        if model!= None: 
     393            self.draw_model( model=model, data= data, smearer= smear, 
    412394                qmin= qmin, qmax= qmax) 
    413395 
  • sansview/perspectives/fitting/gui_thread.py

    r785c8233 rbfe4644  
    7878            # Thread was interrupted, just proceed and re-raise. 
    7979            # Real code should not print, but this is an example... 
    80             raise 
    81         except:  
    82             raise 
     80            raise KeyboardInterrupt 
     81       
    8382         
    8483class CalcChisqr2D(CalcThread): 
     
    149148            # Thread was interrupted, just proceed and re-raise. 
    150149            # Real code should not print, but this is an example... 
    151             raise 
    152         except:  
    153             raise 
     150            raise KeyboardInterrupt 
     151        
  • sansview/perspectives/fitting/model_thread.py

    raeb3c20 rbfe4644  
    115115        index= (self.qmin <= self.x)& (self.x <= self.qmax) 
    116116        output[index] = self.model.evalDistribution(self.x[index]) 
     117      
     118        _first_bin = None 
     119        _last_bin  = None 
     120        
     121        for i_x in xrange(len(self.x)): 
     122            if index[i_x]: 
     123                # Identify first and last bin 
     124                #TODO: refactor this to pass q-values to the smearer 
     125                # and let it figure out which bin range to use 
     126                if _first_bin is None: 
     127                    _first_bin = i_x 
     128                else: 
     129                    _last_bin  = i_x 
    117130       
    118131        ##smearer the ouput of the plot     
    119132        if self.smearer!=None: 
    120             output = self.smearer(output) #Todo: Why always output[0]=0??? 
    121          
     133            #output= self.smearer(output) 
     134            output = self.smearer(output, _first_bin,_last_bin) #Todo: Why always output[0]=0??? 
     135          
    122136        ######Temp. FIX for Qrange w/ smear. #ToDo: Should not pass all the data to 'run' or 'smear'... 
    123         new_index = (self.qmin > self.x) |(self.x > self.qmax) 
    124         output[new_index] = None 
     137        #new_index = (self.qmin > self.x) |(self.x > self.qmax) 
     138        #output[new_index] = None 
    125139                 
     140        #print "output------",output 
    126141        elapsed = time.time()-self.starttime 
    127142        
  • sansview/perspectives/fitting/models.py

    r9002927 rbfe4644  
    1111import os,sys,math 
    1212import os.path 
    13  
     13from sans.models.pluginmodel import Model1DPlugin 
    1414(ModelEvent, EVT_MODEL) = wx.lib.newevent.NewEvent() 
    1515from sans.guicomm.events import StatusEvent   
     
    3333    return [] 
    3434     
     35def _check_plugin(model, name): 
     36    """ 
     37        Do some checking before model adding plugins in the list 
     38        @param model: class model to add into the plugin list 
     39        @param name:name of the module plugin 
     40        @return model: model if valid model or nothing if not valid 
     41    """ 
     42    #Check is the plugin is of type Model1DPlugin 
     43    if not issubclass(model, Model1DPlugin): 
     44        msg= "Plugin %s must be of type Model1DPlugin \n"%str(name) 
     45        log(msg) 
     46        return  
     47    if model.__name__!="Model": 
     48        msg= "Plugin %s class name must be Model \n"%str(name) 
     49        log(msg) 
     50        return  
     51    try: 
     52        new_instance= model() 
     53    except: 
     54        msg="Plugin %s error in __init__ \n\t: %s %s\n"%(str(name), 
     55                                    str(sys.exc_type),sys.exc_value) 
     56        log(msg) 
     57        return 
     58    
     59    new_instance= model()  
     60    if hasattr(new_instance,"function"): 
     61        try: 
     62           value=new_instance.function() 
     63        except: 
     64           msg="Plugin %s: error writing function \n\t :%s %s\n "%(str(name), 
     65                                    str(sys.exc_type),sys.exc_value) 
     66           log(msg) 
     67           return 
     68    else: 
     69       msg="Plugin  %s needs a method called function \n"%str(name) 
     70       log(msg) 
     71       return  
     72    return model 
     73   
     74   
    3575def _findModels(dir): 
    3676    # List of plugin objects 
     
    5191                    if hasattr(module, "Model"): 
    5292                        try: 
    53                             plugins.append(module.Model) 
     93                            if _check_plugin(module.Model, name)!=None: 
     94                            #plugins.append(module.Model) 
     95                                plugins.append(module.Model) 
    5496                        except: 
    55                             log("Error accessing Model in %s\n  %s" % (name, sys.exc_value)) 
     97                            msg="Error accessing Model" 
     98                            msg+="in %s\n  %s %s\n" % (name, 
     99                                    str(sys.exc_type), sys.exc_value) 
     100                            log(msg) 
    56101                except: 
    57                     log("Error accessing Model in %s\n  %s" % (name, sys.exc_value)) 
     102                    msg="Error accessing Model" 
     103                    msg +=" in %s\n  %s %s \n" %(name, 
     104                                    str(sys.exc_type), sys.exc_value) 
     105                    log(msg) 
    58106                finally: 
    59107               
     
    285333                                list1= self.struct_list ) 
    286334         
    287         self._fill_simple_menu( menuinfo = ["Customized Models", added_models, 
     335        self._fill_plugin_menu( menuinfo = ["Customized Models", added_models, 
    288336                                            "List of additional models"], 
    289337                                 list1= self.plugins ) 
     
    297345        return 0 
    298346     
     347    def _fill_plugin_menu(self,menuinfo, list1): 
     348        """ 
     349            fill the plugin menu with costumized models 
     350        """ 
     351        if len(list1)==0: 
     352            id = wx.NewId()  
     353            msg= "No model available check plugins.log for errors to fix problem" 
     354            menuinfo[1].Append(int(id),"Empty",msg) 
     355        self._fill_simple_menu( menuinfo,list1) 
     356         
     357         
    299358    def _fill_simple_menu(self,menuinfo, list1): 
    300359        """ 
Note: See TracChangeset for help on using the changeset viewer.