Skip to content

extracting time series data from a raster brick of AVHRR satellite data

8 messages · Martin, Jan Verbesselt, Robert J. Hijmans

#
what I do to extract a pixel is:
this is extremely fast, but you need to know the row and col of the pixel... 

--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/extracting-time-series-data-from-a-raster-brick-of-AVHRR-satellite-data-tp6622055p6622389.html
Sent from the R-sig-geo mailing list archive at Nabble.com.
#
sorry, it has to be:
btw: does anyone know how to get the row, col information in QGIS or GRASS?

--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/extracting-time-series-data-from-a-raster-brick-of-AVHRR-satellite-data-tp6622055p6623034.html
Sent from the R-sig-geo mailing list archive at Nabble.com.
#
I have done the following:

1. read a small subset of the modis image time series (2000-2011, i.e. 262
images) in and save as a raster stack.
2. below read in the .grd file as a brick with 262 layers and dim = 17,13
containing integer values
3. now I am trying to extract time series per pixel for further processing,
this however is very slow.
It takes more than 30sec for one time series. I have tried modis[row,col]
but this is not faster.

Any advice? Should I do this via Python or can this be done via R but more
efficient?
[1] 262
[1]  17  13 262
user  system elapsed 
 35.985   0.084  36.194
user  system elapsed 
 35.847   0.076  36.051 



--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/extracting-time-series-data-from-a-raster-brick-of-AVHRR-satellite-data-tp6622055p6625919.html
Sent from the R-sig-geo mailing list archive at Nabble.com.
#
Jan,
Interesting problem, that I had not noticed before. I think this is because
a loop that can perhaps be omitted or else perhaps needs to move to a C
routine. I need to investigate that. For now, for speed, either read the
values into memory (if possible; perhaps a spatial subset, via 'crop'), or
perhaps use ncdf files (see example below).
Loading required package: sp
raster version 1.9-3 (27-July-2011)
user  system elapsed 
      0       0       0
[1] FALSE
user  system elapsed 
  61.54    0.14   61.98
[1] TRUE
user  system elapsed 
      0       0       0
Loading required package: ncdf
[1] FALSE
user  system elapsed 
   0.01    0.00    0.02
Robert


--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/extracting-time-series-data-from-a-raster-brick-of-AVHRR-satellite-data-tp6622055p6627415.html
Sent from the R-sig-geo mailing list archive at Nabble.com.
#
Robert,

I have tried the different options - and based on your example below with
the simulated raster brick everything works fine.
However when applying it to my dataset a few things/errors occur.

This is my dataset:
class       : RasterStack
dimensions  : 17, 13, 262  (nrow, ncol, nlayers)
resolution  : 231.6564, 231.6564  (x, y)
extent      : 305554.7, 308566.3, 5713341, 5717279  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=sinu +lon_0=0 +x_0=0 +y_0=0 +a=6371007.181
+b=6371007.181 +units=m +no_defs
min values  : 2874  535 2526 3779 3626 4520 5747 4820  502 4962 ...
max values  : 7671 9126 7660 7181 8723 8217 8513 8581 8979 8854 ...

1/ when trying:
Error in `dataType<-`(`*tmp*`, value = "FLT4S") :
  Cannot set datatype of a RasterStack

I tried setting the datatype to ,datatype='INT2U' but this gave the same
error. How could this be solved?

2/ When doing the following in a new R session:
modis <- stack("modis.grd")
modis <- readAll(modis)
[1] FALSE

somehow when loading the file from disk in a new R session and then doing
readAll() is does not load it into memory and when trying modis[1] is
remains slow. How can I make sure that the file loads into memory?

3/ therefore I currently opted for the following:
user  system elapsed
  0.347   0.030   0.453

## create a time series
d <- as.vector(m[70,]) # extract cell 70 from the matrix m

Thanks for your help. I really like the 'raster' package so let me know how
I can help testing the package.


On Wed, Jul 27, 2011 at 9:23 PM, Robert Hijmans [via R-sig-geo] <
ml-node+6627415-691589920-304146 at n2.nabble.com> wrote:

            
--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/extracting-time-series-data-from-a-raster-brick-of-AVHRR-satellite-data-tp6622055p6629146.html
Sent from the R-sig-geo mailing list archive at Nabble.com.
#
I have also made the 'modis.grd' data available via:
## Public Link
download.file("http://dl.dropbox.com/u/8150174/raster/modis.grd","m.grd")
download.file("http://dl.dropbox.com/u/8150174/raster/modis.gri","m.gri")

More info here:
https://r-forge.r-project.org/forum/forum.php?thread_id=3881&forum_id=962&group_id=294

Thanks, Jan


--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/extracting-time-series-data-from-a-raster-brick-of-AVHRR-satellite-data-tp6622055p6629166.html
Sent from the R-sig-geo mailing list archive at Nabble.com.
#
On Thu, Jul 28, 2011 at 1:53 AM, janverbesselt [via R-sig-geo] <
ml-node+6629146-1537221348-149542 at n2.nabble.com> wrote:

            
Ah, bug, happens when values of b are in memory, not when they are on disk.
Fixed in devel version. Thanks, Robert
Oh, that not right either (readAll with a RasterStack does not set the
inMemory flag correctly).

modis <- brick("modis.grd")
modis <- readAll(modis)
Precisely by sending these type of reports.
Thanks, Robert.
--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/extracting-time-series-data-from-a-raster-brick-of-AVHRR-satellite-data-tp6622055p6629299.html
Sent from the R-sig-geo mailing list archive at Nabble.com.