1 """!@package grass.script.array
3 @brief GRASS Python scripting module (rasters with numpy)
5 Functions to use GRASS rasters with NumPy.
13 # calculate something on array
18 (C) 2010-2011 by Glynn Clements and the GRASS Development Team
19 This program is free software under the GNU General Public
20 License (>=v2). Read the file COPYING that comes with GRASS
23 @author Glynn Clements
33 gettext.install(
'grasslibs', os.path.join(os.getenv(
"GISBASE"),
'locale'), unicode =
True)
37 """!Define new numpy array
40 @param dtype data type (default: numpy.double)
47 filename = grass.tempfile()
49 self = numpy.memmap.__new__(
60 numpy.memmap._close(self)
61 if isinstance(self, array):
64 def read(self, mapname, null = None):
65 """!Read raster map into array
67 @param mapname name of raster map to be read
68 @param null null value
71 @return non-zero code on failure
73 kind = self.dtype.kind
74 size = self.dtype.itemsize
81 raise ValueError(_(
'Invalid kind <%s>') % kind)
83 if size
not in [1,2,4,8]:
84 raise ValueError(_(
'Invalid size <%d>') % size)
86 return grass.run_command(
90 output = self.filename,
95 def write(self, mapname, title = None, null = None, overwrite = None):
96 """!Write array into raster map
98 @param mapname name for raster map
99 @param title title for raster map
100 @param null null value
101 @param overwrite True for overwritting existing raster maps
104 @return non-zero code on failure
106 kind = self.dtype.kind
107 size = self.dtype.itemsize
115 raise ValueError(_(
'Invalid FP size <%d>') % size)
118 if size
not in [1,2,4]:
119 raise ValueError(_(
'Invalid integer size <%d>') % size)
122 raise ValueError(_(
'Invalid kind <%s>') % kind)
126 return grass.run_command(
129 input = self.filename,
134 overwrite = overwrite,
def __new__
Define new numpy array.
def read
Read raster map into array.
def write
Write array into raster map.