[R-sig-Geo] Impoting multiple asci grids into R?

Edzer Pebesma edzer.pebesma at uni-muenster.de
Mon Oct 31 14:55:27 CET 2011


Oscar, good to see that that works (although I couldn't work out the 
logic behind the ordering of months in plot(sMean))

I think the point I wanted to make was, if a function aggregates, can it 
be made into a method instance that has the name "aggregate".

How does a user find out s/he needs zApply? Or Which or which?

Why, in zApply, did you choose the signature (x, by, fun=mean, ...) 
where aggregate has (x, by, FUN, ...) ?

I believe that adding functions adds to complexity, where adding to 
methods reduces it.

On 10/31/2011 12:32 PM, Oscar Perpiñan Lamigueiro wrote:
> 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

-- 
Edzer Pebesma
Institute for Geoinformatics (ifgi), University of Münster
Weseler Straße 253, 48151 Münster, Germany. Phone: +49 251
8333081, Fax: +49 251 8339763  http://ifgi.uni-muenster.de
http://www.52north.org/geostatistics      e.pebesma at wwu.de



More information about the R-sig-Geo mailing list