Changeset 0794ce3 in sasview for src/sas/sascalc
- Timestamp:
- Sep 11, 2017 6:10:58 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:
- fca1f50, d07f863
- Parents:
- ccf58fb (diff), e2b2473 (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. - Location:
- src/sas/sascalc
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/dataloader/data_info.py
r5a8cdbb r17e257b5 1161 1161 final_dataset = None 1162 1162 if isinstance(data, plottable_1D): 1163 final_dataset = Data1D(data.x, data.y )1163 final_dataset = Data1D(data.x, data.y, isSesans=datainfo.isSesans) 1164 1164 final_dataset.dx = data.dx 1165 1165 final_dataset.dy = data.dy 1166 1166 final_dataset.dxl = data.dxl 1167 1167 final_dataset.dxw = data.dxw 1168 final_dataset.x_unit = data._xunit 1169 final_dataset.y_unit = data._yunit 1168 1170 final_dataset.xaxis(data._xaxis, data._xunit) 1169 1171 final_dataset.yaxis(data._yaxis, data._yunit) -
src/sas/sascalc/dataloader/file_reader_base_class.py
rdcb91cf ra78a02f 6 6 7 7 import os 8 import re 8 9 import logging 9 10 import numpy as np … … 106 107 for data in self.output: 107 108 if isinstance(data, Data1D): 109 # Normalize the units for 110 data.x_unit = self.format_unit(data.x_unit) 111 data.y_unit = self.format_unit(data.y_unit) 108 112 # Sort data by increasing x and remove 1st point 109 113 ind = np.lexsort((data.y, data.x)) … … 131 135 for dataset in self.output: 132 136 if isinstance(dataset, Data2D): 137 # Normalize the units for 138 dataset.x_unit = self.format_unit(dataset.Q_unit) 139 dataset.y_unit = self.format_unit(dataset.I_unit) 133 140 dataset.data = dataset.data.astype(np.float64) 134 141 dataset.qx_data = dataset.qx_data.astype(np.float64) … … 155 162 dataset.data = dataset.data.flatten() 156 163 164 def format_unit(self, unit=None): 165 """ 166 Format units a common way 167 :param unit: 168 :return: 169 """ 170 if unit: 171 split = unit.split("/") 172 if len(split) == 1: 173 return unit 174 elif split[0] == '1': 175 return "{0}^".format(split[1]) + "{-1}" 176 else: 177 return "{0}*{1}^".format(split[0], split[1]) + "{-1}" 178 157 179 def set_all_to_none(self): 158 180 """ -
src/sas/sascalc/dataloader/readers/cansas_reader.py
rdcb91cf ra78a02f 299 299 self.current_dataset.dx = np.append(self.current_dataset.dx, data_point) 300 300 elif tagname == 'dQw': 301 if self.current_dataset.dqw is None: self.current_dataset.dqw = np.empty(0) 301 if self.current_dataset.dxw is None: 302 self.current_dataset.dxw = np.empty(0) 302 303 self.current_dataset.dxw = np.append(self.current_dataset.dxw, data_point) 303 304 elif tagname == 'dQl': 304 if self.current_dataset.dxl is None: self.current_dataset.dxl = np.empty(0) 305 if self.current_dataset.dxl is None: 306 self.current_dataset.dxl = np.empty(0) 305 307 self.current_dataset.dxl = np.append(self.current_dataset.dxl, data_point) 306 308 elif tagname == 'Qmean': -
src/sas/sascalc/dataloader/readers/danse_reader.py
r713a047 ra78a02f 189 189 x_vals = np.tile(x_vals, (size_y, 1)).flatten() 190 190 y_vals = np.tile(y_vals, (size_x, 1)).T.flatten() 191 if self.current_dataset.err_data == np.all(np.array(None)) or np.any(self.current_dataset.err_data <= 0): 191 if (np.all(self.current_dataset.err_data == None) 192 or np.any(self.current_dataset.err_data <= 0)): 192 193 new_err_data = np.sqrt(np.abs(self.current_dataset.data)) 193 194 else: -
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.