Changeset b43a009 in sasview


Ignore:
Timestamp:
May 5, 2008 2:44:40 PM (16 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:
edce46e
Parents:
2d06beb
Message:

some modificatiosn made

Location:
guitools
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • guitools/PlotPanel.py

    r150c04a rb43a009  
    116116        self.symbollist = ['o','x','^','v','<','>','+','s','d','D','h','H','p'] 
    117117        #User scale 
    118         self.xscales ="x" 
    119         self.yscales ="log10(y)" 
     118        self.xLabel ="x" 
     119        self.yLabel ="log10(y)" 
    120120        self.viewModel ="--" 
    121121        # keep track if the previous transformation of x and y in Property dialog 
     
    128128        #self.fit_result = Data1D(x=[], y=[],dx=None, dy=None) 
    129129        self.fit_result.name = "Fit" 
     130        # For fit Dialog initial display 
    130131        self.xmin=0.0 
    131132        self.xmax=0.0 
    132133        self.xminView=0.0 
    133134        self.xmaxView=0.0 
     135        self.Avalue=None 
     136        self.Bvalue=None 
     137        self.ErrAvalue=None 
     138        self.ErrBvalue=None 
     139        self.Chivalue=None 
     140    def resetFitView(self): 
     141        # For fit Dialog initial display 
     142        self.xmin=0.0 
     143        self.xmax=0.0 
     144        self.xminView=0.0 
     145        self.xmaxView=0.0 
     146        self.Avalue=None 
     147        self.Bvalue=None 
     148        self.ErrAvalue=None 
     149        self.ErrBvalue=None 
     150        self.Chivalue=None 
    134151    def onWheel(self, event): 
    135152        """ 
     
    175192 
    176193    def returnTrans(self): 
    177         return self.xscales,self.yscales 
     194        return self.xLabel,self.yLabel, self.Avalue, self.Bvalue,\ 
     195        self.ErrAvalue,self.ErrBvalue,self.Chivalue 
    178196     
    179197    def setTrans(self,xtrans,ytrans):  
     
    196214            first_item = list.keys()[0] 
    197215            dlg = LinearFit( None, first_item, self.onFitDisplay,self.returnTrans, -1, 'Fitting') 
     216            
    198217            if (self.xmin !=0.0 )and ( self.xmax !=0.0)\ 
    199218                and(self.xminView !=0.0 )and ( self.xmaxView !=0.0): 
     
    215234                dial.setValues( self.prevXtrans, self.prevYtrans,self.viewModel ) 
    216235                if dial.ShowModal() == wx.ID_OK: 
    217                     self.xscales, self.yscales,self.viewModel = dial.getValues() 
     236                    self.xLabel, self.yLabel,self.viewModel = dial.getValues() 
    218237                    if self.viewModel =="Guinier lny vs x^(2)": 
    219                         self.xscales="x^(2)" 
    220                         self.yscales="ln(y)" 
     238                        self.xLabel="x^(2)" 
     239                        self.yLabel="ln(y)" 
    221240                        self.viewModel = "--" 
    222                         dial.setValues( self.xscales, self.yscales,self.viewModel ) 
     241                        dial.setValues( self.xLabel, self.yLabel,self.viewModel ) 
    223242                    self._onEVT_FUNC_PROPERTY() 
    224243                dial.Destroy() 
     
    456475         
    457476        for item in list: 
    458             item.getTransform(self.xscales,self.yscales) 
    459             if ( self.xscales=="x" ): 
    460                 item.returnTransformationx(transform.toX,transform.errToX) 
     477            item.setLabel(self.xLabel,self.yLabel) 
     478            if ( self.xLabel=="x" ): 
     479                item.transformX(transform.toX,transform.errToX) 
    461480                self.set_xscale("linear") 
    462481                name, units = item.get_xaxis() 
    463482                self.graph.xaxis("%s" % name,  "%s^{-1}" % units) 
    464483                 
    465             if ( self.xscales=="x^(2)" ): 
    466                 item.returnTransformationx(transform.toX2,transform.errToX2) 
     484            if ( self.xLabel=="x^(2)" ): 
     485                item.transformX(transform.toX2,transform.errToX2) 
    467486                self.set_xscale('linear') 
    468487                name, units = item.get_xaxis() 
    469488                self.graph.xaxis("%s^{2}" % name,  "%s^{-2}" % units) 
    470489                 
    471             if (self.xscales=="log10(x)" ): 
    472                 item.returnTransformationx(transform.toX,transform.errToX) 
     490            if (self.xLabel=="log10(x)" ): 
     491                item.transformX(transform.toX,transform.errToX) 
    473492                self.set_xscale("log") 
    474493                name, units = item.get_xaxis()  
    475494                self.graph.xaxis("\log_{10}\ \  %s" % name,  "%s^{-1}" % units) 
    476495                 
    477             if ( self.yscales=="ln(y)" ): 
    478                 item.returnTransformationy(transform.toLogX,transform.errToLogX) 
     496            if ( self.yLabel=="ln(y)" ): 
     497                item.transformY(transform.toLogX,transform.errToLogX) 
    479498                self.set_yscale("linear") 
    480499                name, units = item.get_yaxis() 
    481500                self.graph.yaxis("log\ \ %s" % name,  "%s^{-1}" % units) 
    482501                 
    483             if ( self.yscales=="y" ): 
    484                 item.returnTransformationy(transform.toX,transform.errToX) 
     502            if ( self.yLabel=="y" ): 
     503                item.transformY(transform.toX,transform.errToX) 
    485504                self.set_yscale("linear") 
    486505                name, units = item.get_yaxis() 
    487506                self.graph.yaxis("%s" % name,  "%s^{-1}" % units) 
    488507                 
    489             if ( self.yscales=="log10(y)" ):  
    490                 item.returnTransformationy(transform.toX,transform.errToX) 
     508            if ( self.yLabel=="log10(y)" ):  
     509                item.transformY(transform.toX,transform.errToX) 
    491510                self.set_yscale("log")   
    492511                name, units = item.get_yaxis() 
    493512                self.graph.yaxis("\log_{10}\ \ %s" % name,  "%s^{-1}" % units) 
    494513                 
    495             if ( self.yscales=="y^(2)" ): 
    496                 item.returnTransformationy( transform.toX2,transform.errToX2 )     
     514            if ( self.yLabel=="y^(2)" ): 
     515                item.transformY( transform.toX2,transform.errToX2 )     
    497516                self.set_yscale("linear") 
    498517                name, units = item.get_yaxis() 
    499518                self.graph.yaxis("%s^{2}" % name,  "%s^{-2}" % units) 
    500519                 
    501             if ( self.yscales =="1/y"): 
    502                 item.returnTransformationy(transform.toOneOverX,transform.errOneOverX ) 
     520            if ( self.yLabel =="1/y"): 
     521                item.transformY(transform.toOneOverX,transform.errOneOverX ) 
    503522                self.set_yscale("linear") 
    504523                name, units = item.get_yaxis() 
    505524                self.graph.yaxis("%s" % name,  "\ \%s" % units) 
    506525                 
    507             if ( self.yscales =="1/sqrt(y)" ): 
    508                 item.returnTransformationy(transform.toOneOverSqrtX,transform.errOneOverSqrtX ) 
     526            if ( self.yLabel =="1/sqrt(y)" ): 
     527                item.transformY(transform.toOneOverSqrtX,transform.errOneOverSqrtX ) 
    509528                self.set_yscale("linear") 
    510529                name, units = item.get_yaxis() 
    511530                self.graph.yaxis("\sqrt{%s}" %name,  "%s" % units) 
    512531                 
    513             if ( self.yscales =="ln(y*x)"): 
    514                 item.returnTransformationy( transform.toLogXY,transform.errToLogXY) 
     532            if ( self.yLabel =="ln(y*x)"): 
     533                item.transformY( transform.toLogXY,transform.errToLogXY) 
    515534                self.set_yscale("linear") 
    516535                yname, yunits = item.get_yaxis() 
     
    518537                self.graph.yaxis("log\ %s %s" % (yname,xname),  "%s^{-1}%s^{-1}" % (yunits,xunits)) 
    519538                 
    520             if ( self.yscales =="ln(y*x^(2))"): 
    521                 item.returnTransformationy( transform.toLogYX2,transform.errToLogYX2) 
     539            if ( self.yLabel =="ln(y*x^(2))"): 
     540                item.transformY( transform.toLogYX2,transform.errToLogYX2) 
    522541                self.set_yscale("linear") 
    523542                yname, yunits = item.get_yaxis() 
     
    525544                self.graph.yaxis("Log %s%s^{2}" % (yname,xname),  "%s^{-1}%s^{-2}" % (yunits,xunits)) 
    526545             
    527             if ( self.yscales =="ln(y*x^(4))"): 
    528                 item.returnTransformationy(transform.toLogYX4,transform.errToLogYX4) 
     546            if ( self.yLabel =="ln(y*x^(4))"): 
     547                item.transformY(transform.toLogYX4,transform.errToLogYX4) 
    529548                self.set_yscale("linear") 
    530549                yname, yunits = item.get_yaxis() 
     
    533552             
    534553            if ( self.viewModel == "Guinier lny vs x^(2)"): 
    535                 item.returnTransformationx(transform.toX2,transform.errToX2) 
     554                 
     555                item.transformX(transform.toX2,transform.errToX2) 
    536556                self.set_xscale('linear') 
    537557                name, units = item.get_xaxis() 
    538558                self.graph.xaxis("%s^{2}" % name,  "%s^{-2}" % units) 
    539                 item.returnTransformationy(transform.toLogX,transform.errToLogX ) 
     559                 
     560                item.transformY(transform.toLogX,transform.errToLogX ) 
    540561                self.set_yscale("linear") 
    541562                name, units = item.get_yaxis() 
    542563                self.graph.yaxis("$Log %s$" % name,  "%s^{-1}" % units) 
     564                 
    543565            item.transformView() 
    544         #item.name = self.yscales+" vs " +self.xscales   
     566             
     567        #item.name = self.yLabel+" vs " +self.xLabel   
    545568        self.xmin=0.0 
    546569        self.xmax=0.0 
    547570        self.xminView=0.0 
    548571        self.xmaxView=0.0     
    549         self.prevXtrans = self.xscales  
    550         self.prevYtrans = self.yscales   
     572        self.prevXtrans = self.xLabel  
     573        self.prevYtrans = self.yLabel   
    551574        self.graph.render(self) 
    552575        self.subplot.figure.canvas.draw_idle() 
    553576         
    554     def onFitDisplay(self, tempx,tempy,xminView,xmaxView,xmin,xmax): 
     577    def onFitDisplay(self, tempx,tempy,xminView,xmaxView,xmin,xmax,func): 
    555578        """ 
    556579            Add a new plottable into the graph .In this case this plottable will be used  
     
    558581            @param plottable: the plottable to plot 
    559582        """ 
    560          
     583        self.Avalue,self.Bvalue,self.ErrAvalue,self.ErrBvalue,self.Chivalue=func 
    561584         
    562585        list =[] 
  • guitools/fitDialog.py

    r416223d rb43a009  
    1111 
    1212class LinearFit(wx.Dialog): 
    13     #def __init__(self, parent, id, title): 
    1413    def __init__(self, parent, plottable, push_data,transform, id, title): 
    1514        wx.Dialog.__init__(self, parent, id, title, size=(450, 400)) 
    1615        """ 
    17             for the fit window 
     16            Dialog window pops- up when select Linear fit on Context menu 
     17            Displays fitting parameters 
    1818        """ 
    1919        self.parent = parent 
     
    2222        self.push_data = push_data 
    2323        #dialog self plottable 
     24         
    2425        self.plottable = plottable 
    2526        # Receive transformations of x and y 
    26         self.xtrans,self.ytrans= self.transform() 
     27        self.xLabel,self.yLabel,self.Avalue,self.Bvalue,\ 
     28        self.ErrAvalue,self.ErrBvalue,self.Chivalue= self.transform() 
    2729        #Dialog interface 
    2830        panel = wx.Panel(self, -1, style=wx.SIMPLE_BORDER)    
     
    9193        ix += 2 
    9294        sizer.Add(self.PXmax, (iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
    93         iy += 1 
    94         ix = 1 
    95         sizer.Add(wx.StaticText(panel, -1,"x transofrmation is: "+self.xtrans ),(iy, ix),(1,1),\ 
    96                    wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    97         iy += 1 
    98         ix = 0 
    99         sizer.Add(wx.StaticText(panel, -1, 'Fit Range'),(iy, ix),(1,1),\ 
     95        
     96        iy += 1 
     97        ix = 0 
     98        sizer.Add(wx.StaticText(panel, -1, 'Fit Range of '+self.xLabel),(iy, ix),(1,1),\ 
    10099                   wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    101100        ix += 1 
     
    138137         
    139138        # Set default value of parameter in fit dialog 
    140         self.tcA.SetLabel(str(self.default_A)) 
    141         self.tcB.SetLabel(str(self.default_B)) 
    142         self.tcErrA.SetLabel(str(0.0)) 
    143         self.tcErrB.SetLabel(str(0.0)) 
    144         self.tcChi.SetLabel(str(0.0)) 
    145          
     139         
     140        if self.Avalue==None: 
     141            self.tcA.SetLabel(str(self.default_A)) 
     142        else : 
     143            self.tcA.SetLabel(str(self.Avalue)) 
     144        if self.Bvalue==None: 
     145            self.tcB.SetLabel(str(self.default_B)) 
     146        else: 
     147            self.tcB.SetLabel(str(self.Bvalue)) 
     148        if self.ErrAvalue==None: 
     149            self.tcErrA.SetLabel(str(0.0)) 
     150        else: 
     151            self.tcErrA.SetLabel(str(self.ErrAvalue)) 
     152        if self.ErrBvalue==None: 
     153            self.tcErrB.SetLabel(str(0.0)) 
     154        else: 
     155            self.tcErrB.SetLabel(str(self.ErrBvalue)) 
     156        if self.Chivalue==None: 
     157            self.tcChi.SetLabel(str(0.0)) 
     158        else: 
     159            self.tcChi.SetLabel(str(self.Chivalue)) 
    146160        if self.plottable.x !=[]: 
    147161            self.mini =min(self.plottable.x) 
     
    186200                xminView=self.floatTransform(xmin) 
    187201                xmaxView=self.floatTransform(xmax) 
    188                 if (self.xtrans=="log10(x)"): 
     202                if (self.xLabel=="log10(x)"): 
    189203                    self.FXmin.SetValue(str(math.log10(xminView))) 
    190204                    self.FXmax.SetValue(str(math.log10(xmaxView))) 
     
    195209                self.FXmax.Disable() 
    196210                # Store the transformed values of view x, y,dy in variables  before the fit 
    197                 if  self.ytrans.lower() == "log10(y)": 
    198                     if (self.xtrans.lower() == "log10(x)"): 
     211                if  self.yLabel.lower() == "log10(y)": 
     212                    if (self.xLabel.lower() == "log10(x)"): 
    199213                        for i in range(len(x)): 
    200214                            if x[i]>= math.log10(xmin): 
     
    209223                    tempdy = dy 
    210224                
    211                 if (self.xtrans.lower() == "log10(x)"): 
     225                if (self.xLabel.lower() == "log10(x)"): 
    212226                    for x_i in x: 
    213227                        if x_i >= math.log10(xmin): 
     
    215229                else: 
    216230                    tempx = x 
    217                         
    218                 #for y_i in y: 
    219                 #    dy = math.sqrt(math.fabs(y_i)) 
    220                 #    if dy >= y_i: 
    221                 #        dy = 0.9*y_i 
    222                 #    tempdy.append(dy) 
    223                         
     231               
    224232                #Find the fitting parameters 
    225233                 
    226                 if (self.xtrans.lower() == "log10(x)"): 
     234                if (self.xLabel.lower() == "log10(x)"): 
    227235                    chisqr, out, cov = fittings.sansfit(self.model, [self.cstA, self.cstB], 
    228236                    tempx, tempy,tempdy,math.log10(xmin),math.log10(xmax)) 
     
    230238                    chisqr, out, cov = fittings.sansfit(self.model,  
    231239                                [self.cstA, self.cstB],tempx, tempy,tempdy,xminView,xmaxView) 
    232                 print "this out",out 
     240                #print "this out",out 
    233241                #Check that cov and out are iterable before displaying them 
    234242                if cov ==None: 
     
    253261                # load tempy with the minimum transformation 
    254262                
    255                 if self.xtrans == "log10(x)": 
     263                if self.xLabel == "log10(x)": 
    256264                    y_model = self.model.run(math.log10(xmin)) 
    257265                    tempx.append(xmin) 
     
    260268                    tempx.append(xminView) 
    261269                     
    262                 if self.ytrans == "log10(y)": 
     270                if self.yLabel == "log10(y)": 
    263271                    tempy.append(math.pow(10,y_model)) 
    264272                    print "tempy",tempy 
     
    267275                     
    268276                # load tempy with the maximum transformation 
    269                 if self.xtrans == "log10(x)": 
     277                if self.xLabel == "log10(x)": 
    270278                    y_model = self.model.run(math.log10(xmax)) 
    271279                    tempx.append(xmax) 
     
    274282                    tempx.append(xmaxView) 
    275283                     
    276                 if self.ytrans == "log10(y)": 
     284                if self.yLabel == "log10(y)": 
    277285                    tempy.append(math.pow(10,y_model)) 
    278286                else:  
    279287                    tempy.append(y_model) 
    280                 
    281                 self.push_data(tempx,tempy,xminView,xmaxView,xmin,xmax) 
     288                self.Avalue=cstA 
     289                self.Bvalue=cstB 
     290                self.ErrAvalue=errA 
     291                self.ErrBvalue=errB 
     292                self.Chivalue=chisqr 
     293                self.push_data(tempx,tempy,xminView,xmaxView,xmin,xmax,self._ongetValues()) 
    282294                 
    283295                # Display the fitting value on the Fit Dialog 
    284296                self._onsetValues(cstA, cstB, errA,errB,chisqr) 
     297                
     298                
    285299             
    286300    def _onsetValues(self,cstA,cstB,errA,errB,Chi): 
     
    293307         self.tcErrB.SetValue(str(errB)) 
    294308         self.tcChi.SetValue(str(Chi)) 
     309         
     310    def _ongetValues(self): 
     311         """ 
     312              Display  the value on fit Dialog  
     313         """ 
     314         return self.Avalue, self.Bvalue,self.ErrAvalue,self.ErrBvalue,self.Chivalue 
    295315          
    296316    def _returnPlottable(self): 
     
    322342             not in x 
    323343        """ 
    324         if ( self.xtrans=="x" ): 
     344        if ( self.xLabel=="x" ): 
    325345            return transform.toX(x) 
    326346         
    327         if ( self.xtrans=="x^(2)" ):  
     347        if ( self.xLabel=="x^(2)" ):  
    328348            return transform.toX2(x) 
    329349         
    330         if (self.xtrans=="log10(x)" ): 
     350        if (self.xLabel=="log10(x)" ): 
    331351            if x >0: 
    332352                return x 
     
    341361        value = item.GetValue() 
    342362        # Check for possible values entered 
    343         if (self.xtrans=="log10(x)"): 
     363        if (self.xLabel=="log10(x)"): 
    344364            if (float(value) > 0): 
    345365                item.SetBackgroundColour(wx.WHITE) 
     
    353373        
    354374    def setFitRange(self,xmin,xmax,Reelxmin,Reelxmax): 
    355         if (self.xtrans=="log10(x)"): 
     375        if (self.xLabel=="log10(x)"): 
    356376            self.FXmin.SetValue(str(math.log10(xmin))) 
    357377            self.FXmax.SetValue(str(math.log10(xmax))) 
  • guitools/plottables.py

    r150c04a rb43a009  
    5353            if not cond: return False 
    5454        return True 
    55 def error_msg(msg, parent=None): 
    56     """ 
    57     Signal an error condition -- in a GUI, popup a error dialog 
    58     """ 
    59     # Code brought with minor podifications from mpl.backends.backend_wx 
    60     # Copyright (C) Jeremy O'Donoghue & John Hunter, 2003-4 
    61     dialog =wx.MessageDialog(parent  = parent, 
    62                              message = msg, 
    63                              caption = 'Polplot error', 
    64                              style=wx.OK | wx.CENTRE) 
    65     dialog.ShowModal() 
    66     dialog.Destroy() 
    67     return None 
     55 
    6856# Graph structure for holding multiple plottables 
    6957class Graph: 
     
    204192                     "title":""} 
    205193        self.plottables = {} 
    206     def setGraph(self,listofplottable): 
    207         self.plottables = listofplottable 
     194         
     195         
    208196    def _make_labels(self): 
    209197        # Find groups of related plottables 
     
    223211     
    224212    def returnPlottable(self): 
     213        """ 
     214            This method returns a dictionary of plottables contained in graph 
     215            It is just by Plotpanel to interact with the complete list of plottables  
     216            inside the graph. 
     217        """ 
    225218        return self.plottables 
    226219 
     
    234227        plot.render() 
    235228    
    236     def clear(self,plot):  
    237         plot.clear() 
     229    
    238230 
    239231    def __init__(self,**kw): 
     
    376368    ##Use the following if @classmethod doesn't work 
    377369    # labels = classmethod(labels) 
    378     def getTransform(self,transx,transy): 
    379         self.view.transx = transx 
    380         self.view.transy = transy 
     370    def setLabel(self,labelx,labely): 
     371        """ 
     372            It takes a label of the x and y transformation and set View parameters 
     373            @param transx: The label of x transformation is sent by Properties Dialog 
     374            @param transy: The label of y transformation is sent Properties Dialog 
     375        """ 
     376        self.view.xLabel= labelx 
     377        self.view.yLabel = labely 
    381378         
    382379    def __init__(self): 
     
    418415     
    419416    def transformView(self): 
    420         
     417        """ 
     418            It transforms x, y before displaying 
     419        """ 
    421420        self.view.transform( self.x, self.y, self.dx,self.dy) 
    422421         
    423422    def returnValuesOfView(self): 
     423        """ 
     424            Return View parameters and it is used by Fit Dialog 
     425        """ 
    424426        return self.view.returnXview() 
    425427     
    426428    def check_data_PlottableX(self):  
     429        """ 
     430            Since no transformation is made for log10(x), check that  
     431            no negative values is plot in log scale 
     432        """ 
    427433        self.view.check_data_logX() 
    428434         
    429435    def check_data_PlottableY(self):  
     436        """ 
     437            Since no transformation is made for log10(y), check that  
     438            no negative values is plot in log scale 
     439        """ 
    430440        self.view.check_data_logY()  
    431441         
    432     def returnTransformationx(self,transx,transdx): 
    433         self.view.returntransformx(transx,transdx) 
    434          
    435     def returnTransformationy(self,transy,transdy): 
    436         self.view.returntransformy(transy,transdy) 
     442    def transformX(self,transx,transdx): 
     443        """ 
     444            Receive pointers to function that transform x and dx  
     445            and set corresponding View pointers 
     446            @param transx: pointer to function that transforms x 
     447            @param transdx: pointer to function that transforms dx 
     448        """ 
     449        self.view.setTransformX(transx,transdx) 
     450         
     451    def transformY(self,transy,transdy): 
     452        """ 
     453            Receive pointers to function that transform y and dy  
     454            and set corresponding View pointers 
     455            @param transy: pointer to function that transforms y 
     456            @param transdy: pointer to function that transforms dy 
     457        """ 
     458        self.view.setTransformY(transy,transdy) 
     459         
    437460    def onReset(self): 
     461        """ 
     462            Reset x, y, dx, dy view with its parameters 
     463        """ 
    438464        self.view.onResetView() 
     465         
    439466    def onFitRange(self,xmin=None,xmax=None): 
     467        """ 
     468            It limits View data range to plot from min to max 
     469            @param xmin: the minimum value of x to plot. 
     470            @param xmax: the maximum value of x to plot 
     471        """ 
    440472        self.view.onFitRangeView(xmin,xmax) 
     473         
    441474    class View: 
    442475        """ 
     
    454487            self.dx = dx 
    455488            self.dy = dy 
    456             #to change x range to the reel range 
     489            # To change x range to the reel range 
    457490            self.Xreel = self.x 
    458491            self.Yreel = self.y 
    459492            self.DXreel = self.dx 
    460493            self.DYreel = self.dy 
    461              
    462             self.transx ="" 
    463             self.transy ="" 
    464             # function to transform x and y 
     494            # Labels of x and y received from Properties Dialog 
     495            self.xLabel ="" 
     496            self.yLabel ="" 
     497            # Function to transform x, y, dx and dy 
    465498            self.funcx= None 
    466499            self.funcy= None 
     
    469502        def transform(self, x=None,y=None,dx=None, dy=None): 
    470503            """ 
    471                 Transforms the x and dx vectors and stores the output. 
    472                  
    473                 @param func: function to apply to the data 
     504                Transforms the x,y,dx and dy vectors and stores the output in View parameters 
     505         
    474506                @param x: array of x values 
    475                 @param dx: array of error values 
    476                 @param errfunc: function to apply to errors 
     507                @param y: array of y values 
     508                @param dx: array of  errors values on x  
     509                @param dy: array of error values on y 
    477510            """ 
    478511             
    479512            # Sanity check 
    480             if (x!=None) and (y!=None): 
     513            # Do the transofrmation only when x and y are empty 
     514            if (x!=None) and (y!=None):  
    481515                if dx and not len(x)==len(dx): 
    482516                        raise ValueError, "Plottable.View: Given x and dx are not of the same length"  
     
    522556                and(len(self.x)==len(self.y))and(len(self.y)==len(self.dy)) : 
    523557                        raise ValueError, "Plottable.View: Given x,y,dy and dx are not of the same length"  
     558                # Check that negative values are not plot on x and y axis for log10 transformation 
    524559                self.check_data_logX() 
    525560                self.check_data_logY() 
     561                # Store x ,y dx,and dy in their full range for reset 
    526562                self.Xreel = self.x 
    527563                self.Yreel = self.y 
    528564                self.DXreel = self.dx 
    529565                self.DYreel = self.dy 
     566                 
     567                 
     568                 
    530569        def onResetView(self): 
    531             self.x=self.Xreel 
    532             self.y=self.Yreel 
    533             self.dx=self.DXreel 
    534             self.dy=self.DYreel 
    535         def returntransformx(self,funcx,funcdx):     
     570            """ 
     571                Reset x,y,dx and y in their full range  and in the initial scale 
     572                in case their previous range has changed   
     573            """ 
     574            self.x = self.Xreel 
     575            self.y = self.Yreel 
     576            self.dx = self.DXreel 
     577            self.dy = self.DYreel 
     578             
     579        def setTransformX(self,funcx,funcdx):   
     580            """ 
     581                Receive pointers to function that transform x and dx  
     582                and set corresponding View pointers 
     583                @param transx: pointer to function that transforms x 
     584                @param transdx: pointer to function that transforms dx 
     585            """ 
    536586            self.funcx= funcx 
    537587            self.funcdx= funcdx 
    538588             
    539         def returntransformy(self,funcy,funcdy):     
     589        def setTransformY(self,funcy,funcdy): 
     590            """ 
     591                Receive pointers to function that transform y and dy  
     592                and set corresponding View pointers 
     593                @param transx: pointer to function that transforms y 
     594                @param transdx: pointer to function that transforms dy 
     595            """     
    540596            self.funcy= funcy 
    541597            self.funcdy= funcdy 
    542598        
    543599        def returnXview(self): 
     600            """ 
     601                Return View  x,y,dx,dy 
     602            """ 
    544603            return self.x,self.y,self.dx,self.dy 
    545604         
    546605      
    547606        def check_data_logX(self):  
     607            """ 
     608                 Remove negative value in x vector  
     609                 to avoid plotting negative value of Log10 
     610            """ 
    548611            tempx=[] 
    549612            tempdx=[] 
     
    554617            if self.dy==None: 
    555618                self.dy=numpy.zeros(len(self.y)) 
    556             if self.transx=="log10(x)" : 
     619            if self.xLabel=="log10(x)" : 
    557620                for i in range(len(self.x)): 
    558621                    try: 
     
    568631                        pass  
    569632            
    570                 self.x=[] 
    571                 self.dx=[] 
    572                 self.y=[] 
    573                 self.dy=[] 
    574                 self.x=tempx 
    575                 self.y=tempy 
    576                 self.dx=tempdx 
    577                 self.dy=tempdy 
     633                self.x = tempx 
     634                self.y = tempy 
     635                self.dx = tempdx 
     636                self.dy = tempdy 
    578637             
    579638        def check_data_logY(self):  
     639            """ 
     640                 Remove negative value in y vector  
     641                 to avoid plotting negative value of Log10 
     642            """ 
    580643            tempx=[] 
    581644            tempdx=[] 
     
    586649            if self.dy==None: 
    587650                self.dy=numpy.zeros(len(self.y)) 
    588             if (self.transy == "log10(y)" ): 
     651            if (self.yLabel == "log10(y)" ): 
    589652                for i in range(len(self.x)): 
    590653                     try: 
     
    598661                        print sys.exc_value   
    599662                        pass 
    600                  
    601                 self.x=[] 
    602                 self.dx=[] 
    603                 self.y=[] 
    604                 self.dy=[] 
    605                 self.x=tempx 
    606                 self.y=tempy 
    607                 self.dx=tempdx 
    608                 self.dy=tempdy 
     663               
     664                self.x = tempx 
     665                self.y = tempy 
     666                self.dx = tempdx 
     667                self.dy = tempdy 
    609668                 
    610669        def onFitRangeView(self,xmin=None,xmax=None): 
     670            """ 
     671                It limits View data range to plot from min to max 
     672                @param xmin: the minimum value of x to plot. 
     673                @param xmax: the maximum value of x to plot 
     674            """ 
    611675            tempx=[] 
    612676            tempdx=[] 
     
    676740        The title is the name that will show up on the legend. 
    677741        """ 
    678         self.name= "theo" 
     742        self.name= "theory" 
    679743        self.x = x 
    680744        self.y = y 
     
    683747        self.yaxis( 'intensity', 'cm') 
    684748        self.view = self.View(self.x, self.y, None, self.dy) 
     749         
    685750    def render(self,plot,**kw): 
    686751        #plot.curve(self.x,self.y,dy=self.dy,**kw) 
Note: See TracChangeset for help on using the changeset viewer.