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
130 stars 39 forks source link

Unclassified results of dtwsat using sentinel-2 timeseries #42

Closed khanwaleed247 closed 3 years ago

khanwaleed247 commented 5 years ago

We have been facing some problems using dtwsat. We have created sentinel 2 time series of 5 different dates. The finalized classified image is filled with unclassified data as can be seen in the screenshot below: Capture here is the code:

B3 <- brick(paste(data_folder, "B3/B3.tif", sep = "/")) B2 <- brick(paste(data_folder, "B2/B2.tif", sep = "/")) B4 <- brick(paste(data_folder, "B4/B4.tif", sep = "/")) B5 <- brick(paste(data_folder, "B5/B5.tif", sep = "/")) B6 <- brick(paste(data_folder, "B6/B6.tif", sep = "/")) B7 <- brick(paste(data_folder, "B7/B7.tif", sep = "/")) B8 <- brick(paste(data_folder, "B8/B8.tif", sep = "/")) B8A <- brick(paste(data_folder, "B8A/B8A.tif", sep = "/")) B11 <- brick(paste(data_folder, "B11/B11.tif", sep = "/")) B12 <- brick(paste(data_folder, "B12/B12.tif", sep = "/")) dates <- scan(paste(data_folder, "timeline", sep = "/"), what = "dates") raster_timeseries <- twdtwRaster(B2,B3,B4,B5,B12, timeline = dates) field_samples <- read.csv(paste(data_folder, "samples_own.csv", sep = "/")) proj_str <- scan(paste(data_folder, "samples_projection", sep = "/"),what = "character") field_samples_ts <- getTimeSeries(raster_timeseries, y = field_samples, proj4string = proj_str)

library("caret") set.seed(1) I <- unlist(createDataPartition(field_samples[, "label"], p = 0.9)) training_ts <- subset(field_samples_ts, I) validation_samples <- field_samples[-I,]

temporal_patterns <- createPatterns(training_ts, freq = 1, formula = y ~ s(x,k=4)) plot(temporal_patterns, type = "patterns")

log_fun <- logisticWeight(alpha = -0.1, beta = 50)

beginCluster()

twdtw_dist <- twdtwApplyParallel(x = raster_timeseries, y = temporal_patterns, overlap = 0.5, weight.fun = log_fun, overwrite = TRUE, format = "GTiff") endCluster() land_cover_maps <- twdtwClassify(twdtw_dist, format = "GTiff", overwrite = TRUE) plot(x = land_cover_maps, type = "maps")

Please find the necessary files in the attachment... These are four files that we have edited to run on your code. We are here working with sentinel 2. So for the purpose of low computation, we have extracted a patch from the Sentinel 2 image. So that we have low computation complexity and less time consuming on hit and trial. AllBandsSentinel2 is the zip file of all bands of Sentinel 2. samples.csv is the file containing samples of barren, field, urban, adn wheat. Which we will use as training for classification. Samples_projection is the same file with no modifications as the package. Timeline is the time series of image collected, as explained in the package.

filesoftwdtwpackageformail.zip

khanwaleed247 commented 5 years ago

OK so we solved the problem of Unclassified pixels. There has been some irregularities in our timeline. We solved them and reduced the overlap in twdtwapplyparallel() from 0.5 to 0.1. The classification visual results are way better than before.

Now we are having issues in twdtwasses()

maps_assessment <- twdtwAssess(land_cover_maps, y = validation_samples,proj4string = proj_str, conf.int = 0.95)

Error: Error in twdtwAssess.twdtwRaster(object, y, labels, id.labels, proj4string, : Sample starting date not found, the argument 'y' must have a column called 'from'

Upon entering the start date:

twdtw_assess <- twdtwAssess(land_cover_maps, y = validation_samples, proj4string = proj_str, conf.int = .95, start_date= "2019-11-05")

Error: Error in twdtwAssess.twdtwRaster(object, y, labels, id.labels, proj4string, : Sample starting date not found, the argument 'y' must have a column called 'from'

@vwmaus @appelmar

nk027 commented 5 years ago

Hey!

I can't replicate the first error. However, this would really only occur if(!"from" %in% names(validation_samples)), which is not the case for me. I am not sure how your data gets messed up there. I do get an expected error that start_date is missing.

The second error is to be expected, since nothing changed regarding "from". Your code would still not execute, since you need a time machine to assess "2019-11-05" (YYYY-MM-DD). After adjusting to an available date the function works for me.

@vwmaus It might make sense to add a specific error message for something along the lines of start_date < y$from || start_date > y$to. Currently you get a generic Fehler in to - from : nicht-numerisches Argument für binären Operator.