Search code examples
rzoo

Zoo error: length(time(x)) == length(by[[1]]) is not TRUE


I'm trying to work out evapotranspiration from climate data based on the Hargreaves Samani methodology using this package

The data I'm working on in csv format is available here and the code I'm using (with comments) is below

## Using Evapotranspiration package to get DAILY PE ###
require(Evapotranspiration)
require(zoo)

#load the constants required from the Evapotranspiration package
data("constants")

#converting the CSV to a zoo object
OakPark<- read.csv("mydata.csv", header=TRUE)

#Fill the blanks in the csv with NAs
na.fill(mydata,NA)

#convert to a zoo
mydata <- as.zoo(mydata)

#create a zoo series with the required variables
PE.data <- mydata[ ,c(3,5)]

#converting to a list as ET function works on a list
PE.data <- as.list(PE.data)

#change constants to the local values
constants$Elev = 62
constants$lat_rad = 0.9226

#defining the function
funname <- "HargreavesSamani"
class(PE.data) <- funname

#creating a new variable with the calculation
results <- ET(PE.data,constants)

The error then reads:

Error: length(time(x)) == length(by[[1]]) is not TRUE

I've looked at other help sections such as this but can't see how I can implement this for it to work on this built-in HargreavesSamani function.


Solution

  • Use the ReadInputs function in the same package (Evapotranspiration) package to pre-processing your data and construct the input data. Do not create input data by yourself.

    I got the same error when I tried to create input data by myself. I believe using the ReadInputs function is the best solution to this problem.

    Hope this help.