[R-sig-Geo] Impoting multiple asci grids into R?
Oscar Perpiñan Lamigueiro
oscar.perpinan at upm.es
Mon Oct 31 12:32:19 CET 2011
Hello,
I think the zApply method in raster could be useful here. For example:
library(sp)
library(raster)
## 30 rows, 84 cols, 399 layers of data
url <- "ftp://ftp.wiley.com/public/sci_tech_med/spatio_temporal_data/"
sst.dat = read.table(paste(url, "SST011970_032003.dat", sep=''), header
= FALSE)
sst.ll = read.table(paste(url, "SSTlonlat.dat", sep=''),
header = FALSE)
sp <- SpatialPointsDataFrame(sst.ll, sst.dat)
gridded(sp) <- TRUE
proj4string(sp) = "+proj=longlat +datum=WGS84"
s <- brick(sp)
idx <- seq(as.Date('1970-01-01'), as.Date('2003-03-01'), by='month')
s <- setZ(s, idx)
layerNames(s) <- as.character(idx)
sMean <- zApply(s, by = months)
Best,
Oscar.
-------------------
Oscar Perpiñán Lamigueiro
Dpto. Ingeniería Eléctrica
EUITI-UPM
http://procomun.wordpress.com
>Dear Carsten, Tom, Robert and Edzer,
>thank you very much for your answers! And yes Robert, you are right, I
>like to calculate the mean of raster cells across the layers. I just
>tried the EtRR.sum<- calc(EtRR, mean) on the layer stack.
>Unfortunately the computation of only one month is taking now longer
>than the computation of all 12 months using my old script. I will now
>have a look on Edzers proposal.
>
>Again, thank you all!
>
>Best,
>
>Swen
>
>
>Am 31.10.2011 09:58, schrieb Edzer Pebesma:
>> So, raster::aggregate does spatial aggregation, and calc does
>> temporal aggregation when the stack reflect time. Do you see
>> possibilities to extend the behaviour of raster::aggregate to
>> generalize stats::aggregate, and e.g. in the temporal domain to
>> extend/reuse zoo::aggregate? Besides a grouping predicate ("by"),
>> zoo::aggregate allows a grouping function that works on time, giving
>> you e.g. aggregations to monthly, quarterly and yearly values
>> without effort.
>>
>> I tried this approach for the classes in package spacetime, some of
>> which generalize the raster time-stack but lack its powerful disk
>> caching. For spatio-temporal objects this was documented here:
>> http://cran.r-project.org/web/packages/spacetime/vignettes/sto.pdf
>> and for spatial (sp) objects here:
>> http://cran.r-project.org/web/packages/sp/vignettes/over.pdf
>>
>> Any comments welcome. Best regards,
>> --
>> Edzer
More information about the R-sig-Geo
mailing list