Changeset 0bae207 in sasview for prview/perspectives


Ignore:
Timestamp:
Jul 28, 2008 8:14:16 AM (16 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:
ea5551f
Parents:
6aaf444
Message:

Fixed problem with loading additional data on a scaled graph.

Location:
prview/perspectives/pr
Files:
2 edited

Legend:

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

    r7a2feab r0bae207  
    411411        explanation  = "P(r) is found by fitting a set of base functions to I(Q). " 
    412412        explanation += "The minimization involves a regularization term to ensure " 
    413         explanation += "a smooth P(r). The alpha parameter gives the size of that "   
     413        explanation += "a smooth P(r). The regularization constant gives the size of that "   
    414414        explanation += "term. The suggested value is the value above which the " 
    415415        explanation += "output P(r) will have only one peak." 
     
    837837                if self.standalone==False: 
    838838                    self.file_radio.SetValue(True) 
     839                self.manager.show_data(path, reset=True) 
    839840                self._on_pars_changed(None) 
    840                 self.manager.show_data(path, reset=True) 
    841          
    842  
    843  
    844841 
    845842class HelpDialog(wx.Dialog): 
  • prview/perspectives/pr/pr.py

    r900c787 r0bae207  
    5252        ## Remember last plottable processed 
    5353        self.last_data  = "sphere_60_q0_2.txt" 
     54        self._current_file_data = None 
    5455        ## Time elapsed for last computation [sec] 
    5556        # Start with a good default 
     
    333334        return self.parent.choose_file() 
    334335                 
    335     def load(self, path = "sphere_60_q0_2.txt"): 
     336                 
     337    def load(self, path): 
     338        """ 
     339            Load data. This will eventually be replaced 
     340            by our standard DataLoader class. 
     341        """ 
     342         
     343        class FileData: 
     344            x = None 
     345            y = None 
     346            err = None 
     347            path = None 
     348             
     349            def __init__(self, path): 
     350                self.path = path 
     351                 
     352        self._current_file_data = FileData(path) 
     353        print "load", path 
     354        basename = os.path.basename(path) 
     355        root, ext = os.path.splitext(basename) 
     356        if ext.lower()=='.abs': 
     357            x, y, err = self.load_abs(path) 
     358         
     359        else:  
     360            x, y, err = self.load_columns(path) 
     361             
     362        self._current_file_data.x = x 
     363        self._current_file_data.y = y 
     364        self._current_file_data.err = err 
     365        return x, y, err 
     366                 
     367    def load_columns(self, path = "sphere_60_q0_2.txt"): 
     368        """ 
     369            Load 2- or 3- column ascii 
     370        """ 
    336371        import numpy, math, sys 
    337372        # Read the data from the data file 
     
    374409        return data_x, data_y, data_err      
    375410         
     411    def load_abs(self, path): 
     412        """ 
     413            Load an IGOR .ABS reduced file 
     414            @param path: file path 
     415            @return: x, y, err vectors 
     416        """ 
     417        import numpy, math, sys 
     418        # Read the data from the data file 
     419        data_x   = numpy.zeros(0) 
     420        data_y   = numpy.zeros(0) 
     421        data_err = numpy.zeros(0) 
     422        scale    = None 
     423        min_err  = 0.0 
     424         
     425        data_started = False 
     426        if not path == None: 
     427            input_f = open(path,'r') 
     428            buff    = input_f.read() 
     429            lines   = buff.split('\n') 
     430            for line in lines: 
     431                if data_started==True: 
     432                    try: 
     433                        toks = line.split() 
     434                        x = float(toks[0]) 
     435                        y = float(toks[1]) 
     436                        if len(toks)>2: 
     437                            err = float(toks[2]) 
     438                        else: 
     439                            if scale==None: 
     440                                scale = 0.05*math.sqrt(y) 
     441                                #scale = 0.05/math.sqrt(y) 
     442                                min_err = 0.01*y 
     443                            err = scale*math.sqrt(y)+min_err 
     444                            #err = 0 
     445                             
     446                        data_x = numpy.append(data_x, x) 
     447                        data_y = numpy.append(data_y, y) 
     448                        data_err = numpy.append(data_err, err) 
     449                    except: 
     450                        pass 
     451                elif line.find("The 6 columns")>=0: 
     452                    data_started = True       
     453                    
     454        if not scale==None: 
     455            message = "The loaded file had no error bars, statistical errors are assumed." 
     456            wx.PostEvent(self.parent, StatusEvent(status=message)) 
     457        else: 
     458            wx.PostEvent(self.parent, StatusEvent(status='')) 
     459                         
     460        return data_x, data_y, data_err      
     461         
     462         
     463         
    376464    def pr_theory(self, r, R): 
    377465        """ 
     
    556644        self.control_panel.bck = pr.background 
    557645         
    558         for i in range(len(out)): 
    559             try: 
    560                 print "%d: %g +- %g" % (i, out[i], math.sqrt(math.fabs(cov[i][i]))) 
    561             except:  
    562                 print sys.exc_value 
    563                 print "%d: %g +- ?" % (i, out[i])         
    564          
    565         # Make a plot of I(q) data 
    566646        if False: 
     647            for i in range(len(out)): 
     648                try: 
     649                    print "%d: %g +- %g" % (i, out[i], math.sqrt(math.fabs(cov[i][i]))) 
     650                except:  
     651                    print sys.exc_value 
     652                    print "%d: %g +- ?" % (i, out[i])         
     653         
     654            # Make a plot of I(q) data 
    567655            new_plot = Data1D(self.pr.x, self.pr.y, dy=self.pr.err) 
    568656            new_plot.name = "I_{obs}(q)" 
     
    589677         
    590678         
    591         if not path==None: 
    592             self._create_file_pr(path)   
     679        if path is not None: 
     680            pr = self._create_file_pr(path) 
     681            self.pr = pr   
    593682               
    594683        # Make a plot of I(q) data 
     
    727816        from sans.guiframe.data_loader import load_ascii_1D 
    728817        import numpy 
     818         
    729819        # Load data 
    730820        if os.path.isfile(path): 
    731821             
    732             x, y, err = self.load(path) 
     822            if self._current_file_data is not None \ 
     823                and self._current_file_data.path==path: 
     824                x = self._current_file_data.x 
     825                y = self._current_file_data.y 
     826                err = self._current_file_data.err 
     827            else: 
     828                x, y, err = self.load(path) 
    733829            #x, y, err = load_ascii_1D(path) 
    734830             
     
    756852            pr.slit_width = self.slit_width 
    757853            return pr 
    758             #self.pr = pr 
    759             #return True 
    760         #return False 
    761854        return None 
    762855         
Note: See TracChangeset for help on using the changeset viewer.