[GRASS-dev] problem using pygrass

Javier Martínez-López javi.martinez.lopez at gmail.com
Tue Mar 4 06:38:07 PST 2014


Hello again,

I keep testing it and I get the following errors when trying to save
the results into a new raster map:

out = pygrass.raster.RasterNumpy('eco_pa22') # eco_pa22 is a raster
map which I created just to fill it in with new values

out.open('w',mtype='FCELL')

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: open() got multiple values for keyword argument 'mtype'

out.open('w')

out.max()
1
out.min()
0

out = np.where(out >= 0,(pmh),(pmh))  # filling the map with the values from pmh

out.max()

RasterNumpy(0.9995180622329483)

out.min()

RasterNumpy(0.0)

>>> out.close()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/grass-7.0.svn/etc/python/grass/pygrass/raster/__init__.py",
line 655, in close
    np.memmap._close(self)
AttributeError: type object 'memmap' has no attribute '_close'
>>> out
RasterNumpy([[ 0.,  0.,  0., ...,  0.,  0.,  0.],
       [ 0.,  0.,  0., ...,  0.,  0.,  0.],
       [ 0.,  0.,  0., ...,  0.,  0.,  0.],
       ...,
       [ 0.,  0.,  0., ...,  0.,  0.,  0.],
       [ 0.,  0.,  0., ...,  0.,  0.,  0.],
       [ 0.,  0.,  0., ...,  0.,  0.,  0.]])

Am I doing something wrong? Is there an easy way to get the raster map
out as a tiff file instead to avoid this problem?

Thank you very much!

Cheers,

Javier

On Sat, Mar 1, 2014 at 12:11 AM, Luca Delucchi <lucadeluge at gmail.com> wrote:
> On 27 February 2014 22:06, Pietro <peter.zamb at gmail.com> wrote:
>> Hi Javier,
>>
>
> Hi,
>
>>
>> yes, this bug should be fixed in (r59127), I've tried this code using
>> the North Carolina mapset:
>>
>> from grass.pygrass.raster import RasterNumpy
>> elev = RasterNumpy('elevation')
>> elev.open()
>> flt = elev.flatten()
>> len(flt)
>> elev.close()
>>
>> and it works, are you in Linux?
>>
>
> I confirm this.
> I would also add that it if you want to save the map you have to use:
>
> flt = pygrass.raster.RasterNumpy('elevation_flatten')
> flt.open('w',mtype='FCELL')
> flt = elev.flatten()
> elev.close()
> flt.close()
>
> otherwise you obtain an error (segmentation fault)
>
> --
> ciao
> Luca
>
> http://gis.cri.fmach.it/delucchi/
> www.lucadelu.org


More information about the grass-dev mailing list