Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standardized Streamflow Index and Standardized Groundwater level Index #1877

Open
wants to merge 34 commits into
base: main
Choose a base branch
from

Conversation

LamAdr
Copy link
Collaborator

@LamAdr LamAdr commented Aug 8, 2024

Pull Request Checklist:

  • This PR addresses an already opened issue (for bug fixes / features)
  • Tests for the changes have been added (for bug fixes / features)
    • (If applicable) Documentation has been added / updated (for bug fixes / features)
  • CHANGELOG.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?

  • 2 new indices/indicators : SSI and SGI

Does this PR introduce a breaking change?

No

Other information:

  • SSI will use GEV or log-logistic (scipy does not support tweedie)
  • SGI will use log-normal, gamma or GEV

@github-actions github-actions bot added the indicators Climate indices and indicators label Aug 8, 2024
@LamAdr LamAdr marked this pull request as draft August 9, 2024 13:38
@LamAdr LamAdr changed the title Standardised Streamflow Index and Standardised Groundwater level Index Standardized Streamflow Index and Standardized Groundwater level Index Aug 9, 2024
@github-actions github-actions bot added the docs Improvements to documenation label Aug 13, 2024
@LamAdr
Copy link
Collaborator Author

LamAdr commented Aug 23, 2024

Where things stand
SSI is completed
SGI

  • needs tests (xclim-testdata lacks groundwater data. Maybe we can get some here.)
  • I am not sure about the APP for lognorm

@Zeitsperre
Copy link
Collaborator

Just an FYI, but some tests are expected to fail until #1889 is merged!

@Zeitsperre Zeitsperre added this to the v0.56.0 milestone Feb 11, 2025
@coxipi coxipi marked this pull request as ready for review February 13, 2025 06:09
Copy link

Warning

This Pull Request is coming from a fork and must be manually tagged approved in order to perform additional testing.

@coxipi
Copy link
Contributor

coxipi commented Feb 13, 2025

  • I am not sure about the APP for lognorm

It was exactly the MLE with saddle point estimators, good job

@coxipi
Copy link
Contributor

coxipi commented Feb 13, 2025

  • I can't seem to resolve the coveralls issue
  • still no groundwater testdata
  • I can't be the reviewer on this anymore

@Zeitsperre
Copy link
Collaborator

@coxipi

Ignore the Coveralls problem for now (I think their service is coming back online gradually). I've removed that as a required check for the time being.

I think we could safely add gwl data to the xclim-testdata repository. Something no bigger than 250 KB would be fine.

For reviewing, I don't mind jumping in, but I think @huard would be better.

Copy link
Contributor

@coxipi coxipi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

--------
>>> from datetime import datetime
>>> from xclim.indices import standardized_groundwater_index
>>> ds = xr.open_dataset(path_to_gwl_file)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would need a xclim-testdata

same in the tests, I just used false data

Comment on lines +2010 to +2016


class StandardizedIndexes(ResamplingIndicator):
"""Resampling but flexible inputs indicators."""

src_freq = ["D", "MS"]
context = "hydro"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aulemahal any opposition to this reorginazation? Previously I defined it in _precip, but now it's also needed in _hydrology

Copy link
Collaborator

@huard huard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just want to make sure this PR is not impeding the use of PWM for genextreme and gamma.

Comment on lines +141 to +142
Resampling frequency. A monthly or daily frequency is expected. Option `None` assumes that desired resampling
has already been applied input dataset and will skip the resampling step.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Resampling frequency. A monthly or daily frequency is expected. Option `None` assumes that desired resampling
has already been applied input dataset and will skip the resampling step.
Resampling frequency. A monthly or daily frequency is expected. Option `None` assumes that the desired resampling
has already been applied to the input dataset and will skip the resampling step.

uses a deterministic function that does not involve any optimization.
`PWM` should be used with a `lmoments3` distribution.
fitkwargs : dict, optional
Kwargs passed to ``xclim.indices.stats.fit`` used to impose values of certains parameters (`floc`, `fscale`).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Kwargs passed to ``xclim.indices.stats.fit`` used to impose values of certains parameters (`floc`, `fscale`).
Kwargs passed to ``xclim.indices.stats.fit`` used to impose values of certain parameters (`floc`, `fscale`).

Comment on lines +446 to +447
Resampling frequency. A monthly or daily frequency is expected. Option `None` assumes that desired resampling
has already been applied input dataset and will skip the resampling step.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Resampling frequency. A monthly or daily frequency is expected. Option `None` assumes that desired resampling
has already been applied input dataset and will skip the resampling step.
Resampling frequency. A monthly or daily frequency is expected. Option `None` assumes that the desired resampling
has already been applied to the input dataset and will skip the resampling step.

The approximate method uses a deterministic function that does not involve any optimization.
`PWM` should be used with a `lmoments3` distribution.
fitkwargs : dict, optional
Kwargs passed to ``xclim.indices.stats.fit`` used to impose values of certains parameters (`floc`, `fscale`).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Kwargs passed to ``xclim.indices.stats.fit`` used to impose values of certains parameters (`floc`, `fscale`).
Kwargs passed to ``xclim.indices.stats.fit`` used to impose values of certain parameters (`floc`, `fscale`).

Comment on lines +838 to +844
# "WPM" method doesn't seem to work for gamma or pearson3
dist_and_methods = {
"gamma": ["ML", "APP"],
"fisk": ["ML", "APP"],
"genextreme": ["ML", "APP"],
"lognorm": ["ML", "APP"],
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean PWM ? Why add genextreme and lognorm here ?

Comment on lines +43 to +59
out1 = land.standardized_streamflow_index(
q,
freq="MS",
window=1,
dist="genextreme",
method="APP",
fitkwargs={"floc": 0},
)
out2 = land.standardized_streamflow_index(
qMM,
freq="MS",
window=1,
dist="genextreme",
method="APP",
fitkwargs={"floc": 0},
)
np.testing.assert_array_almost_equal(out1, out2, 3)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand what is checked here, beyond unit changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Improvements to documenation indicators Climate indices and indicators
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New standardized indices
4 participants