[R-sig-Geo] Performance SpatialGridDataFrame to rasterStack

Johannes Radinger JRadinger at gmx.at
Fri Mar 2 13:37:31 CET 2012


Hi,

I am not sure what you mean exactly with building a raster stack directly?
My original raster files are GRASS GIS raster files in a GRASS GIS mapset. AFAIK these files can only be loaded with readRAST6 (with the result of a SpatialGridDataFrame).

So I am not quite sure if you mean I have to use a differnet process to built the stack as my original files are no tifs (like the example).

best regards,
Johannes

-------- Original-Nachricht --------
> Datum: Fri, 2 Mar 2012 13:25:29 +0100
> Von: Johannes Signer <j.m.signer at gmail.com>
> An: Johannes Radinger <JRadinger at gmx.at>
> CC: r-sig-geo at r-project.org
> Betreff: Re: [R-sig-Geo] Performance SpatialGridDataFrame to rasterStack

> Hello,
> 
> not sure if it works for you, but why not directly build a raster
> stack (example below).
> 
> Hope this helps,
> Johannes
> 
> #
> ---------------------------------------------------------------------------- #
> library(raster)
> 
> # Create dummy data
> r1 <- raster(nrows=1000, ncols=800, xmn=0, xmx=100)
> r1 <- setValues(r1, rnorm(800000))
> 
> # write dummy rasters
> sapply(1:60, function(x) writeRaster(r1, paste("r", x, ".tif",
> sep=""), overwrite=T))
> 
> # Read read raster into a stack
> system.time(r <- stack <- do.call("stack",
> lapply(list.files(pattern="*.tif"), raster)))
> 
> # on a 3 GB netbook this took just a bit more than 11 seconds
> 
> On Fri, Mar 2, 2012 at 12:28 PM, Johannes Radinger <JRadinger at gmx.at>
> wrote:
> > Hi,
> >
> > I want to use raster maps for Species Distribution Modelling (SDM) with
> > the package 'dismo'. Therefore I load several rastermaps (around 60)
> with the readRAST6 command. For further processing I want to transform them
> into a raster stack. Each of the raster has the same spatial extent and the
> same resolution (per rastermap: around 765000 cells, thereof 760000 NA's,
> 5000 non null cells).
> >
> > The readRAST6 command to load all rasters in one step into a
> SpatialGridDataFrame works really good (1-2 min). The problem now is the tranformation
> into a stack. This takes very long time (I waited for 45 min), the CPU is
> mostly 100%, the pyhsical memory usage 3 GB (only a few MB left) and the
> virtual memory usage for R 3 GB, the HDD activity 20-30 MB/Sec data written.
> So my Computer seem to be at its maximum, and I don't have access to a
> faster/better one. I am doint all my R processes within an Eclipse workspace.
> >
> > What I do:
> > rast <- readRAST6(rast.list, cat=(FALSE,length(rast.list)),
> ignore.stderr=TRUE, plugin=NULL)
> >
> > rast.stack <- stack(rast)
> >
> >
> > Is there any way how I can improve the performance? As most of the
> raster cells are NULL cells maybe there is a special way consider that? Or
> splitting the SpatialGridDataFrame up and recombining the stacks in the end?
> > Or saving substeps to the harddisk?
> > Any help/suggestion is mostly welcome!
> >
> > Best regards,
> > Johannes
> >
> > --
> >
> > Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a
> >
> > _______________________________________________
> > R-sig-Geo mailing list
> > R-sig-Geo at r-project.org
> > https://stat.ethz.ch/mailman/listinfo/r-sig-geo

-- 

Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a



More information about the R-sig-Geo mailing list