Changeset 911dbe4 in sasview for src/sas/sasgui/perspectives


Ignore:
Timestamp:
Jul 11, 2016 4:36:55 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:
7a219e3e
Parents:
f2bbabf
git-author:
Lewis O'Driscoll <lewis.o'driscoll@…> (07/07/16 11:30:07)
git-committer:
Lewis O'Driscoll <lewis.o'driscoll@…> (07/11/16 04:36:55)
Message:

Add transform functionality

Location:
src/sas/sasgui/perspectives/corfunc
Files:
2 edited

Legend:

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

    r3b8efec r911dbe4  
    2222IQ_DATA_LABEL = r"$I_{obs}(q)$" 
    2323IQ_EXTRAPOLATED_DATA_LABEL = r"$I_{extrap}(q)$" 
     24 
     25GROUP_ID_TRANSFORM = r"$\Gamma(x)$" 
     26TRANSFORM_LABEL = r"$\Gamma(x)$" 
    2427 
    2528 
     
    129132        new_plot = Data1D(data.x, data.y, dy=data.dy) 
    130133 
     134        group_id = "" 
    131135        if label == IQ_DATA_LABEL or label == IQ_EXTRAPOLATED_DATA_LABEL: 
    132136            new_plot.xaxis("\\rm{Q}", 'A^{-1}') 
    133137            new_plot.yaxis("\\rm{Intensity} ", "cm^{-1}") 
    134  
     138            group_id = GROUP_ID_IQ_DATA 
     139        elif label == TRANSFORM_LABEL: 
     140            new_plot.xaxis("{x}", 'A') 
     141            new_plot.yaxis("{\\Gamma}", '') 
     142            group_id = GROUP_ID_TRANSFORM 
    135143        new_plot.symbol = GUIFRAME_ID.CURVE_SYMBOL_NUM 
    136144        new_plot.id = label 
    137145        new_plot.name = label 
     146        new_plot.group_id = group_id 
    138147        new_plot.interactive = True 
    139         new_plot.group_id = GROUP_ID_IQ_DATA 
    140         new_plot.title = "I(q)" 
     148        new_plot.title = group_id.replace('$', '').replace('\\', '') 
    141149        # Show data on a linear scale 
    142150        new_plot.xtransform = 'x' 
    143151        new_plot.ytransform = 'y' 
    144152        wx.PostEvent(self.parent, 
    145                      NewPlotEvent(plot=new_plot, title="I(q)", reset=reset)) 
     153                     NewPlotEvent(plot=new_plot, title=new_plot.title, 
     154                        reset=reset)) 
  • src/sas/sasgui/perspectives/corfunc/corfunc_panel.py

    rf2bbabf r911dbe4  
    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.