Changeset 4e96703 in sasmodels for sasmodels/sasview_model.py
- Timestamp:
- Nov 9, 2018 12:21:36 PM (5 years ago)
- Branches:
- master
- Children:
- e2da671
- Parents:
- 12f77e9 (diff), cf3d0ce (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/sasview_model.py
r12f77e9 r4e96703 288 288 attrs['category'] = model_info.category 289 289 attrs['is_structure_factor'] = model_info.structure_factor 290 attrs['is_form_factor'] = model_info. ERis not None290 attrs['is_form_factor'] = model_info.effective_radius_type is not None 291 291 attrs['is_multiplicity_model'] = variants[0] > 1 292 292 attrs['multiplicity_info'] = variants … … 562 562 # pylint: disable=unpacking-non-sequence 563 563 q, phi = x 564 return self.calculate_Iq([q*math.cos(phi)], [q*math.sin(phi)])[0] 564 result, _ = self.calculate_Iq([q*math.cos(phi)], [q*math.sin(phi)]) 565 return result[0] 565 566 else: 566 return self.calculate_Iq([x])[0] 567 result, _ = self.calculate_Iq([x]) 568 return result[0] 567 569 568 570 … … 579 581 """ 580 582 if isinstance(x, (list, tuple)): 581 return self.calculate_Iq([x[0]], [x[1]])[0] 583 result, _ = self.calculate_Iq([x[0]], [x[1]]) 584 return result[0] 582 585 else: 583 return self.calculate_Iq([x])[0] 586 result, _ = self.calculate_Iq([x]) 587 return result[0] 584 588 585 589 def evalDistribution(self, qdist): … … 615 619 # Check whether we have a list of ndarrays [qx,qy] 616 620 qx, qy = qdist 617 return self.calculate_Iq(qx, qy) 621 result, _ = self.calculate_Iq(qx, qy) 622 return result 618 623 619 624 elif isinstance(qdist, np.ndarray): 620 625 # We have a simple 1D distribution of q-values 621 return self.calculate_Iq(qdist) 626 result, _ = self.calculate_Iq(qdist) 627 return result 622 628 623 629 else: … … 638 644 # so that it returns a results object containing all the bits: 639 645 # the A, B, C, ... of the composition model (and any subcomponents?) 640 # the P and S of the product model ,646 # the P and S of the product model 641 647 # the combined model before resolution smearing, 642 648 # the sasmodel before sesans conversion, … … 659 665 if composition and composition[0] == 'product': # only P*S for now 660 666 with calculation_lock: 661 self._calculate_Iq(qx) 662 return self._intermediate_results 667 _, lazy_results = self._calculate_Iq(qx) 668 # for compatibility with sasview 4.x 669 results = lazy_results() 670 pq_data = results.get("P(Q)") 671 sq_data = results.get("S(Q)") 672 return pq_data, sq_data 663 673 else: 664 674 return None 665 675 666 def calculate_Iq(self, qx, qy=None): 667 # type: (Sequence[float], Optional[Sequence[float]]) -> np.ndarray 676 def calculate_Iq(self, 677 qx, # type: Sequence[float] 678 qy=None # type: Optional[Sequence[float]] 679 ): 680 # type: (...) -> Tuple[np.ndarray, Callable[[], collections.OrderedDict[str, np.ndarray]]] 668 681 """ 669 682 Calculate Iq for one set of q with the current parameters. … … 673 686 This should NOT be used for fitting since it copies the *q* vectors 674 687 to the card for each evaluation. 688 689 The returned tuple contains the scattering intensity followed by a 690 callable which returns a dictionary of intermediate data from 691 ProductKernel. 675 692 """ 676 693 ## uncomment the following when trying to debug the uncoordinated calls … … 683 700 return self._calculate_Iq(qx, qy) 684 701 685 def _calculate_Iq(self, qx, qy=None ):702 def _calculate_Iq(self, qx, qy=None, Fq=False, effective_radius_type=1): 686 703 if self._model is None: 687 704 self._model = core.build_model(self._model_info) … … 703 720 #print("values", values) 704 721 #print("is_mag", is_magnetic) 722 if Fq: 723 result = calculator.Fq(call_details, values, cutoff=self.cutoff, 724 magnetic=is_magnetic, 725 effective_radius_type=effective_radius_type) 705 726 result = calculator(call_details, values, cutoff=self.cutoff, 706 727 magnetic=is_magnetic) 728 lazy_results = getattr(calculator, 'results', 729 lambda: collections.OrderedDict()) 707 730 #print("result", result) 708 self._intermediate_results = getattr(calculator, 'results', None) 731 709 732 calculator.release() 710 733 #self._model.release() 711 return result 712 713 def calculate_ER(self): 734 735 return result, lazy_results 736 737 738 def calculate_ER(self, mode=1): 714 739 # type: () -> float 715 740 """ … … 718 743 :return: the value of the effective radius 719 744 """ 720 if self._model_info.ER is None: 721 return 1.0 722 else: 723 value, weight = self._dispersion_mesh() 724 fv = self._model_info.ER(*value) 725 #print(values[0].shape, weights.shape, fv.shape) 726 return np.sum(weight * fv) / np.sum(weight) 745 Fq = self._calculate_Iq([0.1], True, mode) 746 return Fq[2] 727 747 728 748 def calculate_VR(self): … … 731 751 Calculate the volf ratio for P(q)*S(q) 732 752 733 :return: the value of the volf ratio 734 """ 735 if self._model_info.VR is None: 736 return 1.0 737 else: 738 value, weight = self._dispersion_mesh() 739 whole, part = self._model_info.VR(*value) 740 return np.sum(weight * part) / np.sum(weight * whole) 753 :return: the value of the form:shell volume ratio 754 """ 755 Fq = self._calculate_Iq([0.1], True, mode) 756 return Fq[4] 741 757 742 758 def set_dispersion(self, parameter, dispersion): … … 848 864 P = _make_standard_model('cylinder')() 849 865 model = MultiplicationModel(P, S) 866 model.setParam(product.RADIUS_MODE_ID, 1.0) 850 867 value = model.evalDistribution([0.1, 0.1]) 851 868 if np.isnan(value): … … 908 925 q = np.linspace(-0.35, 0.35, 500) 909 926 qx, qy = np.meshgrid(q, q) 910 result = model.calculate_Iq(qx.flatten(), qy.flatten())927 result, _ = model.calculate_Iq(qx.flatten(), qy.flatten()) 911 928 result = result.reshape(qx.shape) 912 929
Note: See TracChangeset
for help on using the changeset viewer.