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

Processing Time obout Sentinal-2 data #27

Closed ShawnMeng90s closed 2 years ago

ShawnMeng90s commented 6 years ago

Hi Victor, I have used your package successfully on landsat data which is 400400 pixel and 15 layers.But this time i try your method on sentinal-2 NDVI data which is abou 25002300 pixel (10m resolution) and 21 layer,using twdtwApplyParallel ,it has run for more than 24 hours with 0% progress bar.(i am afraid that it will never stop) I find my computer CPU utilization is low but RAM utilization is 99%. By the way,my computer is 4core 3.2GHz,8G RAM. Is there any way to speed up?

ShawnMeng90s commented 6 years ago

here is my code library(dtwSat) setwd("") dates <- scan("timeline",what="date") NDVI <- stack("NDVI.tif")

raster_timeseries <- twdtwRaster(blue,green,nir,red,swir1,swir2,timeline=dates)

proj_str <- scan("sample1_projection",what="character")

training_samples <- read.csv("Training_examples.csv",sep=",",stringsAsFactors = FALSE) training_samples$from = as.Date(training_samples$from) training_samples$to= as.Date(training_samples$to) validation_samples <- read.csv("Validation_examples.csv",sep=",",stringsAsFactors = FALSE) validation_samples$from = as.Date(validation_samples$from) validation_samples$to = as.Date(validation_samples$to) training_ts<-getTimeSeries(raster_timeseries,y=training_samples,proj4string=proj_str)

temporal_patterns <-createPatterns(training_ts,freq=8,formula=y~s(x)) log_fun <- logisticWeight(-0.1,50) beginCluster() twdtw_dist <- twdtwApplyParallel(x=raster_timeseries,y=temporal_patterns,overlap=0.5,weight.fun=log_fun,overwrite=TRUE,format="GTiff",progress="text") endCluster() land_cover_maps <- twdtwClassify(twdtw_dist)

vwmaus commented 6 years ago

@Mengshiyao are you sure you can run this code? It looks very strange to me. Where did you declare the variables blue,green,nir,red,swir1,swir2. As far as I see you only declare NDVI <- stack("NDVI.tif") which you do no use later in the code. Please, be more precise while reporting your issues and provide reproducible code including a minimum amount of data to reproduce the error.

ShawnMeng90s commented 6 years ago

sorry...copy wrong

library(dtwSat) setwd("") dates <- scan("timeline",what="date") NDVI <- stack("NDVI.tif")

raster_timeseries <- twdtwRaster(NDVI,timeline=dates)

proj_str <- scan("sample1_projection",what="character")

training_samples <- read.csv("Training_examples.csv",sep=",",stringsAsFactors = FALSE) training_samples$from = as.Date(training_samples$from) training_samples$to= as.Date(training_samples$to) validation_samples <- read.csv("Validation_examples.csv",sep=",",stringsAsFactors = FALSE) validation_samples$from = as.Date(validation_samples$from) validation_samples$to = as.Date(validation_samples$to) training_ts<-getTimeSeries(raster_timeseries,y=training_samples,proj4string=proj_str)

temporal_patterns <-createPatterns(training_ts,freq=8,formula=y~s(x)) log_fun <- logisticWeight(-0.1,50) beginCluster() twdtw_dist<twdtwApplyParallel(x=raster_timeseries,y=temporal_patterns,overlap=0.5,weight.fun=log_fun,overwrite=TRUE,format="GTiff",progress="text") endCluster() land_cover_maps <- twdtwClassify(twdtw_dist)

ShawnMeng90s commented 5 years ago

besides, when i used function "twdtwApply" in another computer which is 4 core 2.5GHz 12G RAM ,the RStudio replied ‘’Error:memory exhausted (limit reached?)

vwmaus commented 5 years ago

try to limit the memory used by the raster package, this will force the results to be stored in tmp files, e.g.,

raster::rasterOptions(chunksize=1000, maxmemory=1000)

for details see ?raster::rasterOptions

ShawnMeng90s commented 5 years ago

Thanks a lot Victor! But here is another problem as follow. When i try to assess the classification result, it report errors:

twdtw_assess <- twdtwAssess(object=land_cover_maps, y=validation_samples,proj4string=proj_str,conf.int=.95, rm.nosample=TRUE,start_date=dates[1]) Warning message: In twdtwAssess.twdtwRaster(object, y, labels, id.labels, proj4string, :The argument rm.nosample is obsolete and will be removed from the next package release

twdtw_assess

An object of class "twdtwAssessment" Number of classification intervals: 1 Accuracy metrics summary

Overall Accuracy Var sd ci* 0 0 0 0

User's Accuracy Var sd ci* alfalfa 1 0 0 0 durum-wheat 1 0 0 0 fallow 1 0 0 0 lettuce 1 0 0 0 onions 1 0 0 0 otherhay 1 0 0 0 sugar-beets 1 0 0 0 unclassified 1 0 0 0

Producer's Accuracy Var sd ci* alfalfa 1 0 0 0 durum-wheat 1 0 0 0 fallow 1 0 0 0 lettuce 1 0 0 0 onions 1 0 0 0 otherhay 1 0 0 0 sugar-beets 1 0 0 0 unclassified 1 0 0 0

Area and uncertainty Mapped Adjusted ci* alfalfa 9.3e+07 0 0 durum-wheat 2.5e+07 0 0 fallow 2.2e+08 0 0 lettuce 5.9e+07 0 0 onions 3.4e+07 0 0 otherhay 7.5e+07 0 0 sugar-beets 7.8e+07 0 0 unclassified 0.0e+00 0 0

vwmaus commented 5 years ago

I see a warning message but no error

Warning message:
In twdtwAssess.twdtwRaster(object, y, labels, id.labels, proj4string, :The argument rm.nosample is obsolete and will be removed from the next package release

if don't want to have it then remove the argument rm.nosample=TRUE.

ShawnMeng90s commented 5 years ago

but the overall accuracy is 0 , don`t understand what condition is this