Ignore:
Timestamp:
Jul 7, 2016 9:30:07 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:
523ea30
Parents:
938e4bc
Message:

Add transform functionality

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sasgui/perspectives/corfunc/corfunc_panel.py

    r938e4bc rbd9f10e  
    3838        self.SetWindowVariant(variant=FONT_VARIANT) 
    3939        self._manager = manager 
    40         self._data = data # The data to be analysed 
     40        # The data with no correction for background values 
     41        self._data = data # The data to be analysed (corrected fr background) 
    4142        self._extrapolated_data = None # The extrapolated data set 
     43        self._calculator = CorfuncCalculator() 
    4244        self._data_name_box = None # Text box to show name of file 
    4345        self._background_input = None 
     
    4547        self._qmax1_input = None 
    4648        self._qmax2_input = None 
     49        self._transform_btn = None 
     50        self._compute_btn = None 
    4751        self.qmin = 0 
    4852        self.qmax = (0, 0) 
     
    107111        :param data: The data that has been loaded 
    108112        """ 
     113        self._transform_btn.Disable() 
    109114        if data is None: 
    110115            return 
    111116        self._data_name_box.SetValue(str(data.title)) 
    112117        self._data = data 
     118        self._calculator.set_data(data) 
    113119        if self._manager is not None: 
    114120            from sas.sasgui.perspectives.corfunc.corfunc import IQ_DATA_LABEL 
    115             self._manager.show_data(data, IQ_DATA_LABEL, reset=True) 
     121            self._manager.show_data(self._data, IQ_DATA_LABEL, reset=True) 
    116122        if set_qrange: 
    117123            lower = data.x[-1]*0.05 
     
    120126            self.set_qmin(lower) 
    121127            self.set_qmax((upper1, upper2)) 
    122             self.set_background(0.0) 
     128            self.set_background(self._calculator.compute_background(self.qmax)) 
    123129 
    124130    def get_data(self): 
     
    134140            wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 
    135141            return 
    136         calculator = CorfuncCalculator(self._data, self.qmin, self.qmax, 
    137             background=self.background) 
    138         self._extrapolated_data = calculator.compute_extrapolation() 
     142        self._calculator.set_data(self._data) 
     143        self._calculator.lowerq = self.qmin 
     144        self._calculator.upperq = self.qmax 
     145        self._extrapolated_data = self._calculator.compute_extrapolation() 
    139146        # TODO: Find way to set xlim and ylim so full range of data can be 
    140147        # plotted 
     
    148155            IQ_EXTRAPOLATED_DATA_LABEL 
    149156        self._manager.show_data(to_plot, IQ_EXTRAPOLATED_DATA_LABEL) 
     157        self._transform_btn.Enable() 
     158 
     159    def compute_transform(self, event=None): 
     160        transformed_data = self._calculator.compute_transform( 
     161            self._extrapolated_data, self.background) 
     162        from sas.sasgui.perspectives.corfunc.corfunc import TRANSFORM_LABEL 
     163        import numpy as np 
     164        plot_x = transformed_data.x[np.where(transformed_data.x <= 200)] 
     165        plot_y = transformed_data.y[np.where(transformed_data.x <= 200)] 
     166        self._manager.show_data(Data1D(plot_x, plot_y), TRANSFORM_LABEL) 
    150167 
    151168 
     
    183200        self._background_input.SetValue(str(bg)) 
    184201 
     202    def _compute_background(self, event=None): 
     203        self.set_background(self._calculator.compute_background(self.qmax)) 
    185204 
    186205    def _on_enter_input(self, event=None): 
     
    200219        group_id = GROUP_ID_IQ_DATA 
    201220        if event is not None: 
     221            if self._manager is not None and\ 
     222                event.GetEventObject() == self._background_input: 
     223                from sas.sasgui.perspectives.corfunc.corfunc\ 
     224                    import IQ_DATA_LABEL 
     225                self._manager.show_data(self._data, IQ_DATA_LABEL, reset=True) 
    202226            wx.PostEvent(self._manager.parent, PlotQrangeEvent( 
    203227                ctrl=[self._qmin_input, self._qmax1_input, self._qmax2_input], 
     
    309333            wx.RIGHT | wx.EXPAND, 5) 
    310334 
     335        background_button = wx.Button(self, wx.NewId(), "Calculate", 
     336            size=(75, 25)) 
     337        background_button.Bind(wx.EVT_BUTTON, self._compute_background) 
     338        q_sizer.Add(background_button, (1, 2), (1, 1), wx.RIGHT | wx.EXPAND, 5) 
     339 
    311340        qrange_label = wx.StaticText(self, -1, "Q Range:", size=(50,20)) 
    312341        q_sizer.Add(qrange_label, (2,0), (1,1), wx.LEFT | wx.EXPAND, 5) 
     
    395424 
    396425        extrapolate_btn = wx.Button(self, wx.NewId(), "Extrapolate") 
    397         transform_btn = wx.Button(self, wx.NewId(), "Transform") 
    398         compute_btn = wx.Button(self, wx.NewId(), "Compute Measuments") 
     426        self._transform_btn = wx.Button(self, wx.NewId(), "Transform") 
     427        self._compute_btn = wx.Button(self, wx.NewId(), "Compute Measuments") 
     428 
     429        self._transform_btn.Disable() 
     430        self._compute_btn.Disable() 
    399431 
    400432        extrapolate_btn.Bind(wx.EVT_BUTTON, self.compute_extrapolation) 
     433        self._transform_btn.Bind(wx.EVT_BUTTON, self.compute_transform) 
    401434 
    402435        controls_sizer.Add(extrapolate_btn, wx.CENTER | wx.EXPAND) 
    403         controls_sizer.Add(transform_btn, wx.CENTER | wx.EXPAND) 
    404         controls_sizer.Add(compute_btn, wx.CENTER | wx.EXPAND) 
     436        controls_sizer.Add(self._transform_btn, wx.CENTER | wx.EXPAND) 
     437        controls_sizer.Add(self._compute_btn, wx.CENTER | wx.EXPAND) 
    405438 
    406439        controlbox_sizer.Add(controls_sizer, wx.TOP | wx.EXPAND, 0) 
Note: See TracChangeset for help on using the changeset viewer.