Changeset 5d98370 in sasview for prview/perspectives/pr


Ignore:
Timestamp:
May 25, 2009 4:52:02 PM (15 years ago)
Author:
Mathieu Doucet <doucetm@…>
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, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
6f1f129
Parents:
fd4b6f8
Message:

prview: allow to save/load a pr inversion state. removed the load button from the panel.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • prview/perspectives/pr/inversion_panel.py

    r0bae207 r5d98370  
    66 
    77import wx 
     8import os 
    89from sans.guicomm.events import StatusEvent     
     10from inversion_state import InversionState 
    911 
    1012class InversionDlg(wx.Dialog): 
     
    108110    ## Oscillation parameters (sin function = 1.1) 
    109111    oscillation_max = 1.5 
    110      
    111     ## Fraction of P(r) that is positive  
    112     positive = 1.0 
    113      
    114     ## Fraction of P(r) that is greater than zero by more than 1 sigma 
    115     pos_err  = 1.0 
    116112     
    117113    def __init__(self, parent, id = -1, plots = None, standalone=False, **kwargs): 
     
    135131        self.qmin_ctl   = None 
    136132        self.qmax_ctl   = None 
     133        self.swidth_ctl = None 
     134        self.sheight_ctl = None 
    137135         
    138136        self.rg_ctl     = None 
     
    157155        self.standalone = standalone 
    158156         
     157        ## Default file location for save 
     158        self._default_save_location = os.getcwd() 
     159         
    159160        self._do_layout() 
    160161         
     
    164165        """ 
    165166        if name=='nfunc': 
    166             self.nfunc_ctl.SetValue(str(value)) 
     167            self.nfunc_ctl.SetValue(str(int(value))) 
    167168        elif name=='d_max': 
    168169            self.dmax_ctl.SetValue(str(value)) 
     
    185186        elif name=='oscillation': 
    186187            self.osc_ctl.SetValue("%-5.2g" % value) 
     188        elif name=='slit_width': 
     189            self.swidth_ctl.SetValue("%-5.2g" % value) 
     190        elif name=='slit_height': 
     191            self.sheight_ctl.SetValue("%-5.2g" % value) 
    187192        elif name=='positive': 
    188193            self.pos_ctl.SetValue("%-5.2g" % value) 
     
    234239                return float(self.chi2_ctl.GetValue()) 
    235240            except: 
    236                 return -1.0 
     241                return None 
    237242        elif name=='bck': 
    238243            try: 
    239244                return float(self.bck_ctl.GetValue()) 
    240245            except: 
    241                 return -1.0 
     246                return None 
    242247        elif name=='q_min': 
    243248            try: 
     
    254259                return float(self.time_ctl.GetValue()) 
    255260            except: 
    256                 return -1.0 
     261                return None 
    257262        elif name=='rg': 
    258263            try: 
    259264                return float(self.rg_ctl.GetValue()) 
    260265            except: 
    261                 return -1.0 
     266                return None 
    262267        elif name=='iq0': 
    263268            try: 
    264269                return float(self.iq0_ctl.GetValue()) 
    265270            except: 
    266                 return -1.0 
     271                return None 
    267272        elif name=='oscillation': 
    268273            try: 
    269274                return float(self.osc_ctl.GetValue()) 
    270275            except: 
    271                 return -1.0 
     276                return None 
     277        elif name=='slit_width': 
     278            try: 
     279                return float(self.swidth_ctl.GetValue()) 
     280            except: 
     281                return None 
     282        elif name=='slit_height': 
     283            try: 
     284                return float(self.sheight_ctl.GetValue()) 
     285            except: 
     286                return None 
    272287        elif name=='pos': 
    273288            try: 
    274289                return float(self.pos_ctl.GetValue()) 
    275290            except: 
    276                 return -1.0 
     291                return None 
    277292        elif name=='pos_err': 
    278             return self.pos_err_ctl.GetValue() 
     293            try: 
     294                return float(self.pos_err_ctl.GetValue()) 
     295            except: 
     296                return None 
    279297        elif name=='alpha_estimate': 
    280             return self.alpha_estimate_ctl.GetLabel() 
     298            try: 
     299                return float(self.alpha_estimate_ctl.GetLabel()) 
     300            except: 
     301                return None 
    281302        elif name=='nterms_estimate': 
    282             return self.nterms_estimate_ctl.GetLabel() 
     303            try: 
     304                return int(self.nterms_estimate_ctl.GetLabel()) 
     305            except: 
     306                return None 
    283307        elif name=='plotname': 
    284308            if self.standalone==False: 
     
    289313            wx.Panel.__getattr__(self, name) 
    290314         
     315    def _save_state(self, evt=None): 
     316        """ 
     317            Method used to create a memento of the current state 
     318             
     319            @return: state object  
     320        """ 
     321        # Ask the user the location of the file to write to. 
     322        path = None 
     323        dlg = wx.FileDialog(self, "Choose a file", self._default_save_location, "", "*.prv", wx.SAVE) 
     324        if dlg.ShowModal() == wx.ID_OK: 
     325            path = dlg.GetPath() 
     326            self._default_save_location = os.path.dirname(path) 
     327        dlg.Destroy() 
     328                 
     329        # Construct the state object     
     330        state = InversionState() 
     331         
     332        # Read the panel's parameters 
     333        flag, alpha, dmax, nfunc, qmin, \ 
     334        qmax, height, width = self._read_pars() 
     335         
     336        state.nfunc = nfunc 
     337        state.d_max = dmax 
     338        state.alpha = alpha 
     339        state.qmin  = qmin 
     340        state.qmax  = qmax 
     341        state.width = width 
     342        state.height = height 
     343         
     344        # Data file 
     345        state.file = self.data_file.GetValue() 
     346         
     347        # Background evaluation checkbox 
     348        state.estimate_bck = self.bck_chk.IsChecked() 
     349         
     350        # Estimates 
     351        state.nterms_estimate = self.nterms_estimate 
     352        state.alpha_estimate = self.alpha_estimate 
     353         
     354        # Read the output values 
     355        state.chi2    = self.chi2 
     356        state.elapsed = self.elapsed 
     357        state.osc     = self.oscillation 
     358        state.pos     = self.pos 
     359        state.pos_err = self.pos_err 
     360        state.rg      = self.rg 
     361        state.iq0     = self.iq0 
     362        state.bck     = self.bck 
     363             
     364        state.toXML(path) 
     365        return state 
     366     
     367    def set_state(self, state): 
     368        """ 
     369            Set the state of the panel and inversion problem to 
     370            the state passed as a parameter. 
     371            Execute the inversion immediately after filling the  
     372            controls. 
     373             
     374            @param state: InversionState object 
     375        """ 
     376        self.nfunc = state.nfunc 
     377        self.d_max = state.d_max 
     378        self.alpha = state.alpha 
     379        self.q_min  = state.qmin 
     380        self.q_max  = state.qmax 
     381        self.slit_width = state.width 
     382        self.slit_height = state.height 
     383         
     384        # Data file 
     385        self.data_file.SetValue(str(state.file)) 
     386     
     387        # Background evaluation checkbox 
     388        self.bck_chk.SetValue(state.estimate_bck) 
     389         
     390        # Estimates 
     391        self.nterms_estimate = state.nterms_estimate  
     392        self.alpha_estimate = state.alpha_estimate  
     393     
     394         
     395        # Read the output values 
     396        self.chi2    = state.chi2 
     397        self.elapsed = state.elapsed 
     398        self.oscillation = state.osc 
     399        self.positive = state.pos 
     400        self.pos_err = state.pos_err 
     401        self.rg      = state.rg 
     402        self.iq0     = state.iq0 
     403        self.bck     = state.bck 
     404 
     405        # Check whether the file is accessible, if so, 
     406        # load it a recompute P(r) using the new parameters 
     407        if os.path.isfile(state.file): 
     408            self._change_file(filepath=state.file) 
     409            self._on_invert(None)     
     410        else: 
     411            message = "Could not find [%s] on the file system." % state.file 
     412            wx.PostEvent(self.manager.parent, StatusEvent(status=message)) 
     413     
     414             
     415         
    291416    def set_manager(self, manager): 
    292417        self.manager = manager 
     
    312437        else: 
    313438            self.file_radio = wx.StaticText(self, -1, "Data file:") 
    314         self.data_file = wx.TextCtrl(self, -1, size=(100,20)) 
     439        self.data_file = wx.TextCtrl(self, -1, size=(220,20)) 
    315440        self.data_file.SetEditable(False) 
    316441        self.data_file.SetValue("") 
    317442        id = wx.NewId() 
    318         choose_button = wx.Button(self, id, "Choose file") 
    319         self.Bind(wx.EVT_BUTTON, self._change_file, id = id)    
    320443        pars_sizer.Add(self.file_radio, (iy,0), (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    321         #pars_sizer.Add(self.data_file, (iy,1), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    322444        pars_sizer.Add(self.data_file, (iy,1), (1,1), wx.ADJUST_MINSIZE, 15) 
    323         pars_sizer.Add(choose_button, (iy,3), (1,1), wx.RIGHT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    324445         
    325446        if self.standalone==False: 
     
    583704        #button_Cancel = wx.Button(self, wx.ID_CANCEL, "Cancel") 
    584705         
     706        id = wx.NewId() 
     707        button_Save = wx.Button(self, id, "Save") 
     708        button_Save.SetToolTipString("Save the current P(r) work to file.") 
     709        self.Bind(wx.EVT_BUTTON, self._save_state, id = id)    
     710         
    585711        sizer_button = wx.BoxSizer(wx.HORIZONTAL) 
    586712        sizer_button.Add((20, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
     713        sizer_button.Add(button_Save, 0, wx.LEFT|wx.ADJUST_MINSIZE, 10) 
    587714        sizer_button.Add(button_Reset, 0, wx.LEFT|wx.ADJUST_MINSIZE, 10) 
    588715        sizer_button.Add(button_OK, 0, wx.LEFT|wx.ADJUST_MINSIZE, 10) 
     
    825952            wx.PostEvent(self.parent, StatusEvent(status=message)) 
    826953         
    827     def _change_file(self, evt): 
     954    def _change_file(self, evt=None, filepath=None): 
    828955        """ 
    829956            Choose a new input file for I(q) 
     
    831958        import os 
    832959        if not self.manager==None: 
    833             path = self.manager.choose_file() 
     960            path = self.manager.choose_file(path=filepath) 
    834961             
    835962            if path and os.path.isfile(path): 
Note: See TracChangeset for help on using the changeset viewer.