1 | from sas.sascalc.data_util.calcthread import CalcThread |
---|
2 | from sas.sascalc.dataloader.data_info import Data1D |
---|
3 | from scipy.fftpack import dct |
---|
4 | import numpy as np |
---|
5 | from time import sleep |
---|
6 | |
---|
7 | class 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 | |
---|
42 | class 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) |
---|