Skip to content

Commit

Permalink
docstring fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeitsperre committed Aug 5, 2024
1 parent 8b7d8e9 commit 69a576c
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 73 deletions.
17 changes: 8 additions & 9 deletions src/xsdba/_adjustment.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,29 +693,28 @@ def npdf_transform(ds: xr.Dataset, **kwargs) -> xr.Dataset:
----------
ds : xr.Dataset
Dataset variables:
ref : Reference multivariate timeseries
hist : simulated timeseries on the reference period
ref : Reference multivariate timeseries.
hist : simulated timeseries on the reference period.
sim : Simulated timeseries on the projected period.
rot_matrices : Random rotation matrices.
\*\*kwargs
pts_dim : multivariate dimension name
base : Adjustment class
base_kws : Kwargs for initialising the adjustment object
adj_kws : Kwargs of the `adjust` call
pts_dim : multivariate dimension name.
base : Adjustment class.
base_kws : Kwargs for initialising the adjustment object.
adj_kws : Kwargs of the `adjust` call.
n_escore : Number of elements to include in the e_score test (0 for all, < 0 to skip).
Returns
-------
xr.Dataset
Dataset variables:
scenh : Scenario in the reference period (source `hist` transferred to target `ref` inside training)
scens : Scenario in the projected period (source `sim` transferred to target `ref` outside training)
scenh : Scenario in the reference period (source `hist` transferred to target `ref` inside training).
scens : Scenario in the projected period (source `sim` transferred to target `ref` outside training).
escores : Index estimating the dissimilarity between `scenh` and `hist`.
Notes
-----
If `n_escore` is negative, `escores` will be filled with NaNs.
"""
ref = ds.ref.rename(time_hist="time")
hist = ds.hist.rename(time_hist="time")
Expand Down
19 changes: 9 additions & 10 deletions src/xsdba/_processing.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""
"""# noqa: SS01
Compute Functions Submodule
===========================
Expand Down Expand Up @@ -35,24 +35,23 @@ def _adapt_freq(
Parameters
----------
ds : xr.Dataset
With variables : "ref", Target/reference data, usually observed data and "sim", Simulated data.
With variables : "ref", Target/reference data, usually observed data and "sim", Simulated data.
dim : str, or sequence of strings
Dimension name(s). If more than one, the probabilities and quantiles are computed within all the dimensions.
If `window` is in the names, it is removed before the correction
and the final timeseries is corrected along dim[0] only.
Dimension name(s).
If more than one, the probabilities and quantiles are computed within all the dimensions.
If `window` is in the names, it is removed before the correction and the final timeseries is corrected along dim[0] only.
group : Union[str, Grouper]
Grouping information, see base.Grouper
Grouping information, see base.Grouper.
thresh : float
Threshold below which values are considered zero.
Returns
-------
xr.Dataset, with the following variables:
- `sim_adj`: Simulated data with the same frequency of values under threshold than ref.
Adjustment is made group-wise.
- `pth` : For each group, the smallest value of sim that was not frequency-adjusted. All values smaller were
either left as zero values or given a random value between thresh and pth.
- `pth` : For each group, the smallest value of sim that was not frequency-adjusted.
All values smaller were either left as zero values or given a random value between thresh and pth.
NaN where frequency adaptation wasn't needed.
- `dP0` : For each group, the percentage of values that were corrected in sim.
"""
Expand Down Expand Up @@ -125,7 +124,7 @@ def _normalize(
Returns
-------
xr.Dataset
Group-wise anomaly of x
Group-wise anomaly of 'x'.
Notes
-----
Expand Down
43 changes: 20 additions & 23 deletions src/xsdba/calendar.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""
"""# noqa: SS01
Calendar Handling Utilities
===========================
Expand Down Expand Up @@ -435,11 +435,11 @@ def percentile_doy(
Parameters
----------
arr : xr.DataArray
Input data, a daily frequency (or coarser) is required.
Input data, a daily frequency (or coarser) is required.
window : int
Number of time-steps around each day of the year to include in the calculation.
Number of time-steps around each day of the year to include in the calculation.
per : float or sequence of floats
Percentile(s) between [0, 100]
Percentile(s) between [0, 100].
alpha : float
Plotting position parameter.
beta : float
Expand Down Expand Up @@ -541,16 +541,16 @@ def compare_offsets(freqA: str, op: str, freqB: str) -> bool:
Parameters
----------
freqA : str
RHS Date offset string ('YS', '1D', 'QS-DEC', ...)
RHS Date offset string ('YS', '1D', 'QS-DEC', ...).
op : {'<', '<=', '==', '>', '>=', '!='}
Operator to use.
freqB : str
LHS Date offset string ('YS', '1D', 'QS-DEC', ...)
LHS Date offset string ('YS', '1D', 'QS-DEC', ...).
Returns
-------
bool
freqA op freqB
Either freqA op freqB.
"""
from .xclim_submodules.generic import ( # pylint: disable=import-outside-toplevel
get_op,
Expand Down Expand Up @@ -579,23 +579,20 @@ def parse_offset(freq: str) -> tuple[int, str, bool, str | None]:
Parameters
----------
freq : str
Frequency offset.
Frequency offset.
Returns
-------
multiplier : int
Multiplier of the base frequency. "[n]W" is always replaced with "[7n]D",
as xarray doesn't support "W" for cftime indexes.
Multiplier of the base frequency.
"[n]W" is always replaced with "[7n]D", as xarray doesn't support "W" for cftime indexes.
offset_base : str
Base frequency.
is_start_anchored : bool
Whether coordinates of this frequency should correspond to the beginning of the period (`True`)
or its end (`False`). Can only be False when base is Y, Q or M; in other words, xsdba assumes frequencies finer
than monthly are all start-anchored.
Whether coordinates of this frequency should correspond to the beginning of the period (`True`) or its end (`False`).
Can only be False when base is Y, Q or M; in other words, xsdba assumes frequencies finer than monthly are all start-anchored.
anchor : str, optional
Anchor date for bases Y or Q. As xarray doesn't support "W",
neither does xsdba (anchor information is lost when given).
Anchor date for bases Y or Q. As xarray doesn't support "W", neither does xsdba (anchor information is lost when given).
"""
# Useful to raise on invalid freqs, convert Y to A and get default anchor (A, Q)
offset = pd.tseries.frequencies.to_offset(freq)
Expand Down Expand Up @@ -1236,17 +1233,17 @@ def select_time(
Input data.
drop : bool
Whether to drop elements outside the period of interest or to simply mask them (default).
season : string or sequence of strings, optional
season : str or sequence of str, optional
One or more of 'DJF', 'MAM', 'JJA' and 'SON'.
month : integer or sequence of integers, optional
Sequence of month numbers (January = 1 ... December = 12)
doy_bounds : 2-tuple of integers, optional
month : int or sequence of int, optional
Sequence of month numbers (January = 1 ... December = 12).
doy_bounds : 2-tuple of int, optional
The bounds as (start, end) of the period of interest expressed in day-of-year, integers going from
1 (January 1st) to 365 or 366 (December 31st).
If calendar awareness is needed, consider using ``date_bounds`` instead.
date_bounds : 2-tuple of strings, optional
date_bounds : 2-tuple of str, optional
The bounds as (start, end) of the period of interest expressed as dates in the month-day (%m-%d) format.
include_bounds : bool or 2-tuple of booleans
include_bounds : bool or 2-tuple of bool
Whether the bounds of `doy_bounds` or `date_bounds` should be inclusive or not.
Either one value for both or a tuple. Default is True, meaning bounds are inclusive.
Expand Down Expand Up @@ -1343,7 +1340,7 @@ def _get_doys(_start, _end, _inclusive):


def _month_is_first_period_month(time, freq):
"""Returns True if the given time is from the first month of freq."""
"""Return True if the given time is from the first month of freq."""
if isinstance(time, cftime.datetime):
frq_monthly = xr.coding.cftime_offsets.to_offset("MS")
frq = xr.coding.cftime_offsets.to_offset(freq)
Expand Down
2 changes: 1 addition & 1 deletion src/xsdba/datachecks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""
"""# noqa: SS01
Data Checks
===========
Expand Down
4 changes: 2 additions & 2 deletions src/xsdba/formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,8 +627,8 @@ def generate_indicator_docstring(ind) -> str:
Parameters
----------
ind
Indicator instance
ind : Indicator
An Indicator instance.
Returns
-------
Expand Down
12 changes: 4 additions & 8 deletions src/xsdba/indicator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""
"""# noqa: SS01
Indicator Utilities
===================
Expand All @@ -9,8 +9,8 @@
There are many ways to construct indicators. A good place to start is
`this notebook <notebooks/extendxclim.ipynb#Defining-new-indicators>`_.
Dictionary and YAML parser
--------------------------
Dictionary and YAML parser # noqa: GL06
-------------------------- # noqa: GL06
To construct indicators dynamically, xclim can also use dictionaries and parse them from YAML files.
This is especially useful for generating whole indicator "submodules" from files.
Expand Down Expand Up @@ -73,7 +73,6 @@
<var name in compute> : <variable official name>
...
.. code-block:: restructuredtext
Parameters # noqa: D214
Expand All @@ -99,7 +98,6 @@
As xclim has strict definitions of possible input variables (see :py:data:`xclim.core.utils.variables`),
the mapping of `data.input` simply links an argument name from the function given in "compute"
to one of those official variables.
"""

from __future__ import annotations
Expand Down Expand Up @@ -515,7 +513,6 @@ def _parse_indice(compute, passed_parameters): # noqa: F841
'passed_parameters' is only needed when compute is a generic function
(not decorated by `declare_units`) and it takes a string parameter. In that case
we need to check if that parameter has units (which have been passed explicitly).
"""
docmeta = parse_doc(compute.__doc__)
params_dict = docmeta.pop("parameters", {}) # override parent's parameters
Expand Down Expand Up @@ -951,7 +948,7 @@ def _assign_named_args(self, ba):
)

def _postprocess(self, outs, das, params):
"""Actions to done after computing."""
"""Run post-computation actions."""
return outs

def _bind_call(self, func, **das):
Expand Down Expand Up @@ -1162,7 +1159,6 @@ def json(self, args=None):
Notes
-----
This is meant to be used by a third-party library wanting to wrap this class into another interface.
"""
names = ["identifier", "title", "abstract", "keywords"]
out = {key: getattr(self, key) for key in names}
Expand Down
6 changes: 3 additions & 3 deletions src/xsdba/locales.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def get_local_dict(locale: str | Sequence[str] | tuple[str, dict]) -> tuple[str,
Parameters
----------
locale: str or sequence of str
locale : str or sequence of str
IETF language tag or a tuple of the language tag and a translation dict, or a tuple of the language
tag and a path to a json file defining translation of attributes.
Expand All @@ -112,7 +112,7 @@ def get_local_dict(locale: str | Sequence[str] | tuple[str, dict]) -> tuple[str,
Returns
-------
str
The best fitting locale string
The best fitting locale string.
dict
The available translations in this locale.
"""
Expand Down Expand Up @@ -284,7 +284,7 @@ def generate_local_dict(locale: str, init_english: bool = False) -> dict:
Parameters
----------
locale : str
Locale in the IETF format
Locale in the IETF format.
init_english : bool
If True, fills the initial dictionary with the english versions of the attributes.
Defaults to False.
Expand Down
2 changes: 1 addition & 1 deletion src/xsdba/nbutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def _get_indexes(
Returns
-------
array-like, array-like
A tuple of virtual_indexes neighbouring indexes (previous and next)
A tuple of virtual_indexes neighbouring indexes (previous and next).
Notes
-----
Expand Down
7 changes: 3 additions & 4 deletions src/xsdba/processing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# pylint: disable=missing-kwoa
"""
"""# noqa: SS01
Pre- and Post-Processing Submodule
==================================
"""
Expand Down Expand Up @@ -556,7 +556,7 @@ def to_additive_space(
See Also
--------
from_additive_space : for the inverse transformation.
from_additive_space : For the inverse transformation.
jitter_under_thresh : Remove values exactly equal to the lower bound.
jitter_over_thresh : Remove values exactly equal to the upper bound.
Expand Down Expand Up @@ -654,12 +654,11 @@ def from_additive_space(
See Also
--------
to_additive_space : for the original transformation.
to_additive_space : For the original transformation.
References
----------
:cite:cts:`sdba-alavoine_distinct_2022`.
"""
if trans is None and lower_bound is None and units is None:
try:
Expand Down
24 changes: 12 additions & 12 deletions src/xsdba/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,18 @@ def map_cdf(
Parameters
----------
ds : xr.Dataset
Variables: x, Values from which to pick,
y, Reference values giving the ranking
Variables:
x, Values from which to pick,
y, Reference values giving the ranking.
y_value : float, array
Value within the support of `y`.
Value within the support of `y`.
dim : str
Dimension along which to compute quantile.
Dimension along which to compute quantile.
Returns
-------
array
Quantile of `x` with the same CDF as `y_value` in `y`.
Quantile of `x` with the same CDF as `y_value` in `y`.
"""
return xr.apply_ufunc(
map_cdf_1d,
Expand Down Expand Up @@ -826,19 +827,18 @@ def rand_rot_matrix(
Parameters
----------
crd: xr.DataArray
1D coordinate DataArray along which the rotation occurs.
The output will be square with the same coordinate replicated,
the second renamed to `new_dim`.
crd : xr.DataArray
1D coordinate DataArray along which the rotation occurs.
The output will be square with the same coordinate replicated, the second renamed to `new_dim`.
num : int
If larger than 1 (default), the number of matrices to generate, stacked along a "matrices" dimension.
If larger than 1 (default), the number of matrices to generate, stacked along a "matrices" dimension.
new_dim : str
Name of the new "prime" dimension, defaults to the same name as `crd` + "_prime".
Name of the new "prime" dimension, defaults to the same name as `crd` + "_prime".
Returns
-------
xr.DataArray
float, NxN if num = 1, numxNxN otherwise, where N is the length of crd.
A float, NxN if num = 1, numxNxN otherwise, where N is the length of crd.
References
----------
Expand Down

0 comments on commit 69a576c

Please sign in to comment.