Changeset 4b73c3e in sasview


Ignore:
Timestamp:
Apr 12, 2012 3:03:43 PM (12 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:
14cd6b92
Parents:
5a0dac1f
Message:

Fixing code style problems and bugs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • inversionview/src/sans/perspectives/pr/pr.py

    r6813da7d r4b73c3e  
    1919import logging 
    2020import time 
    21 import copy 
    2221import math 
    2322import numpy 
     
    4746class Plugin(PluginBase): 
    4847    """ 
     48        P(r) inversion perspective 
    4949    """ 
    5050    DEFAULT_ALPHA = 0.0001 
     
    119119        delete the data association with prview 
    120120        """ 
    121         if self.calc_thread is not None and self.calc_thread.isrunning(): 
    122             msg = "Data in use in Prview\n" 
    123         if self.estimation_thread is not None and \ 
    124             self.estimation_thread.isrunning(): 
    125              msg = "Data in use in Prview\n" 
    126121        self.control_panel.clear_panel() 
    127122        
    128123    def get_data(self): 
    129124        """ 
     125            Returns the current data 
    130126        """ 
    131127        return self.current_plottable 
     
    149145                data = datainfo 
    150146            if data is None: 
    151                 raise RuntimeError, "Pr.set_state: datainfo parameter cannot be None in standalone mode" 
     147                msg =  "Pr.set_state: datainfo parameter cannot " 
     148                msg += "be None in standalone mode" 
     149                raise RuntimeError, msg 
    152150             
    153151            # Ensuring that plots are coordinated correctly 
     
    160158                max_char = len(data.meta_data['prstate'].file) 
    161159             
    162             datainfo.meta_data['prstate'].file = data.meta_data['prstate'].file[0:max_char] +' [' + time_str + ']' 
     160            datainfo.meta_data['prstate'].file =\ 
     161                data.meta_data['prstate'].file[0:max_char]\ 
     162                + ' [' + time_str + ']' 
     163             
    163164            data.filename = data.meta_data['prstate'].file 
    164165            # TODO: 
     
    166167            # such as ID , Group_ID, etc... 
    167168            #make self.current_plottable = datainfo directly 
    168             self.current_plottable = self.parent.create_gui_data(data,None) 
     169            self.current_plottable = self.parent.create_gui_data(data, None) 
    169170            self.current_plottable.group_id = data.meta_data['prstate'].file 
    170171             
     
    200201        """ 
    201202        """ 
    202         from sans.pr.invertor import Invertor 
    203203        # Generate P(r) for sphere 
    204204        radius = 60.0 
     
    289289        """   
    290290        qtemp = pr.x 
    291         if not q==None: 
     291        if not q == None: 
    292292            qtemp = q 
    293293 
     
    301301         
    302302        # Check for user min/max 
    303         if not pr.q_min==None: 
     303        if not pr.q_min == None: 
    304304            minq = pr.q_min 
    305         if not pr.q_max==None: 
     305        if not pr.q_max == None: 
    306306            maxq = pr.q_max 
    307307                 
     
    335335         
    336336        # If we have used slit smearing, plot the smeared I(q) too 
    337         if pr.slit_width>0 or pr.slit_height>0: 
     337        if pr.slit_width > 0 or pr.slit_height > 0: 
    338338            x = pylab.arange(minq, maxq, maxq/301.0) 
    339339            y = numpy.zeros(len(x)) 
     
    480480        Load 2- or 3- column ascii 
    481481        """ 
    482         import numpy, math, sys 
    483482        # Read the data from the data file 
    484483        data_x   = numpy.zeros(0) 
     
    529528         
    530529        """ 
    531         import numpy, math, sys 
    532530        # Read the data from the data file 
    533531        data_x   = numpy.zeros(0) 
     
    543541            lines   = buff.split('\n') 
    544542            for line in lines: 
    545                 if data_started==True: 
     543                if data_started == True: 
    546544                    try: 
    547545                        toks = line.split() 
     
    551549                            err = float(toks[2]) 
    552550                        else: 
    553                             if scale==None: 
     551                            if scale == None: 
    554552                                scale = 0.05*math.sqrt(y) 
    555553                                #scale = 0.05/math.sqrt(y) 
     
    566564                    data_started = True       
    567565                    
    568         if not scale==None: 
     566        if not scale == None: 
    569567            message = "The loaded file had no error bars, statistical errors are assumed." 
    570568            wx.PostEvent(self.parent, StatusEvent(status=message)) 
     
    576574    def pr_theory(self, r, R): 
    577575        """   
    578         """ 
    579         if r<=2*R: 
     576            Return P(r) of a sphere for a given R  
     577            For test purposes 
     578        """ 
     579        if r <= 2*R: 
    580580            return 12.0* ((0.5*r/R)**2) * ((1.0-0.5*r/R)**2) * ( 2.0 + 0.5*r/R ) 
    581581        else: 
     
    623623            return [] 
    624624        elif item.id == graph.selected_plottable: 
    625                if not self.standalone and issubclass(item.__class__, Data1D): 
     625           if not self.standalone and issubclass(item.__class__, Data1D): 
    626626                return [["Compute P(r)",  
    627627                             "Compute P(r) from distribution",  
     
    714714                         NewPlotEvent(plot=new_plot, update=True, 
    715715                                title=self._added_plots[plot].name))         
    716          
    717          
    718     def _on_add_data(self, evt): 
    719         """ 
    720         Add a data curve to the plot 
    721          
    722         :WARNING: this will be removed once guiframe.plotting has 
    723              its full functionality 
    724         """ 
    725         path = self.choose_file() 
    726         if path==None: 
    727             return 
    728          
    729         #x, y, err = self.parent.load_ascii_1D(path) 
    730         # Use data loader to load file 
    731         try: 
    732             dataread = Loader().load(path) 
    733             x = None 
    734             y = None 
    735             err = None 
    736             if dataread.__class__.__name__ == 'Data1D': 
    737                 x = dataread.x 
    738                 y = dataread.y 
    739                 err = dataread.dy 
    740             else: 
    741                 if isinstance(dataread, list) and len(dataread)>0: 
    742                     x = dataread[0].x 
    743                     y = dataread[0].y 
    744                     err = dataread[0].dy 
    745                     msg = "PrView only allows a single data set at a time. " 
    746                     msg += "Only the first data set was loaded."  
    747                     wx.PostEvent(self.parent, StatusEvent(status=msg)) 
    748                 else: 
    749                     msg = "This tool can only read 1D data" 
    750                     wx.PostEvent(self.parent, StatusEvent(status=msg)) 
    751                     return 
    752              
    753         except: 
    754             wx.PostEvent(self.parent, StatusEvent(status=sys.exc_value)) 
    755             return 
    756          
    757         filename = os.path.basename(path) 
    758         new_plot = Data1D(x, y) 
    759         new_plot.symbol = GUIFRAME_ID.CURVE_SYMBOL_NUM 
    760         new_plot.name = filename 
    761         new_plot.xaxis("\\rm{r}", 'A') 
    762         new_plot.yaxis("\\rm{P(r)} ","cm^{-3}") 
    763         # Store a ref to the plottable for later use 
    764         self._added_plots[filename] = new_plot 
    765         self._default_Iq[filename]  = numpy.copy(y) 
    766         wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title=filename)) 
    767          
     716                 
    768717    def start_thread(self): 
    769718        """ 
    770719        """ 
    771720        from pr_thread import CalcPr 
    772         from copy import deepcopy 
    773721         
    774722        # If a thread is already started, stop it 
     
    846794         
    847795        """ 
    848         from copy import deepcopy 
    849796        # Save useful info 
    850797        self.elapsed = elapsed 
     
    867814        self.control_panel.elapsed = elapsed 
    868815        self.control_panel.oscillation = pr.oscillations(out) 
    869         #print "OSCILL", pr.oscillations(out) 
    870         #print "PEAKS:", pr.get_peaks(out)  
    871816        self.control_panel.positive = pr.get_positive(out) 
    872817        self.control_panel.pos_err  = pr.get_pos_err(out, cov) 
     
    874819        self.control_panel.iq0 = pr.iq0(out) 
    875820        self.control_panel.bck = pr.background 
    876          
    877         if False: 
    878             for i in range(len(out)): 
    879                 try: 
    880                     print "%d: %g +- %g" % (i, out[i], 
    881                                              math.sqrt(math.fabs(cov[i][i]))) 
    882                 except:  
    883                     print sys.exc_value 
    884                     print "%d: %g +- ?" % (i, out[i])         
    885          
    886             # Make a plot of I(q) data 
    887             new_plot = Data1D(self.pr.x, self.pr.y, dy=self.pr.err) 
    888             new_plot.name = IQ_DATA_LABEL 
    889             new_plot.xaxis("\\rm{Q}", 'A^{-1}') 
    890             new_plot.yaxis("\\rm{Intensity} ","cm^{-1}") 
    891             if pr.info.has_key("plot_group_id"): 
    892                 new_plot.group_id = pr.info["plot_group_id"] 
    893             new_plot.id = self.data_id 
    894             self.parent.update_theory(data_id=self.data_id, 
    895                                        theory=new_plot) 
    896             wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title="Iq")) 
    897                  
     821                         
    898822        # Show I(q) fit 
    899823        self.show_iq(out, self.pr) 
     
    901825        # Show P(r) fit 
    902826        x_values, x_range = self.show_pr(out, self.pr, cov)   
    903          
    904         # Popup result panel 
    905         #result_panel = InversionResults(self.parent,  
    906         #-1, style=wx.RAISED_BORDER) 
    907          
     827                 
    908828    def show_data(self, path=None, data=None, reset=False): 
    909829        """ 
     
    13991319                    self.control_panel._change_file(evt=None, data=data) 
    14001320                except: 
    1401                      msg = "Prview Set_data: " + str(sys.exc_value) 
    1402                      wx.PostEvent(self.parent, StatusEvent(status=msg, 
     1321                    msg = "Prview Set_data: " + str(sys.exc_value) 
     1322                    wx.PostEvent(self.parent, StatusEvent(status=msg, 
    14031323                                                            info="error")) 
    14041324            else:     
Note: See TracChangeset for help on using the changeset viewer.