Changeset f193585 in sasview for guitools


Ignore:
Timestamp:
Apr 28, 2008 3:48:59 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:
6ed101a
Parents:
9e8dc22
Message:

some changes

Location:
guitools
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • guitools/PlotPanel.py

    r8035b82 rf193585  
    1010import transform 
    1111from canvas import FigureCanvas 
     12from matplotlib.widgets import RectangleSelector 
     13from pylab import  gca, gcf 
     14 
    1215#TODO: make the plottables interactive 
    1316 
     
    4952        sizer.Add(self.canvas,1,wx.EXPAND) 
    5053        self.SetSizer(sizer) 
    51  
     54         
    5255        # Graph object to manage the plottables 
    5356        self.graph = Graph() 
     
    8891        if len(list.keys())>0: 
    8992            first_item = list.keys()[0] 
    90             #print first_item, list[first_item].__class__.__name__ 
    9193            dlg = LinearFit( None, first_item, self.onFitDisplay,self.returnTrans, -1, 'Fitting') 
    9294            dlg.ShowModal()  
     
    172174         
    173175 
    174  
     176   
     177          
     178    def onselect(self,event1, event2): 
     179        print"went here" 
     180        from matplotlib.widgets import RectangleSelector 
     181        from pylab import  show, gca, gcf 
     182 
     183        'event1 and event2 are the press and release events' 
     184        x1, y1 = event1.xdata, event1.ydata 
     185        x2, y2 = event2.xdata, event2.ydata 
     186        print "(%3.2f, %3.2f) --> (%3.2f, %3.2f)"%(x1,y1,x2,y2) 
     187        print " The button you used were: ",event1.button, event2.button 
     188        gca().set_xlim([x1,x2]) 
     189        gca().set_ylim([y1,y2]) 
     190        gcf().canvas.draw_idle() 
     191        
     192        # drawtype is 'box' or 'line' or 'none' 
     193        LS = RectangleSelector(self.subplot, onselect,drawtype='box',useblit=True) 
     194        show() 
     195 
     196 
     197 
     198         
    175199    def onSaveImage(self, evt): 
    176200        #figure.savefig 
     
    241265        self.subplot.clear() 
    242266        self.subplot.hold(True) 
    243  
    244  
     267         
    245268    def render(self): 
    246269        """Commit the plot after all objects are drawn""" 
     
    330353        list =[] 
    331354        list = self.graph.returnPlottable() 
     355         
    332356        for item in list: 
     357            item.getTransform(self.xscales,self.yscales) 
    333358            if ( self.xscales=="x" ): 
    334                 item.transform_x( transform.toX,transform.errToX ) 
     359                item.returnTransformationx(transform.toX,transform.errToX) 
     360                 
    335361                self.set_xscale("linear") 
    336362                name, units = item.get_xaxis() 
     
    338364                 
    339365            if ( self.xscales=="x^(2)" ): 
    340                 item.transform_x( transform.toX2,transform.errToX2 ) 
     366                item.returnTransformationx(transform.toX2,transform.errToX2) 
    341367                self.set_xscale('linear') 
    342368                name, units = item.get_xaxis() 
     
    344370                 
    345371            if (self.xscales=="log10(x)" ): 
    346                 item.transform_x( transform.toX, transform.errToX ) 
     372                item.returnTransformationx(transform.toX,transform.errToX) 
    347373                self.set_xscale("log") 
    348                 name, units = item.get_xaxis() 
    349                 item.check_data_PlottableX()  
     374                name, units = item.get_xaxis()  
    350375                self.graph.xaxis("Log10 %s" % name,  "%s^{-1}" % units) 
    351376                 
    352377            if ( self.yscales=="ln(y)" ): 
    353                 item.transform_y( transform.toLogX, transform.errToLogX ) 
    354                 self.set_yscale("linear") 
    355                 name, units = item.get_yaxis() 
     378                item.returnTransformationy(transform.toLogX,transform.errToLogX) 
     379                self.set_yscale("linear") 
     380                name, units = item.get_yaxis() 
     381                item.check_data_PlottableY()  
    356382                self.graph.yaxis("log %s" % name,  "%s^{-1}" % units) 
    357383                 
    358384            if ( self.yscales=="y" ): 
    359                 item.transform_y( transform.toX, transform.errToX ) 
     385                item.returnTransformationy(transform.toX,transform.errToX) 
    360386                self.set_yscale("linear") 
    361387                name, units = item.get_yaxis() 
     
    363389                 
    364390            if ( self.yscales=="log10(y)" ):  
    365                 item.transform_y( transform.toX, transform.errToLogX) 
     391                item.returnTransformationy(transform.toX,transform.errToX) 
     392                item.check_data_PlottableY()  
    366393                self.set_yscale("log")   
    367394                name, units = item.get_yaxis() 
     395                self.graph.yaxis("Log10 %s" % name,  "%s^{-1}" % units) 
     396                 
     397            if ( self.yscales=="y^(2)" ): 
     398                item.returnTransformationy( transform.toX2,transform.errToX2 )     
     399                self.set_yscale("linear") 
     400                name, units = item.get_yaxis() 
     401                self.graph.yaxis("%s^2" % name,  "%s^{-2}" % units) 
     402                 
     403            if ( self.yscales =="1/y"): 
     404                item.returnTransformationy(transform.toOneOverX,transform.errOneOverX ) 
     405                self.set_yscale("linear") 
     406                name, units = item.get_yaxis() 
     407                self.graph.yaxis("%s" % name,  "%s" % units) 
     408                 
     409            if ( self.yscales =="1/sqrt(y)" ): 
     410                item.returnTransformationy(transform.toOneOverSqrtX,transform.errOneOverSqrtX ) 
     411                self.set_yscale("linear") 
     412                name, units = item.get_yaxis() 
    368413                item.check_data_PlottableY()  
    369                 self.graph.yaxis("Log10 %s" % name,  "%s^{-1}" % units) 
    370                  
    371             if ( self.yscales=="y^(2)" ): 
    372                 item.transform_y( transform.toX2, transform.errToX2 )     
    373                 self.set_yscale("linear") 
    374                 name, units = item.get_yaxis() 
    375                 self.graph.yaxis("%s^2" % name,  "%s^{-2}" % units) 
    376                  
    377             if ( self.yscales =="1/y"): 
    378                 item.transform_y( transform.toOneOverX , transform.errOneOverX ) 
    379                 self.set_yscale("linear") 
    380                 name, units = item.get_yaxis() 
    381                 self.graph.yaxis("%s" % name,  "%s" % units) 
    382                  
    383             if ( self.yscales =="1/sqrt(y)" ): 
    384                 item.transform_y( transform.toOneOverSqrtX ,transform.errOneOverSqrtX ) 
    385                 self.set_yscale("linear") 
    386                 name, units = item.get_yaxis() 
    387414                self.graph.yaxis("%s" %name,  "%s" % units) 
    388415                 
    389416            if ( self.yscales =="ln(y*x)"): 
    390                 item.transform_y( transform.toLogXY ,transform.errToLogXY ) 
     417                item.returnTransformationy( transform.toLogXY,transform.errToLogXY) 
    391418                self.set_yscale("linear") 
    392419                yname, yunits = item.get_yaxis() 
     
    395422                 
    396423            if ( self.yscales =="ln(y*x^(2))"): 
    397                 item.transform_y( transform.toLogYX2 ,transform.errToLogYX2 ) 
     424                item.returnTransformationy( transform.toLogYX2,transform.errToLogYX2) 
    398425                self.set_yscale("linear") 
    399426                yname, yunits = item.get_yaxis() 
    400427                xname, xunits = item.get_xaxis() 
     428                item.check_data_PlottableY()  
    401429                self.graph.yaxis("Log %s%s^{2}" % (yname,xname),  "%s^{-1}%s^{-2}" % (yunits,xunits)) 
    402430             
    403431            if ( self.yscales =="ln(y*x^(4))"): 
    404                 item.transform_y( transform.toLogYX4 ,transform.errToLogYX4 ) 
     432                item.returnTransformationy(transform.toLogYX4,transform.errToLogYX4) 
    405433                self.set_yscale("linear") 
    406434                yname, yunits = item.get_yaxis() 
     
    409437             
    410438            if ( self.viewModel == "Guinier lny vs x^(2)"): 
    411                  
    412                 item.transform_x( transform.toX2,transform.errToX2 ) 
     439                item.returnTransformationx(transform.toX2,transform.errToX2) 
    413440                self.set_xscale('linear') 
    414441                name, units = item.get_xaxis() 
    415442                self.graph.xaxis("%s^{2}" % name,  "%s^{-2}" % units) 
    416                  
    417                 item.transform_y( transform.toLogX, transform.errToLogX ) 
     443                item.returnTransformationy(transform.toLogX,transform.errToLogX ) 
    418444                self.set_yscale("linear") 
    419445                name, units = item.get_yaxis() 
    420446                self.graph.yaxis("$Log %s$" % name,  "%s^{-1}" % units) 
     447                 
    421448        #item.name = self.yscales+" vs " +self.xscales       
    422449        self.prevXtrans = self.xscales  
    423450        self.prevYtrans = self.yscales   
    424          
     451        item.transformView() 
    425452        self.graph.render(self) 
    426453        self.subplot.figure.canvas.draw_idle() 
    427454         
    428     def onFitDisplay(self, plottable,xmin,xmax): 
     455    def onFitDisplay(self, plottable): 
    429456        """ 
    430457            Add a new plottable into the graph .In this case this plottable will be used  
     
    432459            @param plottable: the plottable to plot 
    433460        """ 
    434         list =[] 
    435         tempx=[] 
    436         tempy=[] 
    437         tempdx=[] 
    438         tempdy=[] 
    439         #Stored plotted plottable in a new plottable  
    440         list = self.graph.returnPlottable() 
    441         if len(list.keys())>0: 
    442             for item in list: 
    443                 if self.graph.isPlotted(item)== True: 
    444                     x,y,dx,dy = item.returnValuesOfView() 
    445                     if((min(x) < xmin )and( max(x) > xmax ))\ 
    446                         or ((min(x) <= xmin )and( max(x) > xmax ))\ 
    447                         or((min(x) < xmin )and( max(x) >= xmax )): 
    448                         print"went here" 
    449                         item.reducedXrange(xmin,xmax) 
    450                     else: 
    451                          item.originalXrange() 
    452              
    453          
    454461        #Add the data to fit  
    455         plottable.reset_view() 
     462        
    456463        self.graph.add(plottable) 
    457464        self.graph.render(self) 
     
    459466        self.subplot.figure.canvas.draw_idle() 
    460467        self.graph.delete(plottable) 
    461      
    462        
    463      
    464      
     468    
     469 
     470         
    465471class NoRepaintCanvas(FigureCanvasWxAgg): 
    466472    """We subclass FigureCanvasWxAgg, overriding the _onPaint method, so that 
  • guitools/canvas.py

    r2bf92f2 rf193585  
    22from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg, _convert_agg_to_wx_bitmap 
    33from matplotlib.backends.backend_agg import FigureCanvasAgg 
     4from matplotlib.backend_bases import MouseEvent 
    45 
    56class FigureCanvas(FigureCanvasWxAgg): 
     
    1920        # doesn't behave as nicely. 
    2021        self.idletimer = wx.CallLater(1,self._onDrawIdle) 
     22        # Support for mouse wheel 
     23        self.Bind(wx.EVT_MOUSEWHEEL, self._onMouseWheel) 
     24 
    2125 
    2226    def draw_idle(self, *args, **kwargs): 
     
    4650        else: 
    4751            self._isRendered = False 
     52    def _onMouseWheel(self, evt): 
     53        """Translate mouse wheel events into matplotlib events""" 
     54        # Determine mouse location 
     55        x = evt.GetX() 
     56        y = self.figure.bbox.height - evt.GetY() 
     57 
     58        # Convert delta/rotation/rate into a floating point step size 
     59        delta = evt.GetWheelDelta() 
     60        rotation = evt.GetWheelRotation() 
     61        rate = evt.GetLinesPerAction() 
     62        #print "delta,rotation,rate",delta,rotation,rate 
     63        step = rate*float(rotation)/delta 
     64 
     65        # Convert to mpl event 
     66        evt.Skip() 
     67        self.scroll_event(x, y, step, guiEvent=evt) 
     68 
     69    def scroll_event(self, x, y, step=1, guiEvent=None): 
     70        """ 
     71        Backend derived classes should call this function on any 
     72        scroll wheel event.  x,y are the canvas coords: 0,0 is lower, 
     73        left.  button and key are as defined in MouseEvent 
     74        """ 
     75        button = 'up' if step >= 0 else 'down' 
     76        self._button = button 
     77        s = 'scroll_event' 
     78        event = MouseEvent(s, self, x, y, button, self._key, guiEvent=guiEvent) 
     79        setattr(event,'step',step) 
     80        self.callbacks.process(s, event) 
     81 
    4882 
    4983    def _onPaint(self, evt): 
     
    6498 
    6599        evt.Skip() 
    66  
     100    
  • guitools/fitDialog.py

    r46693050 rf193585  
    140140        self.file_data1 = Theory1D(x=[], y=[], dy=None) 
    141141        self.file_data1.name = "Fit" 
    142          
     142        # Receive transformations of x and y 
     143        self.xtrans,self.ytrans= self.transform() 
    143144    def _onFit(self ,event): 
    144145        """ 
     
    152153        tempdy = [] 
    153154         
    154         #Check if the field of Fit Dialog contain values and use the x max and min of the user 
    155         xmin,xmax = self._checkVal(self.FXmin.GetValue(),self.FXmax.GetValue()) 
    156155        #store the values of View in x,y, dx,dy 
    157156        x,y,dx,dy=self.plottable.returnValuesOfView() 
     
    162161        # makes transformation for y as a line to fit 
    163162        if x != []:  
    164             xminView=self.floatTransform(xmin) 
    165             xmaxView=self.floatTransform(xmax) 
    166          
    167             # Store the transformed values of view x, y,dy in variables  before the fit 
    168             if  self.ytrans.lower() == "log10(y)": 
    169                 for y_i in y: 
    170                     tempy.append(math.log10(y_i))  
    171             else: 
    172                 tempy = y 
    173             if  self.xtrans.lower() == "log10(x)": 
    174                 for x_i in x: 
    175                     tempx.append(math.log10(x_i))  
    176             else: 
    177                 tempx = x 
    178                     
    179             for y_i in y: 
    180                 dy = 1/y_i 
    181                 if dy >= y_i: 
    182                     dy = 0.9*y_i 
    183                 tempdy.append(dy) 
    184                     
    185             #Find the fitting parameters 
    186             chisqr, out, cov = fittings.sansfit(self.model,  
    187                             [self.cstA, self.cstB],tempx, tempy,tempdy,xminView,xmaxView) 
     163            if(self.checkFitValues(self.FXmin) == True): 
     164                #Check if the field of Fit Dialog contain values and use the x max and min of the user 
     165                xmin,xmax = self._checkVal(self.FXmin.GetValue(),self.FXmax.GetValue()) 
     166                xminView=self.floatTransform(xmin) 
     167                xmaxView=self.floatTransform(xmax) 
     168                 
     169                # Store the transformed values of view x, y,dy in variables  before the fit 
     170                if  self.ytrans.lower() == "log10(y)": 
     171                    if (self.xtrans.lower() == "log10(x)"): 
     172                        for i in range(len(x)): 
     173                            if x[i]>=xmin: 
     174                                tempy.append(math.log10(y[i]))  
     175                                tempdy.append(transform.errToLogX(y[i],0,dy[i],0)) 
     176                    else: 
     177                        for y_i in y: 
     178                            tempy.append(math.log10(y_i))  
     179                            tempdy.append(transform.errToLogX(y[i],0,dy[i],0)) 
     180                else: 
     181                    tempy = y 
     182                    tempdy = dy 
     183                
     184                if (self.xtrans.lower() == "log10(x)"): 
     185                    for x_i in x: 
     186                        if x_i >= xmin: 
     187                            tempx.append(math.log10(x_i))  
     188                else: 
     189                    tempx = x 
     190                        
     191                #for y_i in y: 
     192                #    dy = math.sqrt(math.fabs(y_i)) 
     193                #    if dy >= y_i: 
     194                #        dy = 0.9*y_i 
     195                #    tempdy.append(dy) 
     196                        
     197                #Find the fitting parameters 
     198 
     199                chisqr, out, cov = fittings.sansfit(self.model,  
     200                                [self.cstA, self.cstB],tempx, tempy,tempdy,xminView,xmaxView) 
     201                print "this out",out 
     202                #Check that cov and out are iterable before displaying them 
     203                if cov ==None: 
     204                    errA =0.0 
     205                    errB =0.0 
     206                else: 
     207                    errA= math.sqrt(cov[0][0]) 
     208                    errB= math.sqrt(cov[1][1]) 
     209                if out==None: 
     210                    cstA=0.0 
     211                    cstB=0.0 
     212                else: 
     213                    cstA=out[0] 
     214                    cstB=out[1] 
     215                # Reset model with the right values of A and B  
     216                self.model.setParam('A', float(cstA)) 
     217                self.model.setParam('B', float(cstB)) 
     218                 
     219                tempx = [] 
     220                tempy = [] 
     221                y_model = 0.0 
     222                # load tempy with the minimum transformation 
     223                
     224                if self.xtrans == "log10(x)": 
     225                    y_model = self.model.run(math.log10(xmin)) 
     226                    tempx.append(xmin) 
     227                else: 
     228                    y_model = self.model.run(xminView) 
     229                    tempx.append(xminView) 
     230                     
     231                if self.ytrans == "log10(y)": 
     232                    tempy.append(math.pow(10,y_model)) 
     233                    print "tempy",tempy 
     234                else: 
     235                    tempy.append(y_model) 
     236                     
     237                # load tempy with the maximum transformation 
     238                if self.xtrans == "log10(x)": 
     239                    y_model = self.model.run(math.log10(xmax)) 
     240                    tempx.append(xmax) 
     241                else: 
     242                    y_model = self.model.run(xmaxView) 
     243                    tempx.append(xmaxView) 
     244                     
     245                if self.ytrans == "log10(y)": 
     246                    tempy.append(math.pow(10,y_model)) 
     247                else:  
     248                    tempy.append(y_model) 
     249               
     250                # Create new data plottable with result 
     251                self.file_data1.x =[]  
     252                self.file_data1.y =[]  
     253                self.file_data1.x =tempx   
     254                self.file_data1.y =tempy      
     255                self.file_data1.dx=None 
     256                self.file_data1.dy=None 
     257                #Load the view with the new values 
     258                self.file_data1.reset_view() 
     259                 
     260                #Send the data to display to the PlotPanel 
     261                self.push_data(self.file_data1) 
     262                 
     263                # Display the fitting value on the Fit Dialog 
     264                self._onsetValues(cstA, cstB, errA,errB,chisqr) 
    188265             
    189             #Check that cov and out are iterable before displaying them 
    190             if cov ==None: 
    191                 errA =0.0 
    192                 errB =0.0 
    193             else: 
    194                 errA= math.sqrt(cov[0][0]) 
    195                 errB= math.sqrt(cov[1][1]) 
    196             if out==None: 
    197                 cstA=0.0 
    198                 cstB=0.0 
    199             else: 
    200                 cstA=out[0] 
    201                 cstB=out[1] 
    202             # Reset model with the right values of A and B  
    203             self.model.setParam('A', float(cstA)) 
    204             self.model.setParam('B', float(cstB)) 
    205              
    206             tempx = [] 
    207             tempy = [] 
    208             y_model = 0.0 
    209             # load tempy with the minimum transformation 
    210             
    211             if self.xtrans == "log10(x)": 
    212                 y_model = self.model.run(math.log10(xmin)) 
    213                 tempx.append(xmin) 
    214             else: 
    215                 y_model = self.model.run(xminView) 
    216                 tempx.append(xminView) 
    217                  
    218             if self.ytrans == "log10(y)": 
    219                 tempy.append(math.pow(10,y_model)) 
    220             else: 
    221                 tempy.append(y_model) 
    222                  
    223             # load tempy with the maximum transformation 
    224             if self.xtrans == "log10(x)": 
    225                 y_model = self.model.run(math.log10(xmax)) 
    226                 tempx.append(xmax) 
    227             else: 
    228                 y_model = self.model.run(xmaxView) 
    229                 tempx.append(xmaxView) 
    230                  
    231             if self.ytrans == "log10(y)": 
    232                 tempy.append(math.pow(10,y_model)) 
    233             else:  
    234                 tempy.append(y_model) 
    235            
    236             # Create new data plottable with result 
    237             self.file_data1.x =[]  
    238             self.file_data1.y =[]  
    239             self.file_data1.x =tempx   
    240             self.file_data1.y =tempy      
    241             self.file_data1.dx=None 
    242             self.file_data1.dy=None 
    243             #Load the view with the new values 
    244             self.file_data1.reset_view() 
    245              
    246             #Send the data to display to the PlotPanel 
    247             self.push_data(self.file_data1,xminView, xmaxView) 
    248              
    249             # Display the fitting value on the Fit Dialog 
    250             self._onsetValues(cstA, cstB, errA,errB,chisqr) 
    251     
    252266    def _onsetValues(self,cstA,cstB,errA,errB,Chi): 
    253267         """ 
     
    291305            return transform.toX(x) 
    292306         
    293         if ( self.xtrans=="x^(2)" ): 
     307        if ( self.xtrans=="x^(2)" ):  
    294308            return transform.toX2(x) 
    295309         
     
    299313            else: 
    300314                raise ValueError,"cannot compute log of a negative number" 
     315             
     316    def checkFitValues(self,item): 
     317        """ 
     318            Check the validity of input values 
     319        """ 
     320        flag = True 
     321        value = item.GetValue() 
     322        # Check for possible values entered 
     323        if (self.xtrans=="log10(x)"): 
     324            if (float(value) > 0): 
     325                item.SetBackgroundColour(wx.WHITE) 
     326                item.Refresh() 
     327            else: 
     328                flag = False 
     329                item.SetBackgroundColour("pink") 
     330                item.Refresh() 
     331       
     332        return flag 
    301333        
    302334                 
  • guitools/plottables.py

    r46693050 rf193585  
    4242import copy 
    4343import numpy 
     44import math 
    4445 
    4546if 'any' not in dir(__builtins__): 
     
    181182        else: 
    182183            self.color =0  
     184             
    183185 
    184186    def reset(self): 
     
    361363    ##Use the following if @classmethod doesn't work 
    362364    # labels = classmethod(labels) 
    363  
     365    def getTransform(self,transx,transy): 
     366        self.view.transx = transx 
     367        self.view.transy = transy 
     368         
    364369    def __init__(self): 
    365370        self.view = View() 
     
    417422         
    418423    def returnValuesOfView(self): 
    419          
    420424        return self.view.returnXview() 
     425     
    421426    def check_data_PlottableX(self):  
    422427        self.view.check_data_logX() 
     428         
    423429    def check_data_PlottableY(self):  
    424430        self.view.check_data_logY()  
    425     def originalXrange(self): 
    426         self.view.reelXrange() 
    427     def reducedXrange(self,min,max): 
    428         self.view.reduceXrange(min, max) 
     431    def returnTransformationx(self,transx,transdx): 
     432        self.view.returntransformx(transx,transdx) 
     433    def returnTransformationy(self,transy,transdy): 
     434        self.view.returntransformy(transy,transdy) 
     435    
    429436    class View: 
    430437        """ 
     
    447454            self.DXreel = self.dx 
    448455            self.DYreel = self.dy 
    449             
     456            self.transx ="" 
     457            self.transy ="" 
     458            self.funcx= None 
     459            self.funcy= None 
     460            self.funcdx= None 
     461            self.funcdy= None 
     462     
    450463        def transform_x(self, func, errfunc, x,y=None,dx=None, dy=None): 
    451464            """ 
     
    474487            self.x = [] 
    475488            self.dx = [] 
    476              
     489            tempy=[] 
     490            tempdy=[] 
     491            print "this is initial value of y transformed",self.y 
     492            print "this is initial value of dy transformed",self.dy 
    477493            for i in range(len(x)): 
    478494                if has_y: 
    479495                     try: 
    480496                         xtemp = func(x[i],y[i]) 
    481                           
    482                           
     497                         tempy.append(self.funcy.y[i]) 
     498                         tempdy.append(self.funcdy.dy[i]) 
    483499                         if (dx!=None) and (dy !=None): 
    484500                             dxtemp = errfunc(x[i], y[i], dx[i], dy[i]) 
     
    489505                         else: 
    490506                             dxtemp = errfunc(x[i],y[i],0, 0) 
    491                           
    492507                         self.x.append(xtemp) 
    493                          self.dx.append(dxtemp) 
    494                          self.Xreel = [] 
    495                          self.DXreel=[] 
    496                          self.Xreel = self.x 
    497                          self.DXreel = self.dx 
    498                           
     508                         self.dx.append(dxtemp)   
    499509                     except: 
     510                         if len(tempy)>0: 
     511                             del tempy[len(tempy)-1] 
     512                             del tempdy[len(tempdy)-1] 
    500513                         print "View.transform_x: skipping point %g" % x[i] 
    501                          print sys.exc_value 
    502                           
    503                           
     514                         print sys.exc_value    
    504515                else: 
    505516                    try: 
    506517                        xtemp = func(x[i]) 
     518                        tempy.append(self.funcy.y[i]) 
     519                        tempdy.append(self.funcdy.dy[i]) 
    507520                        if (dx != None): 
    508521                            dxtemp = errfunc(x[i], dx[i]) 
     
    510523                            dxtemp = errfunc(x[i],None)   
    511524                        self.x.append(xtemp) 
    512                         self.dx.append(dxtemp) 
    513                         self.Xreel = [] 
    514                         self.DXreel=[] 
    515                         self.Xreel = self.x 
    516                         self.DXreel = self.dx 
    517                           
     525                        self.dx.append(dxtemp)  
    518526                    except: 
     527                         if len(tempy)>0: 
     528                             del tempy[len(tempy)-1] 
     529                             del tempdy[len(tempdy)-1] 
    519530                         print "View.transform_x: skipping point %g" % x[i] 
    520531                         print sys.exc_value 
    521                      
    522                           
     532            self.y=tempy 
     533            self.dy=tempdy 
     534            self.Xreel = [] 
     535            self.DXreel=[] 
     536        def returntransformx(self,funcx,funcdx):     
     537            self.funcx= funcx 
     538            self.funcdx= funcdx 
     539             
     540        def returntransformy(self,funcy,funcdy):     
     541            self.funcy= funcy 
     542            self.funcdy= funcdy 
    523543        def transform_y(self, func, errfunc, y, x=None,dx=None,dy=None): 
    524544            """ 
     
    547567            self.y = [] 
    548568            self.dy = [] 
    549             
     569            tempx=[] 
     570            tempdx=[] 
     571            print "this is initial value of x transformed",self.x 
     572            print "this is initial value of dx transformed",self.dx 
    550573            for i in range(len(y)): 
    551574                 
     
    553576                     try: 
    554577                         tempy = func(y[i],x[i]) 
     578                         tempx.append(self.funcx.x[i]) 
     579                         tempdx.append(self.funcdx.x[i]) 
    555580                         if (dx!=None) and (dy !=None): 
    556581                             tempdy = errfunc(y[i], x[i], dy[i], dx[i]) 
     
    563588                         self.y.append(tempy) 
    564589                         self.dy.append(tempdy) 
    565                          self.Yreel = [] 
    566                          self.DYreel=[] 
    567                          self.Yreel = self.y 
    568                          self.DYreel = self.dy 
    569590                     except: 
     591                         if len(tempx)>0: 
     592                             del tempx[len(tempx)-1] 
     593                             del tempdx[len(tempdx)-1] 
    570594                         print "View.transform_y: skipping point %g" % y[i] 
    571595                         print sys.exc_value 
     
    574598                     try: 
    575599                         tempy = func(y[i]) 
     600                         tempx.append(self.funcx.x[i]) 
     601                         tempdx.append(self.funcdx.dx[i]) 
    576602                         if (dy != None): 
    577603                             tempdy = errfunc( y[i],dy[i]) 
     
    579605                             tempdy = errfunc( y[i],None) 
    580606                         self.y.append(tempy) 
    581                          self.dy.append(tempdy) 
    582                          self.Yreel = [] 
    583                          self.DYreel=[] 
    584                          self.Yreel = self.y 
    585                          self.DYreel = self.dy 
     607                         self.dy.append(tempdy)    
    586608                     except: 
     609                          if len(tempx)>0: 
     610                              del tempx[len(tempx)-1] 
     611                              del tempdx[len(tempdx)-1] 
    587612                          print "View.transform_y: skipping point %g" % y[i] 
    588613                          print sys.exc_value 
    589                            
    590  
    591              
     614                     
     615            self.x = tempx 
     616            self.dx = tempdx 
     617            self.Yreel = [] 
     618            self.DYreel=[] 
     619            self.Yreel = self.y 
     620            self.DYreel = self.dy 
     621            print "this is x length",self.x 
     622            print "this is y length",self.y 
     623            print "this is dx length",self.dx 
     624            print "this is dy length",self.dy 
    592625        def returnXview(self): 
    593626            return self.x,self.y,self.dx,self.dy 
    594627         
    595         def checkMin(self,x,min,pos=None): 
    596             if pos==None: 
    597                 pos=0 
    598                 for i in range(len(self.x)): 
    599                     if not min in x:# The user enters a value not in x 
    600                         if x[i] > min: 
    601                             index= i-1 
    602                             print "this is index",index 
    603                             return index1 
    604                     else: 
    605                          index=i 
    606                          print"the user enter a value inside x",index 
    607                          return index 
    608             else: 
    609                 index= pos 
    610                 return index 
    611              
    612         def checkMax(self,x,max,pos=None): 
    613             if pos==None: 
    614                 pos=0 
    615                 for i in range(len(self.x)): 
    616                     if not max in x:# The user enters a value not in x 
    617                         if x[i] >max: 
    618                             
    619                             index= i-1 
    620                             return index 
    621                     else: 
    622                          index=i 
    623                          return index 
    624             else: 
    625                 index= pos 
    626                 return index 
    627                
    628         def reduceXrange(self,min,max): 
    629              
    630             # to change the x range to the user range 
    631             self.Xscale = [] 
    632             self.Yscale = [] 
    633             self.DXscale = [] 
    634             self.DYscale = [] 
    635             indexmin =self.checkMin(self.x,min,None) 
    636             indexmax =self.checkMin(self.x,max,None) 
    637             for i in range(len(self.x)): 
    638                 if( self.x[i] >=self.x[indexmin])and( self.x[i] <= max): 
    639                     self.Xscale.append(self.x[i]) 
    640                     self.Yscale.append(self.y[i]) 
    641                     self.DXscale.append(self.dx[i]) 
    642                     self.DYscale.append(self.dy[i]) 
    643             print self.Xscale 
    644             self.x= self.Xscale   
    645             self.y= self.Yscale 
    646             self.dx= self.DXscale 
    647             self.dy= self.DYscale 
    648          
    649              
     628      
    650629        def reelXrange(self): 
    651630            self.x= self.Xreel 
     
    653632            self.dx= self.DXreel 
    654633            self.dy= self.DYreel 
    655             
    656634         
    657635        def check_data_logX(self):  
     
    660638            tempy=[] 
    661639            tempdy=[] 
    662          
    663             for i in range(len(self.x)): 
     640            if self.transx=="log10(x)" : 
     641                for i in range(len(self.x)): 
     642                    try: 
     643                        if (self.x[i]> 0): 
     644                            
     645                            tempx.append(self.x[i]) 
     646                            tempdx.append(self.dx[i]) 
     647                            tempy.append(self.y[i]) 
     648                            tempdy.append(self.dy[i]) 
     649                    except: 
     650                        #print "View.transform_x: skipping point %g" %self.x[i] 
     651                        print sys.exc_value   
     652                        pass  
     653            if (self.transx == "x"):    
     654                if (self.transy == "ln(y*x)"): 
     655                        try: 
     656                            if (self.y[i]*self.x[i]> 0): 
     657                                tempx.append(self.x[i]) 
     658                                tempdx.append(self.dx[i]) 
     659                                tempy.append(self.y[i]) 
     660                                tempdy.append(self.dy[i]) 
     661                        except: 
     662                            #print "View.transform_x: skipping point %g" %self.x[i] 
     663                            print sys.exc_value   
     664                            pass 
     665            if(self.transy =="ln(y*x^(2))")or(self.transy =="ln(y*x^(4))"): 
     666                print "this is y transform",self.y 
     667                print "this is x transform",self.x 
    664668                try: 
    665                     if (self.x[i]> 0): 
    666                         
     669                    if (self.y[i]> 0 )and (self.x[i]!=0): 
    667670                        tempx.append(self.x[i]) 
    668671                        tempdx.append(self.dx[i]) 
     
    672675                    #print "View.transform_x: skipping point %g" %self.x[i] 
    673676                    print sys.exc_value   
    674                     pass      
    675                  
     677                    pass 
    676678            self.x=[] 
    677679            self.dx=[] 
     
    682684            self.dx=tempdx 
    683685            self.dy=tempdy 
     686             
    684687        def check_data_logY(self):  
    685688            tempx=[] 
     
    687690            tempy=[] 
    688691            tempdy=[] 
    689          
    690692            for i in range(len(self.x)): 
     693                if (self.transy == "ln(y)") or (self.transy == "log10(y)" )or\ 
     694                     (self.transy =="1/sqrt(y)") : 
     695                     try: 
     696                        if (self.y[i]> 0): 
     697                            tempx.append(self.x[i]) 
     698                            tempdx.append(self.dx[i]) 
     699                            tempy.append(self.y[i]) 
     700                            tempdy.append(self.dy[i]) 
     701                     except: 
     702                        #print "View.transform_x: skipping point %g" %self.x[i] 
     703                        print sys.exc_value   
     704                        pass 
     705                if(self.transy == "1/y"): 
     706                    try: 
     707                        if (self.y[i]!=0): 
     708                            tempx.append(self.x[i]) 
     709                            tempdx.append(self.dx[i]) 
     710                            tempy.append(self.y[i]) 
     711                            tempdy.append(self.dy[i]) 
     712                    except: 
     713                        #print "View.transform_x: skipping point %g" %self.x[i] 
     714                        print sys.exc_value   
     715                        pass   
     716            if (self.transx == "x"):    
     717                if (self.transy == "ln(y*x)"): 
     718                        try: 
     719                            if (self.y[i]*self.x[i]> 0): 
     720                                tempx.append(self.x[i]) 
     721                                tempdx.append(self.dx[i]) 
     722                                tempy.append(self.y[i]) 
     723                                tempdy.append(self.dy[i]) 
     724                        except: 
     725                            #print "View.transform_x: skipping point %g" %self.x[i] 
     726                            print sys.exc_value   
     727                            pass 
     728            if(self.transy =="ln(y*x^(2))")or(self.transy =="ln(y*x^(4))"): 
     729                print "this is y transform",self.y 
     730                print "this is x transform",self.x 
    691731                try: 
    692                     if (self.y[i]> 0): 
    693                         
     732                    if (self.y[i]> 0 )and (self.x[i]!= 0): 
    694733                        tempx.append(self.x[i]) 
    695734                        tempdx.append(self.dx[i]) 
     
    699738                    #print "View.transform_x: skipping point %g" %self.x[i] 
    700739                    print sys.exc_value   
    701                     pass      
     740                    pass 
    702741                 
    703742            self.x=[] 
     
    735774    def render(self,plot,**kw): 
    736775        plot.points(self.view.x,self.view.y,dx=self.view.dx,dy=self.view.dy,**kw) 
    737         #plot.points(self.x,self.y,dx=self.dx,dy=self.dy,**kw) 
     776      
    738777    
    739778    def changed(self): 
  • guitools/transform.py

    r46693050 rf193585  
    4343    else: 
    4444        raise ValueError,"cannot divide by zero" 
    45 def toOneOverSqrtX(x=None,y=None): 
     45def toOneOverSqrtX(y , x=None): 
    4646    if y!=None: 
    4747        if y > 0: 
     
    4949        else: 
    5050            raise ValueError,"cannot be computed" 
    51     if x!= None: 
    52         if x > 0: 
    53             return 1/math.sqrt(x) 
    54         else: 
    55             raise ValueError,"cannot be computed" 
    56      
    57 def toLogYX2(x,y): 
     51     
     52     
     53def toLogYX2(y,x): 
    5854    if y*(x**2) >0: 
    5955        return math.log(y*(x**2)) 
     
    6258      
    6359 
    64 def toLogYX4(x, y): 
     60def toLogYX4(y, x): 
    6561    if math.pow(x,4)*y > 0: 
    6662        return math.log(math.pow(x,4)*y) 
    6763 
    68 def toLogXY(x,y): 
     64def toLogXY(y,x): 
    6965    """ 
    7066        This function is used to load value on Plottable.View 
     
    8581        @param dx: float value 
    8682    """ 
     83    if dx==None: 
     84        dx=0 
    8785    return dx 
    8886 
Note: See TracChangeset for help on using the changeset viewer.