[GRASS-dev] remove RasterNumpy class from pygrass

Pietro peter.zamb at gmail.com
Mon Dec 15 04:41:41 PST 2014


Dear all,

If you are ok with that, I would like to remove the RasterNumpy class,
as far as I aware, nobody is using it.
So I would like to avoid to introduce a class in grass70 and remove
the class in grass71.
However the RasterNumpy class can be easily replaced by functions like:

{{{
def raster2numpy(rastname):
    """Return a numpy array from a raster map"""
    with RasterRow(rastname, mode='r') as rast:
        return np.array(rast)


def numpy2raster(array, mtype, rastname):
    """Save a numpy array to a raster map"""
    reg = Region()
    if (reg.rows, reg.cols) != array.shape:
        msg = "Region and array are different: %r != %r"
        raise TypeError(msg % ((reg.rows, reg.cols), array.shape))
    with RasterRow(rastname, mode='w', mtype=mtype) as new:
        newrow = Buffer((array.shape[1],), mtype=mtype)
        for row in array:
            newrow[:] = row[:]
            new.put_row(newrow)
}}}

Any concern on this?

Best regards

Pietro


More information about the grass-dev mailing list