edzer / spacetime

Classes and methods for spatio-temporal data
73 stars 20 forks source link

Question about the use of STFDF #44

Open Doltrix opened 1 year ago

Doltrix commented 1 year ago

Hello, I have a question about the use of STFDF: My thesis is about increasing the monitoring stations of a climatological network for which I will work on the basis of satellite information. This information I downloaded from Era5 land servers, which I have already transformed into a data frame extracting the data from each layer of the multitemporal raster in the locations corresponding to each current station. This data frame is conformed in its columns by all the dates of 20 years, corresponding to 7671 dates and 37 rows corresponding to the monitoring stations considered for the analysis. I also have the location coordinates of these stations in an object that contains the coordinates (X,Y,Z) of each station and other properties such as name and code. I want to apply spatio-temporal kriging to find the location of these new stations or new sensors for each variable, for this I require the use of STFDF. The problem is that I get errors when using the structure. This is my code and the corresponding error:

nombres_estaciones <- data.frame(Estacion = ubic_est$Estacion) projection(Temp_00_20) <- CRS("+init=epsg:4326") datos_estaciones <- raster::extract(Temp_00_20,ubic_est) datos_df <- as.data.frame(datos_estaciones) coords <- ubic_est[, c("X", "Y")] sp <- as(ubic_est, "Spatial") dates <- seq(as.Date("2000-01-01"), as.Date("2020-12-31"), by = "day") datos_xts <- xts(t(datos_df), order.by = dates) datos_dfr <- as.data.frame(datos_xts) stfdf <- STFDF(sp, dates, datos_df)

Error in validityMethod(object) : nrow(object@data) == length(object@sp) * nrow(object@time) is not TRUE

edzer commented 1 year ago

I abandoned using spacetime quite some time ago; a more modern take on doing similar things is given here: https://r-spatial.org/book/13-Geostatistics.html