raster

Parallel processing of big rasters in R (windows)

夙愿已清 提交于 2020-01-23 05:34:05
问题 I'm using the doSNOW package and more specifically the parLapply function to perform reclassification (and subsequently other operations) on a list of big raster datasets (OS: Windows x64). The code looks a little like this minimalistic example: library(raster) library(doSNOW) #create list containing test rasters x <- raster(ncol=10980,nrow=10980) x <- setValues(x,1:ncell(x)) list.x <- replicate( 9 , x ) #setting up cluster NumberOfCluster <- 8 cl <- makeCluster(NumberOfCluster)

Fastest way to extract a raster in R (improve the time of my reproducible code)

蓝咒 提交于 2020-01-23 01:11:10
问题 I'm wondering if I have maximized the speed at which a mean of an area buffered around a point in a raster can be extracted. Can performance be improved any further on these LOCALLY? I use parallel mclapply already, and I know I could get further gains by setting up and running this on a cluster (use a cluster or get more cpu's is not the answer I'm looking for). Replicate some data: library(raster) library(parallel) library(truncnorm) library(gdalUtils) library(velox) library(sf) ras <-

How to set use ggplot2 to map a raster

筅森魡賤 提交于 2020-01-22 04:19:07
问题 I would like to make a plot using R studio similar to the one below (created in Arc Map) I have tried the following code: # data processing library(ggplot2) # spatial library(raster) library(rasterVis) library(rgdal) # test <- raster(paste(datafold,'oregon_masked_tmean_2013_12.tif',sep="")) # read the temperature raster OR<-readOGR(dsn=ORpath, layer="Oregon_10N") # read the Oregon state boundary shapefile gplot(test) + geom_tile(aes(fill=factor(value),alpha=0.8)) + geom_polygon(data=OR, aes(x

Matching the resolution of two rasters

会有一股神秘感。 提交于 2020-01-15 03:11:28
问题 Im working with two rasters each with a different resolution. Im wondering if there is a more efficient way of matching the coarser raster resolution to the finer raster resolution. Right now I am using the mask function to save some time, clip to the correct extent and change the resolution: library(raster) #the raster template with the desired resolution r <- raster(extent(-180, 180, -64, 84), res=0.04166667) # set some pixels to values, others to NA r <- setValues(r, sample(c(1:3, NA),

R: Interpolation between raster layers of different dates

心不动则不痛 提交于 2020-01-14 13:31:29
问题 Let's say I have 4 raster layers with the same extend with data of 4 different years: 2006,2008,2010 and 2012: library(raster) r2006<-raster(ncol=3, nrow=3) values(r2006)<-1:9 r2008<-raster(ncol=3, nrow=3) values(r2008)<-3:11 r2010<-raster(ncol=3, nrow=3) values(r2010)<-5:13 r2012<-raster(ncol=3, nrow=3) values(r2012)<-7:15 Now I want to create raster layers for every year between 2006 and 2013 (or even longer) by inter-/extrapolating (a linear method should be a good start) the values of the

How to replace NA's in a raster object

岁酱吖の 提交于 2020-01-12 03:21:50
问题 I need to replace the NA 's in the raster object ( r ) from the example below. library(raster) filename <- system.file("external/test.grd", package="raster") r <- raster(filename) I also tried to remove these these (and place the result in a data.frame ), but to no avail. dfr <- as.data.frame(r, na.rm=T) summary(dfr) # test # Min. : 128.4 # 1st Qu.: 293.2 # Median : 371.4 # Mean : 423.2 # 3rd Qu.: 499.8 # Max. :1805.8 # NA's :6097 回答1: I'm not sure it makes sense to remove NA values from a

Plotting a raster with the color ramp diverging around zero

我只是一个虾纸丫 提交于 2020-01-10 08:30:09
问题 I am trying to plot a map with positive and negative values. All positive values should have red color while negative should have blue color and zero should have white just like in this sample plot with discrete colors Below is the code I'm using: library (rasterVis) ras1 <- raster(nrow=10,ncol=10) set.seed(1) ras1[] <- rchisq(df=10,n=10*10) ras2=ras1*(-1)/2 s <- stack(ras1,ras2) levelplot(s,par.settings=RdBuTheme()) Thanks very much for providing a general solution which can be applied in

Plotting a raster with the color ramp diverging around zero

妖精的绣舞 提交于 2020-01-10 08:29:31
问题 I am trying to plot a map with positive and negative values. All positive values should have red color while negative should have blue color and zero should have white just like in this sample plot with discrete colors Below is the code I'm using: library (rasterVis) ras1 <- raster(nrow=10,ncol=10) set.seed(1) ras1[] <- rchisq(df=10,n=10*10) ras2=ras1*(-1)/2 s <- stack(ras1,ras2) levelplot(s,par.settings=RdBuTheme()) Thanks very much for providing a general solution which can be applied in

Increment Loop in Batches

…衆ロ難τιáo~ 提交于 2020-01-07 01:49:39
问题 I was hoping someone could help me with a loop function I'm working with. I have tried searching Google and Stack Overflow extensively but, as I don't know the exact search terminology, I fear I am missing some results. With that in mind, I apologise in advance if this question has already been asked but I hope that someone can point me in the right direction for a solution. About My Data I have downloaded 1000s of files from NASAs MODIS satellite. As my study area covers a large area, I've

Thornthwaite evapotranspiration on a raster dataset . Error formula not vectorised

浪子不回头ぞ 提交于 2020-01-06 06:00:08
问题 I am trying to calculate evapotranspiration (ET) for running SPEI on a raster dataset by using the Thornthwaite ET formula included in the SPEI package this is my code library(SPEI) library(raster) library(zoo) tm = array(1:(3*4*12*64),c(3,4,12*64)) tm = brick(tm) dates=seq(as.Date("1950-01-01"), as.Date("2013-12-31"), by="month") tm<- setZ(tm,dates) names(tm) <- as.yearmon(getZ(tm)) thornthwaite ET th <- function(Tave, lat) { SPEI::thornthwaite(Tave, lat) } lat <- setValues(a, coordinates(tm