Changeset 6e7ba14 in sasmodels for sasmodels/kernel.py
- Timestamp:
- Aug 20, 2018 8:52:21 AM (6 years ago)
- Branches:
- master, core_shell_microgels, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
- Children:
- aa44a6a
- Parents:
- bad3093
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/kernel.py
r2d81cfe r6e7ba14 41 41 dtype = None # type: np.dtype 42 42 43 def __call__(self, call_details, values, cutoff, magnetic):43 def Iq(self, call_details, values, cutoff, magnetic): 44 44 # type: (CallDetails, np.ndarray, np.ndarray, float, bool) -> np.ndarray 45 raise NotImplementedError("need to implement __call__") 45 Pq, Reff = self.Pq_Reff(call_details, values, cutoff, magnetic, effective_radius_type=0) 46 scale = values[0] 47 background = values[1] 48 return scale*Pq + background 49 __call__ = Iq 50 51 def Pq_Reff(self, call_details, values, cutoff, magnetic, effective_radius_type): 52 # type: (CallDetails, np.ndarray, np.ndarray, float, bool, int) -> np.ndarray 53 self._call_kernel(call_details, values, cutoff, magnetic, effective_radius_type) 54 #print("returned",self.q_input.q, self.result) 55 nout = 2 if self.info.have_Fq else 1 56 total_weight = self.result[nout*self.q_input.nq + 0] 57 if total_weight == 0.: 58 total_weight = 1. 59 weighted_volume = self.result[nout*self.q_input.nq + 1] 60 weighted_radius = self.result[nout*self.q_input.nq + 2] 61 effective_radius = weighted_radius/total_weight 62 # compute I = scale*P + background 63 # = scale*(sum(w*F^2)/sum w)/(sum (w*V)/sum w) + background 64 # = scale/sum (w*V) * sum(w*F^2) + background 65 scale = values[0]/(weighted_volume if weighted_volume != 0.0 else 1.0) 66 background = values[1] 67 #print("scale",scale,background) 68 return self.result[0:nout*self.q_input.nq:nout], effective_radius 69 70 def beta(self, call_details, values, cutoff, magnetic, effective_radius_type): 71 # type: (CallDetails, np.ndarray, np.ndarray, float, bool, int) -> np.ndarray 72 if self.dim == '2d': 73 raise NotImplementedError("beta not yet supported for 2D") 74 if not self.info.have_Fq: 75 raise NotImplementedError("beta not yet supported for "+self.info.id) 76 self._call_kernel(call_details, values, cutoff, magnetic, effective_radius_type) 77 total_weight = self.result[2*self.q_input.nq + 0] 78 if total_weight == 0.: 79 total_weight = 1. 80 weighted_volume = self.result[2*self.q_input.nq + 1] 81 weighted_radius = self.result[2*self.q_input.nq + 2] 82 volume_average = weighted_volume/total_weight 83 effective_radius = weighted_radius/total_weight 84 F2 = self.result[0:2*self.q_input.nq:2]/total_weight 85 F1 = self.result[1:2*self.q_input.nq:2]/total_weight 86 return F1, F2, volume_average, effective_radius 46 87 47 88 def release(self): 48 89 # type: () -> None 49 90 pass 91 92 def _call_kernel(self, call_details, values, cutoff, magnetic, effective_radius_type): 93 # type: (CallDetails, np.ndarray, np.ndarray, float, bool, int) -> np.ndarray 94 raise NotImpmentedError()
Note: See TracChangeset
for help on using the changeset viewer.