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

Error in qnorm(pze + (1 - pze) * pnorm(std[ff, s])) : object 'pze' not found #16

Closed DavidFeitschinger closed 2 years ago

DavidFeitschinger commented 6 years ago

Hello, when I try to run a SPI-3 with triangular kernel and coefficients in "param=" from another SPI file with the same dimensions I get the following error:

Error in qnorm(pze + (1 - pze) * pnorm(std[ff, s])) : object 'pze' not found

I am unsure how to solve this. I have attached two of the datasets I am using and a section of annotated script that should show my thought process. Maybe that will provide insights into my issue. a

Thank you for your help

Supporting files and script.zip

dariomasante commented 5 years ago

Same here, spei function assumes the pze variable exists when parameters are provided, but it does not. In fact it is declared only inside code section matching conditional if(is.null(params))

jocossau commented 5 years ago

so... there is any way to skip that issue??

DavidFeitschinger commented 5 years ago

Hey... sadly I did not manage to find a solution to the problem.

tpilz commented 3 years ago

I came across the same problem. I contacted @sbegueria but he didn't react to my e-mail so far and as no changes to the package have been made for several years I am not sure if the package is still maintained.

In the meantime, to fix it, in R/spei.R I just moved the lines

# Probability of monthly precipitation = 0 (pze)
pze <- sum(month==0)/length(month)

to a position before the if (is.null(params)) {...} statement which seems to work.

sbegueria commented 2 years ago

Yes, that was a bug due to pie calculation located within an if loop, as @tpilz suggested. This issue has now been solved in the development version and will be consolidated in the next stable release.