[STATSGRASS] Problems understanding how to use Rpy ( a Python
module) to access GRASS rasters in R
Trevor Wiens
twiens at interbaun.com
Thu Feb 17 21:41:14 EST 2005
On Thu, 17 Feb 2005 08:24:05 -0700
William Hudspeth <bhudspeth at edac.unm.edu> wrote:
> Hello,
>
> I have previously used BASH shell scripts to successfully pass GRASS
> raster data sets to R, and then run basic statistics and plotting
> functions. Now, I am using Rpy 0.4.0 in an application that loads the
> GRASS GIS library. Prior to calling Rpy functions, I make sure to use
> Python to set up all of my environmental variables. I am then able to
> use code such as you see below to load my GRASS location metadata into
> Python objects:
>
> r_results=r.library('GRASS')
> G=r.gmeta()
> maps=r.get_mapsets()
> raster_layers=r.list_grass(type="cell")
>
> I understand that the variables on the left are Python objects - I can
> print out correct locational values to screen. However, if I want to
> summarize and plot the values in a certain raster map layer, I know that
> I probably need to create an R object first. It is not clear to me how I
> go about doing this given what I have read in the Rpy documentation. I
> have tried to move a raster into a Python object as such:
>
> elev=r.rast_get(G,"elevation")
>
> but, this fails with the error
>
> sh: line 1: rm command not found
>
I've done some work with Rpy with varied success. What I have often found difficult is the translation betwen Python objects and R objects with can be controlled with
mode = get_default_mode()
set_default_mode(NO_CONVERSION)
so you can set it back later. This is important for sum functions. I've not tried to use the GRASS library through Rpy.
There is also an Rpy mailing list which I read and their may be individuals on that list who may be able to help. Roger had suggested simple examples, and I have found those types of tasks, regression, AIC model selection and such work fine along with many plotting tasks in conjunction with pyPgSQL.
T
--
Trevor Wiens
twiens at interbaun.com
The significant problems that we face cannot be solved at the same
level of thinking we were at when we created them.
(Albert Einstein)
More information about the grass-stats
mailing list