Changeset 412c509 in sasview
- Timestamp:
- Jul 11, 2017 9:59:44 AM (7 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, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 2a54ba5
- Parents:
- 457f735
- git-author:
- Lewis O'Driscoll <lewis.o'driscoll@…> (07/11/17 09:59:23)
- git-committer:
- Lewis O'Driscoll <lewis.o'driscoll@…> (07/11/17 09:59:44)
- Location:
- src/sas
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/corfunc/corfunc_calculator.py
rff11b21 r412c509 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 124 125 def compute_transform(self, extrapolation, trans_type, background=None,126 completefn=None, updatefn=None):131 return params, extrapolation, s2 132 133 def compute_transform(self, extrapolation, trans_type, extrap_fn=None, 134 background=None, completefn=None, updatefn=None): 127 135 """ 128 136 Transform an extrapolated scattering curve into a correlation function. … … 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, extrap_fn=extrap_fn, 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
r457f735 r412c509 2 2 from sas.sascalc.dataloader.data_info import Data1D 3 3 from scipy.fftpack import dct 4 from scipy.integrate import simps, trapz 4 5 import numpy as np 5 6 from time import sleep 6 7 7 8 class FourierThread(CalcThread): 8 def __init__(self, raw_data, extrapolated_data, bg, updatefn=None,9 completefn=None):9 def __init__(self, raw_data, extrapolated_data, bg, extrap_fn=None, 10 updatefn=None, completefn=None): 10 11 CalcThread.__init__(self, updatefn=updatefn, completefn=completefn) 11 12 self.data = raw_data 12 13 self.background = bg 13 14 self.extrapolation = extrapolated_data 15 self.extrap_fn = extrap_fn 14 16 15 17 def compute(self): … … 19 21 background = self.background 20 22 23 xs = np.pi*np.arange(len(qs),dtype=np.float32)/(q[1]-q[0])/len(qs) 24 21 25 self.ready(delay=0.0) 22 self.update(msg=" Starting Fourier transform.")26 self.update(msg="Fourier transform in progress.") 23 27 self.ready(delay=0.0) 28 24 29 if self.isquit(): 25 30 return … … 27 32 gamma1 = dct((iqs-background)*qs**2) 28 33 gamma1 = gamma1 / gamma1.max() 29 except: 34 35 # gamma3(R) = 1/R int_{0}^{R} gamma1(x) dx 36 # simps uses simpson's rule to calculate the integral 37 gamma3 = [trapz(gamma1[:n], xs[:n])/xs[n-1] for n in range(1, len(xs+1))] 38 gamma3 = np.array(gamma3) 39 except Exception as e: 40 import logging 41 logger = logging.getLogger(__name__) 42 logger.error(e) 43 30 44 self.update(msg="Fourier transform failed.") 31 self.complete(transform =None)45 self.complete(transforms=None) 32 46 return 33 47 if self.isquit(): … … 35 49 self.update(msg="Fourier transform completed.") 36 50 37 xs = np.pi*np.arange(len(qs),dtype=np.float32)/(q[1]-q[0])/len(qs)38 51 transform1 = Data1D(xs, gamma1) 39 transform3 = Data1D( )52 transform3 = Data1D(xs, gamma3) 40 53 41 54 transforms = (transform1, transform3) -
src/sas/sasgui/perspectives/corfunc/corfunc_panel.py
r457f735 r412c509 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 representing 58 # the extrapolated and interpolated data 59 self._extrapolated_fn = None 57 60 self._transformed_data = None # Fourier trans. of the extrapolated data 58 61 self._calculator = CorfuncCalculator() … … 218 221 219 222 try: 220 params, self._extrapolated_data = self._calculator.compute_extrapolation() 223 params, self._extrapolated_data, self._extrapolated_fn = \ 224 self._calculator.compute_extrapolation() 221 225 except Exception as e: 222 226 msg = "Error extrapolating data:\n" … … 241 245 self._calculator.compute_transform(self._extrapolated_data, 242 246 self.transform_type, background=self.background, 247 extrap_fn=self._extrapolated_fn, 243 248 completefn=self.transform_complete, 244 249 updatefn=self.transform_update) … … 276 281 plot_y = transform1.y[np.where(transform1.x <= 200)] 277 282 self._manager.show_data(Data1D(plot_x, plot_y), TRANSFORM_LABEL1) 283 plot_x = transform3.x[np.where(transform3.x <= 200)] 284 plot_y = transform3.y[np.where(transform3.x <= 200)] 285 self._manager.show_data(Data1D(plot_x, plot_y), TRANSFORM_LABEL3) 278 286 # Only enable extract params button if a fourier trans. has been done 279 287 if self.transform_type == 'fourier':
Note: See TracChangeset
for help on using the changeset viewer.