Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rfmerge Error #3

Open
Ahmadffrahmand opened this issue Sep 26, 2020 · 0 comments
Open

Rfmerge Error #3

Ahmadffrahmand opened this issue Sep 26, 2020 · 0 comments

Comments

@Ahmadffrahmand
Copy link

Respected Sir,

I created a zoo object from my precipitation file of 11 station and projected as utm zone 42, but following the instruction when i want to create a spatial object of the precipitation data i got the NA projection.

all other layers have the same utm zone 42 projection. but after running the Rfmerge i am getting this error.
setwd("D:\Time Series\chirps\station data and precipitation data")
ValparaisoPPts<-read.csv(file="data_ALLLL_copy.csv",header=TRUE, stringsAsFactors = FALSE)

dd<-seq(as.Date("2008-05-01"), as.Date("2019-12-31"), by = "day")

####################################################################
ldates <- hydroTSM::dip("2008-05-01", "2019-12-31")
ldates <- seq(from=as.Date("2008-05-01"), to=as.Date("2019-12-31"), by="day")

class(ValparaisoPPts)
names(CHIRPS5km) <- ldates
names(PERSIANNcdr5km) <- ldates
head(ValparaisoPPgis)
main <- paste("Daily precipitation for the station", ValparaisoPPgis$Code[1])
ylab <- "Precipitation [mm]"
x.ts <- ValparaisoPPts[,1]
hydroTSM::hydroplot(x.ts, pfreq="o", main=main, ylab= ylab)
plot(x.ts, main=main, ylab= ylab, col="blue")
grid()
chirps.total <- sum(CHIRPS5km, na.rm= FALSE)
persiann.total <- sum(PERSIANNcdr5km, na.rm= FALSE)
plot(chirps.total, main = "CHIRPSv2 [May - Aug] ", xlab = "Longitude", ylab = "Latitude")
plot(ValparaisoSHP[1], add=TRUE, col="transparent")
plot(persiann.total, main = "PERSIANN-CDR [May - Dec]", xlab = "Longitude", ylab = "Latitude")
plot(ValparaisoSHP[1], add=TRUE, col="transparent")
#################reading as zoo object
K101111<- zoo(x=ValparaisoPPts$K101111, order.by=dd)
K101112<- zoo(x=ValparaisoPPts$K101112, order.by=dd)
K101113<- zoo(x=ValparaisoPPts$K101113, order.by=dd)
K101114<- zoo(x=ValparaisoPPts$K101114, order.by=dd)
K101115<- zoo(x=ValparaisoPPts$K101115, order.by=dd)
K101116<- zoo(x=ValparaisoPPts$K101116, order.by=dd)
K101117<- zoo(x=ValparaisoPPts$K101117, order.by=dd)
K101118<- zoo(x=ValparaisoPPts$K101118, order.by=dd)
K101119<- zoo(x=ValparaisoPPts$K101119, order.by=dd)
K1011110<- zoo(x=ValparaisoPPts$K1011110, order.by=dd)
K1011111<- zoo(x=ValparaisoPPts$K1011111, order.by=dd)
ValparaisoPPts = cbind(K101111, K101112, K101113, K101114, K101115, K101116, K101117, K101118, K101119, K1011110, K1011111)

######################### Station csv which is Station location in studyarea ###
ValparaisoPPgis<-read.csv(file="kunduz_ST4.csv",header=TRUE, stringsAsFactors = FALSE)
names(ValparaisoPPgis)[1]<-c("Code")
str(ValparaisoPPgis)
class(ValparaisoPPgis)
ValparaisoSHP <- sf::st_transform(ValparaisoPPgis, crs=32642)
stations <- ValparaisoPPgis
( stations <- st_as_sf(stations, coords = c('lon', 'lat'), crs = 32642) )
stations.utm <- sf::st_transform(stations, crs=32642)
st.coords <- st_coordinates(stations.utm)
lon <- st.coords[, "X"]
lat <- st.coords[, "Y"]

ValparaisoPPgis.utm <- data.frame(Id=stations.utm[["Code"]], lon=lon, lat=lat)
ValparaisoPPgis<-ValparaisoPPgis.utm
crs(ValparaisoPPgis)
class(ValparaisoPPgis)
ValparaisoPPgis <- st_set_crs(ValparaisoPPgis, crs = +proj=longlat +datum=WGS84 +no_defs )
#################################################################
##################################Study area Border#############
setwd("D:\Time Series\chirps\studyarea")
ValparaisoSHP = st_read(dsn = "kunduz_WGS.shp",layer="kunduz_WGS")
ValparaisoSHP = st_read(dsn = ("kunduz_WGS.shp"))
ValparaisoSHP <- sf::st_transform(ValparaisoSHP, crs=32642)
ValparaisoSHP.utm <- sf::st_transform(ValparaisoSHP, crs=32642)
crs(ValparaisoSHP)
ValparaisoSHP<-ValparaisoSHP.utm
plot(ValparaisoSHP)
#######################################Chirps_v2_monthly data
setwd("D:\Time Series\chirps\chirsps2")
chirps<-list.files(path=getwd(), pattern="tif$") # 140 files
ch<-raster(chirps[1])
#crs(ch)<- +proj=utm +zone=42 +datum=WGS84 +units=m +no_defs
ch <- st_set_crs(ch, "+proj=utm +zone=42 +datum=WGS84 +units=m +no_defs")
crs(ch) <- CRS('+init=EPSG:32642')
crs(ch)
crs(CHIRPS5km)<- CRS('+init=EPSG:32642')
crs(CHIRPS5km)
######################################################
############### ersion Data set #############
setwd("D:\Time Series\chirps\cdr")
prsnncdr.fname<-list.files(path=getwd(), pattern=".tif$") # 140 files
cdr<-raster(prsnncdr.fname[1])
crs(cdr) <- CRS('+init=EPSG:32642')
crs(cdr)<- CRS('+init=EPSG:32642')
crs(cdr)
crs(PERSIANNcdr5km)<- CRS('+init=EPSG:32642')
crs(PERSIANNcdr5km)
#########################################################
############# Dem of study area ####################
setwd("D:\Time Series\chirps\dem")
dem.fname<-raster("Kunduz_Dem.tif")
dem<-raster(dem.fname)
crs(dem) <- CRS('+init=EPSG:32642')
crs(dem)
crs(ValparaisoDEM5km)<- CRS('+init=EPSG:32642')
crs(ValparaisoDEM5km)
plot(ValparaisoDEM5km, main="SRTM-v4", xlab="Longitude", ylab="Latitude", col=terrain.colors(255))
plot(ValparaisoSHP[1], add=TRUE, col="transparent")
plot(stations[1], add=TRUE, pch = 16, col="black")

#########################################################3
CHIRPS5km <- brick(ch)
PERSIANNcdr5km <- brick(cdr)
ValparaisoDEM5km <- raster(dem)
######################### resampling of all same spatial resolution ###
rsch<-resample(PERSIANNcdr5km,CHIRPS5km, method='bilinear')
rsdem<-resample(ValparaisoDEM5km ,CHIRPS5km,method='bilinear')

CHIRPS5km <- brick(CHIRPS5km)
ValparaisoDEM5km <- raster(rsdem)
PERSIANNcdr5km<-brick(rsch)
############################################################3

CHIRPS5km <- brick(CHIRPS5km)
PERSIANNcdr5km <- brick(rsch)
ValparaisoDEM5km <- raster(rsdem)
#####################################################projections####
################################################################
extent(ValparaisoDEM5km)
#crs(cdr)<- "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +to wgs84=0,0,0"
extent(rsch)
##########################################################

covariates <- list(chirps=CHIRPS5km, persianncdr=PERSIANNcdr5km,
dem=ValparaisoDEM5km)
################################################################
onWin <- ( (R.version$os=="mingw32") | (R.version$os=="mingw64") )
ifelse(onWin, parallel <- "parallelWin", parallel <- "parallel")
par.nnodes <- min(parallel::detectCores()-1,5)
###################### RfMerge ###############################

rfmep <- RFmerge(x=ValparaisoPPts, metadata=ValparaisoPPgis, cov=covariates,
id="Id", lon="lon", lat = "lat", mask=ValparaisoSHP,
training=0.8, parallel=parallel, par.nnodes=par.nnodes)

Error in sapply(x, fromDisk) & sapply(x, inMemory) :
operations are possible only for numeric, logical or complex types
In addition: Warning message:
In RFmerge.zoo(x = ValparaisoPPts, metadata = ValparaisoPPgis, cov = covariates, :
Invalid argument: 'cov' and 'mask' have different CRS. Please ensure they actually have the same CRS !

Also when i run this part of the code i get this error.

names(CHIRPS5km) <- ldates
Error in names<-(*tmp*, value = c(14000, 14001, 14002, 14003, 14004, :
incorrect number of layer names
i have daily precipitation data and monthly chirps data.
could you please instruct me how to resolve this part.
the code i run is attached .

Regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant