Changeset 4d270706 in sasview
- Timestamp:
- Jan 6, 2010 8:26:11 PM (15 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 4cbaf35
- Parents:
- 196608d
- Location:
- Invariant
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
Invariant/invariant.py
r25a92d1 r4d270706 7 7 import numpy 8 8 9 from DataLoader.data_infoimport Data1D as LoaderData1D9 from sans.guiframe.dataFitting import Data1D as LoaderData1D 10 10 from DataLoader.qsmearing import smear_selection 11 11 … … 114 114 & (self.data.x <= self._qmax_unsmeared) 115 115 116 def fit(self, power 116 def fit(self, power=None): 117 117 """ 118 118 Fit data for y = ax + b return a and b … … 129 129 print "The dy data for Invariant calculation should be prepared before get to FitFunctor.fit()..." 130 130 sigma = one[self.idx_unsmeared ] 131 sigma2 = sigma *sigma131 sigma2 = sigma * sigma 132 132 133 133 # Compute theory data f(x) … … 145 145 A = numpy.vstack([ self.data.x[self.idx]/sigma, 146 146 numpy.ones(len(self.data.x[self.idx]))/sigma]).T 147 147 148 148 a, b = numpy.linalg.lstsq(A, fx)[0] 149 149 return a, b … … 231 231 for power_law will be the power value 232 232 """ 233 fit_x = numpy.array([math.log(x) for x in self._data.x]) 234 if function.__name__ == "guinier": 233 #fit_x = numpy.array([math.log(x) for x in self._data.x]) 234 if function.__name__ == "guinier": 235 fit_x = numpy.array([x * x for x in self._data.x]) 235 236 qmin = qmin**2 236 237 qmax = qmax**2 … … 240 241 241 242 elif function.__name__ == "power_law": 243 fit_x = numpy.array([math.log(x) for x in self._data.x]) 242 244 qmin = math.log(qmin) 243 245 qmax = math.log(qmax) … … 495 497 return math.sqrt(sum) 496 498 497 def _get_qstar_low(self):499 def get_qstar_low(self): 498 500 """ 499 501 Compute the invariant for extrapolated data at low q range. … … 505 507 @return q_star: the invariant for data extrapolated at low q. 506 508 """ 507 data = self. _get_extra_data_low()509 data = self.get_extra_data_low() 508 510 return self._get_qstar(data=data) 509 511 510 def _get_qstar_high(self):512 def get_qstar_high(self): 511 513 """ 512 514 Compute the invariant for extrapolated data at high q range. … … 518 520 @return q_star: the invariant for data extrapolated at high q. 519 521 """ 520 data = self. _get_extra_data_high()522 data = self.get_extra_data_high() 521 523 return self._get_qstar(data=data) 522 524 523 def _get_extra_data_low(self):525 def get_extra_data_low(self): 524 526 """ 525 527 This method creates a new data set from the invariant calculator. … … 546 548 qmin = self._data.x[0] 547 549 qmax = self._data.x[self._low_extrapolation_npts - 1] 548 549 550 try: 550 551 # fit the data with a model to get the appropriate parameters … … 554 555 power=self._low_extrapolation_power) 555 556 except: 557 #raise 556 558 return None 557 559 … … 583 585 return data_min 584 586 585 def _get_extra_data_high(self):587 def get_extra_data_high(self): 586 588 """ 587 589 This method creates a new data from the invariant calculator. … … 677 679 return qstar_0 678 680 if extrapolation==low: 679 return qstar_0 + self. _get_qstar_low()681 return qstar_0 + self.get_qstar_low() 680 682 elif extrapolation==high: 681 return qstar_0 + self. _get_qstar_high()683 return qstar_0 + self.get_qstar_high() 682 684 elif extrapolation==both: 683 return qstar_0 + self. _get_qstar_low() + self._get_qstar_high()685 return qstar_0 + self.get_qstar_low() + self.get_qstar_high() 684 686 685 687 @param extrapolation: string to apply optional extrapolation … … 689 691 checking that the scale and the background are properly apply to the data 690 692 691 @warning: if error occur self. _get_qstar_low() or self._get_qstar_low()693 @warning: if error occur self.get_qstar_low() or self.get_qstar_low() 692 694 their returned value will be ignored 693 695 """ … … 700 702 extrapolation = extrapolation.lower() 701 703 if extrapolation == "low": 702 self._qstar = qstar_0 + self. _get_qstar_low()704 self._qstar = qstar_0 + self.get_qstar_low() 703 705 return self._qstar 704 706 elif extrapolation == "high": 705 self._qstar = qstar_0 + self. _get_qstar_high()707 self._qstar = qstar_0 + self.get_qstar_high() 706 708 return self._qstar 707 709 elif extrapolation == "both": 708 self._qstar = qstar_0 + self. _get_qstar_low() + self._get_qstar_high()710 self._qstar = qstar_0 + self.get_qstar_low() + self.get_qstar_high() 709 711 return self._qstar 710 712 … … 723 725 @return: specific surface 724 726 """ 727 if contrast is None or porod_const is None: 728 return 725 729 #Check whether we have Q star 726 730 if self._qstar is None: … … 754 758 @note: volume fraction must have no unit 755 759 """ 760 if contrast is None: 761 return 756 762 if contrast < 0: 757 763 raise ValueError, "contrast must be greater than zero" … … 812 818 @return: V, dV = self.get_volume_fraction_with_error(contrast), dV 813 819 """ 820 if contrast is None: 821 return 814 822 self._qstar, self._qstar_err = self.get_qstar_with_error() 815 823 … … 845 853 @return S, dS: the surface, with its uncertainty 846 854 """ 855 if contrast is None or porod_const is None: 856 return 847 857 v, dv = self.get_volume_fraction_with_error(contrast) 848 858 self._qstar, self._qstar_err = self.get_qstar_with_error() -
Invariant/test/utest_use_cases.py
r6e74ee4 r4d270706 1 1 """ 2 2 Implementation of the use-case from a usage perspective. 3 TODO: check the return values to perform actual unit testing.3 4 4 """ 5 5 import unittest … … 8 8 from sans.invariant import invariant 9 9 _ERR_SURFACE = 0.3 10 10 11 class Data1D: 11 12 print "I am not of type Dataloader.Data1D"
Note: See TracChangeset
for help on using the changeset viewer.