Changeset b297ba9 in sasmodels for sasmodels/kernel.py


Ignore:
Timestamp:
Mar 20, 2019 7:03:50 PM (5 months ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, core_shell_microgels, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
4e28511
Parents:
0d362b7
Message:

lint

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/kernel.py

    r36a2418 rb297ba9  
    2525 
    2626class KernelModel(object): 
     27    """ 
     28    Model definition for the compute engine. 
     29    """ 
    2730    info = None  # type: ModelInfo 
    2831    dtype = None # type: np.dtype 
    2932    def make_kernel(self, q_vectors): 
    3033        # type: (List[np.ndarray]) -> "Kernel" 
     34        """ 
     35        Instantiate a kernel for evaluating the model at *q_vectors*. 
     36        """ 
    3137        raise NotImplementedError("need to implement make_kernel") 
    3238 
    3339    def release(self): 
    3440        # type: () -> None 
     41        """ 
     42        Free resources associated with the kernel. 
     43        """ 
    3544        pass 
    3645 
    3746 
    3847class Kernel(object): 
    39     #: kernel dimension, either "1d" or "2d" 
     48    """ 
     49    Instantiated model for the compute engine, applied to a particular *q*. 
     50 
     51    Subclasses should define :meth:`_call_kernel` to evaluate the kernel over 
     52    its inputs. 
     53    """ 
     54    #: Kernel dimension, either "1d" or "2d". 
    4055    dim = None  # type: str 
     56    #: Model info. 
    4157    info = None  # type: ModelInfo 
    42     results = None # type: List[np.ndarray] 
     58    #: Numerical precision for the computation. 
    4359    dtype = None  # type: np.dtype 
     60    #: q values at which the kernel is to be evaluated 
     61    q_input = None  # type: Any 
     62    #: Place to hold result of :meth:`_call_kernel` for subclass. 
     63    result = None # type: np.ndarray 
    4464 
    4565    def Iq(self, call_details, values, cutoff, magnetic): 
     
    5777        built into the model, and do not need an additional scale. 
    5878        """ 
    59         _, F2, _, shell_volume, _ = self.Fq(call_details, values, cutoff, magnetic, 
    60                               effective_radius_type=0) 
     79        _, F2, _, shell_volume, _ = self.Fq(call_details, values, cutoff, 
     80                                            magnetic, effective_radius_type=0) 
    6181        combined_scale = values[0]/shell_volume 
    6282        background = values[1] 
     
    6484    __call__ = Iq 
    6585 
    66     def Fq(self, call_details, values, cutoff, magnetic, effective_radius_type=0): 
     86    def Fq(self, call_details, values, cutoff, magnetic, 
     87           effective_radius_type=0): 
    6788        # type: (CallDetails, np.ndarray, np.ndarray, float, bool, int) -> np.ndarray 
    6889        r""" 
     
    81102        .. math:: 
    82103 
    83             I(q) = \text{scale} * P (1 + <F>^2/<F^2> (S - 1)) + \text{background} 
     104            I(q) = \text{scale} P (1 + <F>^2/<F^2> (S - 1)) + \text{background} 
    84105                 = \text{scale}/<V> (<F^2> + <F>^2 (S - 1)) + \text{background} 
    85106 
     
    90111        .. math:: 
    91112 
    92             P(q) = \frac{\sum w_k F^2(q, x_k) / \sum w_k}{\sum w_k V_k / \sum w_k} 
     113            P(q)=\frac{\sum w_k F^2(q, x_k) / \sum w_k}{\sum w_k V_k / \sum w_k} 
    93114 
    94115        The form factor itself is scaled by volume and contrast to compute the 
     
    131152        hollow and solid shapes. 
    132153        """ 
    133         self._call_kernel(call_details, values, cutoff, magnetic, effective_radius_type) 
     154        self._call_kernel(call_details, values, cutoff, magnetic, 
     155                          effective_radius_type) 
    134156        #print("returned",self.q_input.q, self.result) 
    135157        nout = 2 if self.info.have_Fq and self.dim == '1d' else 1 
     
    146168        if shell_volume == 0.: 
    147169            shell_volume = 1. 
    148         F1 = self.result[1:nout*self.q_input.nq:nout]/total_weight if nout == 2 else None 
     170        F1 = (self.result[1:nout*self.q_input.nq:nout]/total_weight 
     171              if nout == 2 else None) 
    149172        F2 = self.result[0:nout*self.q_input.nq:nout]/total_weight 
    150173        return F1, F2, effective_radius, shell_volume, form_volume/shell_volume 
     
    152175    def release(self): 
    153176        # type: () -> None 
     177        """ 
     178        Free resources associated with the kernel instance. 
     179        """ 
    154180        pass 
    155181 
    156     def _call_kernel(self, call_details, values, cutoff, magnetic, effective_radius_type): 
     182    def _call_kernel(self, call_details, values, cutoff, magnetic, 
     183                     effective_radius_type): 
    157184        # type: (CallDetails, np.ndarray, np.ndarray, float, bool, int) -> np.ndarray 
    158185        """ 
Note: See TracChangeset for help on using the changeset viewer.