Skip to content

Commit

Permalink
Fix window attrs in SPI/SPEI (#1554)
Browse files Browse the repository at this point in the history
<!--Please ensure the PR fulfills the following requirements! -->
<!-- If this is your first PR, make sure to add your details to the
AUTHORS.rst! -->
### Pull Request Checklist:
- [x] This PR addresses an already opened issue (for bug fixes /
features)
    - This PR fixes #xyz
- [ ] Tests for the changes have been added (for bug fixes / features)
- [ ] (If applicable) Documentation has been added / updated (for bug
fixes / features)
- [x] CHANGES.rst has been updated (with summary of main changes)
- [ ] Link to issue (:issue:`number`) and pull request (:pull:`number`)
has been added

### What kind of change does this PR introduce?

* If `params` is not given, we pre-process dataset (resampling with
`freq` rolling with a general `window`) before doing anything, then
compute `params` with `freq=None, window=1`. But we must adjust attrs to
reflect the rolling `window` done before computing the params.
* I added a missing reference for the approximation of gamma parameters

### Does this PR introduce a breaking change?
No

### Other information:
Yet another spi fix attrs ... oups
  • Loading branch information
coxipi authored Jan 9, 2024
2 parents 7d79184 + 02f7457 commit dd9db13
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ Breaking changes

Bug fixes
^^^^^^^^^
* Fixed passing ``missing=0`` to ``xclim.core.calendar.convert_calendar`` (:issue:`1562`, :pull:`1563`).
* Fixed passing ``missing=0`` to ``xclim.core.calendar.convert_calendar``. (:issue:`1562`, :pull:`1563`).
* Fix wrong `window` attributes in ``xclim.indices.standardized_precipitation_index``, ``xclim.indices.standardized_precipitation_evapotranspiration_index``. (:issue:`1552` :pull:`1554`).

Internal changes
^^^^^^^^^^^^^^^^
Expand Down
15 changes: 15 additions & 0 deletions docs/references.bib
Original file line number Diff line number Diff line change
Expand Up @@ -2103,3 +2103,18 @@ @article{Lafferty2023
url = {https://www.nature.com/articles/s41612-023-00486-0},
year = {2023},
}

@article{thom_1958,
title = {A Note on the Gamma Distribution},
author = {Thom, H. C. S.},
year = {1958},
journal = {Monthly Weather Review},
volume = {86},
number = {4},
pages = {117--122},
publisher = {{American Meteorological Society}},
issn = {1520-0493, 0027-0644},
doi = {10.1175/1520-0493(1958)086<0117:ANOTGD>2.0.CO;2},
abstract = {Abstract The general properties of the gamma distribution, which has several applications in meteorology, are discussed. A short review of the general properties of good statistical estimators is given. This is applied to the gamma distribution to show that the maximum likelihood estimators are jointly sufficient. A new, simple approximation of the likelihood solutions is given, and the efficiency of the fitting procedure is computed.},
chapter = {Monthly Weather Review},
}
1 change: 1 addition & 0 deletions xclim/indices/_agro.py
Original file line number Diff line number Diff line change
Expand Up @@ -1239,6 +1239,7 @@ def standardized_precipitation_index(
spi = standardized_index(pr, params)
spi.attrs = params.attrs
spi.attrs["freq"] = freq or xarray.infer_freq(spi.time)
spi.attrs["window"] = window
spi.attrs["units"] = ""
return spi

Expand Down
2 changes: 1 addition & 1 deletion xclim/indices/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ def _fit_start(x, dist: str, **fitkwargs: Any) -> tuple[tuple, dict]:
References
----------
:cite:cts:`coles_introduction_2001,cohen_parameter_2019`
:cite:cts:`coles_introduction_2001,cohen_parameter_2019, thom_1958`
"""
x = np.asarray(x)
Expand Down

0 comments on commit dd9db13

Please sign in to comment.