sbegueria / SPEI

An R package for computing the Standardized Precipitation-Evapotranspiration Index (SPEI), Penman-Monteith and other reference evapotranspiration, SPI, etc.
78 stars 34 forks source link

Penman function not working #75

Open Lucy84 opened 7 months ago

Lucy84 commented 7 months ago

I have a set of data to calculate PET. The Hargreaves function has worked perfectly but the Penman keeps giving "Error in Tmean[2, , ] : subscript out of bounds". Tmean isn't requested in the documentation, I include Tmax and Tmin as stated. Running a value for Tmean included just gives the same error.

My data is as follows for one month: U2 1.7 m/s (average) Ra 2.23 MJ/day (average) RH 89.65% (average) lat 52.76624 Tmax 14.3 (degrees C) Tmin 6.9 (degrees C) z 59 (mASL)

Here is the code that I put in R

penman<-penman(Tmin, Tmax, U2, Ra, lat, RH, z = 59, crop='short', na.rm = TRUE) View(penman)

I've had to state the z value in the code because for some reason calling it from a datafile kept giving an error. The rest of the variables are stated values in R studio.

Any help appreciated.

Reproducible code:

U2 <- 1.7 #m/s (average)
Pre <- 43.2 #mm (total)
Ra <- 2.23 #MJ/day (average)
RH <- 89.65 #% (average)
lat <- 52.76624
Tmax <- 14.3 #(degrees C)
Tmin <- 6.9 #(degrees C)

penman<-penman(Tmin, Tmax, U2, Ra, lat, RH, z = 59, crop='short', na.rm = TRUE)
Lucy84 commented 7 months ago

This has now been solved over on Stack Overflow. You must have a dataset with at least three values for each variable to use in the algorithm. I had been trying to get it to work on data from one month, incorrectly thinking that less data was better but in fact if I'd just run the algorithm with three months' data then it would have worked. An update in the instructions would be very helpful @sbegueria

jassler commented 7 months ago

I'd keep this issue open, as it's not at all clear from the documentation or error message that there is a minimum number of values required. Given that the penman function contains a large flock of parameter checks, this might have been an oversight :)

Lucy84 commented 7 months ago

Thanks, I've reopened it and will close it when the documentation is improved.