raster data in R

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

raster data in R

Marisa Donnelly

Hello, 
I am currently working on a project attempts to summarize the potential mosquito reproductive rate of regions in California given the region's mean annual daily temperature. I have a written a model in R that uses temperature as an input and outputs the reproductive rate given that temperature. I have also constructed a raster map in GRASS GIS version 7.1 of the aggregated California daily tmean values for a year. I would like to take the tmean temperature value of each pixel in the California map, input it into my model in R, and generate a reproductive rate for each pixel, which I would then like to be able to map. I would like to find the best and most efficient way to bring in the map data into R and input it into my model. Do you any suggestions for the best way to do this? 
--
Marisa Donnelly
Ph.D. Student
Graduate Group in Epidemiology
University of California, Davis
[hidden email]

_______________________________________________
grass-stats mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-stats
Reply | Threaded
Open this post in threaded view
|

Re: raster data in R

RKrug
Marisa Donnelly <[hidden email]> writes:

> Hello,
> I am currently working on a project attempts to summarize the potential
> mosquito reproductive rate of regions in California given the region's mean
> annual daily temperature. I have a written a model in R that uses
> temperature as an input and outputs the reproductive rate given that
> temperature. I have also constructed a raster map in GRASS GIS version 7.1
> of the aggregated California daily tmean values for a year. I would like to
> take the tmean temperature value of each pixel in the California map, input
> it into my model in R, and generate a reproductive rate for each pixel,
> which I would then like to be able to map. I would like to find the best
> and most efficient way to bring in the map data into R and input it into my
> model. Do you any suggestions for the best way to do this?
I assume that you are accustomed to using R.

Just check out the rgrass7 package - readRAST() allows you to read your
raster, then you do your calculations with the data, then you add them
to the map object in R and finally you can safe them by using
writeRAST() back to GRASS.

Cheers,

Rainer
--
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Stellenbosch University
South Africa

Tel :       +33 - (0)9 53 10 27 44
Cell:       +33 - (0)6 85 62 59 98
Fax :       +33 - (0)9 58 10 27 44

Fax (D):    +49 - (0)3 21 21 25 22 44

email:      [hidden email]

Skype:      RMkrug

PGP: 0x0F52F982

_______________________________________________
grass-stats mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-stats

signature.asc (490 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: raster data in R

Markus Neteler
Hi Rainer,

On Thu, Sep 10, 2015 at 4:36 PM, Rainer M Krug <[hidden email]> wrote:
...
> Just check out the rgrass7 package - readRAST() allows you to read your
> raster, then you do your calculations with the data,

... this calculation part is the question of Marisa... any recommended
tutorials on how to loop over pixels in R after having used
readRAST()?

> then you add them
> to the map object in R and finally you can safe them by using
> writeRAST() back to GRASS.

Yes, that part is clear. Just the "loop" best practice not so much.

thanks
Markus
_______________________________________________
grass-stats mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-stats
Reply | Threaded
Open this post in threaded view
|

Re: raster data in R

Marisa Donnelly
Hi Rainer, 
This clarifies things a great deal. I'll try it and let you know, but it makes sense so I don't anticipate needing an example. 
Thank you!
Marisa

On Thu, Sep 10, 2015 at 8:22 PM, Rainer M Krug <[hidden email]> wrote:


Envoyé de mon iPhone

> Le 10 sept. 2015 à 16:47, Markus Neteler <[hidden email]> a écrit :
>
> Hi Rainer,
>
>> On Thu, Sep 10, 2015 at 4:36 PM, Rainer M Krug <[hidden email]> wrote:
>> ...
>> Just check out the rgrass7 package - readRAST() allows you to read your
>> raster, then you do your calculations with the data,
>
> ... this calculation part is the question of Marisa... any recommended
> tutorials on how to loop over pixels in R after having used
> readRAST()?

The data slot of the returned SpatialGridDataFrame is simply a data.frame with one cell per row. So you can simply iterate over each row and add the results as a new column, which you can then save. If the function is vectorizes, you don't even have to iterate but R can do the work. If necessary, I can send you a small example tomorrow- just let me know.

Hope this helps,

Rainer

>
>> then you add them
>> to the map object in R and finally you can safe them by using
>> writeRAST() back to GRASS.
>
> Yes, that part is clear. Just the "loop" best practice not so much.
>
> thanks
> Markus



--
Marisa Donnelly
Ph.D. Student
Graduate Group in Epidemiology
University of California, Davis
[hidden email]

_______________________________________________
grass-stats mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-stats
Reply | Threaded
Open this post in threaded view
|

Re: raster data in R

RKrug
Marisa Donnelly <[hidden email]> writes:

> Hi Rainer,
> This clarifies things a great deal. I'll try it and let you know, but it
> makes sense so I don't anticipate needing an example.
> Thank you!

Pleasure

Just check out

?"SpatialGridDataFrame-class"

in R and you find the info about the object returned by readfRAST().

Among other info, it states:

,----
| Slots:
|
|      ‘grid’: see GridTopology-class; grid parameters
|
|      ‘bbox’: Object of class ‘"matrix"’; bounding box
|
|      ‘proj4string’: Object of class ‘"CRS"’; projection
|
|      ‘data’: Object of class data.frame, containing attribute data
`----

Cheers,

Rainer

> Marisa
>
> On Thu, Sep 10, 2015 at 8:22 PM, Rainer M Krug <[hidden email]> wrote:
>
>>
>>
>> Envoyé de mon iPhone
>>
>> > Le 10 sept. 2015 à 16:47, Markus Neteler <[hidden email]> a écrit :
>> >
>> > Hi Rainer,
>> >
>> >> On Thu, Sep 10, 2015 at 4:36 PM, Rainer M Krug <[hidden email]> wrote:
>> >> ...
>> >> Just check out the rgrass7 package - readRAST() allows you to read your
>> >> raster, then you do your calculations with the data,
>> >
>> > ... this calculation part is the question of Marisa... any recommended
>> > tutorials on how to loop over pixels in R after having used
>> > readRAST()?
>>
>> The data slot of the returned SpatialGridDataFrame is simply a data.frame
>> with one cell per row. So you can simply iterate over each row and add the
>> results as a new column, which you can then save. If the function is
>> vectorizes, you don't even have to iterate but R can do the work. If
>> necessary, I can send you a small example tomorrow- just let me know.
>>
>> Hope this helps,
>>
>> Rainer
>>
>> >
>> >> then you add them
>> >> to the map object in R and finally you can safe them by using
>> >> writeRAST() back to GRASS.
>> >
>> > Yes, that part is clear. Just the "loop" best practice not so much.
>> >
>> > thanks
>> > Markus
>>
--
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Stellenbosch University
South Africa

Tel :       +33 - (0)9 53 10 27 44
Cell:       +33 - (0)6 85 62 59 98
Fax :       +33 - (0)9 58 10 27 44

Fax (D):    +49 - (0)3 21 21 25 22 44

email:      [hidden email]

Skype:      RMkrug

PGP: 0x0F52F982

_______________________________________________
grass-stats mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-stats

signature.asc (490 bytes) Download Attachment