hzambran / rfmerge Goto Github PK
View Code? Open in Web Editor NEWMerging of Satellite Datasets with Ground Observations using Random Forests
Home Page: https://cran.r-project.org/package=RFmerge
Merging of Satellite Datasets with Ground Observations using Random Forests
Home Page: https://cran.r-project.org/package=RFmerge
I followed the tutorial and tried to run with my own data. Everything seems to run well but the RFmerge function gave this error.
Please i need help to fix this error.
Error in if (!sf::st_is(mask, c("POLYGON", "MULTIPOLYGON"))) { :
the condition has length > 1
station data and precipitation data.zip
Respected sir
i run the code and i got this error.
every thing is projected as utm.
data(ValparaisoPPts)
data(ValparaisoPPgis)
data(ValparaisoSHP)
rfmep <- RFmerge(x=pcp, metadata=ValparaisoPPgis, cov=covariates,
id="Code", lat="lat", lon="lon", mask=shp,
training=0.8, parallel=parallel, par.nnodes=par.nnodes)
Error in RFmerge.zoo(x = pcp, metadata = ValparaisoPPgis, cov = covariates, :
Invalid argument: 'metadata' must have 'id' (identifier), 'lon' (longitude) and 'lat' (latitude) fields !
metadata' must have 'id' (identifier), 'lon' (longitude) and 'lat' (latitude) fields !
x=pcp is the xts object of rainfaill from stations
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
See
somewhere the package makes an assumption of the legacy crs
structure, which is going to change. Please modify and submit to CRAN.
See: https://r-spatial.org/r/2022/04/12/evolution.html. sp on CRAN now offers control of the environment variable, so the attached log is from _SP_EVOLUTION_STATUS_=2 _R_CHECK_FORCE_SUGGESTS_=FALSE R CMD check RFmerge_0.1-10.tar.gz
:
00check.log
Hi,
I am trying to run the RF-Merge using the trial data provided along with the package, by following the steps in the tutorial (https://cran.r-project.org/web/packages/RFmerge/vignettes/RFmerge-RainfallExample-minimal.pdf). However, when I am in the verification of covariates (section 6.2), the extent and resolution of the CHIRPS data do not match with DEM.
> nlayers(CHIRPS5km)
[1] 243
> ( nlayers(CHIRPS5km) == nlayers(PERSIANNcdr5km) )
[1] TRUE
> ( nlayers(CHIRPS5km) == nrow(ValparaisoPPts) )
[1] TRUE
> extent(CHIRPS5km)
class : Extent
xmin : -71.85
xmax : -69.95
ymin : -34
ymax : -32
> ( extent(CHIRPS5km) == extent(PERSIANNcdr5km) )
[1] TRUE
> ( extent(CHIRPS5km) == extent(ValparaisoDEM5km) )
[1] FALSE
> res(CHIRPS5km)
[1] 0.05 0.05
> ( res(CHIRPS5km) == res(PERSIANNcdr5km) )
[1] TRUE TRUE
> ( res(CHIRPS5km) == res(ValparaisoDEM5km) )
[1] FALSE FALSE
I am following the exact steps mentioned in the example tutorial. What is the solution for this?
Hi, while running the RFmerge function I am getting this error quoted below.
"Error in obs.values[i] <- train.ts[day, grep(metadata[, id], names(train.ts))] : replacement has length zero".
Any help would be much appreciated. Also, I would like to have the output as NetCDF, so bring an option to specify output file format. Thanks in advance.
Excuse me sir, I am interested in using this rfmerge package, if there is missing data (no observations) in the gauge data, how can I keep run this rfmerge library ? Thank you, please give some advice
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.