Changeset 6e7ff6d in sasmodels for sasmodels/generate.py


Ignore:
Timestamp:
Apr 7, 2016 2:01:54 PM (8 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, core_shell_microgels, costrafo411, magnetic_model, release_v0.94, release_v0.95, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
3543141
Parents:
8bd7b77
Message:

reenable python models

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/generate.py

    r4937980 r6e7ff6d  
    125125An *model_info* dictionary is constructed from the kernel meta data and 
    126126returned to the caller. 
    127  
    128 The model evaluator, function call sequence consists of q inputs and the return vector, 
    129 followed by the loop value/weight vector, followed by the values for 
    130 the non-polydisperse parameters, followed by the lengths of the 
    131 polydispersity loops.  To construct the call for 1D models, the 
    132 categories *fixed-1d* and *pd-1d* list the names of the parameters 
    133 of the non-polydisperse and the polydisperse parameters respectively. 
    134 Similarly, *fixed-2d* and *pd-2d* provide parameter names for 2D models. 
    135 The *pd-rel* category is a set of those parameters which give 
    136 polydispersitiy as a portion of the value (so a 10% length dispersity 
    137 would use a polydispersity value of 0.1) rather than absolute 
    138 dispersity such as an angle plus or minus 15 degrees. 
    139  
    140 The *volume* category lists the volume parameters in order for calls 
    141 to volume within the kernel (used for volume normalization) and for 
    142 calls to ER and VR for effective radius and volume ratio respectively. 
    143  
    144 The *orientation* and *magnetic* categories list the orientation and 
    145 magnetic parameters.  These are used by the sasview interface.  The 
    146 blank category is for parameters such as scale which don't have any 
    147 other marking. 
    148127 
    149128The doc string at the start of the kernel module will be used to 
     
    552531    @property 
    553532    def ctypes(self): return self.details.ctypes 
     533 
    554534    @property 
    555535    def pd_par(self): return self._pd_par 
     536 
    556537    @property 
    557538    def pd_length(self): return self._pd_length 
     539 
    558540    @property 
    559541    def pd_offset(self): return self._pd_offset 
     542 
    560543    @property 
    561544    def pd_stride(self): return self._pd_stride 
     545 
    562546    @property 
    563547    def pd_coord(self): return self._pd_coord 
     548 
    564549    @property 
    565550    def par_coord(self): return self._par_coord 
     551 
    566552    @property 
    567553    def par_offset(self): return self._par_offset 
     554 
     555    @property 
     556    def num_active(self): return self.details[-4] 
     557    @num_active.setter 
     558    def num_active(self, v): self.details[-4] = v 
     559 
     560    @property 
     561    def total_pd(self): return self.details[-3] 
     562    @total_pd.setter 
     563    def total_pd(self, v): self.details[-3] = v 
     564 
    568565    @property 
    569566    def num_coord(self): return self.details[-2] 
    570567    @num_coord.setter 
    571568    def num_coord(self, v): self.details[-2] = v 
    572     @property 
    573     def total_pd(self): return self.details[-3] 
    574     @total_pd.setter 
    575     def total_pd(self, v): self.details[-3] = v 
    576     @property 
    577     def num_active(self): return self.details[-4] 
    578     @num_active.setter 
    579     def num_active(self, v): self.details[-4] = v 
     569 
     570    @property 
     571    def theta_par(self): return self.details[-1] 
    580572 
    581573    def show(self): 
     
    638630 
    639631 
     632def create_vector_Iq(model_info): 
     633    """ 
     634    Define Iq as a vector function if it exists. 
     635    """ 
     636    Iq = model_info['Iq'] 
     637    if callable(Iq) and not getattr(Iq, 'vectorized', False): 
     638        def vector_Iq(q, *args): 
     639            """ 
     640            Vectorized 1D kernel. 
     641            """ 
     642            return np.array([Iq(qi, *args) for qi in q]) 
     643        model_info['Iq'] = vector_Iq 
     644 
     645def create_vector_Iqxy(model_info): 
     646    """ 
     647    Define Iqxy as a vector function if it exists, or default it from Iq(). 
     648    """ 
     649    Iq, Iqxy = model_info['Iq'], model_info['Iqxy'] 
     650    if callable(Iqxy) and not getattr(Iqxy, 'vectorized', False): 
     651        def vector_Iqxy(qx, qy, *args): 
     652            """ 
     653            Vectorized 2D kernel. 
     654            """ 
     655            return np.array([Iqxy(qxi, qyi, *args) for qxi, qyi in zip(qx, qy)]) 
     656        model_info['Iqxy'] = vector_Iqxy 
     657    elif callable(Iq): 
     658        # Iq is vectorized because create_vector_Iq was already called. 
     659        def default_Iqxy(qx, qy, *args): 
     660            """ 
     661            Default 2D kernel. 
     662            """ 
     663            return Iq(np.sqrt(qx**2 + qy**2), *args) 
     664        model_info['Iqxy'] = default_Iqxy 
     665 
    640666def create_default_functions(model_info): 
    641667    """ 
     
    643669 
    644670    This only works for Iqxy when Iq is written in python. :func:`make_source` 
    645     performs a similar role for Iq written in C. 
    646     """ 
    647     if callable(model_info['Iq']) and model_info['Iqxy'] is None: 
    648         partable = model_info['parameters'] 
    649         if partable.has_2d: 
    650             raise ValueError("Iqxy model is missing") 
    651         Iq = model_info['Iq'] 
    652         def Iqxy(qx, qy, **kw): 
    653             return Iq(np.sqrt(qx**2 + qy**2), **kw) 
    654         model_info['Iqxy'] = Iqxy 
    655  
     671    performs a similar role for Iq written in C.  This also vectorizes 
     672    any functions that are not already marked as vectorized. 
     673    """ 
     674    create_vector_Iq(model_info) 
     675    create_vector_Iqxy(model_info)  # call create_vector_Iq() first 
    656676 
    657677def load_kernel_module(model_name): 
Note: See TracChangeset for help on using the changeset viewer.