source: sasview/src/sas/sascalc/corfunc/transform_thread.py @ 8b645cc

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 8b645cc was d03228e, checked in by lewis, 8 years ago

Add backbone for Hilbert transform

  • Property mode set to 100644
File size: 2.0 KB
Line 
1from sas.sascalc.data_util.calcthread import CalcThread
2from sas.sascalc.dataloader.data_info import Data1D
3from scipy.fftpack import dct
4import numpy as np
5from time import sleep
6
7class FourierThread(CalcThread):
8    def __init__(self, raw_data, extrapolated_data, bg, updatefn=None,
9        completefn=None):
10        CalcThread.__init__(self, updatefn=updatefn, completefn=completefn)
11        self.data = raw_data
12        self.background = bg
13        self.extrapolation = extrapolated_data
14
15    def compute(self):
16        qs = self.extrapolation.x
17        iqs = self.extrapolation.y
18        q = self.data.x
19        background = self.background
20
21        self.ready(delay=0.0)
22        self.update(msg="Starting Fourier transform.")
23        self.ready(delay=0.0)
24        if self.isquit():
25            return
26        try:
27            gamma = dct((iqs-background)*qs**2)
28            gamma = gamma / gamma.max()
29        except:
30            self.update(msg="Fourier transform failed.")
31            self.complete(transform=None)
32            return
33        if self.isquit():
34            return
35        self.update(msg="Fourier transform completed.")
36
37        xs = np.pi*np.arange(len(qs),dtype=np.float32)/(q[1]-q[0])/len(qs)
38        transform = Data1D(xs, gamma)
39
40        self.complete(transform=transform)
41
42class HilbertThread(CalcThread):
43    def __init__(self, raw_data, extrapolated_data, bg, updatefn=None,
44        completefn=None):
45        CalcThread.__init__(self, updatefn=updatefn, completefn=completefn)
46        self.data = raw_data
47        self.background = bg
48        self.extrapolation = extrapolated_data
49
50    def compute(self):
51        qs = self.extrapolation.x
52        iqs = self.extrapolation.y
53        q = self.data.x
54        background = self.background
55
56        self.ready(delay=0.0)
57        self.update(msg="Starting Hilbert transform.")
58        self.ready(delay=0.0)
59        if self.isquit():
60            return
61
62        # TODO: Implement hilbert transform
63
64        self.update(msg="Hilbert transform completed.")
65
66        self.complete(transform=None)
Note: See TracBrowser for help on using the repository browser.