repDoy.Rd 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. % Generated by roxygen2: do not edit by hand
  2. % Please edit documentation in R/repDoy.R
  3. \name{repDoy}
  4. \alias{repDoy}
  5. \title{Repair MODIS "composite_day_of_the_year" SDS}
  6. \usage{
  7. repDoy(pixX, layerDate = NULL, bias = 0)
  8. }
  9. \arguments{
  10. \item{pixX}{\code{matrix} of values, usually derived from
  11. \code{\link{as.matrix}}.}
  12. \item{layerDate}{If \code{NULL} (default), try to autodetect layer dates. If
  13. you want to be sure, use the result from
  14. \code{extractDate(..., asDate = TRUE)} or \code{\link{orgTime}}.}
  15. \item{bias}{\code{integer}. Bias applied to all values in \code{pixX}.}
  16. }
  17. \value{
  18. A \code{matrix} with sequential Julian dates.
  19. }
  20. \description{
  21. Currently works only for MODIS 16 days composites! In MODIS composites, the
  22. Julian dates inside the 'composite_day_of_the_year' SDS are referring always
  23. to the year they are effectively in. The problem is that the layer/SDS name
  24. from the last files from Terra and Aqua within a year can include dates from
  25. the following year and so starting again with 1. The problem comes if you
  26. want to sort values of a time series by date (e.g. for precise time series
  27. functions). This function generates a sequential vector beginning always
  28. with the earielst SDS/layer date and ending with the total sum of days of
  29. the time serie length.
  30. }
  31. \examples{
  32. \dontrun{
  33. runGdal(product="M.D13A2", begin="2010350", end="2011016", extent="Luxembourg",
  34. job="deleteme", SDSstring="100000000010")
  35. ndviFiles <- preStack(path=paste(MODIS:::.getDef()$outDirPath,"deleteme",sep="/")
  36. ,pattern="*_NDVI.tif$")
  37. ndvi <- stack(ndviFiles)
  38. doyFiles <- preStack(path=paste(MODIS:::.getDef()$outDirPath,"deleteme",sep="/")
  39. ,pattern="*_composite_day_of_the_year.tif$")
  40. doy <- stack(doyFiles)
  41. layerDates <- extractDate(names(doy))
  42. pixX <- 169
  43. y <- ndvi[pixX]
  44. x1 <- doy[pixX]
  45. x2 <- repDoy(doy[pixX],layerDates)
  46. x1
  47. x2
  48. # the plotting example is not really good.
  49. # To create a figurative example it would be necessary to dolwnload to much data!
  50. plot("",xlim=c(1,max(x1,x2)),ylim=c(0,2000),xlab="time",ylab="NDVI*10000")
  51. lines(y=y,x=x1,col="red",lwd=3)
  52. lines(y=y,x=x2,col="green",lwd=2)
  53. # repDoy function is thought to be enbeded in something like that:
  54. tr <- blockSize(ndvi)
  55. doyOk <- brick(doy)
  56. doyOk <- writeStart(doyOk, filename='test.tif', overwrite=TRUE)
  57. for (i in 1:tr$n)
  58. {
  59. pixX <- getValues(doy,tr$row[i],tr$nrows[i])
  60. ok <- repDoy(pixX,layerDates)
  61. doyOk <- writeValues(x=doyOk,v=ok,start=tr$row[i])
  62. }
  63. doyOk <- writeStop(doyOk)
  64. # unlink(filename(doyOk))
  65. }
  66. }
  67. \author{
  68. Matteo Mattiuzzi
  69. }