Giter Club home page Giter Club logo

spei's People

Contributors

martinvonk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

spei's Issues

Issue Report: AttributeError in 'spei' package

Hi there,

I encountered an issue while using the 'spei' package. Here's a summary:

Problem:
When attempting to execute the following code snippet:
spei_fisk = si.SI(pe, dist=scs.fisk, fit_freq="ME") spei_fisk.fit_distribution()

I received the following error message:
AttributeError: module 'spei' has no attribute 'SI'

Please let me know if you need any further information to address this issue. Thanks for your attention to this matter.

Best regards,
Simón.

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

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

Switch to Object-Oriented

The original setup was functional. But it is better to transform to SI class and save all data and fitted distributions and logic there.

Invalid frequency passed to pd.Grouper

Invalid frequency string passed to pd.Grouper.

The group_yearly_df function passes either "YE" or "Y" to pd.Grouper, depending on the pandas version. Using pandas version '2.1.4', the frequency passed to pd.Grouper is invalid. The correct string is "Y", but "YE" is passed.

The following error was caused:

File ~/.local/lib/python3.10/site-packages/spei/utils.py:85, in group_yearly_df(series)
83 grs = {}
84 freq = "YE" if pd_version >= "2.1.0" else "Y"
---> 85 for year_timestamp, gry in series.groupby(Grouper(freq=freq)):
86 index = validate_index(gry.index)
87 gry.index = to_datetime(
88 "2000-" + index.strftime(strfstr), format="%Y-" + strfstr
89 )

File /g/data/hh5/public/apps/miniconda3/envs/analysis3-23.10/lib/python3.10/site-packages/pandas/core/resample.py:2046, in TimeGrouper.init(self, freq, closed, label, how, axis, fill_method, limit, kind, convention, origin, offset, group_keys, **kwargs)
2043 if convention not in {None, "start", "end", "e", "s"}:
2044 raise ValueError(f"Unsupported value {convention} for convention")
-> 2046 freq = to_offset(freq)
2048 end_types = {"M", "A", "Q", "BM", "BA", "BQ", "W"}
2049 rule = freq.rule_code

File offsets.pyx:4460, in pandas._libs.tslibs.offsets.to_offset()

File offsets.pyx:4557, in pandas._libs.tslibs.offsets.to_offset()

ValueError: Invalid frequency: YE

ValueError: cannot set using a list-like indexer with a different length than the value

Hello,

I am having the following error when running si.spei() with a series without any missing value and the index as datetimeindex: ValueError: cannot set using a list-like indexer with a different length than the value

Here is the traceback:
`File ~/miniconda3/envs/FluxNet/lib/python3.8/site-packages/spei/si.py:170, in spei(series, dist)
143 def spei(series: Series, dist: ContinuousDist = fisk) -> Series:
144 """Method to compute the Standardized Precipitation Evaporation Index
145 [spei_2010]_.
146
(...)
167 Journal of Climate, 23, 1696-1718, 2010.
168 """
--> 170 return compute_si_ppf(series=series, dist=dist)

File ~/miniconda3/envs/FluxNet/lib/python3.8/site-packages/spei/si.py:56, in compute_si_ppf(series, dist, index, sgi, prob_zero)
54 cdf = compute_cdf_nsf(data=data)
55 ppf = norm.ppf(cdf)
---> 56 si.loc[data.index] = ppf
57 return si

File ~/miniconda3/envs/FluxNet/lib/python3.8/site-packages/pandas/core/indexing.py:849, in _LocationIndexer.setitem(self, key, value)
846 self._has_valid_setitem_indexer(key)
848 iloc = self if self.name == "iloc" else self.obj.iloc
--> 849 iloc._setitem_with_indexer(indexer, value, self.name)

File ~/miniconda3/envs/FluxNet/lib/python3.8/site-packages/pandas/core/indexing.py:1837, in _iLocIndexer._setitem_with_indexer(self, indexer, value, name)
1835 self._setitem_with_indexer_split_path(indexer, value, name)
1836 else:
-> 1837 self._setitem_single_block(indexer, value, name)

File ~/miniconda3/envs/FluxNet/lib/python3.8/site-packages/pandas/core/indexing.py:2077, in _iLocIndexer._setitem_single_block(self, indexer, value, name)
2074 self.obj._check_is_chained_assignment_possible()
2076 # actually do the set
-> 2077 self.obj._mgr = self.obj._mgr.setitem(indexer=indexer, value=value)
2078 self.obj._maybe_update_cacher(clear=True, inplace=True)

File ~/miniconda3/envs/FluxNet/lib/python3.8/site-packages/pandas/core/internals/managers.py:394, in BaseBlockManager.setitem(self, indexer, value)
389 if using_copy_on_write() and not self._has_no_reference(0):
390 # if being referenced -> perform Copy-on-Write and clear the reference
391 # this method is only called if there is a single block -> hardcoded 0
392 self = self.copy()
--> 394 return self.apply("setitem", indexer=indexer, value=value)

File ~/miniconda3/envs/FluxNet/lib/python3.8/site-packages/pandas/core/internals/managers.py:352, in BaseBlockManager.apply(self, f, align_keys, **kwargs)
350 applied = b.apply(f, **kwargs)
351 else:
--> 352 applied = getattr(b, f)(**kwargs)
353 result_blocks = extend_blocks(applied, result_blocks)
355 out = type(self).from_blocks(result_blocks, self.axes)

File ~/miniconda3/envs/FluxNet/lib/python3.8/site-packages/pandas/core/internals/blocks.py:1041, in Block.setitem(self, indexer, value, using_cow)
1038 values = values.T
1040 # length checking
-> 1041 check_setitem_lengths(indexer, value, values)
1043 value = extract_array(value, extract_numpy=True)
1044 try:

File ~/miniconda3/envs/FluxNet/lib/python3.8/site-packages/pandas/core/indexers/utils.py:168, in check_setitem_lengths(indexer, value, values)
162 indexer = np.array(indexer)
163 if not (
164 isinstance(indexer, np.ndarray)
165 and indexer.dtype == np.bool_
166 and indexer.sum() == len(value)
167 ):
--> 168 raise ValueError(
169 "cannot set using a list-like indexer "
170 "with a different length than the value"
171 )
172 if not len(indexer):
173 no_op = True

ValueError: cannot set using a list-like indexer with a different length than the value`

I am running Python 3.8, Numpy 1.24.3, Pandas 2.0.3 and Scipy 1.10.1

ValueError: zero-size array to reduction operation minimum which has no identity

Hello!

I've been trying several datasets and I keep getting the same error:

Traceback (most recent call last):

Cell In[31], line 3
si.ssfi(pd.Series(df_mean_month['vazao']), dist=scs.fisk)

File ~/miniconda3/envs/spyder-env/lib/python3.12/site-packages/spei/si.py:251 in ssfi
ssfi.fit_distribution()

File ~/miniconda3/envs/spyder-env/lib/python3.12/site-packages/spei/si.py:394 in fit_distribution
fd = Dist(

File :7 in init

File ~/miniconda3/envs/spyder-env/lib/python3.12/site-packages/spei/dist.py:66 in post_init
pars, loc, scale = self.fit_dist(data=data_fit, dist=self.dist)

File ~/miniconda3/envs/spyder-env/lib/python3.12/site-packages/spei/dist.py:93 in fit_dist
fit_tuple = dist.fit(data, scale=std(data))

File ~/miniconda3/envs/spyder-env/lib/python3.12/site-packages/scipy/stats/_distn_infrastructure.py:2620 in fit
start = self._fitstart(data)

File ~/miniconda3/envs/spyder-env/lib/python3.12/site-packages/scipy/stats/_distn_infrastructure.py:2366 in _fitstart
loc, scale = self._fit_loc_scale_support(data, *args)

File ~/miniconda3/envs/spyder-env/lib/python3.12/site-packages/scipy/stats/_distn_infrastructure.py:2703 in _fit_loc_scale_support
data_a = np.min(data)

File ~/miniconda3/envs/spyder-env/lib/python3.12/site-packages/numpy/core/fromnumeric.py:2953 in min
return _wrapreduction(a, np.minimum, 'min', axis, None, out,

File ~/miniconda3/envs/spyder-env/lib/python3.12/site-packages/numpy/core/fromnumeric.py:88 in _wrapreduction
return ufunc.reduce(obj, axis, dtype, out, **passkwargs)

ValueError: zero-size array to reduction operation minimum which has no identity

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.