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

Small typing fixes #47

Merged
merged 2 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions environment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ channels:
- conda-forge
dependencies:
- python >=3.9,<3.12
# Don't forget to sync the changes here with environment.yml!
# Don't forget to sync changes between environment.yml, environment-dev.yml, and setup.py!
# Main packages
- numpy
- scipy
- statsmodels
- xarray
- xclim >=0.45.0
Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: xhydro
channels:
- conda-forge
dependencies:
# Don't forget to sync changes between environment.yml, environment-dev.yml, and setup.py!
- python >=3.9,<3.12
- numpy
- scipy
- statsmodels
- xarray
- xclim >=0.45.0
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
with open("README.rst") as readme_file:
readme = readme_file.read()

requirements = ["numpy", "scipy", "statsmodels", "xarray", "xclim>=0.45.0", "xscen"]
# Don't forget to sync changes between environment.yml, environment-dev.yml, and setup.py!
requirements = ["numpy", "statsmodels", "xarray", "xclim>=0.45.0", "xscen"]

dev_requirements = ["pytest", "pytest-cov"]

Expand Down
18 changes: 11 additions & 7 deletions xhydro/frequency_analysis/local.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
"""Local frequency analysis functions and utilities."""

import datetime
from typing import Union
from typing import Optional, Union

import numpy as np
import scipy.stats
import statsmodels
import xarray as xr
import xclim.indices.stats
Expand All @@ -18,18 +17,21 @@


def fit(
ds, distributions: list = None, min_years=None, method: str = "ML"
ds,
distributions: Optional[list[str]] = None,
min_years: Optional[int] = None,
method: str = "ML",
) -> xr.Dataset:
"""Fit multiple distributions to data.

Parameters
----------
ds : xr.Dataset
Dataset containing the data to fit. All variables will be fitted.
distributions : list of str
distributions : list of str, optional
List of distribution names as defined in `scipy.stats`. See https://docs.scipy.org/doc/scipy/reference/stats.html#continuous-distributions.
Defaults to ["expon", "gamma", "genextreme", "genpareto", "gumbel_r", "pearson3", "weibull_min"].
min_years : int
min_years : int, optional
Minimum number of years required for a distribution to be fitted.
method : str
Fitting method. Defaults to "ML" (maximum likelihood).
Expand Down Expand Up @@ -86,7 +88,9 @@ def fit(
return out


def parametric_quantiles(p, t: Union[float, list], mode: str = "max") -> xr.Dataset:
def parametric_quantiles(
p: xr.Dataset, t: Union[float, list[float]], mode: str = "max"
) -> xr.Dataset:
"""Compute quantiles from fitted distributions.

Parameters
Expand Down Expand Up @@ -159,7 +163,7 @@ def parametric_quantiles(p, t: Union[float, list], mode: str = "max") -> xr.Data
return out


def criteria(ds, p) -> xr.Dataset:
def criteria(ds: xr.Dataset, p: xr.Dataset) -> xr.Dataset:
"""Compute information criteria (AIC, BIC, AICC) from fitted distributions, using the log-likelihood.

Parameters
Expand Down
13 changes: 7 additions & 6 deletions xhydro/indicators.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Module to compute indicators using xclim's build_indicator_module_from_yaml."""
import warnings
from typing import Optional

import xarray as xr
import xclim as xc
Expand All @@ -17,7 +18,7 @@


def compute_volume(
da: xr.DataArray, *, out_units: str = "m3", attrs: dict = None
da: xr.DataArray, *, out_units: str = "m3", attrs: Optional[dict] = None
) -> xr.DataArray:
"""Compute the volume of water from a streamflow variable, keeping the same frequency.

Expand All @@ -27,7 +28,7 @@ def compute_volume(
Streamflow variable.
out_units : str
Output units. Defaults to "m3".
attrs : dict
attrs : dict, optional
Attributes to add to the output variable.
Default attributes for "long_name", "units", "cell_methods" and "description" will be added if not provided.

Expand Down Expand Up @@ -58,9 +59,9 @@ def get_yearly_op(
*,
input_var: str = "streamflow",
window: int = 1,
timeargs: dict = None,
timeargs: Optional[dict] = None,
missing: str = "skip",
missing_options: dict = None,
missing_options: Optional[dict] = None,
interpolate_na: bool = False,
) -> xr.Dataset:
"""
Expand All @@ -77,7 +78,7 @@ def get_yearly_op(
window: int
Size of the rolling window. A "mean" operation is performed on the rolling window before the call to xclim.
This parameter cannot be used with the "sum" operation.
timeargs: dict
timeargs: dict, optional
Dictionary of time arguments for the operation. Keys are the name of the period that will be added to the results (e.g. "winter", "summer", "annual").
Values are up to two dictionaries, with both being optional.
The first is {'freq': str}, where str is a frequency supported by xarray (e.g. "YS", "AS-JAN", "AS-DEC"). It needs to be a yearly frequency. Defaults to "AS-JAN".
Expand All @@ -87,7 +88,7 @@ def get_yearly_op(
missing: str
How to handle missing values. One of "skip", "any", "at_least_n", "pct", "wmo".
See :py:func:`xclim.core.missing` for more information.
missing_options: dict
missing_options: dict, optional
Dictionary of options for the missing values' method. See :py:func:`xclim.core.missing` for more information.
interpolate_na: bool
Whether to interpolate missing values before computing the operation. Only used with the "sum" operation. Defaults to False.
Expand Down