Changeset 946b452 in sasview for sansmodels/src/sans/models


Ignore:
Timestamp:
Aug 29, 2011 12:13:50 PM (13 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:
c832374d
Parents:
2c60cb69
Message:

improve pickling smearer

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sansmodels/src/sans/models/qsmearing.py

    r5d2e4c1 r946b452  
    404404    def __setstate__(self, state): 
    405405        """ 
     406        Restore the state of the object by reconstruction the (smearer) object 
    406407        """ 
    407408        self.__dict__, self.model,  self.data = state 
     
    409410        self._smearer = smearer.new_slit_smearer_with_q(self.width,  
    410411                                                    self.height, self.qvalues) 
     412        self.__dict__['_smearer'] = self._smearer 
    411413         
    412414    def __reduce_ex__(self, proto): 
    413415        """ 
    414         Overwrite the __reduce_ex__ of PyTypeObject *type call in the init of  
    415         c model. 
     416        Overwrite the __reduce_ex__to avoid pickle PyCobject(smearer) 
    416417        """ 
    417418        model = copy.deepcopy(self.model) 
    418419        data = copy.deepcopy(self.data) 
    419         dict = self.__dict__ 
    420         if "_smearer" in dict.keys(): 
    421             del dict["_smearer"] 
     420        dict = {} 
     421        for k , v in self.__dict__.iteritems(): 
     422            if k != "_smearer": 
     423                dict[k] = v 
    422424        state = (dict, model, data) 
    423         return (QSmearer, (data, model), state, None, None) 
     425        return (SlitSmearer, (data, model), state, None, None) 
    424426         
    425427 
     
    450452        self._weights = None 
    451453        self.qvalues  = None 
     454       
    452455         
    453456    def _initialize_smearer(self): 
     
    515518        ## Q-values 
    516519        self.qvalues = data1d_x 
     520        
    517521         
    518522    def __deepcopy__(self, memo={}): 
     
    541545    def __setstate__(self, state): 
    542546        """ 
     547        Restore the state of the object by reconstruction the (smearer) object 
    543548        """ 
    544549        self.__dict__, self.model,  self.data = state 
     
    546551        self._smearer =  smearer.new_q_smearer_with_q(numpy.asarray(self.width), 
    547552                                                      self.qvalues) 
     553        self.__dict__['_smearer'] = self._smearer 
    548554  
    549555    def __reduce_ex__(self, proto): 
    550556        """ 
    551         Overwrite the __reduce_ex__ of PyTypeObject *type call in the init of  
    552         c model. 
     557        Overwrite the __reduce_ex__to avoid pickle PyCobject(smearer) 
    553558        """ 
    554559        model = copy.deepcopy(self.model) 
    555560        data = copy.deepcopy(self.data) 
    556         dict = self.__dict__ 
    557         if "_smearer" in dict.keys(): 
    558             del dict["_smearer"] 
     561        dict = {} 
     562        for k , v in self.__dict__.iteritems(): 
     563            if k != "_smearer": 
     564                dict[k] = v 
    559565        state = (dict, model, data) 
    560566        return (QSmearer, (data, model), state, None, None) 
Note: See TracChangeset for help on using the changeset viewer.