Changeset d03228e in sasview for src/sas


Ignore:
Timestamp:
Jul 12, 2016 6:13:24 AM (8 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, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
8bdc103
Parents:
41345d7e
Message:

Add backbone for Hilbert transform

Location:
src/sas
Files:
3 edited

Legend:

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

    reb320682 rd03228e  
    1010from numpy.linalg import lstsq 
    1111from sas.sascalc.dataloader.data_info import Data1D 
    12 from sas.sascalc.corfunc.transform_thread import TransformThread 
     12from sas.sascalc.corfunc.transform_thread import FourierThread 
     13from sas.sascalc.corfunc.transform_thread import HilbertThread 
    1314 
    1415class CorfuncCalculator(object): 
     
    122123        return extrapolation 
    123124 
    124     def compute_transform(self, extrapolation, background=None, 
     125    def compute_transform(self, extrapolation, trans_type, background=None, 
    125126        completefn=None, updatefn=None): 
    126127        """ 
     
    141142        if background is None: background = self.background 
    142143 
    143         self._transform_thread = TransformThread(self._data, extrapolation, 
    144         background, completefn=completefn, updatefn=updatefn) 
     144        if trans_type == 'fourier': 
     145            self._transform_thread = FourierThread(self._data, extrapolation, 
     146            background, completefn=completefn, updatefn=updatefn) 
     147        elif trans_type == 'hilbert': 
     148            self._transform_thread = HilbertThread(self._data, extrapolation, 
     149            background, completefn=completefn, updatefn=updatefn) 
     150        else: 
     151            err = ("Incorrect transform type supplied, must be 'fourier'", 
     152                " or 'hilbert'") 
     153            raise ValueError, err 
     154 
    145155        self._transform_thread.queue() 
    146156 
  • src/sas/sascalc/corfunc/transform_thread.py

    ra2db1ab rd03228e  
    55from time import sleep 
    66 
    7 class TransformThread(CalcThread): 
     7class FourierThread(CalcThread): 
    88    def __init__(self, raw_data, extrapolated_data, bg, updatefn=None, 
    99        completefn=None): 
     
    3939 
    4040        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) 
  • src/sas/sasgui/perspectives/corfunc/corfunc_panel.py

    reb320682 rd03228e  
    6464        self.background = 0 
    6565        self.extracted_params = None 
     66        self.transform_type = 'fourier' 
    6667        # Dictionary for saving refs to text boxes used to display output data 
    6768        self._output_boxes = None 
     
    167168        return self._data 
    168169 
     170    def radio_changed(self, event=None): 
     171        if event is not None: 
     172            self.transform_type = event.GetEventObject().GetName() 
     173 
    169174    def compute_extrapolation(self, event=None): 
    170175        """ 
     
    206211        if not self._calculator.transform_isrunning(): 
    207212            self._calculator.compute_transform(self._extrapolated_data, 
    208                 self.background, completefn=self.transform_complete, 
     213                self.transform_type, background=self.background, 
     214                completefn=self.transform_complete, 
    209215                updatefn=self.transform_update) 
     216 
    210217            self._transform_btn.SetLabel("Stop Tansform") 
    211218        else: 
    212219            self._calculator.stop_transform() 
    213             self.transform_update("Fourier transform cancelled.") 
     220            self.transform_update("Transform cancelled.") 
    214221            self._transform_btn.SetLabel("Tansform") 
    215222 
    216223    def transform_update(self, msg=""): 
    217224        """ 
    218         Called from TransformThread to update on status of calculation 
     225        Called from FourierThread to update on status of calculation 
    219226        """ 
    220227        wx.PostEvent(self._manager.parent, 
     
    223230    def transform_complete(self, transform=None): 
    224231        """ 
    225         Called from TransformThread when calculation has completed 
    226         """ 
     232        Called from FourierThread when calculation has completed 
     233        """ 
     234        self._transform_btn.SetLabel("Tansform") 
    227235        if transform is None: 
    228236            msg = "Error calculating Transform." 
     237            if self.transform_type == 'hilbert': 
     238                msg = "Not yet implemented" 
    229239            wx.PostEvent(self._manager.parent, 
    230240                StatusEvent(status=msg, info="Error")) 
     
    236246        plot_y = transform.y[np.where(transform.x <= 200)] 
    237247        self._manager.show_data(Data1D(plot_x, plot_y), TRANSFORM_LABEL) 
    238         self._transform_btn.SetLabel("Tansform") 
    239         self._extract_btn.Enable() 
     248        # Only enable extract params button if a fourier trans. has been done 
     249        if self.transform_type == 'fourier': 
     250            self._extract_btn.Enable() 
     251        else: 
     252            self._extract_btn.Disable() 
    240253 
    241254    def extract_parameters(self, event=None): 
     
    421434 
    422435        # Parameters 
    423         qbox = wx.StaticBox(self, -1, "Parameters") 
     436        qbox = wx.StaticBox(self, -1, "Input Parameters") 
    424437        qbox_sizer = wx.StaticBoxSizer(qbox, wx.VERTICAL) 
    425438        qbox_sizer.SetMinSize((_STATICBOX_WIDTH, 75)) 
     
    497510 
    498511        vbox.Add(qbox_sizer, (1, 0), (1, 1), 
     512            wx.LEFT | wx.RIGHT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
     513 
     514        # Transform type 
     515        transform_box = wx.StaticBox(self, -1, "Transform Type") 
     516        transform_sizer = wx.StaticBoxSizer(transform_box, wx.VERTICAL) 
     517 
     518        radio_sizer = wx.GridBagSizer(5,5) 
     519 
     520        fourier_btn = wx.RadioButton(self, -1, "Fourier", name='fourier', 
     521            style=wx.RB_GROUP) 
     522        hilbert_btn = wx.RadioButton(self, -1, "Hilbert", name='hilbert') 
     523 
     524        fourier_btn.Bind(wx.EVT_RADIOBUTTON, self.radio_changed) 
     525        hilbert_btn.Bind(wx.EVT_RADIOBUTTON, self.radio_changed) 
     526 
     527        radio_sizer.Add(fourier_btn, (0,0), (1,1), wx.LEFT | wx.EXPAND) 
     528        radio_sizer.Add(hilbert_btn, (0,1), (1,1), wx.RIGHT | wx.EXPAND) 
     529 
     530        transform_sizer.Add(radio_sizer, wx.TOP, 0) 
     531        vbox.Add(transform_sizer, (2, 0), (1, 1), 
    499532            wx.LEFT | wx.RIGHT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
    500533 
     
    522555        outputbox_sizer.Add(output_sizer, wx.TOP, 0) 
    523556 
    524         vbox.Add(outputbox_sizer, (2, 0), (1, 1), 
     557        vbox.Add(outputbox_sizer, (3, 0), (1, 1), 
    525558            wx.LEFT | wx.RIGHT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
    526559 
     
    547580 
    548581        controlbox_sizer.Add(controls_sizer, wx.TOP | wx.EXPAND, 0) 
    549         vbox.Add(controlbox_sizer, (3, 0), (1, 1), 
     582        vbox.Add(controlbox_sizer, (4, 0), (1, 1), 
    550583            wx.LEFT | wx.RIGHT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
    551584 
Note: See TracChangeset for help on using the changeset viewer.