[GRASS-SVN] r56895 - in grass/trunk/lib/python/pygrass: . raster

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Jun 23 13:03:26 PDT 2013


Author: zarch
Date: 2013-06-23 13:03:26 -0700 (Sun, 23 Jun 2013)
New Revision: 56895

Modified:
   grass/trunk/lib/python/pygrass/functions.py
   grass/trunk/lib/python/pygrass/raster/abstract.py
Log:
Add '_repr_html_' to raster Info and RasterAbstract, add r_export to functions, and fix some indent in the the docstring.

Modified: grass/trunk/lib/python/pygrass/functions.py
===================================================================
--- grass/trunk/lib/python/pygrass/functions.py	2013-06-23 20:00:59 UTC (rev 56894)
+++ grass/trunk/lib/python/pygrass/functions.py	2013-06-23 20:03:26 UTC (rev 56895)
@@ -204,3 +204,15 @@
     else:
         poi.attrs.commit()
         return True
+
+
+def r_export(rast, output='', fmt='png', **kargs):
+    from grass.pygrass.modules import Module
+    if rast.exist():
+        output = output if output else "%s_%s.%s" % (rast.name, rast.mapset,
+                                                     fmt)
+        Module('r.out.%s' % fmt, input=rast.fullname(), output=output,
+               overwrite=True, **kargs)
+        return output
+    else:
+        raise ValueError('Raster map does not exist.')

Modified: grass/trunk/lib/python/pygrass/raster/abstract.py
===================================================================
--- grass/trunk/lib/python/pygrass/raster/abstract.py	2013-06-23 20:00:59 UTC (rev 56894)
+++ grass/trunk/lib/python/pygrass/raster/abstract.py	2013-06-23 20:03:26 UTC (rev 56895)
@@ -19,6 +19,8 @@
 from grass.pygrass import functions
 from grass.pygrass.gis.region import Region
 from grass.pygrass.errors import must_be_open
+from grass.pygrass.shell.conversion import dict2html
+from grass.pygrass.shell.show import raw_figure
 
 #
 # import raster classes
@@ -142,8 +144,19 @@
                            tbres=self.tbres, zone=self.zone,
                            proj=self.proj, min=self.min, max=self.max)
 
+    def keys(self):
+        return ['name', 'mapset', 'rows', 'cols', 'north', 'south',
+                'east', 'west', 'top', 'bottom', 'nsres', 'ewres', 'tbres',
+                'zone', 'proj', 'min', 'max']
 
+    def items(self):
+        return [(k, self.__getattribute__(k)) for k in self.keys()]
 
+    def _repr_html_(self):
+        return dict2html(dict(self.items()), keys=self.keys(),
+                         border='1', kdec='b')
+
+
 class RasterAbstractBase(object):
     """Raster_abstract_base: The base class from which all sub-classes
     inherit. It does not implement any row or map access methods:
@@ -249,7 +262,6 @@
 
     name = property(fget=_get_name, fset=_set_name)
 
-
     @must_be_open
     def _get_cats_title(self):
         return self.cats.title
@@ -293,15 +305,18 @@
         """Return a constructor of the class"""
         return (self.__getitem__(irow) for irow in xrange(self._rows))
 
+    def _repr_png_(self):
+        return raw_figure(functions.r_export(self))
+
     def exist(self):
         """Return True if the map already exist, and
-           set the mapset if were not set.
+        set the mapset if were not set.
 
-           call the C function `G_find_raster`.
+        call the C function `G_find_raster`. ::
 
-           >>> ele = RasterAbstractBase('elevation')
-           >>> ele.exist()
-           True
+            >>> ele = RasterAbstractBase('elevation')
+            >>> ele.exist()
+            True
         """
         if self.name:
             if self.mapset == '':
@@ -313,11 +328,11 @@
             return False
 
     def is_open(self):
-        """Return True if the map is open False otherwise
+        """Return True if the map is open False otherwise. ::
 
-           >>> ele = RasterAbstractBase('elevation')
-           >>> ele.is_open()
-           False
+            >>> ele = RasterAbstractBase('elevation')
+            >>> ele.is_open()
+            False
 
         """
         return True if self._fd is not None and self._fd >= 0 else False
@@ -342,11 +357,11 @@
         return "{name}@{mapset}".format(name=self.name, mapset=self.mapset)
 
     def name_mapset(self, name=None, mapset=None):
-        """Return the full name of the Raster
+        """Return the full name of the Raster. ::
 
-           >>> ele = RasterAbstractBase('elevation')
-           >>> ele.name_mapset()
-           'elevation at PERMANENT'
+            >>> ele = RasterAbstractBase('elevation')
+            >>> ele.name_mapset()
+            'elevation at PERMANENT'
 
         """
         if name is None:



More information about the grass-commit mailing list