r-spatial / dtwSat

Time-Weighted Dynamic Time Warping for satellite image time series analysis
https://www.victor-maus.com/dtwSat/
GNU General Public License v3.0
131 stars 39 forks source link

How to deal with unequal length time series #28

Closed ShawnMeng90s closed 5 years ago

ShawnMeng90s commented 5 years ago

library(dtwSat) setwd("") blue <- stack("cp_blue.tif") # 15 bands blue2 <-stack("new-blue.tif") # 15 bands dates <- scan("timeline",what="date") dates2 <-scan("timeline",what="date2") raster_timeseries <- twdtwRaster(blue,timeline=dates) raster_timeseries2 <- twdtwRaster(blue2,timeline = dates2) proj_str <- scan("sample1_projection",what="character") training_samples <- read.csv("Training_examples.csv",sep=",",stringsAsFactors = FALSE) training_ts<-getTimeSeries(raster_timeseries,y=training_samples,proj4string=proj_str) temporal_patterns <-createPatterns(training_ts,freq=16,formula=y~s(x)) log_fun <- logisticWeight(-0.1,50) twdtw_dist <-twdtwApply(x=raster_timeseries2,y=temporal_patterns,overlap=0.5,weight.fun=log_fun,overwrite=TRUE,format="GTiff",progress="text")

Error in twdtwApply.twdtwRaster(x, y, weight.fun, dist.method, step.matrix, : Bands from twdtwRaster do not match the bands from patterns

vwmaus commented 5 years ago

The error message is clear. The problem is not related to the length of the time series but the satellite bands.

Error in twdtwApply.twdtwRaster(x, y, weight.fun, dist.method, step.matrix, :
Bands from twdtwRaster do not match the bands from patterns

replace

raster_timeseries2 <- twdtwRaster(blue2,timeline = dates2)

with

raster_timeseries2 <- twdtwRaster(blue = blue2,timeline = dates2)