Skip to main content
edited title
Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

Apply Applying SPEI::hargreaves function to time series from each pixel rasterbrick using R?

deleted 25 characters in body; edited tags
Source Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345
library(SPEI)
library(raster)

Basically, given a monthly time series for two variables a and b as follows:

a = array(1:(3*4*12*64),c(3,4,12*64))
a = brick(a)
    
dates=seq(as.Date("1950-01-01"), as.Date("2013-12-31"), by="month")
a<- setZ(a,dates)
names(a) <- as.yearmon(getZ(a))



b = array(1:(3*4*12*64),c(3,4,12*64))
b = brick(b)

dates=seq(as.Date("1950-01-01"), as.Date("2013-12-31"), by="month")
b<- setZ(b,dates)
names(b) <- as.yearmon(getZ(b))

Both a and b are time series with a time dimension. Now, I would like to apply the function SPEI::hargreaves to time series of each pixel in a and b and return a rasterbrick C

From the SPEI package , har <- hargreaves(TMIN,TMAX,lat=37.6475). Here, consider Tmin=a, Tmax=b and lat=latitude of each pixel which is the same in a and b. I will parallelize the process once I get an idea how to apply the function to my rasterbricks.

At the moment, I am using data.table to collapse my rasterbricks and then applying hargreaves to the table. This approach is very inefficient so far.

Thanks for your help.

library(SPEI)
library(raster)

Basically, given a monthly time series for two variables a and b as follows:

a = array(1:(3*4*12*64),c(3,4,12*64))
a = brick(a)
    
dates=seq(as.Date("1950-01-01"), as.Date("2013-12-31"), by="month")
a<- setZ(a,dates)
names(a) <- as.yearmon(getZ(a))



b = array(1:(3*4*12*64),c(3,4,12*64))
b = brick(b)

dates=seq(as.Date("1950-01-01"), as.Date("2013-12-31"), by="month")
b<- setZ(b,dates)
names(b) <- as.yearmon(getZ(b))

Both a and b are time series with a time dimension. Now, I would like to apply the function SPEI::hargreaves to time series of each pixel in a and b and return a rasterbrick C

From the SPEI package , har <- hargreaves(TMIN,TMAX,lat=37.6475). Here, consider Tmin=a, Tmax=b and lat=latitude of each pixel which is the same in a and b. I will parallelize the process once I get an idea how to apply the function to my rasterbricks.

At the moment, I am using data.table to collapse my rasterbricks and then applying hargreaves to the table. This approach is very inefficient so far.

Thanks for your help.

library(SPEI)
library(raster)

Basically, given a monthly time series for two variables a and b as follows:

a = array(1:(3*4*12*64),c(3,4,12*64))
a = brick(a)
    
dates=seq(as.Date("1950-01-01"), as.Date("2013-12-31"), by="month")
a<- setZ(a,dates)
names(a) <- as.yearmon(getZ(a))



b = array(1:(3*4*12*64),c(3,4,12*64))
b = brick(b)

dates=seq(as.Date("1950-01-01"), as.Date("2013-12-31"), by="month")
b<- setZ(b,dates)
names(b) <- as.yearmon(getZ(b))

Both a and b are time series with a time dimension. Now, I would like to apply the function SPEI::hargreaves to time series of each pixel in a and b and return a rasterbrick C

From the SPEI package , har <- hargreaves(TMIN,TMAX,lat=37.6475). Here, consider Tmin=a, Tmax=b and lat=latitude of each pixel which is the same in a and b. I will parallelize the process once I get an idea how to apply the function to my rasterbricks.

At the moment, I am using data.table to collapse my rasterbricks and then applying hargreaves to the table. This approach is very inefficient so far.

Source Link
code123
  • 345
  • 4
  • 13

Apply SPEI::hargreaves function to time series from each pixel rasterbrick R

library(SPEI)
library(raster)

Basically, given a monthly time series for two variables a and b as follows:

a = array(1:(3*4*12*64),c(3,4,12*64))
a = brick(a)
    
dates=seq(as.Date("1950-01-01"), as.Date("2013-12-31"), by="month")
a<- setZ(a,dates)
names(a) <- as.yearmon(getZ(a))



b = array(1:(3*4*12*64),c(3,4,12*64))
b = brick(b)

dates=seq(as.Date("1950-01-01"), as.Date("2013-12-31"), by="month")
b<- setZ(b,dates)
names(b) <- as.yearmon(getZ(b))

Both a and b are time series with a time dimension. Now, I would like to apply the function SPEI::hargreaves to time series of each pixel in a and b and return a rasterbrick C

From the SPEI package , har <- hargreaves(TMIN,TMAX,lat=37.6475). Here, consider Tmin=a, Tmax=b and lat=latitude of each pixel which is the same in a and b. I will parallelize the process once I get an idea how to apply the function to my rasterbricks.

At the moment, I am using data.table to collapse my rasterbricks and then applying hargreaves to the table. This approach is very inefficient so far.

Thanks for your help.