Ignore:
Timestamp:
07/09/09 12:52:39 (11 years ago)
Author:
pnorton
Message:

Improved the colour bar code so it now accepts the data array instead of just a minimum + maximum. It also now defaults to creating a Normalize instance with vmin=None and vmax=None instead of 0 and 1.

Also modified the layer_drawer objects to use the ColourBar? class instead of implementing it themselves.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • qesdi/geoplot/trunk/lib/geoplot/tests/unit/test_colour_bar.py

    r5636 r5688  
    6060 
    6161    def test_003_getNormalize(self): 
    62          
     62        #check returns limits when no data provided 
    6363        norm = self.cb.getNormalize() 
    6464        nt.assert_equal((norm.vmin, norm.vmax), self.colourBarRange) 
    6565         
     66        #fixes the norm if the limits are given the wrong way round 
     67        self.cb.colourBarMin = self.colourBarRange[1]         
     68        self.cb.colourBarMax = self.colourBarRange[0]         
     69        norm = self.cb.getNormalize() 
     70        nt.assert_equal((norm.vmin, norm.vmax), self.colourBarRange)         
     71         
     72        #check returns None,None when no data and no limits 
     73        self.cb.colourBarMin = None 
     74        self.cb.colourBarMax = None 
     75        norm = self.cb.getNormalize() 
     76        nt.assert_equal((norm.vmin, norm.vmax), (None, None)) 
     77         
     78        #set up some mock data 
     79        data = numpy.array([-9.43, -10.0, 23.232, 143.2, 13.111]) 
    6680        dMin = -10.0; dMax = 143.2 
    6781         
     82        #still returns set limits when data present 
     83        self.cb.colourBarMin = self.colourBarRange[0]         
     84        self.cb.colourBarMax = self.colourBarRange[1]         
     85        norm = self.cb.getNormalize(data=data) 
     86        nt.assert_equal((norm.vmin, norm.vmax), self.colourBarRange) 
     87         
     88        #returns data minimum when colourBarMin = None 
    6889        self.cb.colourBarMin = None 
    69         norm = self.cb.getNormalize(dataMin=dMin, dataMax=dMax) 
     90        self.cb.colourBarMax = self.colourBarRange[1] 
     91        norm = self.cb.getNormalize(data=data) 
    7092        nt.assert_equal((norm.vmin, norm.vmax), (dMin, self.colourBarRange[1])) 
    7193         
     94        #returns data maximum when colourBarMax = None 
    7295        self.cb.colourBarMin = self.colourBarRange[0] 
    7396        self.cb.colourBarMax = None 
    74         norm = self.cb.getNormalize(dataMin=dMin, dataMax=dMax) 
     97        norm = self.cb.getNormalize(data=data) 
    7598        nt.assert_equal((norm.vmin, norm.vmax), (self.colourBarRange[0], dMax)) 
    7699         
     100        #returns data range when limits are both None 
    77101        self.cb.colourBarMin = None 
    78         norm = self.cb.getNormalize(dataMin=dMin, dataMax=dMax) 
     102        self.cb.colourBarMax = None 
     103        norm = self.cb.getNormalize(data=data) 
    79104        nt.assert_equal((norm.vmin, norm.vmax), (dMin, dMax)) 
    80105         
     106        #check it dosent fall over when data is all masked 
     107        data = numpy.ma.MaskedArray([-9.43, -10.0, 23.232, 143.2, 13.111], 
     108                                    mask=[True, True, True, True, True]) 
    81109        dMin = numpy.ma.MaskedArray([0], mask=True) 
    82110        dMax = numpy.ma.MaskedArray([0], mask=True) 
     111                 
     112        self.cb.colourBarMin = None 
     113        self.cb.colourBarMax = None 
    83114         
    84         norm = self.cb.getNormalize(dataMin=dMin, dataMax=dMax) 
    85         nt.assert_equal((norm.vmin, norm.vmax), (0.0, 1.0)) 
     115        #still returns 0,1 as the default 
     116        norm = self.cb.getNormalize(data=data) 
     117        nt.assert_equal((norm.vmin, norm.vmax), (None,None)) 
     118         
     119        #will still use limits when data is masked 
     120        self.cb.colourBarMin = self.colourBarRange[0]         
     121        self.cb.colourBarMax = self.colourBarRange[1] 
     122        norm = self.cb.getNormalize(data=data) 
     123        nt.assert_equal((norm.vmin, norm.vmax), self.colourBarRange) 
     124         
    86125 
    87126    #position ticks (if 
Note: See TracChangeset for help on using the changeset viewer.