I have multiple time series as *.csv files. They all have a first column for date, and a second column for (ndvi) values. The time series is describes irregular, a few years are missing in between the 30 year time span and also the values are not spaced evenly within each year (which excludes working with class "ts" and a few other from the beginning). Each year in my series has some kind of seasonal amplitude that i would like to fit a function to.
For those familiar with phenology and remote sensing, i would like to basically retrieve the same metrics as what TIMESAT does (for the years containing enough values). I've found the phenex package, including the function modelNDVI(), which I think would do exactly what I am looking for - correcting my values using bise (best index slope extraction) and smoothing with Savitzky-Golay or Assymetric Gaussian. My data looks basically like this:
head(test) system.time_start X1 3 1985-01-17 01:00:00 0.04546319 6 1985-02-10 01:00:00 0.05106874 7 1985-02-18 01:00:00 0.10060238 8 1985-02-26 01:00:00 0.04757872 9 1985-03-06 01:00:00 0.03484827 11 1985-03-22 01:00:00 0.02705866 ... 2357 2015-11-17 01:00:00 0.04524300 2358 2015-11-17 01:00:00 0.04476613 2359 2015-11-25 01:00:00 0.03424461 2360 2015-11-25 01:00:00 0.05062974 2364 2015-12-11 01:00:00 0.09578227 2368 2015-12-27 01:00:00 0.09661864
Clearly modelNDVI() needs a vector, so:
test.vec <- as.vector(test$X1)
.
I've also found out it must be a vector of length [1:365] which is my first problem. So I figured i have to convert my vector to another vector that is of the desired length, containing my values and a lot of NA's to be handled by the function.
Second problem:
I would like to model my whole time series, not only a single year (modelNDVI() only accpects year.int as a single observation year as an argument). So my question is, does anyone know if I can get modelNDVI() to work with my dataset? And if not, can anyone suggest a different way to handle my problem with modeling my irregular multi-year time series? Any packages, tutorials? I'm still relatively new to R and while I was looking for a solution I came accross numerous ways of handling irregular timeseries but none really could solve my problem of ending up with correcting and modeling my data. Thanks for any advice!
After puzzling over a similar problem, I realized that the NDVI vector needs to be 365/366 days long (as you discovered), but also that it needs to be an NDVI
class object. Check out ?bise1
for example code.
As for multi-year applications, I can't comment.
Ran into this same problem. Here is my fix which creates a vector 365 days long and adds the ndvi value for each day i had data based on the ndvi.tiff file (eg 20160131_NDVI.tiff is 31/01/2016 or 31st day of the year) but you can easily modify this if you already have the ndvi values and their respective date of acquisition.
library(raster)
library(plyr)
library(rgdal)
library(rgeos)
library(phenex)
library(lubridate)
ndvi.list <- list.files(path = ".", pattern = "*ndvi.tif$", ignore.case = TRUE,
full.names = TRUE, recursive = TRUE)
ndvi.stack <- stack(ndvi.list)
ndvi_values <- matrix(0,0,366)
# find mean ndvi (e.g. within a shapefile boundaries)
ndvi <- extract(ndvi.stack, shapefile, fun=mean, df=TRUE)
#use filenames to retrieve data information from ndvi.tiff files (e.g. mine were
called 20160210_NDVI.tif)
ndvicols <- names(ndvi.stack)
ndvicols <- sub("X","",ndvicols)
ndvicols <- sub("_NDVI","",ndvicols)
dates <- as.Date(ndvicols, format = "%Y%m%d")
doy <- lubridate::yday(dates)
#create ndvi vector
vec <- rep(0, 365)
ndvi.vals <- as.vector(t(ndvi[,2:ncol(ndvi)]))
vec[doy] <- ndvi.vals
# create NDVI object, apply correction (e.g. BISE) and model values (e.g. Linear interpolation)
ndvi.list <- modelNDVI(ndvi.values=vec,
year.int=2016, multipleSeasons=FALSE, correction="bise",
method="LinIP", MARGIN=2, doParallel=FALSE, slidingperiod=10)
# create vector of modelled values
vec.mod <- ndvi.list[[1]]@modelledValues
NOTE: for multiple years you'll have to run each year separately and append the data for each subsequent year
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.