[GRASS-user] garray.read() returns 0-filled array

Ken Mankoff mankoff at gmail.com
Sun Mar 15 08:36:14 PDT 2020


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 


More information about the grass-user mailing list