我们在Ubuntu上运行的实验室中有一个24核HP工作站。我们正在使用RStudio并使用并行计算包。以下是我们的代码。
但是,我们总是得到错误消息:.local(x,...)中的错误:不是有效的子集
setwd("/home/physics/Documents/PNU OJT/January")
getwd()
library(RNetCDF)
library(ncdf4)
library(raster)
library(sp)
library(rasterVis)
library(chron)
library(RColorBrewer)
library(lattice)
library(maptools)
library(parallel)
library(rgdal)
library(rgeos)
f <- function(s){
for(i in 1:5){
mask(s, PHL[PHL@data$OBJECTID== i,])
MeanPW<- cellStats(mask(s, PHL[PHL@data$OBJECTID== i,]),
stat=mean, na.rm=TRUE)
if (is.na(MeanPW)) (MeanPW<-NaN)
MeanPW<-toString(MeanPW)
date <- substr(list.files(pattern= ".nc")[O], 15, 17)
date <- as.numeric(date)
date2 <- as.Date(date, origin = "2002/12/31")
date1 <- format(date2, "%Y/%b/%d")
date2 <- as.character(date2)
year <- substr(date1, 1, 4)
month <- substr(date1, 6, 8)
month_name <- substr(date2, 6, 7)
season <- if (as.numeric(month_name) < 06 |
as.numeric(month_name)==12) {"Dry"} else("Wet")
Table <- cbind(date2, year, month, season, MeanPW,
matrix(Classification$Classification)[i],
PHL@data$NAME_2[1:length(PHL@data$OBJECTID)],
matrix(Region$Region)[1:length(PHL@data$OBJECTID)])
write.table(Table, paste("Urban", 13, ".csv", sep=""), sep=",",
append=TRUE)
}
return(Table)
}
cl <- makeCluster(16)
PHL <- readRDS("PHL_adm2.rds")
Classification <- read.csv("Classification.csv")
Region <- read.csv("Region.csv")
PHL@data <- cbind(PHL@data, Classification, Classification$Region)
M <- list.files(pattern= ".nc")
s <- raster(nrow=1800, ncol=3600)
for(O in 1:2){
Dataname <- M[O]
AlltheFiles <- open.nc(Dataname)
read.nc(AlltheFiles)
PWV <- raster(Dataname)
PW_PHL <- crop(PWV, PHL)
s <- resample(PW_PHL, s)
s <- crop(s, PHL)
s <- mask(s, PHL)
clusterApply(cl, s, f)
}
我希望你能帮助我们。