Changeset 3b8efec in sasview for src/sas/sasgui


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:
77e9ac6
Parents:
b564ea2
git-author:
Lewis O'Driscoll <lewis.o'driscoll@…> (07/07/16 07:29:10)
git-committer:
Lewis O'Driscoll <lewis.o'driscoll@…> (07/11/16 04:36:55)
Message:

Add extrapolation functionality

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

Legend:

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

    r9c90cf3 r3b8efec  
    55import sys 
    66import logging 
     7import copy 
    78from sas.sasgui.guiframe.plugin_base import PluginBase 
    89from sas.sasgui.guiframe.gui_manager import MDIFrame 
     
    1819 
    1920 
    20 GROUP_ID_IQ_DATA = r"$I_{obs}(q)$" 
     21GROUP_ID_IQ_DATA = r"$I(q)$" 
    2122IQ_DATA_LABEL = r"$I_{obs}(q)$" 
     23IQ_EXTRAPOLATED_DATA_LABEL = r"$I_{extrap}(q)$" 
    2224 
    2325 
     
    117119                        info='error')) 
    118120 
    119     def show_data(self, path=None, data=None, reset=False): 
     121    def show_data(self, data, label, path=None, reset=False): 
    120122        """ 
    121123        Show data read from a file 
     
    125127        :param reset: If True, all other plottables will be cleared 
    126128        """ 
    127         if data.dy is not None: 
    128             new_plot = Data1D(data.x, data.y, dy=data.dy) 
    129         else: 
    130             new_plot = Data1D(data.x, data.y) 
     129        new_plot = Data1D(data.x, data.y, dy=data.dy) 
     130 
     131        if label == IQ_DATA_LABEL or label == IQ_EXTRAPOLATED_DATA_LABEL: 
     132            new_plot.xaxis("\\rm{Q}", 'A^{-1}') 
     133            new_plot.yaxis("\\rm{Intensity} ", "cm^{-1}") 
     134 
    131135        new_plot.symbol = GUIFRAME_ID.CURVE_SYMBOL_NUM 
    132         new_plot.name = IQ_DATA_LABEL 
    133         new_plot.xaxis("\\rm{Q}", 'A^{-1}') 
    134         new_plot.yaxis("\\rm{Intensity} ", "cm^{-1}") 
     136        new_plot.id = label 
     137        new_plot.name = label 
    135138        new_plot.interactive = True 
    136139        new_plot.group_id = GROUP_ID_IQ_DATA 
    137         new_plot.id = self.data_id 
    138140        new_plot.title = "I(q)" 
    139141        # Show data on a linear scale 
  • src/sas/sasgui/perspectives/corfunc/corfunc_panel.py

    rb564ea2 r3b8efec  
    66from sas.sasgui.guiframe.panel_base import PanelBase 
    77from sas.sasgui.guiframe.utils import check_float 
     8from sas.sasgui.guiframe.dataFitting import Data1D 
    89from sas.sasgui.perspectives.invariant.invariant_widgets import OutputTextCtrl 
    910from sas.sasgui.perspectives.invariant.invariant_widgets import InvTextCtrl 
    1011from sas.sasgui.perspectives.fitting.basepage import ModelTextCtrl 
    1112from sas.sasgui.perspectives.corfunc.corfunc_state import CorfuncState 
     13import sas.sasgui.perspectives.corfunc.corfunc 
     14from sas.sascalc.corfunc.corfunc_calculator import CorfuncCalculator 
    1215 
    1316if sys.platform.count("win32") > 0: 
     
    3639        self._manager = manager 
    3740        self._data = data # The data to be analysed 
     41        self._extrapolated_data = None # The extrapolated data set 
    3842        self._data_name_box = None # Text box to show name of file 
    3943        self._background_input = None 
     
    5256        self._qmax1_input.Bind(wx.EVT_TEXT, self._on_enter_input) 
    5357        self._qmax2_input.Bind(wx.EVT_TEXT, self._on_enter_input) 
     58        self._background_input.Bind(wx.EVT_TEXT, self._on_enter_input) 
    5459 
    5560    def set_state(self, state=None, data=None): 
     
    6772        if data is not None: 
    6873            self.state.data = data 
    69         self.set_data(self.state.data, set_qrange=False) 
     74        self.set_data(data, set_qrange=False) 
    7075        if self.state.qmin is not None: 
    7176            self.set_qmin(self.state.qmin) 
     
    107112        self._data = data 
    108113        if self._manager is not None: 
    109             self._manager.show_data(data=data, reset=True) 
     114            from sas.sasgui.perspectives.corfunc.corfunc import IQ_DATA_LABEL 
     115            self._manager.show_data(data, IQ_DATA_LABEL, reset=True) 
    110116        if set_qrange: 
    111117            lower = data.x[-1]*0.05 
     
    118124    def get_data(self): 
    119125        return self._data 
     126 
     127    def compute_extrapolation(self, event=None): 
     128        if self._data is None: 
     129            msg = "Data must be loaded in order to perform an extrapolation." 
     130            wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 
     131            return 
     132        if not self._validate_inputs: 
     133            msg = "Invalid Q range entered." 
     134            wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 
     135            return 
     136        calculator = CorfuncCalculator(self._data, self.qmin, self.qmax, 
     137            background=self.background) 
     138        self._extrapolated_data = calculator.compute_extrapolation() 
     139        # TODO: Find way to set xlim and ylim so full range of data can be 
     140        # plotted 
     141        maxq = self._data.x.max() 
     142        mask = self._extrapolated_data.x <= maxq 
     143        numpts = len(self._extrapolated_data.x[mask]) + 250 
     144        plot_x = self._extrapolated_data.x[0:numpts] 
     145        plot_y = self._extrapolated_data.y[0:numpts] 
     146        to_plot = Data1D(plot_x, plot_y) 
     147        from sas.sasgui.perspectives.corfunc.corfunc import\ 
     148            IQ_EXTRAPOLATED_DATA_LABEL 
     149        self._manager.show_data(to_plot, IQ_EXTRAPOLATED_DATA_LABEL) 
     150 
    120151 
    121152    def save_project(self, doc=None): 
     
    165196        self.qmax = (new_qmax1, new_qmax2) 
    166197        self.background = float(self._background_input.GetValue()) 
    167         data_id = self._manager.data_id 
    168         from sas.sasgui.perspectives.corfunc.corfunc import GROUP_ID_IQ_DATA 
     198        from sas.sasgui.perspectives.corfunc.corfunc import GROUP_ID_IQ_DATA,\ 
     199            IQ_DATA_LABEL 
    169200        group_id = GROUP_ID_IQ_DATA 
    170201        if event is not None: 
    171202            wx.PostEvent(self._manager.parent, PlotQrangeEvent( 
    172203                ctrl=[self._qmin_input, self._qmax1_input, self._qmax2_input], 
    173                 active=event.GetEventObject(), id=data_id, group_id=group_id, 
     204                active=event.GetEventObject(), id=IQ_DATA_LABEL, group_id=group_id, 
    174205                leftdown=False)) 
    175206 
     
    201232                qmin_valid = False 
    202233            elif background < 0 or background > self._data.y.max(): 
    203                 msg = "background must be positive and less than highest I value" 
     234                msg = "background must be positive and less than highest I" 
    204235                background_valid = False 
    205236        if not qmin_valid: 
     
    365396        compute_btn = wx.Button(self, wx.NewId(), "Compute Measuments") 
    366397 
     398        extrapolate_btn.Bind(wx.EVT_BUTTON, self.compute_extrapolation) 
     399 
    367400        controls_sizer.Add(extrapolate_btn, wx.CENTER | wx.EXPAND) 
    368401        controls_sizer.Add(transform_btn, wx.CENTER | wx.EXPAND) 
Note: See TracChangeset for help on using the changeset viewer.