Changeset d07f863 in sasview for src/sas/sascalc
- Timestamp:
- Sep 16, 2017 10:50:38 PM (7 years ago)
- Parents:
- cfd27dd (diff), 0794ce3 (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. - git-author:
- Lewis O'Driscoll <lewis.o'driscoll@…> (09/16/17 22:50:38)
- git-committer:
- GitHub <noreply@…> (09/16/17 22:50:38)
- Location:
- src/sas/sascalc/corfunc
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/corfunc/corfunc_calculator.py
rff11b21 rc728295 34 34 35 35 def __call__(self, x): 36 if self._lastx == [] or x.tolist() != self._lastx.tolist(): 36 # If input is a single number, evaluate the function at that number 37 # and return a single number 38 if type(x) == float or type(x) == int: 39 return self._smoothed_function(np.array([x]))[0] 40 # If input is a list, and is different to the last input, evaluate 41 # the function at each point. If the input is the same as last time 42 # the function was called, return the result that was calculated 43 # last time instead of explicity evaluating the function again. 44 elif self._lastx == [] or x.tolist() != self._lastx.tolist(): 37 45 self._lasty = self._smoothed_function(x) 38 46 self._lastx = x … … 121 129 extrapolation = Data1D(qs, iqs) 122 130 123 return params, extrapolation 131 return params, extrapolation, s2 124 132 125 133 def compute_transform(self, extrapolation, trans_type, background=None, … … 131 139 :param background: The background value (if not provided, previously 132 140 calculated value will be used) 141 :param extrap_fn: A callable function representing the extraoplated data 133 142 :param completefn: The function to call when the transform calculation 134 143 is complete` … … 144 153 if trans_type == 'fourier': 145 154 self._transform_thread = FourierThread(self._data, extrapolation, 146 background, completefn=completefn, updatefn=updatefn) 155 background, completefn=completefn, 156 updatefn=updatefn) 147 157 elif trans_type == 'hilbert': 148 158 self._transform_thread = HilbertThread(self._data, extrapolation, -
src/sas/sascalc/corfunc/transform_thread.py
rd03228e ra309667 2 2 from sas.sascalc.dataloader.data_info import Data1D 3 3 from scipy.fftpack import dct 4 from scipy.integrate import trapz 4 5 import numpy as np 5 6 from time import sleep … … 13 14 self.extrapolation = extrapolated_data 14 15 16 def check_if_cancelled(self): 17 if self.isquit(): 18 self.update("Fourier transform cancelled.") 19 self.complete(transforms=None) 20 return True 21 return False 22 15 23 def compute(self): 16 24 qs = self.extrapolation.x … … 19 27 background = self.background 20 28 29 xs = np.pi*np.arange(len(qs),dtype=np.float32)/(q[1]-q[0])/len(qs) 30 21 31 self.ready(delay=0.0) 22 self.update(msg=" Starting Fourier transform.")32 self.update(msg="Fourier transform in progress.") 23 33 self.ready(delay=0.0) 24 if self.isquit(): 25 34 35 if self.check_if_cancelled(): return 26 36 try: 27 gamma = dct((iqs-background)*qs**2) 28 gamma = gamma / gamma.max() 29 except: 37 # ----- 1D Correlation Function ----- 38 gamma1 = dct((iqs-background)*qs**2) 39 Q = gamma1.max() 40 gamma1 /= Q 41 42 if self.check_if_cancelled(): return 43 44 # ----- 3D Correlation Function ----- 45 # gamma3(R) = 1/R int_{0}^{R} gamma1(x) dx 46 # trapz uses the trapezium rule to calculate the integral 47 mask = xs <= 200.0 # Only calculate gamma3 up to x=200 (as this is all that's plotted) 48 gamma3 = [trapz(gamma1[:n], xs[:n])/xs[n-1] for n in range(2, len(xs[mask]) + 1)] 49 gamma3.insert(0, 1.0) # Gamma_3(0) is defined as 1 50 gamma3 = np.array(gamma3) 51 52 if self.check_if_cancelled(): return 53 54 # ----- Interface Distribution function ----- 55 idf = dct(-qs**4 * (iqs-background)) 56 57 if self.check_if_cancelled(): return 58 59 # Manually calculate IDF(0.0), since scipy DCT tends to give us a 60 # very large negative value. 61 # IDF(x) = int_0^inf q^4 * I(q) * cos(q*x) * dq 62 # => IDF(0) = int_0^inf q^4 * I(q) * dq 63 idf[0] = trapz(-qs**4 * (iqs-background), qs) 64 idf /= Q # Normalise using scattering invariant 65 66 except Exception as e: 67 import logging 68 logger = logging.getLogger(__name__) 69 logger.error(e) 70 30 71 self.update(msg="Fourier transform failed.") 31 self.complete(transform =None)72 self.complete(transforms=None) 32 73 return 33 74 if self.isquit(): … … 35 76 self.update(msg="Fourier transform completed.") 36 77 37 xs = np.pi*np.arange(len(qs),dtype=np.float32)/(q[1]-q[0])/len(qs) 38 transform = Data1D(xs, gamma) 78 transform1 = Data1D(xs, gamma1) 79 transform3 = Data1D(xs[xs <= 200], gamma3) 80 idf = Data1D(xs, idf) 39 81 40 self.complete(transform=transform) 82 transforms = (transform1, transform3, idf) 83 84 self.complete(transforms=transforms) 41 85 42 86 class HilbertThread(CalcThread): … … 64 108 self.update(msg="Hilbert transform completed.") 65 109 66 self.complete(transform =None)110 self.complete(transforms=None)
Note: See TracChangeset
for help on using the changeset viewer.