[GRASS-user] garray.read() returns 0-filled array
Stefan Blumentrath
Stefan.Blumentrath at nina.no
Sun Mar 15 15:11:16 PDT 2020
Hi Ken,
I have no experience with garray, but raster2numpy function in pygrass worked quite well for me:
https://grass.osgeo.org/grass78/manuals/libpython/pygrass.raster.html#pygrass.raster.raster2numpy
Cheers
Stefan
-----Original Message-----
From: grass-user <grass-user-bounces at lists.osgeo.org> On Behalf Of Ken Mankoff
Sent: søndag 15. mars 2020 16:36
To: GRASS user list <grass-user at lists.osgeo.org>
Subject: [GRASS-user] garray.read() returns 0-filled array
Hello,
I'm trying to use GRASS via Python and import some rasters into numpy. I'm using garray.read(raster) and the result is always 0. When I inspect the raster in GRASS (via bash) it is not zero. I can re-create this with the following MWE. Can someone suggest what I might be doing wrong or if this is a bug?
Thank you,
-k.
import numpy as np
import shutil
import os
from grass_session import Session
from grass.pygrass.modules.shortcuts import general as g from grass.pygrass.modules.shortcuts import raster as r import grass.script.array as garray
if os.path.exists("G_test"): # reset everything
shutil.rmtree("G_test", ignore_errors=False, onerror=None)
W = Session()
W.open(gisdb='.', location='G_test', create_opts="EPSG:3413") g.region(w=0, s=0, n=100, e=100) r.mapcalc("foo = 42.24") foo = garray.array().read("foo", null=np.nan)
W.close()
print(np.max(foo))
# 0.0 is
_______________________________________________
grass-user mailing list
grass-user at lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user
More information about the grass-user
mailing list