-
Notifications
You must be signed in to change notification settings - Fork 27
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
(ready for review) Draft docstring template #690
base: develop
Are you sure you want to change the base?
Changes from all commits
710b656
089d8fe
eb56e4e
a74c821
c59fd69
da8961e
6d92fd1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# Docstring Template | ||
-------------------- | ||
|
||
Below is a docstring example. It contains a suggested docstring layout, example text and example MathJax. | ||
|
||
The layout below will render properly in Read the Docs. Please adjust the example text and MathJax as required. | ||
|
||
Note: backticks render differently in docstrings to elsewhere. Should you wish to include text in backticks, please use double backticks - e.g. ``scores.continuous.mean_error``. (If you only use one set of backticks, the text will instead be rendered as italics in Read the Docs). | ||
|
||
``` | ||
def function_name(*args, *, **kwargs) -> type hint: | ||
''' | ||
A short one or two line description of what the function does. | ||
|
||
Additional information (e.g. a paragraph or two) may be included here following the short description. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Longer lines aren't wrapping on 228. I suggest limiting the line length so that it renders correctly |
||
|
||
MathJax giving the mathematical formula for the metric. Below is some MathJax to use as a | ||
starting point. Note that double-backslash formatting is required to ensure proper rendering in docstrings. | ||
|
||
.. math:: | ||
\\text{mean error} =\\frac{1}{N}\\sum_{i=1}^{N}(x_i - y_i) | ||
\\text{where } x = \\text{the forecast, and } y = \\text{the observation} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to be split into two sections, otherwise the second line becomes part of the first equation. I suggest just using :math:` around the x and y |
||
|
||
Where applicable, say what the range of the score is. For example: | ||
Range: 0 to infinity, 0 is perfect. | ||
|
||
Mathjax can also be included inline, like this :math:`\\text{obs_cdf}(x) = 0` | ||
|
||
Args: | ||
fcst: Forecast data. | ||
obs: Observation data. | ||
reduce_dims: Dimensions to reduce. Can be "all" to reduce all dimensions. | ||
preserve_dims: Dimensions to preserve. Can be "all" to preserve all dimensions. | ||
weights: Weights for calculating a weighted mean of individual scores (e.g. by area, by latitude, | ||
by population, custom). Note that these weights are different to threshold weighting which is done | ||
by decision threshold. | ||
|
||
Returns: | ||
A semantic description of what is returned. Note - type information is automatically included based on type hinting. | ||
|
||
Raises: | ||
A type and description of any special error checking which may result in an exception, e.g. | ||
ValueError: if there are values in `fcst` and `obs` which are invalid | ||
|
||
Notes: | ||
- This section is optional. | ||
- Any additional comments or notes should go here. | ||
|
||
References: | ||
- If possible, a citation to the first (original) paper introducing the score/metric. | ||
- In addition, if that paper is not open access, please also add an open access reference. | ||
- The preferred referencing style for journal articles is [APA (7th edition).](https://apastyle.apa.org/style-grammar-guidelines/references/examples/journal-article-references) | ||
- Example reference below: | ||
- Sorooshian, S., Duan, Q., & Gupta, V. K. (1993). Calibration of rainfall-runoff models: | ||
Application of global optimization to the Sacramento Soil Moisture Accounting Model. | ||
Water Resources Research, 29(4), 1185-1194. https://doi.org/10.1029/92WR02617 | ||
- Optionally, if there is a website(s) that has particularly good information about the metric, please feel free to list it as well. | ||
|
||
See also: | ||
- This section is optional. | ||
- If there are other functions which are directly relevant, you can add e.g. :py:func:`scores.continuous.rmse` with a description. | ||
|
||
Examples: | ||
|
||
>>> import numpy as np # NOTE - the previous line should be empty for rendering to work properly. | ||
>>> import xarray as xr | ||
>>> from scores.probability import interval_tw_crps_for_ensemble | ||
>>> fcst = xr.DataArray(np.random.uniform(-40, 10, size=(10, 10)), dims=['time', 'ensemble']) | ||
>>> obs = xr.DataArray(np.random.uniform(-40, 10, size=10), dims=['time']) | ||
|
||
''' | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the
scores.continuous.mean_error
example, when writing the name of a function it is better to use ":py:func:`"Consider updating this to suggest writing function names with ":py:func:" and non-functions that you want to render as a block (or whatever it's called) with double backtracks (e.g.,
reduce_dims="all"
). I hope that makes senseThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that you use ":py:func:" further down in the example. Consider just updating this example to something like
reduce_dims="all"