[GRASS-user] Read/Write numpy array

Johannes Radinger JRadinger at gmx.at
Tue Apr 5 05:37:34 EDT 2011


Hello,

I try to do a mapcalculation with scipy (do to limited functionality of 
usual mapcalc functions.

Therefore I want to read a map into numpy-array, do the calculation on it and write it back to a GRASS-map. I tried to follow the instructions in the wiki (http://grass.osgeo.org/wiki/GRASS_and_Python#Interfacing_with_NumPy) but I got stucked when it comes to the writing-process.
Thats my code so far:

    x = garray.array()
    x.read("distance_raster")
    Density = garray.array()
    Density = p * stats.norm.pdf(x,loc=m, scale=s1*K) + (1-p) * stats.norm.pdf(x, loc=m, scale=s2*K)
    Density.write("Density")

The stats.norm.pdf is from the stats-scipy module. I get following error when I try to process the script:

   Density.write("Density")
AttributeError: 'numpy.ndarray' object has no attribute
'write'

I don't know excactly what how I have to use the write command. I am working on 6.5 and I read there were some problems with numpy-arrays. Are the solved now?

/johannes
-- 
GMX DSL Doppel-Flat ab 19,99 Euro/mtl.! Jetzt mit 
gratis Handy-Flat! http://portal.gmx.net/de/go/dsl


More information about the grass-user mailing list