Changes in / [0794ce3:e2b2473] in sasview
- Location:
- src/sas
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/corfunc/corfunc_calculator.py
rc728295 rff11b21 34 34 35 35 def __call__(self, x): 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(): 36 if self._lastx == [] or x.tolist() != self._lastx.tolist(): 45 37 self._lasty = self._smoothed_function(x) 46 38 self._lastx = x … … 129 121 extrapolation = Data1D(qs, iqs) 130 122 131 return params, extrapolation , s2123 return params, extrapolation 132 124 133 125 def compute_transform(self, extrapolation, trans_type, background=None, … … 139 131 :param background: The background value (if not provided, previously 140 132 calculated value will be used) 141 :param extrap_fn: A callable function representing the extraoplated data142 133 :param completefn: The function to call when the transform calculation 143 134 is complete` … … 153 144 if trans_type == 'fourier': 154 145 self._transform_thread = FourierThread(self._data, extrapolation, 155 background, completefn=completefn, 156 updatefn=updatefn) 146 background, completefn=completefn, updatefn=updatefn) 157 147 elif trans_type == 'hilbert': 158 148 self._transform_thread = HilbertThread(self._data, extrapolation, -
src/sas/sascalc/corfunc/transform_thread.py
ra309667 rd03228e 2 2 from sas.sascalc.dataloader.data_info import Data1D 3 3 from scipy.fftpack import dct 4 from scipy.integrate import trapz5 4 import numpy as np 6 5 from time import sleep … … 14 13 self.extrapolation = extrapolated_data 15 14 16 def check_if_cancelled(self):17 if self.isquit():18 self.update("Fourier transform cancelled.")19 self.complete(transforms=None)20 return True21 return False22 23 15 def compute(self): 24 16 qs = self.extrapolation.x … … 27 19 background = self.background 28 20 29 xs = np.pi*np.arange(len(qs),dtype=np.float32)/(q[1]-q[0])/len(qs)30 31 21 self.ready(delay=0.0) 32 self.update(msg=" Fourier transform in progress.")22 self.update(msg="Starting Fourier transform.") 33 23 self.ready(delay=0.0) 34 35 if self.check_if_cancelled():return24 if self.isquit(): 25 return 36 26 try: 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 27 gamma = dct((iqs-background)*qs**2) 28 gamma = gamma / gamma.max() 29 except: 71 30 self.update(msg="Fourier transform failed.") 72 self.complete(transform s=None)31 self.complete(transform=None) 73 32 return 74 33 if self.isquit(): … … 76 35 self.update(msg="Fourier transform completed.") 77 36 78 transform1 = Data1D(xs, gamma1) 79 transform3 = Data1D(xs[xs <= 200], gamma3) 80 idf = Data1D(xs, idf) 37 xs = np.pi*np.arange(len(qs),dtype=np.float32)/(q[1]-q[0])/len(qs) 38 transform = Data1D(xs, gamma) 81 39 82 transforms = (transform1, transform3, idf) 83 84 self.complete(transforms=transforms) 40 self.complete(transform=transform) 85 41 86 42 class HilbertThread(CalcThread): … … 108 64 self.update(msg="Hilbert transform completed.") 109 65 110 self.complete(transform s=None)66 self.complete(transform=None) -
src/sas/sasgui/perspectives/corfunc/corfunc.py
r9b90bf8 r463e7ffc 189 189 # Show the transformation as a curve instead of points 190 190 new_plot.symbol = GUIFRAME_ID.CURVE_SYMBOL_NUM 191 elif label == IDF_LABEL:192 new_plot.xaxis("{x}", 'A')193 new_plot.yaxis("{g_1}", '')194 # Linear scale195 new_plot.xtransform = 'x'196 new_plot.ytransform = 'y'197 group_id = GROUP_ID_IDF198 # Show IDF as a curve instead of points199 new_plot.symbol = GUIFRAME_ID.CURVE_SYMBOL_NUM200 191 new_plot.id = label 201 192 new_plot.name = label -
src/sas/sasgui/perspectives/corfunc/corfunc_panel.py
r9b90bf8 r7432acb 55 55 self._data = data # The data to be analysed (corrected fr background) 56 56 self._extrapolated_data = None # The extrapolated data set 57 # Callable object of class CorfuncCalculator._Interpolator representing58 # the extrapolated and interpolated data59 self._extrapolated_fn = None60 57 self._transformed_data = None # Fourier trans. of the extrapolated data 61 58 self._calculator = CorfuncCalculator() … … 221 218 222 219 try: 223 params, self._extrapolated_data, self._extrapolated_fn = \ 224 self._calculator.compute_extrapolation() 220 params, self._extrapolated_data = self._calculator.compute_extrapolation() 225 221 except Exception as e: 226 222 msg = "Error extrapolating data:\n" … … 261 257 StatusEvent(status=msg)) 262 258 263 def transform_complete(self, transform s=None):259 def transform_complete(self, transform=None): 264 260 """ 265 261 Called from FourierThread when calculation has completed 266 262 """ 267 263 self._transform_btn.SetLabel("Transform") 268 if transform sis None:264 if transform is None: 269 265 msg = "Error calculating Transform." 270 266 if self.transform_type == 'hilbert': … … 274 270 self._extract_btn.Disable() 275 271 return 276 277 self._transformed_data = transforms 278 (transform1, transform3, idf) = transforms 279 plot_x = transform1.x[transform1.x <= 200] 280 plot_y = transform1.y[transform1.x <= 200] 272 self._transformed_data = transform 273 import numpy as np 274 plot_x = transform.x[np.where(transform.x <= 200)] 275 plot_y = transform.y[np.where(transform.x <= 200)] 281 276 self._manager.show_data(Data1D(plot_x, plot_y), TRANSFORM_LABEL1) 282 # No need to shorten gamma3 as it's only calculated up to x=200283 self._manager.show_data(transform3, TRANSFORM_LABEL3)284 285 plot_x = idf.x[idf.x <= 200]286 plot_y = idf.y[idf.x <= 200]287 self._manager.show_data(Data1D(plot_x, plot_y), IDF_LABEL)288 289 277 # Only enable extract params button if a fourier trans. has been done 290 278 if self.transform_type == 'fourier': … … 298 286 """ 299 287 try: 300 params = self._calculator.extract_parameters(self._transformed_data [0])288 params = self._calculator.extract_parameters(self._transformed_data) 301 289 except: 302 290 params = None -
src/sas/sasgui/perspectives/corfunc/corfunc_state.py
r457f735 r7432acb 59 59 self.q = None 60 60 self.iq = None 61 # TODO: Add extrapolated data and transformed data (when implemented) 61 62 62 63 def __str__(self): -
src/sas/sasgui/perspectives/corfunc/media/corfunc_help.rst
rd78b5cb r1404cce 10 10 11 11 This performs a correlation function analysis of one-dimensional 12 SAXS/SANS data, or generates a model-independent volume fraction 12 SAXS/SANS data, or generates a model-independent volume fraction 13 13 profile from the SANS from an adsorbed polymer/surfactant layer. 14 14 15 A correlation function may be interpreted in terms of an imaginary rod moving 16 through the structure of the material. Î\ :sub:`1D`\ (R) is the probability that 17 a rod of length R moving through the material has equal electron/neutron scattering 18 length density at either end. Hence a frequently occurring spacing within a structure 15 A correlation function may be interpreted in terms of an imaginary rod moving 16 through the structure of the material. Î\ :sub:`1D`\ (R) is the probability that 17 a rod of length R moving through the material has equal electron/neutron scattering 18 length density at either end. Hence a frequently occurring spacing within a structure 19 19 manifests itself as a peak. 20 20 … … 30 30 * Fourier / Hilbert Transform of the smoothed data to give the correlation 31 31 function / volume fraction profile, respectively 32 * (Optional) Interpretation of the 1D correlation function based on an ideal 32 * (Optional) Interpretation of the 1D correlation function based on an ideal 33 33 lamellar morphology 34 34 … … 74 74 :align: center 75 75 76 76 77 77 Smoothing 78 78 --------- 79 79 80 The extrapolated data set consists of the Guinier back-extrapolation from Q~0 80 The extrapolated data set consists of the Guinier back-extrapolation from Q~0 81 81 up to the lowest Q value in the original data, then the original scattering data, and the Porod tail-fit beyond this. The joins between the original data and the Guinier/Porod fits are smoothed using the algorithm below to avoid the formation of ripples in the transformed data. 82 82 … … 93 93 h_i = \frac{1}{1 + \frac{(x_i-b)^2}{(x_i-a)^2}} 94 94 95 95 96 96 Transform 97 97 --------- … … 102 102 If "Fourier" is selected for the transform type, the analysis will perform a 103 103 discrete cosine transform on the extrapolated data in order to calculate the 104 1D correlation function: 104 correlation function 105 105 106 106 .. math:: … … 115 115 \left(n + \frac{1}{2} \right) k \right] } \text{ for } k = 0, 1, \ldots, 116 116 N-1, N 117 118 The 3D correlation function is also calculated:119 120 .. math::121 \Gamma _{3D}(R) = \frac{1}{Q^{*}} \int_{0}^{\infty}I(q) q^{2}122 \frac{sin(qR)}{qR} dq123 117 124 118 Hilbert … … 171 165 .. figure:: profile1.png 172 166 :align: center 173 167 174 168 .. figure:: profile2.png 175 169 :align: center 176 170 177 171 178 172 References … … 197 191 ----- 198 192 Upon sending data for correlation function analysis, it will be plotted (minus 199 the background value), along with a *red* bar indicating the *upper end of the 193 the background value), along with a *red* bar indicating the *upper end of the 200 194 low-Q range* (used for back-extrapolation), and 2 *purple* bars indicating the range to be used for forward-extrapolation. These bars may be moved my clicking and 201 195 dragging, or by entering appropriate values in the Q range input boxes. … … 227 221 :align: center 228 222 229 223 230 224 .. note:: 231 225 This help document was last changed by Steve King, 08Oct2016 -
src/sas/sasgui/perspectives/corfunc/plot_labels.py
r7dda833 r1dc8ec9 4 4 5 5 GROUP_ID_TRANSFORM = r"$\Gamma(x)$" 6 TRANSFORM_LABEL1 = r"$\Gamma_1(x)$" 7 TRANSFORM_LABEL3 = r"$\Gamma_3(x)$" 8 9 GROUP_ID_IDF = r"$g_1(x)$" 10 IDF_LABEL = r"$g_1(x)$" 6 TRANSFORM_LABEL1 = r"$\Gamma1(x)$" 7 TRANSFORM_LABEL3 = r"$\Gamma3(x)$"
Note: See TracChangeset
for help on using the changeset viewer.