[GRASS-dev] remove RasterNumpy class from pygrass

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

Hello,

May I suggest to remove any reference to RasterNumpy in the documentation ? I just spend some time writing a code with RasterNumpy just to realize the class was not existing.

Thanks for the workaround.

Best regards,
Laurent

···

2014-12-15 6:41 GMT-06:00 Pietro <peter.zamb@gmail.com>:

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


grass-dev mailing list
grass-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-dev