Giter Site home page Giter Site logo

Comments (4)

mnosshi avatar mnosshi commented on May 27, 2024

Thanks for opening this in a new issue..
It seems like a common enough problem, adding temporal information to a raster stack, and I see your note in the vignette to use the setZ argument in raster, for example:
setZ(s, ts, name= time ), where s is the rasterstack, and ts is the range of dates of interest.
How can I set the ts with an 8 day interval, but always starts at Jan 01 with every year in the ts?
when I run:
ts <- seq(as.Date("2002-06-26"), as.Date("2017-06-26"), by="8 days") the beginning of every year does not start on Jan 01, and I end up with ts being shorted than s -- if that makes sense?

from modistsp.

lbusett avatar lbusett commented on May 27, 2024

Hi,

first of all, note that you don't really need to create the stacks "by hand": MODIStsp provides you with ready-made time series in the "Time_Series/RData" subfolder (See http://lbusett.github.io/MODIStsp/articles/output.html#virtual-multi-band-outputs)

You can open those using something like:

in__file <- ..../my_moditsp_folder/Time_Series/MOD13Q1_MYD13Q1_NDVI_49_2000_353_2015_RData.RData" 
indata          <- get(load(in__file))

those files already have the "time information" saved, both in the bandnames and in the "Z" attribute:

times <- raster::getZ(indata)

I recon that:

  1. this is probably not sufficiently documented (I'll update the website when I have time) and,
  2. the current organization of the "Time_Series" subfolder is a mess, since all layers are saved in the same folder. I am already working on an improvement which will be available soon.

PS : Making a time series of dates that always start at DOY 1 is definitely possibile. A quick workaround would be to create one year as you did, then create the other by adding 365 * nĀ° of elapsed years (watch out for leap years)

from modistsp.

mnosshi avatar mnosshi commented on May 27, 2024

Hi,
Thank you for your notes on this.
The reason I am figuring this out manually is that I am trying to get 8 day observations by inter-leafing terra and aqua 16d data, and when I created the Rdata stack using MODIStsp I did not combine both (which is what I should have done).
In any case, I came up with the following way to add the time attribute to the rasterStack, using your notes on setZ and the raster.pdf. Rather than create a sequence and deal with leap years, I did the following 2 steps:

  1. parsed the date information from filenames such as (MXD13C1_EVI_2002_177.tif)
    library(stringr) dd <- str_extract_all(dat, "\\d{3,4}") df <- data.frame(matrix(unlist(dd), nrow=691, byrow=T)) colnames(df) <- c("year","DOY")

  2. convert DOY and year to Date:
    ts <- as.Date(paste(df$year, df$DOY), format="%Y %j")

then I created a stack from my directory and added the Zvalue
library(raster) s <- stack(dir()) s <- setZ(s, ts, name= "time" )
then saved
save(s,file="~/Documents...RData

from modistsp.

lbusett avatar lbusett commented on May 27, 2024

Yes, this is definitely a better way... and it's more or less what we use internally while building the rasterstacks !

I may be mistaken, but (unless you renamed MODIStsp outputs) I think you could need to sort ts in ascending order and then the results of dir() on the basis of the order of ts before calling stack if you want a properly ordered time series. This because a directory listing on MODIStsp files gives you all terra files, and then all aqua files.

from modistsp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    šŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. šŸ“ŠšŸ“ˆšŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ā¤ļø Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.