Changeset 75df58b in sasview for prview


Ignore:
Timestamp:
Jan 21, 2011 12:44:46 PM (13 years ago)
Author:
Gervaise Alina <gervyh@…>
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:
f444b20
Parents:
8dc02d8b
Message:

working on loading for prview

Location:
prview
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • prview/PrView.py

    r43db4a8 r75df58b  
    66import local_config 
    77import sys 
    8 from perspectives.pr.pr import NewPrFileEvent 
     8 
    99 
    1010# Application dimensions 
     
    1818        """ 
    1919        """ 
    20         wx.PostEvent(self, NewPrFileEvent()) 
     20        pass 
     21 
    2122 
    2223class PrApp(gui_manager.ViewApp): 
  • prview/perspectives/pr/inversion_panel.py

    r3e41f43 r75df58b  
    1010import logging 
    1111from wx.lib.scrolledpanel import ScrolledPanel 
    12 from sans.guicomm.events import StatusEvent     
     12from sans.guiframe.events import StatusEvent    
     13from sans.guiframe.panel_base import PanelBase  
    1314from inversion_state import InversionState 
    1415from pr_widgets import PrTextCtrl 
     
    1819 
    1920 
    20 class InversionControl(ScrolledPanel): 
     21class InversionControl(ScrolledPanel, PanelBase): 
    2122    """ 
    2223    """ 
     
    3536        """ 
    3637        ScrolledPanel.__init__(self, parent, id=id, **kwargs) 
     38        PanelBase.__init__(self) 
    3739        self.SetupScrolling() 
    3840         
     
    7274        self.alpha_estimate_ctl = None 
    7375        self.nterms_estimate_ctl = None 
    74          
    7576        ## D_max distance explorator 
    7677        self.distance_explorator_ctl = None 
    77          
    7878        ## Data manager 
    7979        self.manager   = None 
    80          
    8180        ## Standalone flage 
    8281        self.standalone = standalone 
    83          
    8482        ## Default file location for save 
    8583        self._default_save_location = os.getcwd() 
    86          
    87          
    8884        # Default width 
    8985        self._default_width = 350 
     
    578574        hint_msg = "Radius of gyration for the computed P(r)." 
    579575        self.rg_ctl.SetToolTipString(hint_msg) 
    580         self.iq0_ctl   = OutputTextCtrl(self, -1, size=(60,20)) 
     576        self.iq0_ctl   = OutputTextCtrl(self, -1, size=(60, 20)) 
    581577        hint_msg = "Scattering intensity at Q=0 for the computed P(r)." 
    582578        self.iq0_ctl.SetToolTipString(hint_msg) 
    583         self.bck_ctl   = OutputTextCtrl(self, -1, size=(60,20)) 
     579        self.bck_ctl   = OutputTextCtrl(self, -1, size=(60, 20)) 
    584580        self.bck_ctl.SetToolTipString("Value of estimated constant background.") 
    585581         
     
    592588        label_pos_err = wx.StaticText(self, -1, "1-sigma positive fraction") 
    593589         
    594         self.time_ctl = OutputTextCtrl(self, -1, size=(60,20)) 
     590        self.time_ctl = OutputTextCtrl(self, -1, size=(60, 20)) 
    595591        hint_msg = "Computation time for the last inversion, in seconds." 
    596592        self.time_ctl.SetToolTipString(hint_msg) 
    597593         
    598         self.chi2_ctl = OutputTextCtrl(self, -1, size=(60,20)) 
     594        self.chi2_ctl = OutputTextCtrl(self, -1, size=(60, 20)) 
    599595        self.chi2_ctl.SetToolTipString("Chi^2 over degrees of freedom.") 
    600596         
    601597        # Oscillation parameter 
    602         self.osc_ctl = OutputTextCtrl(self, -1, size=(60,20)) 
     598        self.osc_ctl = OutputTextCtrl(self, -1, size=(60, 20)) 
    603599        hint_msg = "Oscillation parameter. P(r) for a sphere has an " 
    604600        hint_msg += " oscillation parameter of 1.1." 
     
    606602         
    607603        # Positive fraction figure of merit 
    608         self.pos_ctl = OutputTextCtrl(self, -1, size=(60,20)) 
     604        self.pos_ctl = OutputTextCtrl(self, -1, size=(60, 20)) 
    609605        hint_msg = "Fraction of P(r) that is positive. " 
    610606        hint_msg += "Theoretically, P(r) is defined positive." 
     
    612608         
    613609        # 1-simga positive fraction figure of merit 
    614         self.pos_err_ctl = OutputTextCtrl(self, -1, size=(60,20)) 
     610        self.pos_err_ctl = OutputTextCtrl(self, -1, size=(60, 20)) 
    615611        message  = "Fraction of P(r) that is at least 1 standard deviation" 
    616612        message += " greater than zero.\n" 
     
    775771        height = 0 
    776772        width  = 0 
    777          
    778773        flag = True 
    779          
    780          
    781774        # Read slit height 
    782775        try: 
     
    917910            wx.PostEvent(self.parent, StatusEvent(status=message)) 
    918911         
    919     def _change_file(self, evt=None, filepath=None): 
     912    def _change_file(self, evt=None, filepath=None, data=None): 
    920913        """ 
    921914        Choose a new input file for I(q) 
    922915        """ 
    923         import os 
    924         if not self.manager==None: 
    925             path = self.manager.choose_file(path=filepath) 
    926              
    927             if path and os.path.isfile(path): 
    928                 self.plot_data.SetValue(str(path)) 
    929                 try: 
    930                     self.manager.show_data(path, reset=True) 
    931                     self._on_pars_changed(None) 
    932                  
    933                     # Perform inversion 
    934                     if self.standalone == True: 
    935                         self._on_invert(None) 
    936                 except: 
    937                     # Invalid data 
    938                     msg = "InversionControl._change_file: %s" % sys.exc_value 
    939                     logging.error(msg)                     
     916        if not self.manager is None: 
     917            self.plot_data.SetValue(str(data.name)) 
     918            try: 
     919                self.manager.show_data(data=data, reset=True) 
     920                self._on_pars_changed(None) 
     921                self._on_invert(None) 
     922            except: 
     923                msg = "InversionControl._change_file: %s" % sys.exc_value 
     924                logging.error(msg)                     
    940925 
    941926class HelpDialog(wx.Dialog): 
     
    954939        explanation = help() 
    955940            
    956         label_explain = wx.StaticText(self, -1, explanation, size=(350,320)) 
     941        label_explain = wx.StaticText(self, -1, explanation, size=(350, 320)) 
    957942             
    958943        vbox.Add(label_explain, 0, wx.ALL|wx.EXPAND, 15) 
     
    991976         
    992977        label_npts = wx.StaticText(self, -1, "Number of points") 
    993         self.npts_ctl = PrTextCtrl(self, -1, size=(100,20)) 
     978        self.npts_ctl = PrTextCtrl(self, -1, size=(100, 20)) 
    994979                  
    995         pars_sizer = wx.GridBagSizer(5,5) 
     980        pars_sizer = wx.GridBagSizer(5, 5) 
    996981        iy = 0 
    997         pars_sizer.Add(label_npts,      (iy,0), (1,1), wx.LEFT, 15) 
    998         pars_sizer.Add(self.npts_ctl,   (iy,1), (1,1), wx.RIGHT, 0) 
     982        pars_sizer.Add(label_npts, (iy, 0), (1, 1), wx.LEFT, 15) 
     983        pars_sizer.Add(self.npts_ctl, (iy, 1), (1, 1), wx.RIGHT, 0) 
    999984         
    1000985        vbox.Add(pars_sizer, 0, wx.ALL|wx.EXPAND, 15) 
    1001  
    1002986 
    1003987        static_line = wx.StaticLine(self, -1) 
  • prview/perspectives/pr/pr.py

    r3e41f43 r75df58b  
    1919import logging 
    2020import time 
    21 from sans.guiframe.dataFitting import Data1D, Theory1D 
    22 from sans.guicomm.events import NewPlotEvent, StatusEvent     
    23 import math, numpy 
     21import copy 
     22import math 
     23import numpy 
     24import pylab 
     25from sans.guiframe.dataFitting import Data1D 
     26from sans.guiframe.dataFitting import Theory1D 
     27from sans.guiframe.events import NewPlotEvent 
     28from sans.guiframe.events import StatusEvent     
     29 
    2430from sans.pr.invertor import Invertor 
    2531from DataLoader.loader import Loader 
     32from DataLoader.data_info import Data1D as LoaderData1D 
    2633import DataLoader 
    2734from sans.guiframe.data_loader import load_error  
    28  
    29 import copy 
     35from sans.guiframe.plugin_base import PluginBase 
     36 
    3037 
    3138PR_FIT_LABEL       = r"$P_{fit}(r)$" 
     
    3542IQ_SMEARED_LABEL   = r"$I_{smeared}(q)$" 
    3643 
    37 import wx.lib 
    38 (NewPrFileEvent, EVT_PR_FILE) = wx.lib.newevent.NewEvent() 
    39  
    40 from sans.guiframe.plugin_base import PluginBase 
     44#import wx.lib 
     45#(NewPrFileEvent, EVT_PR_FILE) = wx.lib.newevent.NewEvent() 
     46 
     47 
    4148 
    4249class Plugin(PluginBase): 
     
    169176        """ 
    170177        from sans.pr.invertor import Invertor 
    171         import numpy 
    172         import pylab 
    173         import math 
    174         from sans.guicomm.events import NewPlotEvent             
    175         from danse.common.plottools import Data1D, Theory1D 
     178             
     179        from danse.common.plottools import Data1D as PlotData1D 
     180        from danse.common.plottools import Theory1D as Theory1D 
    176181         
    177182        # Generate P(r) for sphere 
     
    205210 
    206211        # Show input P(r) 
    207         new_plot = Data1D(pr.x, pr.y, dy=pr.err) 
     212        new_plot = PlotData1D(pr.x, pr.y, dy=pr.err) 
    208213        new_plot.name = "P_{obs}(r)" 
    209214        new_plot.xaxis("\\rm{r}", 'A') 
    210215        new_plot.yaxis("\\rm{P(r)} ","cm^{-3}") 
     216        print "_fit_pr" 
    211217        wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title="Pr")) 
    212218 
     
    221227        """ 
    222228        """ 
    223         import numpy 
    224         import pylab 
    225         import math 
    226         from sans.guicomm.events import NewPlotEvent             
    227         from danse.common.plottools import Data1D, Theory1D 
     229        from danse.common.plottools import Theory1D as PlotTheory1D 
    228230        # Show P(r) 
    229231        y_true = numpy.zeros(len(x)) 
     
    237239         
    238240        # Show the theory P(r) 
    239         new_plot = Theory1D(x, y_true) 
     241        new_plot = PlotTheory1D(x, y_true) 
    240242        new_plot.name = "P_{true}(r)" 
    241243        new_plot.xaxis("\\rm{r}", 'A') 
    242244        new_plot.yaxis("\\rm{P(r)} ","cm^{-3}") 
    243245         
    244          
    245246        #Put this call in plottables/guitools     
    246247        wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title="Sphere P(r)")) 
     248        
    247249         
    248250    def get_npts(self): 
     
    257259    def show_iq(self, out, pr, q=None): 
    258260        """ 
    259         """ 
    260         import numpy 
    261         import pylab 
    262         import math 
    263         from sans.guicomm.events import NewPlotEvent             
    264         from danse.common.plottools import Data1D, Theory1D 
     261        """   
     262        from danse.common.plottools import Theory1D as PlotTheory1D 
    265263 
    266264        qtemp = pr.x 
     
    294292                print "Error getting error", value, x[i] 
    295293                 
    296         new_plot = Theory1D(x, y) 
     294        new_plot = PlotTheory1D(x, y) 
    297295        new_plot.name = IQ_FIT_LABEL 
    298296        new_plot.xaxis("\\rm{Q}", 'A^{-1}') 
     
    348346    def show_pr(self, out, pr, cov=None): 
    349347        """ 
    350         """ 
    351         import numpy 
    352         import pylab 
    353         import math 
    354         from sans.guicomm.events import NewPlotEvent             
    355         from danse.common.plottools import Data1D, Theory1D 
     348        """      
     349        from danse.common.plottools import Data1D as PlotData1D  
     350        from danse.common.plottools import Theory1D as PlotTheory1D 
    356351         
    357352        # Show P(r) 
     
    387382         
    388383        if cov2==None: 
    389             new_plot = Theory1D(x, y) 
     384            new_plot = PlotTheory1D(x, y) 
    390385        else: 
    391             new_plot = Data1D(x, y, dy=dy) 
     386            new_plot = PlotData1D(x, y, dy=dy) 
    392387        new_plot.name = PR_FIT_LABEL 
    393388        new_plot.xaxis("\\rm{r}", 'A') 
    394389        new_plot.yaxis("\\rm{P(r)} ","cm^{-3}") 
     390        new_plot.title = "P(r) fit" 
    395391        # Make sure that the plot is linear 
    396392        new_plot.xtransform="x" 
     
    400396        return x, pr.d_max 
    401397         
    402          
    403     def choose_file(self, path=None): 
    404         """ 
    405         """ 
    406         #TODO: this should be in a common module 
    407         return self.parent.choose_file(path=path) 
    408                  
    409                  
    410     def load(self, path): 
     398                 
     399    def load(self, data): 
    411400        """ 
    412401        Load data. This will eventually be replaced 
     
    422411                self.path = path 
    423412                 
    424         self._current_file_data = FileData(path) 
     413        self._current_file_data = FileData(data.path) 
    425414         
    426415        # Use data loader to load file 
    427         dataread = Loader().load(path) 
    428          
     416        #dataread = Loader().load(path) 
     417        dataread = data 
    429418        # Notify the user if we could not read the file 
    430419        if dataread is None: 
     
    574563        #if graph.selected_plottable==IQ_DATA_LABEL: 
    575564        for item in graph.plottables: 
    576             if item.name==PR_FIT_LABEL: 
    577                 m_list = [["Add P(r) data", "Load a data file and display it on this plot", self._on_add_data], 
    578                        ["Change number of P(r) points", "Change the number of points on the P(r) output", self._on_pr_npts]] 
    579  
    580                 if self._scale_output_unity==True or self._normalize_output==True: 
    581                     m_list.append(["Disable P(r) scaling",  
    582                                    "Let the output P(r) keep the scale of the data",  
     565            if item.name == PR_FIT_LABEL: 
     566                #add_data_hint = "Load a data file and display it on this plot" 
     567                #["Add P(r) data",add_data_hint , self._on_add_data], 
     568                change_n_hint = "Change the number of" 
     569                change_n_hint += " points on the P(r) output" 
     570                change_n_label = "Change number of P(r) points" 
     571                m_list = [[change_n_label, change_n_hint , self._on_pr_npts]] 
     572 
     573                if self._scale_output_unity or self._normalize_output: 
     574                    hint = "Let the output P(r) keep the scale of the data" 
     575                    m_list.append(["Disable P(r) scaling", hint,  
    583576                                   self._on_disable_scaling]) 
    584                  
    585                 if self._scale_output_unity==False: 
     577                if not self._scale_output_unity: 
    586578                    m_list.append(["Scale P_max(r) to unity",  
    587579                                   "Scale P(r) so that its maximum is 1",  
    588580                                   self._on_scale_unity]) 
    589                      
    590                 if self._normalize_output==False: 
     581                if not self._normalize_output: 
    591582                    m_list.append(["Normalize P(r) to unity",  
    592583                                   "Normalize the integral of P(r) to 1",  
     
    594585                     
    595586                return m_list 
    596                 #return [["Add P(r) data", "Load a data file and display it on this plot", self._on_add_data], 
    597                 #       ["Change number of P(r) points", "Change the number of points on the P(r) output", self._on_pr_npts]] 
    598  
    599             elif item.name==graph.selected_plottable: 
    600                     #TODO: we might want to check that the units are consistent with I(q) 
    601                     #      before allowing this menu item 
    602                 if not self.standalone and issubclass(item.__class__, DataLoader.data_info.Data1D): 
    603                     return [["Compute P(r)", "Compute P(r) from distribution", self._on_context_inversion]]       
     587                #return [["Add P(r) data",  
     588                #"Load a data file and display it on this plot", 
     589                # self._on_add_data], 
     590                #       ["Change number of P(r) points", 
     591                # "Change the number of points on the P(r) output", 
     592                # self._on_pr_npts]] 
     593 
     594            elif item.name == graph.selected_plottable: 
     595                    #TODO: we might want to check that the units are  
     596                    #     consistent with I(q) before allowing this menu item 
     597                if not self.standalone and \ 
     598                issubclass(item.__class__, DataLoader.data_info.Data1D): 
     599                    return [["Compute P(r)",  
     600                             "Compute P(r) from distribution",  
     601                             self._on_context_inversion]]       
    604602                 
    605603        return [] 
     
    619617        for plot in self._added_plots: 
    620618            self._added_plots[plot].y = numpy.copy(self._default_Iq[plot]) 
    621             wx.PostEvent(self.parent, NewPlotEvent(plot=self._added_plots[plot],  
    622                                                    title=self._added_plots[plot].name, 
     619            wx.PostEvent(self.parent,  
     620                         NewPlotEvent(plot=self._added_plots[plot],  
     621                                      title=self._added_plots[plot].name, 
    623622                                                   update=True))         
    624623         
     
    651650            new_plot.yaxis("\\rm{P(r)} ","cm^{-3}") 
    652651             
    653             wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, update=True, 
    654                                                    title=self._added_plots[plot].name)) 
     652            wx.PostEvent(self.parent,  
     653                         NewPlotEvent(plot=new_plot, update=True, 
     654                                         title=self._added_plots[plot].name)) 
    655655         
    656656    def _on_scale_unity(self, evt): 
     
    679679            new_plot.yaxis("\\rm{P(r)} ","cm^{-3}") 
    680680             
    681             wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, update=True, 
    682                                                    title=self._added_plots[plot].name))         
     681            wx.PostEvent(self.parent,  
     682                         NewPlotEvent(plot=new_plot, update=True, 
     683                                title=self._added_plots[plot].name))         
    683684         
    684685         
     
    714715                    wx.PostEvent(self.parent, StatusEvent(status=msg)) 
    715716                else: 
    716                     wx.PostEvent(self.parent, StatusEvent(status="This tool can only read 1D data")) 
     717                    msg = "This tool can only read 1D data" 
     718                    wx.PostEvent(self.parent, StatusEvent(status=msg)) 
    717719                    return 
    718720             
     
    748750                 
    749751        pr = self.pr.clone() 
    750         self.calc_thread = CalcPr(pr, self.nfunc, error_func=self._thread_error, completefn=self._completed, updatefn=None) 
     752        self.calc_thread = CalcPr(pr, self.nfunc, 
     753                                   error_func=self._thread_error,  
     754                                   completefn=self._completed, updatefn=None) 
    751755        self.calc_thread.queue() 
    752756        self.calc_thread.ready(2.5) 
     
    815819        self.pr = pr 
    816820         
    817         #message = "Computation completed in %g seconds [chi2=%g]" % (elapsed, pr.chi2) 
     821        #message = "Computation completed in" 
     822        #message +=  %g seconds [chi2=%g]" % (elapsed, pr.chi2) 
    818823        #wx.PostEvent(self.parent, StatusEvent(status=message)) 
    819824 
     
    835840            for i in range(len(out)): 
    836841                try: 
    837                     print "%d: %g +- %g" % (i, out[i], math.sqrt(math.fabs(cov[i][i]))) 
     842                    print "%d: %g +- %g" % (i, out[i], 
     843                                             math.sqrt(math.fabs(cov[i][i]))) 
    838844                except:  
    839845                    print sys.exc_value 
     
    855861         
    856862        # Popup result panel 
    857         #result_panel = InversionResults(self.parent, -1, style=wx.RAISED_BORDER) 
    858          
    859     def show_data(self, path=None, reset=False): 
     863        #result_panel = InversionResults(self.parent,  
     864        #-1, style=wx.RAISED_BORDER) 
     865         
     866    def show_data(self, path=None, data=None, reset=False): 
    860867        """ 
    861868        Show data read from a file 
     
    865872         
    866873        """ 
    867         if path is not None: 
     874        print "show_data", data.name 
     875        #if path is not None: 
     876        if data is not None: 
    868877            try: 
    869                 pr = self._create_file_pr(path) 
     878                #pr = self._create_file_pr(path) 
     879                pr = self._create_file_pr(data) 
    870880            except: 
    871                 status="Problem reading data: %s" % sys.exc_value 
     881                status = "Problem reading data: %s" % sys.exc_value 
    872882                wx.PostEvent(self.parent, StatusEvent(status=status)) 
    873883                raise RuntimeError, status 
     
    878888             
    879889            self.pr = pr 
    880                
     890        
    881891        # Make a plot of I(q) data 
    882892        if self.pr.err==None: 
     
    889899        new_plot.interactive = True 
    890900        #new_plot.group_id = "test group" 
    891         wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title="I(q)", reset=reset)) 
     901        wx.PostEvent(self.parent,  
     902                     NewPlotEvent(plot=new_plot, title="I(q)", reset=reset)) 
    892903         
    893904        self.current_plottable = new_plot 
     
    918929        # Write the output to file 
    919930        # First, check that the data is of the right type 
    920         if issubclass(self.current_plottable.__class__, DataLoader.data_info.Data1D): 
     931        if issubclass(self.current_plottable.__class__, 
     932                       DataLoader.data_info.Data1D): 
    921933            self.state_reader.write(filepath, self.current_plottable, prstate) 
    922934        else: 
    923             raise RuntimeError, "pr.save_data: the data being saved is not a DataLoader.data_info.Data1D object"  
     935            msg = "pr.save_data: the data being saved is not a" 
     936            msg += " DataLoader.data_info.Data1D object"  
     937            raise RuntimeError, msg 
    924938         
    925939         
     
    945959            wx.PostEvent(self.parent, StatusEvent(status=sys.exc_value)) 
    946960 
    947     def estimate_plot_inversion(self, alpha, nfunc, d_max, q_min=None, q_max=None,  
     961    def estimate_plot_inversion(self, alpha, nfunc, d_max,  
     962                                q_min=None, q_max=None,  
    948963                                bck=False, height=0, width=0): 
    949964        """ 
     
    10161031                    min_err = 0.01*pr.y[i] 
    10171032                err[i] = scale*math.sqrt( math.fabs(pr.y[i]) ) + min_err 
    1018             message = "The loaded file had no error bars, statistical errors are assumed." 
     1033            message = "The loaded file had no error bars, " 
     1034            message += "statistical errors are assumed." 
    10191035            wx.PostEvent(self.parent, StatusEvent(status=message)) 
    10201036 
     
    10241040 
    10251041           
    1026     def setup_file_inversion(self, alpha, nfunc, d_max, path, q_min=None, q_max=None,  
     1042    def setup_file_inversion(self, alpha, nfunc, d_max, data, 
     1043                             path=None, q_min=None, q_max=None,  
    10271044                             bck=False, height=0, width=0): 
    10281045        """ 
     
    10381055         
    10391056        try: 
    1040             pr = self._create_file_pr(path) 
     1057            #pr = self._create_file_pr(path) 
     1058            pr = self._create_file_pr(data) 
    10411059            if not pr==None: 
    10421060                self.pr = pr 
     
    10451063            wx.PostEvent(self.parent, StatusEvent(status=sys.exc_value)) 
    10461064           
    1047     def estimate_file_inversion(self, alpha, nfunc, d_max, path, q_min=None, q_max=None,  
     1065    def estimate_file_inversion(self, alpha, nfunc, d_max, data, 
     1066                                path=None, q_min=None, q_max=None,  
    10481067                                bck=False, height=0, width=0): 
    10491068        """ 
     
    10591078         
    10601079        try: 
    1061             pr = self._create_file_pr(path) 
    1062             if not pr==None: 
     1080            pr = self._create_file_pr(data) 
     1081            #pr = self._create_file_pr(path) 
     1082            if not pr is None: 
    10631083                self.pr = pr 
    10641084                self.perform_estimate() 
     
    10671087                 
    10681088           
    1069     def _create_file_pr(self, path): 
     1089    def _create_file_pr(self, data): 
    10701090        """ 
    10711091        Create and prepare invertor instance from 
     
    10761096        """ 
    10771097        # Load data 
    1078         if os.path.isfile(path): 
    1079              
    1080             if self._current_file_data is not None \ 
    1081                 and self._current_file_data.path==path: 
    1082                 # Protect against corrupted data from  
    1083                 # previous failed load attempt 
    1084                 if self._current_file_data.x is None: 
    1085                     return None 
    1086                 x = self._current_file_data.x 
    1087                 y = self._current_file_data.y 
    1088                 err = self._current_file_data.err 
    1089                  
    1090                 message = "The data from this file has already been loaded." 
    1091                 wx.PostEvent(self.parent, StatusEvent(status=message)) 
    1092             else: 
    1093                 # Reset the status bar so that we don't get mixed up 
    1094                 # with old messages.  
    1095                 #TODO: refactor this into a proper status handling 
    1096                 wx.PostEvent(self.parent, StatusEvent(status='')) 
    1097                 try: 
    1098                     x, y, err = self.load(path) 
    1099                 except: 
    1100                     load_error(sys.exc_value) 
    1101                     return None 
    1102                  
    1103                 # If the file contains no data, just return 
    1104                 if x is None or len(x)==0: 
    1105                     load_error("The loaded file contains no data") 
    1106                     return None 
    1107              
    1108             # If we have not errors, add statistical errors 
    1109             if err==None and y is not None: 
    1110                 err = numpy.zeros(len(y)) 
    1111                 scale = None 
    1112                 min_err = 0.0 
    1113                 for i in range(len(y)): 
    1114                     # Scale the error so that we can fit over several decades of Q 
    1115                     if scale==None: 
    1116                         scale = 0.05*math.sqrt(y[i]) 
    1117                         min_err = 0.01*y[i] 
    1118                     err[i] = scale*math.sqrt( math.fabs(y[i]) ) + min_err 
    1119                 message = "The loaded file had no error bars, statistical errors are assumed." 
    1120                 wx.PostEvent(self.parent, StatusEvent(status=message)) 
    1121              
    1122             try: 
    1123                 # Get the data from the chosen data set and perform inversion 
    1124                 pr = Invertor() 
    1125                 pr.d_max = self.max_length 
    1126                 pr.alpha = self.alpha 
    1127                 pr.q_min = self.q_min 
    1128                 pr.q_max = self.q_max 
    1129                 pr.x = x 
    1130                 pr.y = y 
    1131                 pr.err = err 
    1132                 pr.has_bck = self.has_bck 
    1133                 pr.slit_height = self.slit_height 
    1134                 pr.slit_width = self.slit_width 
    1135                 return pr 
    1136             except: 
    1137                 load_error(sys.exc_value) 
     1098        #if os.path.isfile(path): 
     1099        """     
     1100        if self._current_file_data is not None \ 
     1101            and self._current_file_data.path==path: 
     1102            # Protect against corrupted data from  
     1103            # previous failed load attempt 
     1104            if self._current_file_data.x is None: 
     1105                return None 
     1106            x = self._current_file_data.x 
     1107            y = self._current_file_data.y 
     1108            err = self._current_file_data.err 
     1109             
     1110            message = "The data from this file has already been loaded." 
     1111            wx.PostEvent(self.parent, StatusEvent(status=message)) 
     1112        else: 
     1113        """ 
     1114        # Reset the status bar so that we don't get mixed up 
     1115        # with old messages.  
     1116        #TODO: refactor this into a proper status handling 
     1117        wx.PostEvent(self.parent, StatusEvent(status='')) 
     1118        try: 
     1119            class FileData: 
     1120                x = None 
     1121                y = None 
     1122                err = None 
     1123                path = None 
     1124                def __init__(self, path): 
     1125                    self.path = path 
     1126                 
     1127            self._current_file_data = FileData(data.path) 
     1128            self._current_file_data.x = data.x 
     1129            self._current_file_data.y = data.y 
     1130            self._current_file_data.err = data.dy 
     1131            x, y, err = data.x, data.y, data.dy 
     1132        except: 
     1133            load_error(sys.exc_value) 
     1134            return None 
     1135         
     1136        # If the file contains no data, just return 
     1137        if x is None or len(x) == 0: 
     1138            load_error("The loaded file contains no data") 
     1139            return None 
     1140         
     1141        # If we have not errors, add statistical errors 
     1142        if err is not None and y is not None: 
     1143            err = numpy.zeros(len(y)) 
     1144            scale = None 
     1145            min_err = 0.0 
     1146            for i in range(len(y)): 
     1147                # Scale the error so that we can fit over several decades of Q 
     1148                if scale == None: 
     1149                    scale = 0.05 * math.sqrt(y[i]) 
     1150                    min_err = 0.01 * y[i] 
     1151                err[i] = scale * math.sqrt(math.fabs(y[i])) + min_err 
     1152            message = "The loaded file had no error bars, " 
     1153            message += "statistical errors are assumed." 
     1154            wx.PostEvent(self.parent, StatusEvent(status=message)) 
     1155         
     1156        try: 
     1157            # Get the data from the chosen data set and perform inversion 
     1158            pr = Invertor() 
     1159            pr.d_max = self.max_length 
     1160            pr.alpha = self.alpha 
     1161            pr.q_min = self.q_min 
     1162            pr.q_max = self.q_max 
     1163            pr.x = x 
     1164            pr.y = y 
     1165            pr.err = err 
     1166            pr.has_bck = self.has_bck 
     1167            pr.slit_height = self.slit_height 
     1168            pr.slit_width = self.slit_width 
     1169            return pr 
     1170        except: 
     1171            load_error(sys.exc_value) 
    11381172        return None 
    11391173         
     
    11451179         
    11461180        # If a thread is already started, stop it 
    1147         if self.estimation_thread != None and self.estimation_thread.isrunning(): 
     1181        if self.estimation_thread != None and \ 
     1182            self.estimation_thread.isrunning(): 
    11481183            self.estimation_thread.stop() 
    11491184                 
    11501185        pr = self.pr.clone() 
    1151         self.estimation_thread = EstimatePr(pr, self.nfunc, error_func=self._thread_error,  
    1152                                             completefn = self._estimate_completed,  
     1186        self.estimation_thread = EstimatePr(pr, self.nfunc, 
     1187                                             error_func=self._thread_error,  
     1188                                         completefn = self._estimate_completed,  
    11531189                                            updatefn   = None) 
    11541190        self.estimation_thread.queue() 
     
    11701206        pr.slit_height = 0.0 
    11711207        pr.slit_width  = 0.0 
    1172         self.estimation_thread = EstimateNT(pr, self.nfunc, error_func=self._thread_error,  
    1173                                             completefn = self._estimateNT_completed,  
     1208        self.estimation_thread = EstimateNT(pr, self.nfunc,  
     1209                                            error_func=self._thread_error,  
     1210                                        completefn = self._estimateNT_completed,  
    11741211                                            updatefn   = None) 
    11751212        self.estimation_thread.queue() 
     
    11951232        for i in range(len(out)): 
    11961233            try: 
    1197                 print "%d: %g +- %g" % (i, out[i], math.sqrt(math.fabs(cov[i][i]))) 
     1234                print "%d: %g +- %g" % (i, out[i], 
     1235                                         math.sqrt(math.fabs(cov[i][i]))) 
    11981236            except:  
    11991237                print "%d: %g +- ?" % (i, out[i])         
     
    12051243        new_plot.yaxis("\\rm{Intensity} ","cm^{-1}") 
    12061244        wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title="Iq")) 
    1207                  
    12081245        # Show I(q) fit 
    12091246        self.show_iq(out, self.pr) 
    1210          
    12111247        # Show P(r) fit 
    12121248        x_values, x_range = self.show_pr(out, self.pr, cov=cov) 
    12131249         
    1214          
    1215            
    12161250    def _on_context_inversion(self, event): 
     1251        """ 
     1252        """ 
    12171253        panel = event.GetEventObject() 
    12181254 
    12191255        # If we have more than one displayed plot, make the user choose 
    1220         if len(panel.plots)>1 and panel.graph.selected_plottable in panel.plots: 
     1256        if len(panel.plots) > 1 and \ 
     1257            panel.graph.selected_plottable in panel.plots: 
    12211258            dataset = panel.graph.selected_plottable 
    1222         elif len(panel.plots)==1: 
     1259        elif len(panel.plots) == 1: 
    12231260            dataset = panel.plots.keys()[0] 
    12241261        else: 
    1225             print "Error: No data is available" 
     1262            logging.info("Prview Error: No data is available") 
    12261263            return 
    12271264         
     
    12331270        except: 
    12341271            self.control_panel.alpha = self.alpha 
    1235             print "No estimate yet" 
     1272            logging.info("Prview :Alpha Not estimate yet") 
    12361273            pass 
    12371274        try: 
     
    12401277        except: 
    12411278            self.control_panel.nfunc = self.nfunc 
    1242             print "No estimate yet" 
     1279            logging.info("Prview : ntemrs Not estimate yet") 
    12431280            pass 
    12441281         
     
    12641301        self.control_panel.d_max = self.max_length 
    12651302        self.control_panel.alpha = self.alpha 
    1266          
    12671303        self.perspective = [] 
    12681304        self.perspective.append(self.control_panel.window_name) 
    1269          
    1270         self.parent.Bind(EVT_PR_FILE, self._on_new_file) 
    1271          
     1305      
    12721306        return [self.control_panel] 
    12731307     
    1274     def _on_new_file(self, evt): 
    1275         """ 
    1276             Called when the application manager posted an 
    1277             EVT_PR_FILE event. Just prompt the control 
    1278             panel to load a new data file. 
    1279         """ 
    1280         self.control_panel._change_file(None) 
    1281  
     1308    def set_data(self, data_list): 
     1309        """ 
     1310        receive a list of data to compute pr 
     1311        """ 
     1312        if len(data_list) > 1: 
     1313            msg = "Pr panel does not allow more than one value" 
     1314            msg += " at this time" 
     1315            raise ValueError, msg 
     1316        elif len(data_list) == 1: 
     1317            if issubclass(data_list[0].__class__, LoaderData1D): 
     1318                self.control_panel._change_file(evt=None, data=data_list[0]) 
     1319            else: 
     1320                msg = "Pr cannot be computed for" 
     1321                msg += " data of type %s" % (data_list[0].__class__.__name__) 
     1322                raise ValueError, msg 
     1323             
    12821324    def post_init(self): 
    12831325        """ 
  • prview/perspectives/pr/pr_thread.py

    r7116b6e0 r75df58b  
    1 import sys, time 
     1 
     2################################################################################ 
     3#This software was developed by the University of Tennessee as part of the 
     4#Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 
     5#project funded by the US National Science Foundation.  
     6# 
     7#See the license text in license.txt 
     8# 
     9#copyright 2009, University of Tennessee 
     10################################################################################ 
     11 
     12import sys 
     13import time 
    214from data_util.calcthread import CalcThread 
    315 
Note: See TracChangeset for help on using the changeset viewer.