Changeset b297ba9 in sasmodels for sasmodels/kernel.py
 Timestamp:
 Mar 20, 2019 7:03:50 PM (5 months ago)
 Branches:
 master, core_shell_microgels, magnetic_model, ticket1257vesicleproduct, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
 Children:
 4e28511
 Parents:
 0d362b7
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

sasmodels/kernel.py
r36a2418 rb297ba9 25 25 26 26 class KernelModel(object): 27 """ 28 Model definition for the compute engine. 29 """ 27 30 info = None # type: ModelInfo 28 31 dtype = None # type: np.dtype 29 32 def make_kernel(self, q_vectors): 30 33 # type: (List[np.ndarray]) > "Kernel" 34 """ 35 Instantiate a kernel for evaluating the model at *q_vectors*. 36 """ 31 37 raise NotImplementedError("need to implement make_kernel") 32 38 33 39 def release(self): 34 40 # type: () > None 41 """ 42 Free resources associated with the kernel. 43 """ 35 44 pass 36 45 37 46 38 47 class 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". 40 55 dim = None # type: str 56 #: Model info. 41 57 info = None # type: ModelInfo 42 results = None # type: List[np.ndarray]58 #: Numerical precision for the computation. 43 59 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 44 64 45 65 def Iq(self, call_details, values, cutoff, magnetic): … … 57 77 built into the model, and do not need an additional scale. 58 78 """ 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) 61 81 combined_scale = values[0]/shell_volume 62 82 background = values[1] … … 64 84 __call__ = Iq 65 85 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): 67 88 # type: (CallDetails, np.ndarray, np.ndarray, float, bool, int) > np.ndarray 68 89 r""" … … 81 102 .. math:: 82 103 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} 84 105 = \text{scale}/<V> (<F^2> + <F>^2 (S  1)) + \text{background} 85 106 … … 90 111 .. math:: 91 112 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} 93 114 94 115 The form factor itself is scaled by volume and contrast to compute the … … 131 152 hollow and solid shapes. 132 153 """ 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) 134 156 #print("returned",self.q_input.q, self.result) 135 157 nout = 2 if self.info.have_Fq and self.dim == '1d' else 1 … … 146 168 if shell_volume == 0.: 147 169 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) 149 172 F2 = self.result[0:nout*self.q_input.nq:nout]/total_weight 150 173 return F1, F2, effective_radius, shell_volume, form_volume/shell_volume … … 152 175 def release(self): 153 176 # type: () > None 177 """ 178 Free resources associated with the kernel instance. 179 """ 154 180 pass 155 181 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): 157 184 # type: (CallDetails, np.ndarray, np.ndarray, float, bool, int) > np.ndarray 158 185 """
Note: See TracChangeset
for help on using the changeset viewer.