Changeset 5710 for qesdi


Ignore:
Timestamp:
14/09/09 09:53:45 (10 years ago)
Author:
pnorton
Message:

Cleaned up a the import statements for the geoplot modules, also fixed a couple of the tests.

Location:
qesdi/geoplot/trunk/lib/geoplot
Files:
1 deleted
32 edited

Legend:

Unmodified
Added
Removed
  • qesdi/geoplot/trunk/lib/geoplot/colour_bar.py

    r5699 r5710  
    44import numpy 
    55 
    6 import matplotlib.colors 
    7 from matplotlib.colors import Normalize, ListedColormap, BoundaryNorm 
     6from matplotlib.colors import Normalize, ListedColormap 
    87 
    98import matplotlib.ticker 
     
    8685        cb = ColorbarBase(colourBarAxis, **kwargs) 
    8786 
    88         if cb.cmap.__class__ == matplotlib.colors.ListedColormap \ 
     87        if cb.cmap.__class__ == ListedColormap \ 
    8988           and not self.intervalColourbar: 
    9089            ColourBar._repositionColourBarTicks(cb) 
     
    108107            cmap = self.cmap 
    109108     
    110         if self.intervalColourbar and  cmap.__class__ != matplotlib.colors.ListedColormap: 
     109        if self.intervalColourbar and  cmap.__class__ != ListedColormap: 
    111110             
    112111            cbMin, cbMax = self._getCbarMinMax() 
     
    114113            oldCmap = cmap 
    115114            uniqueVals = grid.getUniqueValues(cbMin, cbMax) 
    116             n = matplotlib.colors.Normalize(uniqueVals[0], uniqueVals[-1]) 
     115            n = Normalize(uniqueVals[0], uniqueVals[-1]) 
    117116            colours = [oldCmap(n(x)) for x in uniqueVals] 
    118             cmap = matplotlib.colors.ListedColormap(colours) 
     117            cmap = ListedColormap(colours) 
    119118                 
    120119        if self.hideOutsideBounds: 
     
    202201            norm = FixedBoundaryNorm(bounds, n) 
    203202        else: 
    204             norm = matplotlib.colors.Normalize(cbMin,  cbMax) 
     203            norm = Normalize(cbMin,  cbMax) 
    205204            # this should work event if data is none (as N.ma.maximum(None) = None) 
    206205            data = None 
  • qesdi/geoplot/trunk/lib/geoplot/config.py

    r5605 r5710  
    66""" 
    77 
    8 import ConfigParser 
    9 import re 
    108import logging 
    119import pkg_resources 
     
    2119"""The location and name of the config file""" 
    2220 
    23 #_conf = ConfigParser.ConfigParser() 
    24 #_conf.read(configFile) 
    2521_conf = None 
    26  
    2722 
    2823 
     
    134129    return value 
    135130 
    136 def _convertVal(val): 
    137     """ 
    138     Converts a gven string based on the contents of the string. 
    139  
    140     The value returned will attempt to be converted differently by inspecting the pattern 
    141     of the value. 
    142      * Simple numbers '1','-2' will be converted to ints. 
    143      * Decimal numbers '1.0','-2.0','3.' will be converted to floats. 
    144      * 'true' and 'false' will be converted to booleans 
    145      * strings quoted by ' or " characters will be left as strings 
    146      * strings including ' ' characters will be split into lists 
    147  
    148     @param val: the value to be converted 
    149     @type val: string 
    150     """ 
    151  
    152     if stringPattern.match(val) != None: 
    153         pass # dont try to convert it to anything else 
    154      
    155     elif intPattern.match(val) != None: 
    156         val = _convertValToType(val,int) 
    157          
    158     elif floatPattern.match(val) != None: 
    159         val = _convertValToType(val,float) 
    160          
    161     elif val.lower() == 'true' or val.lower() == 'false': 
    162         val = _convertValToType(val,bool) 
    163          
    164     elif val.find(' ') > 0: 
    165         val = _convertToList(val) 
    166      
    167     return val 
    168  
    169131def _convertValToType(val, t): 
    170132     
     
    175137            val = False 
    176138        else: 
    177             val = bool(_convertVal(val)) 
     139            val = bool(evalString(val)) 
    178140    elif t == list: 
    179141        val = _convertToList(val) 
     
    188150    valNew = [] 
    189151    for v in val.split(' '): 
    190         valNew.append(_convertVal(v)) 
     152        valNew.append(evalString(v)) 
    191153    return valNew 
    192154 
  • qesdi/geoplot/trunk/lib/geoplot/contour_drawer.py

    r5699 r5710  
    1010import logging 
    1111import operator 
    12 import re 
    1312from math import * 
    1413 
    1514#third party modules 
    16 from geoplot.mpl_imports import basemap 
    17 import matplotlib 
    1815import matplotlib.colors 
    1916import matplotlib.cm 
    2017import matplotlib.collections 
    2118import numpy as N 
    22 import numpy.ma as MA 
    23 import geoplot.mpl_imports 
    2419 
    2520#internal modules 
    2621from geoplot.array_util import * 
    27 from geoplot.grid import Grid 
    28 from geoplot.grid_builder_base import GridBuilderBase 
    2922import geoplot.config as geoplot_config 
    3023 
  • qesdi/geoplot/trunk/lib/geoplot/filtered_basemap.py

    r5636 r5710  
    33 
    44@author: pnorton 
     5 
     6The filtered basemap inherits from Basemap and changes it in 3 main ways: 
     7 
     8 * The drawcoastlines and drawrivers methods now accept xLimits and yLimits and  
     9   only the coast or river lines within these limits should be drawn on the map. 
     10   This is important as it allows a single basemap to be used in multiple plots. 
     11    
     12 * The self.coastsegs and self.riversegs arrays are parsed into Line objects, these 
     13   are cached after the first call. The Line objects makes calculating which 
     14   lines to draw faster.   
     15    
     16 * Implements a fix for the CAIRO backend that splits up lines which are too long 
     17   into mutliple shorter lines. 
    518''' 
    619 
     
    1225from matplotlib.collections import LineCollection 
    1326 
    14 from geoplot.utils import ispointInLimits, isRangeInLimits, isValueInLimits 
     27from geoplot.utils import ispointInLimits, isRangeInLimits 
    1528 
    1629log = logging.getLogger(__name__) 
    1730 
    1831class Line(object): 
     32    """ 
     33    A simple object that stores a number of x,y points along with a latitude and longitude range. 
     34    The latitude and longitude range correspond to the total range of the line.  
     35    (i.e the maximum and minimum of all the points in the line) 
     36    """ 
    1937     
    2038    def __init__(self, points, lonRange, latRange): 
     
    2442 
    2543class FilteredBasemap(Basemap): 
     44    """ 
     45    A Filtered version of the Basemap object that should only draw coast lines  
     46    and river lines within the ranges specified. 
     47    """ 
     48     
    2649 
    2750    def __init__(self, *args, **kwargs): 
     
    4770            ax = self.ax 
    4871         
    49 #        print "self.coastsegs has %s lines and %s points" % (len(self.coastsegs), 
    50 #                                                             sum([len(x) for x in self.coastsegs])) 
     72        #log.debug("self.coastsegs has %s lines and %s points" % (len(self.coastsegs), sum([len(x) for x in self.coastsegs]))) 
    5173         
    5274        xLimitsMapUnits, yLimitsMapUnits = self.__call__(xLimits, yLimits) 
     
    5476        segs = self.__getSegments(xLimitsMapUnits, yLimitsMapUnits) 
    5577 
    56         log.debug("segs has %s lines and %s points" % (len(segs), 
    57                                         sum([len(x) for x in segs]))) 
     78        #log.debug("segs has %s lines and %s points" % (len(segs),  sum([len(x) for x in segs]))) 
    5879         
    5980        self._cairoLengthFix(segs) 
    60  
    61                  
    62 #        width = (xLimits[1] - xLimits[0]) 
    63 #        height = (yLimits[1] - yLimits[0]) 
    64 # 
    65 #        segs.append(                 [ (xLimits[0] + 0.1*width,yLimits[0] + 0.1*height),  
    66 #                   (xLimits[1] - 0.1*width, yLimits[0]+ 0.1*height),  
    67 #                   (xLimits[1] - 0.1*width, yLimits[1] - 0.1*height), 
    68 #                   (xLimits[0] + 0.1*width, yLimits[1] - 0.1*height), 
    69 #                   (xLimits[0] + 0.1*width,yLimits[0] + 0.1*height), ] ) 
    7081 
    7182        coastlines = LineCollection(segs, antialiaseds=(antialiased,)) 
     
    91102        if self.resolution is None: 
    92103            raise AttributeError, 'there are no boundary datasets associated with this Basemap instance' 
     104         
    93105        # read in river line segments, only keeping those that 
    94106        # intersect map boundary polygon. 
     
    110122        segs = self.__getRiverSegments(xLimitsMapUnits, yLimitsMapUnits) 
    111123 
    112         log.debug("segs has %s lines and %s points" % (len(segs), 
    113                                         sum([len(x) for x in segs]))) 
     124        #log.debug("segs has %s lines and %s points" % (len(segs), sum([len(x) for x in segs]))) 
    114125  
    115126        self._cairoLengthFix(segs) 
     
    132143     
    133144    def __getSegments(self, xLimits, yLimits): 
     145        """ 
     146        Returns the coast segments within the limits xLimits and yLimits. 
     147        xLimits and yLimits are given in map units. If xLimits and yLimits are both 
     148        None then all of self.coastsegs is returned. 
     149        """ 
    134150         
    135151        if xLimits == None and yLimits == None: 
    136152            return self.coastsegs 
    137153         
     154        #if the lines cache has't been build yet then build it using the coastsegs 
    138155        if self.__lines == None: 
    139156            self.__lines = self.__buildLines(self.coastsegs) 
    140              
     157         
     158        #filter the lines using the limits 
    141159        segs = self.__filterLines(xLimits, yLimits, self.__lines)  
    142160 
     
    144162     
    145163    def __getRiverSegments(self, xLimits, yLimits): 
    146          
     164        """ 
     165        Returns the river segments within the limits xLimits and yLimits. 
     166        xLimits and yLimits are given in map units. If xLimits and yLimits are both 
     167        None then all of self.riversegs is returned. 
     168        """ 
     169                 
    147170        if xLimits == None and yLimits == None: 
    148171            return self.riversegs 
     
    156179     
    157180    def __buildLines(self, segs): 
     181        """ 
     182        Builds a list of Line object for the segments given 
     183        """ 
    158184         
    159185        lines = [] 
     
    185211             
    186212            return True 
    187              
     213         
     214        # filter out the lines which are competly outside the limits 
    188215        linesInLimits = filter(isLineInSelectionLimits, lines) 
    189216         
    190217        segs = [l.points for l in linesInLimits] 
    191218         
     219        # now trim down the segments to only include bits of lines which are  
     220        # inside the limits 
    192221        segs = self.__filterSegments(segs, xLimits, yLimits) 
    193222         
  • qesdi/geoplot/trunk/lib/geoplot/grid.py

    r5699 r5710  
    4949     
    5050    def getUniqueValues(self, minVal=None, maxVal=None): 
     51        """ 
     52        Returns a sorted numpy array of the unique non-masked values found in the 
     53        .values array. If minVal and maxVal are both specified then only the unique 
     54        values between these bounds (inclusive) will be returned. 
     55        """ 
    5156        uniqueVals = list(sets.Set(self.values.compressed().tolist())) 
    5257        uniqueVals.sort() 
     
    5863     
    5964    def getUniqueValueBounds(self, minVal=None, maxVal=None): 
     65        """ 
     66        Returns an array of bounds for the unique values found in the .values array. 
     67        The first and last bounds are interpolated using the first two and 
     68        the last two data points but the rest of the bounds are calculated. 
     69        """ 
    6070        return utils.getBounds(self.getUniqueValues(minVal, maxVal)) 
    6171             
     
    6979 
    7080    from numpy import meshgrid 
    71     from cdms_utils.cdms_compat import N, MA 
     81    from cdms_utils.cdms_compat import MA 
    7282 
    7383    x = [-6,-4,-2, 0, 2] 
  • qesdi/geoplot/trunk/lib/geoplot/grid_builder_base.py

    r5612 r5710  
    1616#internal modules 
    1717from geoplot.grid import Grid 
    18 import cdms2 as cdms 
    1918 
    2019import numpy as N 
     
    181180        @return: the midpoint data  as (xMidpoints, yMidpoints) 
    182181        @rtype: 2 Numpy Arrays 
    183         """ 
    184         raise NotImplementedError 
    185  
    186     def _buildGridValues(self,cdmsVar): 
    187         """ 
    188         Builds a numpy array of values for each of the grid boxes.  
    189          
    190         e.g. values[x,y] is the value for grid box x,y. 
    191          
    192         @param cdmsVar: the variable to extract the values from 
    193         @type cdmsVar: cdms.variable 
    194         @return: the value data 
    195         @rtype: numpy.array 
    196182        """ 
    197183        raise NotImplementedError 
  • qesdi/geoplot/trunk/lib/geoplot/grid_builder_lat_lon.py

    r5683 r5710  
    1313#third party modules 
    1414import numpy as N 
    15 import numpy.ma as MA 
    1615 
    1716#internal modules 
    18 from geoplot.grid import Grid 
    1917from geoplot.grid_builder_base import GridBuilderBase 
    2018 
     
    142140    import os 
    143141    import pkg_resources 
     142    import cdms2 as cdms 
     143    from geoplot.mpl_imports import basemap 
     144    from matplotlib.backends.backend_agg import FigureCanvasAgg 
     145    from matplotlib.figure import Figure 
     146    from matplotlib import cm 
    144147 
    145148    outputsDir = os.path.abspath(pkg_resources.resource_filename('geoplot', '../../outputs')) 
     
    161164    xLimits=(-20.0, 15.0) ; yLimits=(42.0, 65.0) 
    162165 
    163     from geoplot.mpl_imports import basemap 
    164     from matplotlib.backends.backend_agg import FigureCanvasAgg 
    165     from matplotlib.figure import Figure 
    166     from matplotlib import cm 
    167     from numpy import meshgrid 
    168166 
    169167    figsize=(600 / 80, 800 / 80) 
  • qesdi/geoplot/trunk/lib/geoplot/grid_builder_national.py

    r5612 r5710  
    1616 
    1717#internal modules 
    18 import cdms2 as cdms 
    1918import numpy as N 
    20 import numpy.ma as MA 
    21  
    22 from geoplot.grid import Grid 
     19 
    2320from geoplot.grid_builder_base import GridBuilderBase 
    2421 
     
    202199    from matplotlib.figure import Figure 
    203200    from matplotlib import cm 
    204     from numpy import meshgrid 
    205201 
    206202    width=600;height=800;dpi=80 
  • qesdi/geoplot/trunk/lib/geoplot/grid_builder_rotated.py

    r5610 r5710  
    1313 
    1414#third party modules 
    15 from geoplot.mpl_imports import basemap 
     15import numpy as N 
    1616 
    1717#internal modules 
    18 import cdms2 as cmds 
    19 import numpy as N 
    20 import numpy.ma as MA 
    21  
    2218from geoplot.array_util import * 
    23 from geoplot.grid import Grid 
    2419from geoplot.grid_builder_base import GridBuilderBase 
    2520from geoplot.rotgrid import Rotgrid 
     
    369364    from matplotlib.figure import Figure 
    370365    from matplotlib import cm 
    371     from numpy import meshgrid 
    372366 
    373367    width=600;height=800;dpi=80 
  • qesdi/geoplot/trunk/lib/geoplot/grid_drawer.py

    r5699 r5710  
    1616#third party modules 
    1717from geoplot.mpl_imports import basemap 
    18 import matplotlib 
    1918import matplotlib.colors 
    2019import matplotlib.cm 
     
    2726from geoplot.array_util import * 
    2827from geoplot.grid import Grid 
    29 from geoplot.grid_builder_base import GridBuilderBase 
    3028import geoplot.utils as geoplot_utils 
    3129 
     
    9896 
    9997    def _transformLimits(self, limits, basemap): 
     98        """ 
     99        Use the basemap object specified to transform the limits into map units. 
     100        """ 
     101         
    100102        if limits == None: 
    101103            return (None, None) 
     
    109111        Draws the grid boxes onto the axes. 
    110112        """ 
    111                          
    112  
     113         
    113114        gridColour = 'k' 
    114115        gridLineWidth = 0.25 
     
    138139        # if True + True = 2. 
    139140        # valuesFound = not grid.values.mask.sum() == len(grid.values.mask.flatten()) 
     141        # valuesFound = not grid.values.mask.sum() == reduce(lambda a,b: a*b, grid.values.shape) 
    140142         
    141143        # for now this is so quick it doesn't matter. 
    142144        valuesFound = not reduce(operator.and_, grid_mapUnits.values.mask.flat) 
    143145 
    144          
    145146        #if all the values are masked make sure the outline is drawn 
    146147        if self.showGridLines == True: 
     
    197198 
    198199    def _drawPcolormesh(self, axes, X, Y, Z, kwargs): 
     200        """ 
     201        Draw the vlaues Z at using the bounds X and Y and the pcolormesh method on the axes object.  
     202        The kwargs dictionary is passed to the pcolormesh method. 
     203        """ 
    199204        res = axes.pcolormesh(X, Y, Z, **kwargs) 
    200205        return res 
    201206     
    202207    def _drawImshow(self, axes, X, Y, Z, kwargs): 
     208        """ 
     209        Draw the values Z using the bounds X and Y and the imshow method on the axis. 
     210        The kwargs dictionary is passed to the imshow method. 
     211        """ 
    203212        yStart = Y[0,0] 
    204213        yEnd = Y[-1,-1] 
     
    212221            extent=(X.min(), X.max(),Y.min(), Y.max()) 
    213222 
    214 #        extent=(X.min(), X.max(),Y.min(), Y.max()) 
    215          
    216223        kwargs.pop('edgecolors') 
    217224        kwargs.pop('linestyle') 
     
    450457 
    451458    from numpy import meshgrid 
    452     from cdms_utils.cdms_compat import N, MA 
    453459 
    454460    x = [-6.,-4.,-2., 0., 2.] 
  • qesdi/geoplot/trunk/lib/geoplot/grid_factory.py

    r5605 r5710  
    33 
    44@author: pnorton 
     5 
     6This class is responsible for producing grid objects when given a netCDF variable  
     7and a grid type.  
     8 
     9The grid factory dosen't know how to create the grid objects for each different type,  
     10instead it uses the GridBuilder class correspoding to the datatype. 
    511''' 
    612 
     
    1117class GridFactory(object): 
    1218    """ 
     19    Object that can produced Grid objects from netCDF variables as long as the 
     20    data in the variable matches the dataType specified. 
    1321    """ 
    1422     
    1523    def __init__(self, cdmsVar=None, dataType='latlon' ): 
     24        """ 
     25        Constructor 
     26        """ 
    1627         
    1728        self.dataType = dataType 
    1829        self.cdmsVar = cdmsVar 
    1930         
    20     def getGrid(self, xLimits, yLimits): 
     31    def getGrid(self, xLimits=None, yLimits=None): 
    2132        """ 
    22         Use the current argument to build a grid object 
     33        Use the current argument to build a grid object, if possible the data in 
     34        the grid will be trimmed down to the lat/lon limits (if given). 
    2335        """ 
    2436         
    25         if self.dataType == None: 
    26             dataType = 'latlon' 
    27         else: 
    28             dataType = self.dataType 
    29          
    30         builderClass = self._getBuilderClass(dataType) 
     37        builderClass = self._getBuilderClass() 
    3138         
    3239        builder =  builderClass(self.cdmsVar) 
     
    3643        return grid 
    3744         
    38     def _getBuilderClass(self, projection): 
     45    def _getBuilderClass(self): 
     46        """ 
     47        Map the self.dataType to the correct Grid builder class, if self.dataType  
     48        is None then the latlon Grid Builder class will be returned. 
    3949         
    40         if self.dataType == 'latlon': 
     50        Raises an Exception if no Grid Builder class is found for self.dataType. 
     51        """ 
     52         
     53        if self.dataType == 'latlon' or self.dataType == None: 
    4154            return GridBuilderLatLon 
    4255         
     
    4659        elif self.dataType == 'rotated': 
    4760            return GridBuilderRotated 
     61        else: 
     62            raise Exception("No matching grid builder object found for data type '%s'" % (self.dataType,)) 
  • qesdi/geoplot/trunk/lib/geoplot/grid_plot.py

    r5699 r5710  
    88 
    99#Standard library imports 
    10 import os 
    11 import sys 
    12 import time 
    1310import logging 
    1411 
    1512from geoplot.plot_base import PlotBase 
    1613from geoplot.grid_drawer import GridDrawer 
    17  
    18 import geoplot.utils as geoplot_utils 
    1914import geoplot.config as geoplot_config 
    2015 
     
    5651         
    5752    def _drawDiagram(self, map, grid, axes): 
     53        """ 
     54        Uses the self._gridDrawer object to draw the grid onto the axis given,  
     55        using the projection described by map.basemap. 
     56        """ 
    5857         
    5958        log.debug("grid.values.min() = %s" % (grid.values.min(),)) 
  • qesdi/geoplot/trunk/lib/geoplot/image_import.py

    r5704 r5710  
    11''' 
    2 Created on 9 Sep 2009 
    3  
    4 @author: pnorton 
    5  
    62Fix to import the Image module whether it resided in PIL or not. 
    73''' 
  • qesdi/geoplot/trunk/lib/geoplot/layer_drawer.py

    r5704 r5710  
    66 
    77import logging 
    8 import StringIO 
    9 import thread 
    108import time 
    119 
    1210from matplotlib.figure import Figure 
    1311 
    14 from geoplot.image_import import Image 
    15 from geoplot.grid_builder_lat_lon import GridBuilderLatLon 
    16 from geoplot.grid_builder_national import GridBuilderNational 
    17 from geoplot.grid_builder_rotated import GridBuilderRotated 
    18  
     12import geoplot.utils as geoplot_utils 
     13from geoplot.colour_bar import ColourBar 
    1914from geoplot.grid_factory import GridFactory 
    2015from geoplot.map_factory import MapFactory 
    2116 
    22 import geoplot.utils as geoplot_utils 
    23  
    24 from geoplot.colour_bar import ColourBar 
     17 
    2518 
    2619log = logging.getLogger(__name__) 
     
    4639        self.transparent = transparent 
    4740        self.cmap = cmap 
     41         
     42        log.debug("cmapRange = %s" % (cmapRange,)) 
     43         
     44        if cmapRange[0] is not None and cmapRange[1] is not None and \ 
     45            cmapRange[0] > cmapRange[1]: 
     46            log.warning("cmapRange[0] > cmapRange[1], swapping values") 
     47            cmapRange = (cmapRange[1], cmapRange[0])              
     48         
    4849        self.cmapRange = cmapRange 
    4950        self.intervalColourbar = intervalColourbar 
     
    184185     
    185186    showGridLines = property(__get_showGridLines, __set_showGridLines)  
    186      
    187     def __set_cmapRange(self, value): 
    188         self._cmapRange = value 
    189          
    190     def __get_cmapRange(self): 
    191         return self._cmapRange 
    192      
    193     cmapRange = property(__get_cmapRange, __set_cmapRange) 
    194      
     187         
    195188    def __set_outline(self, value): 
    196189        self._gridDrawer.outline = value 
  • qesdi/geoplot/trunk/lib/geoplot/layer_drawer_coastline.py

    r5704 r5710  
    11""" 
    2 An object to draw just the layer (map + grid) from the plot,  
    3 can draw to a file, a string or create an Image object. 
     2A layer drawer that instead of drawing the data to an image just draws the  
     3coastline (and optionally the rivers) at a specified resolution. 
    44""" 
    55 
    6  
    76import logging 
    8 import StringIO 
    9 import thread 
    10  
    11 import numpy as N 
    12  
    13 from matplotlib.patches import Rectangle 
    14 from matplotlib.figure import Figure 
    15 from matplotlib.backends.backend_agg import FigureCanvasAgg 
    16 from matplotlib.lines import Line2D 
    17  
    18 from geoplot.image_import import Image 
    19 from geoplot.grid_builder_lat_lon import GridBuilderLatLon 
    20 from geoplot.grid_builder_national import GridBuilderNational 
    21 from geoplot.grid_builder_rotated import GridBuilderRotated 
    22  
    237 
    248from geoplot.layer_drawer import LayerDrawerBase 
  • qesdi/geoplot/trunk/lib/geoplot/layer_drawer_contour.py

    r5704 r5710  
    11""" 
    2 An object to draw just the layer (map + grid) from the plot,  
    3 can draw to a file, a string or create an Image object. 
     2A layer drawer that draws contours of the data onto an image object. 
    43""" 
    54 
     5import logging 
    66 
    7 import logging 
    8 import StringIO 
    9 import thread 
    10  
    11 from geoplot.image_import import Image 
    127from geoplot.contour_drawer import ContourDrawer 
    13 import geoplot.utils as geoplot_utils 
    14  
    158from geoplot.layer_drawer import LayerDrawerBase 
    169 
     
    7467    fontSize = property(__get_fontSize, __set_fontSize) 
    7568     
    76      
    7769    def __set_labelInterval(self, value): 
    7870        self._contourDrawer.contourLabelInterval = value 
  • qesdi/geoplot/trunk/lib/geoplot/layer_drawer_grid.py

    r5704 r5710  
    11""" 
    2 An object to draw just the layer (map + grid) from the plot,  
    3 can draw to a file, a string or create an Image object. 
     2A layer drawer that draws the grid boxes of the data onto an image object. 
    43""" 
    54 
     5import logging 
    66 
    7 import logging 
    8 import StringIO 
    9 import thread 
    10  
    11 import numpy as N 
    12  
    13 from matplotlib.patches import Rectangle 
    14 from matplotlib.figure import Figure 
    15 from matplotlib.backends.backend_agg import FigureCanvasAgg 
    16 from matplotlib.lines import Line2D 
    17  
    18 from geoplot.image_import import Image 
    19  
    20 from geoplot.grid_builder_lat_lon import GridBuilderLatLon 
    21 from geoplot.grid_builder_national import GridBuilderNational 
    22 from geoplot.grid_builder_rotated import GridBuilderRotated 
    23  
    24 from geoplot.map_lat_lon import MapLatLon 
    25  
     7import geoplot.utils as geoplot_utils 
    268from geoplot.grid_drawer import GridDrawer 
    27 import geoplot.utils as geoplot_utils 
    28  
    299from geoplot.layer_drawer import LayerDrawerBase 
    30 from geoplot.colour_bar import ColourBar 
    31  
    32 from matplotlib.colors import Normalize 
    3310 
    3411log = logging.getLogger(__name__) 
    35  
    36 VALID_GRID_TYPES = ['latlon', 'national', 'rotated'] 
    3712 
    3813class LayerDrawerGrid(LayerDrawerBase): 
     
    4419                 intervalNames=None): 
    4520         
    46         log.debug("transparent = %s" % (transparent,)) 
    4721        self._gridDrawer = GridDrawer() 
    4822         
    49         log.debug("cmapRange = %s" % (cmapRange,)) 
    50          
    51         if cmapRange[0] > cmapRange[1]: 
    52             log.warning("cmapRange[0] > cmapRange[1], swapping values") 
    53             cmapRange = (cmapRange[1], cmapRange[0])         
     23    
    5424         
    5525        self.cdmsVar = cdmsVar 
  • qesdi/geoplot/trunk/lib/geoplot/map_base.py

    r5683 r5710  
    99 
    1010import logging 
     11import time 
    1112 
    1213from matplotlib.collections import LineCollection 
    13 import numpy as N 
    14  
    15 import time 
    1614 
    1715log = logging.getLogger(__name__) 
    18  
    1916BASEMAP_RESOLUTION = 'i' 
    20  
    2117 
    2218class MapBase(object): 
  • qesdi/geoplot/trunk/lib/geoplot/map_lat_lon.py

    r5612 r5710  
    77import logging 
    88 
    9 from geoplot.mpl_imports import basemap 
    109from geoplot.map_base import MapBase 
    1110from geoplot.filtered_basemap import FilteredBasemap 
  • qesdi/geoplot/trunk/lib/geoplot/map_national_grid.py

    r5612 r5710  
    44Holds the MapNationalGrid class which is used to draw a grid above a national grid scaled map. This class uses the matplotlib.toolkits.basemap class to render the national grid map. 
    55""" 
    6 import time 
     6 
    77import logging 
    88import math 
     
    1111 
    1212import geoplot.mpl_imports 
    13 from geoplot.mpl_imports import basemap 
    1413from geoplot.map_base import MapBase 
    1514from geoplot.filtered_basemap import FilteredBasemap 
  • qesdi/geoplot/trunk/lib/geoplot/plot_national_grid.py

    r5610 r5710  
    66 
    77""" 
    8 import sys 
    9 import os 
    108 
    11 #geoplot imports 
     9import logging 
     10 
    1211from geoplot.grid_plot import GridPlot 
    1312 
    14 import logging 
    1513log = logging.getLogger(__name__) 
    1614 
  • qesdi/geoplot/trunk/lib/geoplot/plot_writer.py

    r5704 r5710  
    55""" 
    66import os 
    7 import sys 
    8 import pkg_resources 
    9 import time 
    107 
    118import StringIO 
  • qesdi/geoplot/trunk/lib/geoplot/plotarea.py

    r5704 r5710  
    55Holds the PlotArea class. This class is used as a wrapper to various matplotlib objects. 
    66""" 
    7 import re 
    8 import os 
    9 import pkg_resources 
    107import logging 
    118from copy import copy 
    12 from copy import deepcopy 
    139 
    1410from matplotlib.figure import Figure 
    15 from matplotlib.image import imread 
    16 from matplotlib.patches import Rectangle 
    1711from matplotlib import rcParams 
    18 import matplotlib.ticker 
    19 from geoplot.image_import import Image 
    20  
    21 from geoplot.plot_font import PlotFont 
     12 
    2213import geoplot.config as geoplot_config 
    2314 
  • qesdi/geoplot/trunk/lib/geoplot/simple_string_parsing.py

    r5605 r5710  
    22import re 
    33import csv 
    4 from StringIO import StringIO 
    54 
    65intPattern = re.compile('^\-?\d+$') 
  • qesdi/geoplot/trunk/lib/geoplot/tests/create_lat_lon_grid_var.py

    r5403 r5710  
    1 import time 
    2  
    31from cdms_utils.cdms_compat import N, cdms 
    42from geoplot.mpl_imports import basemap 
  • qesdi/geoplot/trunk/lib/geoplot/tests/make_national_grid_data.py

    r5403 r5710  
    11 
    22import cdms2 as cdms 
    3 from math import cos, sin 
    43import numpy as N 
    54from mpl_toolkits.basemap import Basemap 
  • qesdi/geoplot/trunk/lib/geoplot/tests/make_rotated_grid_data.py

    r5530 r5710  
    11 
    22import cdms2 as cdms 
    3 from math import cos, sin 
    43import numpy as N 
    54from mpl_toolkits.basemap import Basemap 
  • qesdi/geoplot/trunk/lib/geoplot/tests/unit/test_colour_bar.py

    r5688 r5710  
    99import numpy 
    1010 
     11from mock import patch, patch_object, Mock, sentinel 
     12 
    1113import matplotlib 
    1214import matplotlib.ticker 
     
    1719import geoplot.utils 
    1820import geoplot.tests.test_utils 
    19  
     21from geoplot.grid import Grid 
    2022from geoplot.plot_font import PlotFont 
    2123from geoplot.colour_bar import ColourBar 
     
    6365        norm = self.cb.getNormalize() 
    6466        nt.assert_equal((norm.vmin, norm.vmax), self.colourBarRange) 
    65          
    6667        #fixes the norm if the limits are given the wrong way round 
    6768        self.cb.colourBarMin = self.colourBarRange[1]         
     
    7778         
    7879        #set up some mock data 
    79         data = numpy.array([-9.43, -10.0, 23.232, 143.2, 13.111]) 
     80        grid = Mock(spec=Grid) 
     81        grid.values = Mock(spec=numpy.ndarray) 
    8082        dMin = -10.0; dMax = 143.2 
    81          
     83        grid.values = numpy.array([-9.43, -10.0, 23.232, 143.2, 13.111]) 
     84 
    8285        #still returns set limits when data present 
    8386        self.cb.colourBarMin = self.colourBarRange[0]         
    8487        self.cb.colourBarMax = self.colourBarRange[1]         
    85         norm = self.cb.getNormalize(data=data) 
     88        norm = self.cb.getNormalize(grid=grid) 
    8689        nt.assert_equal((norm.vmin, norm.vmax), self.colourBarRange) 
    8790         
     
    8992        self.cb.colourBarMin = None 
    9093        self.cb.colourBarMax = self.colourBarRange[1] 
    91         norm = self.cb.getNormalize(data=data) 
     94        norm = self.cb.getNormalize(grid=grid) 
    9295        nt.assert_equal((norm.vmin, norm.vmax), (dMin, self.colourBarRange[1])) 
    9396         
     
    9598        self.cb.colourBarMin = self.colourBarRange[0] 
    9699        self.cb.colourBarMax = None 
    97         norm = self.cb.getNormalize(data=data) 
     100        norm = self.cb.getNormalize(grid=grid) 
    98101        nt.assert_equal((norm.vmin, norm.vmax), (self.colourBarRange[0], dMax)) 
    99102         
     
    101104        self.cb.colourBarMin = None 
    102105        self.cb.colourBarMax = None 
    103         norm = self.cb.getNormalize(data=data) 
     106        norm = self.cb.getNormalize(grid=grid) 
    104107        nt.assert_equal((norm.vmin, norm.vmax), (dMin, dMax)) 
    105108         
    106109        #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], 
     110        grid.values = numpy.ma.MaskedArray([-9.43, -10.0, 23.232, 143.2, 13.111], 
    108111                                    mask=[True, True, True, True, True]) 
    109112        dMin = numpy.ma.MaskedArray([0], mask=True) 
     
    114117         
    115118        #still returns 0,1 as the default 
    116         norm = self.cb.getNormalize(data=data) 
     119        norm = self.cb.getNormalize(grid=grid) 
    117120        nt.assert_equal((norm.vmin, norm.vmax), (None,None)) 
    118121         
     
    120123        self.cb.colourBarMin = self.colourBarRange[0]         
    121124        self.cb.colourBarMax = self.colourBarRange[1] 
    122         norm = self.cb.getNormalize(data=data) 
     125        norm = self.cb.getNormalize(grid=grid) 
    123126        nt.assert_equal((norm.vmin, norm.vmax), self.colourBarRange) 
    124127         
     
    149152    def test_013_raiseErrorWhenSettingInvalidPositionValue(self): 
    150153        nose.tools.assert_raises(ValueError, setattr, self.cb, 'colourBarPosition', 'sideways') 
     154 
     155         
     156def not_a_method(): 
     157    raise Exception("Not a method!") 
    151158 
    152159 
     
    186193    def set_ticks_position(self, val): 
    187194        self._tickPosition = val 
     195 
    188196if __name__ == '__main__': 
    189  
    190     import geoplot.log_util 
    191  
    192     geoplot.log_util.setGeoplotHandlerToStdOut() 
    193197 
    194198    nose.runmodule() 
  • qesdi/geoplot/trunk/lib/geoplot/tests/unit/test_grid_drawer.py

    r5636 r5710  
    77 
    88from geoplot.grid import Grid 
    9 from mock import Mock 
    109 
    1110from mock import patch, patch_object, Mock, sentinel 
  • qesdi/geoplot/trunk/lib/geoplot/tests/unit/test_layer_drawer.py

    r5704 r5710  
    4141 
    4242    def test_002_makeImage(self): 
    43         #create a mock grid builder 
    44         mockGridBuilderLatLon = Mock(spec=layer_drawer.GridBuilderLatLon) 
    45         mockGridBuilderLatLon.return_value = mockGridBuilderLatLon 
    46         #create a mock grid drawer 
    47         mockGridDrawer = Mock(spec=layer_drawer_grid.GridDrawer) 
    48         mockGridDrawer.return_value = mockGridDrawer 
    4943         
    5044        #create a function that draws something on an axis 
    51         def drawBoxOnAxis(axes, grid, **kwargs): 
     45        def drawBoxOnAxis(inst, axes, xLimits=None, yLimits=None): 
    5246            axes.add_patch(Rectangle((0.1, 0.25), 0.2, 0.5, edgecolor='b', fill=False, linewidth=1)) 
    53                  
     47         
     48        ld = LayerDrawerBase() 
     49         
     50        width = 150; height=100; dpi=100 
     51         
     52        #create the figure + the axis with the layer drawer base 
     53        fig = ld._getFigure(width, height, dpi) 
     54        axes = ld._addAxes(fig) 
     55         
    5456        #use this function to create a test image 
    55         width = 150; height=100; 
    56         fig = Figure((width / 100.0, height / 100.0), dpi=100, facecolor='w') 
    57         axes = fig.add_axes([0.0, 0.0, 1.0, 1.0], xticks=[], yticks=[], frameon=False) 
    58         drawBoxOnAxis(axes, None) 
    59         #axes.add_patch(Rectangle((0.1, 0.30), 0.2, 0.5, edgecolor='b', fill=False, linewidth=1)) 
     57        drawBoxOnAxis(None, axes) 
    6058         
    6159        testImage = geoplot_utils.figureToImage(fig) 
    62                         
    63         #draw the box on the axis instead of the grid 
    64         mockGridDrawer.draw.side_effect = drawBoxOnAxis 
    6560         
    66         #apply the mocks and run the code 
     61        #replace the drawToAxes method with the drawBoxOnAxis method  
    6762        @apply 
    68         @patch('geoplot.grid_factory.GridBuilderLatLon', mockGridBuilderLatLon) 
    69         @patch('geoplot.layer_drawer_grid.GridDrawer',mockGridDrawer) 
     63        @patch('geoplot.layer_drawer.LayerDrawerBase._drawToAxes',drawBoxOnAxis) 
    7064        def do_test(): 
    71             ld = layer_drawer_grid.LayerDrawerGrid(sentinel) 
    72             im = ld.makeImage(width=width, height=height) 
     65            ld = LayerDrawerBase() 
     66            im = ld.makeImage(width=width, height=height, dpi=dpi) 
    7367             
    7468            assert issubclass(im.__class__, Image.Image) 
    75             testImage.save('/tmp/test_image.png') 
    76             im.save('/tmp/resulting_image.png') 
     69#            testImage.save('/tmp/test_image.png') 
     70#            im.save('/tmp/resulting_image.png') 
    7771            assert compareImages(testImage, im) 
    7872     
  • qesdi/geoplot/trunk/lib/geoplot/tests/unit/test_plot_base_old.py

    r5636 r5710  
    3131             'metadataList': [('Name one', 'value 1'), ('Name two', 'value 2')], 
    3232             'fontSize': "large", 'units': "degrees",  
    33              'outputCMYK':True, 'addShapefile':'some/shape/file/'} 
     33             'outputCMYK':True, 'addShapefile':'some/shape/file/', 
     34             'intervalColourbar':True, 'intervalNames':['1','2']} 
    3435 
    3536argumentTypes = {'format':str, 'width': int, 'height':int,  
     
    4344                 'plotTitle': str, 'metadataList': list, 'fontSize': str, 
    4445                 'units': str, 'outputCMYK':bool, 
    45                  'addShapefile':str} 
     46                 'addShapefile':str,'intervalColourbar':bool, 'intervalNames': list} 
    4647 
    4748dynamicDefaultArgs = ['colourBarLabel', 'colourBarPosition', 'cmap'] 
     
    8788 
    8889    def test_002_checkInitialiserSetsProperties(self): 
    89         """ 
    90         Checks that the arguments provided can be retrieved via the objects  
    91         properties. 
    92         """ 
     90        #Checks that the arguments provided can be retrieved via the objects  
     91        #properties. 
     92         
    9393        self.constructUsingArguments() 
    9494 
     
    101101         
    102102    def test_003_checkPropertiesCanBeSet(self): 
    103         """ 
    104         Chekcs that the properties can be set and then read back 
    105         """ 
     103        #Chekcs that the properties can be set and then read back 
     104         
    106105        self.constructUsingDefaults() 
    107106         
     
    213212 
    214213    import geoplot.log_util 
    215     geoplot.log_util.setGeoplotHandlerToStdOut() 
     214#    geoplot.log_util.setGeoplotHandlerToStdOut() 
    216215 
    217216    nose.runmodule() 
  • qesdi/geoplot/trunk/lib/geoplot/utils.py

    r5704 r5710  
    1414import matplotlib.colors as colors 
    1515#from matplotlib import colors 
    16 import matplotlib.backends.backend_agg 
    1716 
    1817# was having problems with alpha belnding so swapped the backend 
Note: See TracChangeset for help on using the changeset viewer.