martinvonk/SPEI

Question : Exception has occurred: ValueError -- Formating issue of the input ?

agnespeltan opened this issue · 7 comments

Hi, I with spei_series = si.spei(input, timescale=30, dist=scs.fisk, fit_freq="MS")
I get
Exception has occurred: ValueError
No objects to concatenate. What is wrong with my input ?

Here is a view of my input series
1961-01-01 897.0
1961-02-01 -69.0
1961-03-01 -706.0
1961-04-01 86.0
1961-05-01 -380.0
...
2020-08-01 -960.0
2020-09-01 -363.0
2020-10-01 1067.0
2020-11-01 -215.0
2020-12-01 1849.0

Are you sure the index is a DateTimeIndex? And why are you using timescale=30 if the series looks like monthly values already?

Yes it is date time index :
date_range = pd.date_range(start=f'1-{start_year}', end=f'12-{end_year}', freq='MS')
input = pd.Series(bhc_array[:, i, j], index=date_range)

to what timescale refer to ? I want to compute the spei withh ranges of 3, 6, 12, and 18 months

From the docstring:

timescale : int, optional, default=0
        Rolling window timescale in days over which the series is summed. For
        SI1 the user would provide timescale=30, for SI3: timescale=90, SI6:
        timescale=180 etc.

In your case since you have monthly data the best thing to do is to compute the timescale yourself similar to the example notebook 1

Thanks for the answer but I do not understand. Do you mean computing SPEI with timescale = 0 and then summing over 3, 6, ... months ? with series.rolling("3M").sum() ?

Yes, that is how it is done in the first example notebook. The summation occurs over the provided window. The timescale argument does the same as series.rolling(window=timescale).sum() but then internally if timescale > 0 .

In your case, note that monthly ("M", "MS", or "ME") is a non-fixed frequency so you need to provide the rolling window as an integer. So:

spei1 = si.spei(input)
spei3 = si.spei(input.rolling(window=3).sum().dropna())
spei6 = si.spei(input.rolling(window=6).sum().dropna())

etc.

Thanks again. Is this correct for spei3:

date_range = pd.date_range(start=f'1-{start_year}', end=f'12-{end_year}', freq='MS')
input = pd.Series(bhc_array[:, i, j], index=date_range)
input = input.rolling(window=3).sum().dropna()
spei_series = si.spei(input, timescale=0, dist=scs.fisk, fit_freq="MS")
spei_series = spei_series.rolling("3M").sum()

No, you only sum the input series. Not the output.

Please check the example notebooks. Those can be of great help.