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

Invalid timeseries object, class different from list of zoo objects. > #22

Closed lfpdroubi closed 6 years ago

lfpdroubi commented 6 years ago

Hello,

I am trying to reproduce the example of Raster time series classification you made in your README, with my own data. I don't know exactly why I get an error, probably due to some dates in the from/to columns of my field_samples data.frame. I have tried to change these dates to make it work, but I could not.

My data is available at https://github.com/lfpdroubi/analise-multitemporal.

Here is my code:

proj_str <- "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"
blue <- brick(list("IMAGENS\\2013.B2.tif", "IMAGENS\\2014.B2.tif", 
                   "IMAGENS\\2015.B2.tif", "IMAGENS\\2016.B2.tif", 
                   "IMAGENS\\2017.B2.tif", "IMAGENS\\2018.B2.tif"))
green <- brick(list("IMAGENS\\2013.B3.tif", "IMAGENS\\2014.B3.tif", 
                    "IMAGENS\\2015.B3.tif", "IMAGENS\\2016.B3.tif", 
                    "IMAGENS\\2017.B3.tif", "IMAGENS\\2018.B3.tif"))
red <- brick(list("IMAGENS\\2013.B4.tif", "IMAGENS\\2014.B4.tif", 
                  "IMAGENS\\2015.B4.tif", "IMAGENS\\2016.B4.tif", 
                  "IMAGENS\\2017.B4.tif", "IMAGENS\\2018.B4.tif"))
timeline <- c("2013-01-01", "2014-01-01", "2015-01-01", "2016-01-01", 
                      "2017-01-01", "2018-01-01")
rts <- twdtwRaster(blue, green,  red, timeline = timeline)
field_samples <- read.csv("samples.csv")
set.seed(1)
i <- unlist(createDataPartition(field_samples$label, p = 0.1))
training_samples <- field_samples[i, ]
validation_samples <- field_samples[-i, ]
training_ts <- getTimeSeries(rts, y = training_samples, proj4string = proj_str)

and the error message:

time period of sample 130 does not overlap rester time seriestime period of sample 131 does not overlap rester time seriestime period of sample 132 does not overlap rester time seriestime period of sample 133 does not overlap rester time seriestime period of sample 134 does not overlap rester time seriestime period of sample 135 does not overlap rester time seriestime period of sample 136 does not overlap rester time seriestime period of sample 137 does not overlap rester time seriestime period of sample 138 does not overlap rester time seriestime period of sample 139 does not overlap rester time seriestime period of sample 140 does not overlap rester time seriestime period of sample 141 does not overlap rester time seriestime period of sample 142 does not overlap rester time seriestime period of sample 143 does not overlap rester time seriestime period of sample 144 does not overlap rester time seriestime period of sample 145 does not overlap rester time seriestime period of sample 146 does not overlap rester time seriestime period of sample 147 does not overlap rester time seriestime period of sample 148 does not overlap rester time seriestime period of sample 149 does not overlap rester time seriestime period of sample 150 does not overlap rester time seriestime period of sample 151 does not overlap rester time seriestime period of sample 152 does not overlap rester time seriestime period of sample 153 does not overlap rester time seriestime period of sample 154 does not overlap rester time seriestime period of sample 155 does not overlap rester time seriestime period of sample 156 does not overlap rester time seriestime period of sample 157 does not overlap rester time seriestime period of sample 158 does not overlap rester time seriestime period of sample 159 does not overlap rester time seriestime period of sample 160 does not overlap rester time seriestime period of sample 161 does not overlap rester time seriesError in validityMethod(object) : [twdtwTimeSeries: validation] Invalid timeseries object, class different from list of zoo objects.

lfpdroubi commented 6 years ago

@jlpfarias, acompanhar!

ShawnMeng90s commented 6 years ago

omg ,may i ask if your sample.csv edit from EXCEL?and where is your PROJECTION file?

lfpdroubi commented 6 years ago

@Mengshiyao , yes, my sample.csv was edited in excel. But I think this is not the issue. The errors I get are all with the 2019 to dates...Is there a right way to generate samples.csv? The projection was given by proj4string option.

ShawnMeng90s commented 6 years ago

me too excel,and my .csv file didn't work。...it said can't find "from" column

vwmaus commented 6 years ago

see #23. In case you still get the error, please provide me with a minimum reproducible example so that I can debug it!

lfpdroubi commented 6 years ago

Hi, @vwmaus !

What follows is my reproducible example. Sorry you have to download some files.

I think it is a problem whith the "to" dates column, since I haven't figured out how to fill those dates columns in the field samples files.

We have just one image per year, since 2013. What I have tried, then, was to set the "from" dates 2013-2018, then the "to" dates were set 2014-2019. I have tried also with "from" dates set to 2012-2017 and "to" dates 2013-2018. Neither approach worked for me: the issue may be with those dates limits.

library(dtwSat)
library(caret)
proj_str <- "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"
setwd("E:/")
dir.create("/images")
download.file("https://github.com/lfpdroubi/analise-multitemporal/raw/master/IMAGENS/2013.zip",
              "images/2013.zip")
download.file("https://github.com/lfpdroubi/analise-multitemporal/raw/master/IMAGENS/2014.zip",
              "images/2014.zip")
download.file("https://github.com/lfpdroubi/analise-multitemporal/raw/master/IMAGENS/2015.zip",
              "images/2015.zip")
download.file("https://github.com/lfpdroubi/analise-multitemporal/raw/master/IMAGENS/2016.zip",
              "images/2016.zip")
download.file("https://github.com/lfpdroubi/analise-multitemporal/raw/master/IMAGENS/2017.zip",
              "images/2017.zip")
download.file("https://github.com/lfpdroubi/analise-multitemporal/raw/master/IMAGENS/2018.zip",
              "images/2018.zip")
download.file("https://raw.githubusercontent.com/lfpdroubi/analise-multitemporal/master/samples.csv",
              "samples.csv")

unzip("images/2013.zip", exdir = "images")
unzip("images/2014.zip", exdir = "images")
unzip("images/2015.zip", exdir = "images")
unzip("images/2016.zip", exdir = "images")
unzip("images/2017.zip", exdir = "images")
unzip("images/2018.zip", exdir = "images")

blue <- brick(list("images/2013.B2.tif", 
                   "images/2014.B2.tif", 
                   "images/2015.B2.tif", 
                   "images/2016.B2.tif", 
                   "images/2017.B2.tif", 
                   "images/2018.B2.tif"))
green <- brick(list("images/2013.B3.tif", 
                    "images/2014.B3.tif", 
                    "images/2015.B3.tif", 
                    "images/2016.B3.tif", 
                    "images/2017.B3.tif", 
                    "images/2018.B3.tif"))
red <- brick(list("images/2013.B4.tif", 
                  "images/2014.B4.tif", 
                  "images/2015.B4.tif", 
                  "images/2016.B4.tif", 
                  "images/2017.B4.tif", 
                  "images/2018.B4.tif"))
timeline <- c("2013-01-01", "2014-01-01", "2015-01-01", "2016-01-01", 
                      "2017-01-01", "2018-01-01")
rts <- twdtwRaster(blue, green,  red, timeline = timeline)
field_samples <- read.csv("samples.csv", stringsAsFactors = FALSE)
field_samples$from <- as.Date(field_samples$from)
field_samples$to <- as.Date(field_samples$to)
set.seed(1)
i <- unlist(createDataPartition(field_samples$label, p = 0.1))
training_samples <- field_samples[i, ]
validation_samples <- field_samples[-i, ]
training_ts <- getTimeSeries(rts, y = training_samples, proj4string = proj_str)
validation_ts <- getTimeSeries(rts, y = validation_samples, proj4string = proj_str)
# See which are the overlaps problems (2019 "to" dates)
training_samples[136:161,]
validation_samples[1133:1431, ]
vwmaus commented 6 years ago

Hi @lfpdroubi the main assumption of the TWDTW algorithm is that the phenological cycle of the vegetation is represented in the images time series. One image per year is definitely insufficient to apply TWDTW, please see http://www.esensing.org/docs/Maus_TWDTW_JSTARS2016.pdf.