grass
grass copied to clipboard
[Bug] numpy2raster does not respect pygrass region
Describe the bug in contrast to raster2numpy, numpy2raster does not respect region set with pygrass, but rather reads WIND file to check if columns and rows in array match with the computational region.
To Reproduce
from grass.pygrass.gis.region import Region
from grass.pygrass.raster import raster2numpy
from grass.pygrass.raster import numpy2raster
pygrass_region = Region()
# Show pygrass region
print(pygrass_region)
# Adjust pygrass region
pygrass_region.south = pygrass_region.south + 100 * pygrass_region.nsres
pygrass_region.set_raster_region()
# Show changed pygrass region
print(pygrass_region)
np_array = raster2numpy("landclass96")
# Check rows and columns in numpy array
print(np_array.shape)
# Try to write np_array back with the changed region
numpy2raster(np_array, "CELL", "testwrite", overwrite=True)
# Fails, however after:
pygrass_region.write() # WIND file is changed
numpy2raster(np_array, "CELL", "testwrite", overwrite=True)
# writes properly
Expected behavior
numpy2raster should behave just like raster2numpy and work with the computational region set with Region() object in pygrass, so workarounds with gscript.use_temp_region() or os.environ["WIND_OVERRIDE"] = tempregion are no longer necessary.
System description:
- Operating System: Ubuntu Linux 18.04
- GRASS GIS version: 7.8.3, 7.9