Changeset c1799d3 in sasmodels for sasmodels/sasview_model.py
- Timestamp:
- Nov 9, 2018 12:16:05 PM (5 years ago)
- Branches:
- master, core_shell_microgels, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
- Children:
- c11d09f
- Parents:
- 17695aa (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
r17695aa rc1799d3 283 283 attrs['category'] = model_info.category 284 284 attrs['is_structure_factor'] = model_info.structure_factor 285 attrs['is_form_factor'] = model_info. ERis not None285 attrs['is_form_factor'] = model_info.effective_radius_type is not None 286 286 attrs['is_multiplicity_model'] = variants[0] > 1 287 287 attrs['multiplicity_info'] = variants … … 556 556 # pylint: disable=unpacking-non-sequence 557 557 q, phi = x 558 return self.calculate_Iq([q*math.cos(phi)], [q*math.sin(phi)])[0] 558 result, _ = self.calculate_Iq([q*math.cos(phi)], [q*math.sin(phi)]) 559 return result[0] 559 560 else: 560 return self.calculate_Iq([x])[0] 561 result, _ = self.calculate_Iq([x]) 562 return result[0] 561 563 562 564 … … 573 575 """ 574 576 if isinstance(x, (list, tuple)): 575 return self.calculate_Iq([x[0]], [x[1]])[0] 577 result, _ = self.calculate_Iq([x[0]], [x[1]]) 578 return result[0] 576 579 else: 577 return self.calculate_Iq([x])[0] 580 result, _ = self.calculate_Iq([x]) 581 return result[0] 578 582 579 583 def evalDistribution(self, qdist): … … 609 613 # Check whether we have a list of ndarrays [qx,qy] 610 614 qx, qy = qdist 611 return self.calculate_Iq(qx, qy) 615 result, _ = self.calculate_Iq(qx, qy) 616 return result 612 617 613 618 elif isinstance(qdist, np.ndarray): 614 619 # We have a simple 1D distribution of q-values 615 return self.calculate_Iq(qdist) 620 result, _ = self.calculate_Iq(qdist) 621 return result 616 622 617 623 else: … … 632 638 # so that it returns a results object containing all the bits: 633 639 # the A, B, C, ... of the composition model (and any subcomponents?) 634 # the P and S of the product model ,640 # the P and S of the product model 635 641 # the combined model before resolution smearing, 636 642 # the sasmodel before sesans conversion, … … 653 659 if composition and composition[0] == 'product': # only P*S for now 654 660 with calculation_lock: 655 self._calculate_Iq(qx) 656 return self._intermediate_results 661 _, lazy_results = self._calculate_Iq(qx) 662 # for compatibility with sasview 4.x 663 results = lazy_results() 664 pq_data = results.get("P(Q)") 665 sq_data = results.get("S(Q)") 666 return pq_data, sq_data 657 667 else: 658 668 return None 659 669 660 def calculate_Iq(self, qx, qy=None): 661 # type: (Sequence[float], Optional[Sequence[float]]) -> np.ndarray 670 def calculate_Iq(self, 671 qx, # type: Sequence[float] 672 qy=None # type: Optional[Sequence[float]] 673 ): 674 # type: (...) -> Tuple[np.ndarray, Callable[[], collections.OrderedDict[str, np.ndarray]]] 662 675 """ 663 676 Calculate Iq for one set of q with the current parameters. … … 667 680 This should NOT be used for fitting since it copies the *q* vectors 668 681 to the card for each evaluation. 682 683 The returned tuple contains the scattering intensity followed by a 684 callable which returns a dictionary of intermediate data from 685 ProductKernel. 669 686 """ 670 687 ## uncomment the following when trying to debug the uncoordinated calls … … 677 694 return self._calculate_Iq(qx, qy) 678 695 679 def _calculate_Iq(self, qx, qy=None ):696 def _calculate_Iq(self, qx, qy=None, Fq=False, effective_radius_type=1): 680 697 if self._model is None: 681 698 self._model = core.build_model(self._model_info) … … 697 714 #print("values", values) 698 715 #print("is_mag", is_magnetic) 716 if Fq: 717 result = calculator.Fq(call_details, values, cutoff=self.cutoff, 718 magnetic=is_magnetic, 719 effective_radius_type=effective_radius_type) 699 720 result = calculator(call_details, values, cutoff=self.cutoff, 700 721 magnetic=is_magnetic) 722 lazy_results = getattr(calculator, 'results', 723 lambda: collections.OrderedDict()) 701 724 #print("result", result) 702 self._intermediate_results = getattr(calculator, 'results', None) 725 703 726 calculator.release() 704 727 #self._model.release() 705 return result 706 707 def calculate_ER(self): 728 729 return result, lazy_results 730 731 732 def calculate_ER(self, mode=1): 708 733 # type: () -> float 709 734 """ … … 712 737 :return: the value of the effective radius 713 738 """ 714 if self._model_info.ER is None: 715 return 1.0 716 else: 717 value, weight = self._dispersion_mesh() 718 fv = self._model_info.ER(*value) 719 #print(values[0].shape, weights.shape, fv.shape) 720 return np.sum(weight * fv) / np.sum(weight) 739 Fq = self._calculate_Iq([0.1], True, mode) 740 return Fq[2] 721 741 722 742 def calculate_VR(self): … … 725 745 Calculate the volf ratio for P(q)*S(q) 726 746 727 :return: the value of the volf ratio 728 """ 729 if self._model_info.VR is None: 730 return 1.0 731 else: 732 value, weight = self._dispersion_mesh() 733 whole, part = self._model_info.VR(*value) 734 return np.sum(weight * part) / np.sum(weight * whole) 747 :return: the value of the form:shell volume ratio 748 """ 749 Fq = self._calculate_Iq([0.1], True, mode) 750 return Fq[4] 735 751 736 752 def set_dispersion(self, parameter, dispersion): … … 842 858 P = _make_standard_model('cylinder')() 843 859 model = MultiplicationModel(P, S) 860 model.setParam(product.RADIUS_MODE_ID, 1.0) 844 861 value = model.evalDistribution([0.1, 0.1]) 845 862 if np.isnan(value): … … 930 947 q = np.linspace(-0.35, 0.35, 500) 931 948 qx, qy = np.meshgrid(q, q) 932 result = model.calculate_Iq(qx.flatten(), qy.flatten())949 result, _ = model.calculate_Iq(qx.flatten(), qy.flatten()) 933 950 result = result.reshape(qx.shape) 934 951
Note: See TracChangeset
for help on using the changeset viewer.