Ignore:
Timestamp:
Sep 11, 2017 6:08:09 AM (7 years ago)
Author:
lewis
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:
0794ce3
Parents:
a309667 (diff), f9ba422 (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.
Message:

Merge branch 'master' into corfunc3d

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sascalc/corfunc/transform_thread.py

    rd03228e ra309667  
    22from sas.sascalc.dataloader.data_info import Data1D 
    33from scipy.fftpack import dct 
     4from scipy.integrate import trapz 
    45import numpy as np 
    56from time import sleep 
     
    1314        self.extrapolation = extrapolated_data 
    1415 
     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 
    1523    def compute(self): 
    1624        qs = self.extrapolation.x 
     
    1927        background = self.background 
    2028 
     29        xs = np.pi*np.arange(len(qs),dtype=np.float32)/(q[1]-q[0])/len(qs) 
     30 
    2131        self.ready(delay=0.0) 
    22         self.update(msg="Starting Fourier transform.") 
     32        self.update(msg="Fourier transform in progress.") 
    2333        self.ready(delay=0.0) 
    24         if self.isquit(): 
    25             return 
     34 
     35        if self.check_if_cancelled(): return 
    2636        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 
    3071            self.update(msg="Fourier transform failed.") 
    31             self.complete(transform=None) 
     72            self.complete(transforms=None) 
    3273            return 
    3374        if self.isquit(): 
     
    3576        self.update(msg="Fourier transform completed.") 
    3677 
    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) 
    3981 
    40         self.complete(transform=transform) 
     82        transforms = (transform1, transform3, idf) 
     83 
     84        self.complete(transforms=transforms) 
    4185 
    4286class HilbertThread(CalcThread): 
     
    64108        self.update(msg="Hilbert transform completed.") 
    65109 
    66         self.complete(transform=None) 
     110        self.complete(transforms=None) 
Note: See TracChangeset for help on using the changeset viewer.