[GRASS-dev] pygrass numpy object int and float data

Hi,
I have a CELL (integer) layer.

If I write these lines:

map=raster.RasterNumpy("grassmap")
map.open()
map.close()

I obtain:

  File "./r.grow.dir.incl4.py", line 310, in <module>
    main()
  File "./r.grow.dir.incl4.py", line 133, in main
    visited.close()
  File
"/usr/local/grass-7.0.svn/etc/python/grass/pygrass/raster/__init__.py",
line 664, in close
    self._write()
  File
"/usr/local/grass-7.0.svn/etc/python/grass/pygrass/raster/__init__.py",
line 607, in _write
    self.tofile(self.filename)
ValueError: 160000 requested and 0 written

if i write:

map=raster.RasterNumpy("grassmap")
map.open()
map=map*1.0
map.close()

it works.

Do the numpy raster object is, by default, a float type?

what I miss?

Many thanks

Ivan

Hi Ivan,

On Thu, Jun 27, 2013 at 10:03 AM, Ivan Marchesini
<ivan.marchesini@gmail.com> wrote:

Hi,
I have a CELL (integer) layer.

Do the numpy raster object is, by default, a float type?

yes, a numpy array is by default a float, you can open a map with
different type with:

rast.open(mode='w', mtype='CELL')

This should work, however I had some Segmentation Fault using
RasterNumpy and integer in the past and I'm not sure it is working at
the moment...
Let me know! :slight_smile:

Pietro