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

Contributing and overall doc comments #1308

Merged
merged 39 commits into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
40914d9
move CONTRIBUTING to top level
Zeitsperre Feb 27, 2023
e130bf8
add license information to README.rst
Zeitsperre Feb 27, 2023
dd7db71
add sphinx-autodoc-typehints
Zeitsperre Feb 27, 2023
2916280
Merge branch 'add_repo_badges-docfix' into reviewer_1_comments
Zeitsperre Feb 27, 2023
f6d6b6b
update history
Zeitsperre Feb 27, 2023
7d78c8e
Add table of contents to API page
Zeitsperre Feb 27, 2023
50c2ad7
Merge branch 'master' into reviewer_1_comments
Zeitsperre Mar 1, 2023
d34c9a5
no longer use generic type for Mapping when parameters are always dicts
Zeitsperre Mar 1, 2023
23216ae
Deal with type hinting warnings within class variable signatures
Zeitsperre Mar 1, 2023
2ef0865
Move SDBA API into API documentation
Zeitsperre Mar 1, 2023
1180825
docstring fixes, mark note about class types
Zeitsperre Mar 1, 2023
9ee2d61
fix default and value signatures
Zeitsperre Mar 1, 2023
d2076b3
make top-most info into note
Zeitsperre Mar 1, 2023
f5b600a
update HISTORY.rst
Zeitsperre Mar 1, 2023
c89d850
collect API documentation under API pages, restructure API documentat…
Zeitsperre Mar 2, 2023
b30434c
split developer functions to developer API
Zeitsperre Mar 2, 2023
f5b0c0c
add new linkcheck exceptions, fix references
Zeitsperre Mar 2, 2023
b48f97d
Clean up wording
Zeitsperre Mar 2, 2023
d19605a
(WIP) More restructuring - working hyperlinks for indicators and indi…
Zeitsperre Mar 2, 2023
acb8a0e
use new generation method on RtD
Zeitsperre Mar 3, 2023
66623df
Stage page detailing why use xclim and comparison to other projects
Zeitsperre Mar 3, 2023
5e7b91b
finally remove llvmlite workaround
Zeitsperre Mar 3, 2023
7c5fe5a
fix linking of targets to prevent collisions on ReadTheDocs
Zeitsperre Mar 3, 2023
0f55bee
fix link
Zeitsperre Mar 3, 2023
ed25808
Update docs/explanation.rst
Zeitsperre Mar 6, 2023
8da44a9
history to CHANGES.rst/changelog
Zeitsperre Mar 6, 2023
03aca77
note about indices and indicators
Zeitsperre Mar 6, 2023
d6aa953
update changelog formatter
Zeitsperre Mar 6, 2023
76c044e
Merge branch 'master' into reviewer_1_comments
Zeitsperre Mar 6, 2023
3817c83
fix bad merge
Zeitsperre Mar 6, 2023
9bba321
make note about Purpose section
Zeitsperre Mar 7, 2023
1531dfd
Working version of purpose and add explanations for similarities with…
Zeitsperre Mar 8, 2023
379e400
Apply suggestions from code review
Zeitsperre Mar 8, 2023
57e9e12
Merge branch 'master' into reviewer_1_comments
Zeitsperre Mar 8, 2023
3208975
add OGC exception
Zeitsperre Mar 8, 2023
f3efd69
Merge remote-tracking branch 'origin/reviewer_1_comments' into review…
Zeitsperre Mar 8, 2023
446dab5
increase tolerance level in test
Zeitsperre Mar 8, 2023
5a1ca6b
fix makefile calls
Zeitsperre Mar 8, 2023
87696b1
[skip ci] update history
Zeitsperre Mar 8, 2023
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
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ repos:
hooks:
- id: pyupgrade
args: ['--py38-plus']
exclude: 'xclim/core/indicator.py'
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
Expand Down
File renamed without changes.
13 changes: 13 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@
History
=======

0.42.0 (unreleased)
-------------------
Contributors to this version: Trevor James Smith (:user:`Zeitsperre`).

Internal changes
^^^^^^^^^^^^^^^^
* Documentation adjustments. (:issue:`1305`, :pull:`1308`):
* The CONTRIBUTING page has been moved to the top level of the repository.
* Information concerning the licensing of xclim is clearly indicated in README.
* `sphinx-autodoc-typehints` is now used to simplify call signatures generated in documentation.
* The SDBA module API is now found with the rest of the User API documentation.
* Removed `Mapping` abstract base class types in call signatures (`dict` variables were always expected). (:pull:`1308`).

0.41.0 (2023-02-28)
-------------------
Contributors to this version: Trevor James Smith (:user:`Zeitsperre`), Pascal Bourgault (:user:`aulemahal`), Ludwig Lierhammer (:user:`ludwiglierhammer`), Éric Dupuis (:user:`coxipi`).
Expand Down
12 changes: 10 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,21 @@ xclim is in active development and is being used in production by climate servic
* If you would like to contribute code or documentation (which is greatly appreciated!), check out the `Contributing Guidelines`_ before you begin!

.. _issue tracker: https://github.com/Ouranosinc/xclim/issues
.. _Contributing Guidelines: https://github.com/Ouranosinc/xclim/blob/master/.github/CONTRIBUTING.rst
.. _Contributing Guidelines: https://github.com/Ouranosinc/xclim/blob/master/CONTRIBUTING.rst

How to cite this library
------------------------
If you wish to cite xclim in a research publication, we kindly ask that you use the bibliographical reference information available through `Zenodo`_

.. _Zenodo: https://doi.org/10.5281/zenodo.2795043
.. _Zenodo: https://doi.org/10.5281/zenodo.2795043S

License
-------
This is free software: you can redistribute it and/or modify it under the terms of the `Apache License 2.0`_. A copy of this license is provided in the code repository (`LICENSE`_).


.. _Apache License 2.0: https://opensource.org/license/apache-2-0/
.. _LICENSE: https://github.com/Ouranosinc/xclim/blob/master/LICENSE

Credits
-------
Expand Down
95 changes: 91 additions & 4 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@
API
===

The API of the statistical downscaling and bias adjustment module (sdba) is documented :ref:`on this page <sdba:SDBA User API>`.
The API of the ``cfchecks``, ``datachecks``, ``missing`` and ``dataflags`` modules are in :ref:`checks:Health Checks`.
Finally, the API of the translating tools is on the :ref:`internationalization:Internationalization` page.
.. note::

The API of the ``cfchecks``, ``datachecks``, ``missing`` and ``dataflags`` modules are located under :ref:`checks:Health Checks`.

The API for the translation tools can be found within :ref:`internationalization:Internationalization`.

.. contents:: Table of Contents
:depth: 1
:local:
:backlinks: none

Indicators
==========
Expand All @@ -17,6 +24,7 @@ Indices
=======

.. toctree::
:maxdepth: 3

indices

Expand All @@ -33,16 +41,19 @@ Ensembles module
.. Use of autofunction is so that paths do not include private modules.
.. autofunction:: xclim.ensembles.kkz_reduce_ensemble
:noindex:

.. autofunction:: xclim.ensembles.kmeans_reduce_ensemble
:noindex:

.. autofunction:: xclim.ensembles.plot_rsqprofile
:noindex:

.. automodule:: xclim.ensembles._robustness
:noindeX:
:noindex:

.. autofunction:: xclim.ensembles.change_significance
:noindex:

.. autofunction:: xclim.ensembles.robustness_coefficient
:noindex:

Expand All @@ -64,6 +75,82 @@ Unit Handling module
:show-inheritance:
:noindex:

.. _sdba-user-api:

SDBA module
===========

.. automodule:: xclim.sdba.adjustment
:members:
:exclude-members: BaseAdjustment
:special-members:
:show-inheritance:
:noindex:

.. automodule:: xclim.sdba.processing
:members:
:noindex:

.. automodule:: xclim.sdba.detrending
:members:
:show-inheritance:
:exclude-members: BaseDetrend
:noindex:

.. automodule:: xclim.sdba.utils
:members:
:noindex:

.. autoclass:: xclim.sdba.base.Grouper
:members:
:class-doc-from: init
:noindex:

.. automodule:: xclim.sdba.nbutils
:members:
:noindex:

.. automodule:: xclim.sdba.loess
:members:
:noindex:

.. automodule:: xclim.sdba.properties
:members:
:exclude-members: StatisticalProperty
:noindex:

.. automodule:: xclim.sdba.measures
:members:
:exclude-members: StatisticalMeasure
:noindex:

SDBA Developer tools
--------------------

.. automodule:: xclim.sdba.base
:members:
:show-inheritance:
:exclude-members: Grouper
:noindex:

.. autoclass:: xclim.sdba.detrending.BaseDetrend
:members:
:noindex:

.. autoclass:: xclim.sdba.adjustment.TrainAdjust
:members:
:noindex:

.. autoclass:: xclim.sdba.adjustment.Adjust
:members:
:noindex:

.. autofunction:: xclim.sdba.properties.StatisticalProperty
:noindex:

.. autofunction:: xclim.sdba.measures.StatisticalMeasure
:noindex:

Other Utilities
===============

Expand Down
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def _indicator_table(module):
"autodoc_indicator",
"sphinxcontrib.bibtex",
"sphinxcontrib.cairosvgconverter",
"sphinx_autodoc_typehints",
"sphinx_codeautolink",
"sphinx_copybutton",
"sphinx_rtd_theme",
Expand Down
2 changes: 1 addition & 1 deletion docs/contributing.rst
Original file line number Diff line number Diff line change
@@ -1 +1 @@
.. include:: ../.github/CONTRIBUTING.rst
.. include:: ../CONTRIBUTING.rst
95 changes: 8 additions & 87 deletions docs/sdba.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Bias Adjustment and Downscaling Algorithms
==========================================


The `xclim.sdba` submodule provides a collection of bias-adjustment methods meant to correct for systematic biases found in climate model simulations relative to observations.
Almost all adjustment algorithms conform to the `train` - `adjust` scheme, meaning that adjustment factors are first estimated on training data sets, then applied in a distinct step to the data to be adjusted.
Given a reference time series (ref), historical simulations (hist) and simulations to be adjusted (sim),
Expand All @@ -29,8 +28,7 @@ series, and possibly reduce the number of quantile bins that needs to be used.

Modular Approach
================

The module atempts to adopt a modular approach instead of implementing published and named methods directly.
The module attempts to adopt a modular approach instead of implementing published and named methods directly.
A generic bias adjustment process is laid out as follows:

- preprocessing on ``ref``, ``hist`` and ``sim`` (using methods in :py:mod:`xclim.sdba.processing` or :py:mod:`xclim.sdba.detrending`)
Expand All @@ -40,7 +38,7 @@ A generic bias adjustment process is laid out as follows:

The train-adjust approach allows to inspect the trained adjustment object. The training information is stored in
the underlying `Adj.ds` dataset and usually has a `af` variable with the adjustment factors. Its layout and the
other available variables vary between the different algorithm, refer to :ref:`Adjustment methods <sdbauserapi>`.
other available variables vary between the different algorithm, refer to :ref:`Adjustment methods <sdba-user-api>`.

Parameters needed by the training and the adjustment are saved to the ``Adj.ds`` dataset as a `adj_params` attribute.
Parameters passed to the `adjust` call are written to the history attribute in the output scenario DataArray.
Expand All @@ -49,7 +47,6 @@ Parameters passed to the `adjust` call are written to the history attribute in t

Grouping
========

For basic time period grouping (months, day of year, season), passing a string to the methods needing it is sufficient.
Most methods acting on grouped data also accept a `window` int argument to pad the groups with data from adjacent ones.
Units of `window` are the sampling frequency of the main grouping dimension (usually `time`). For more complex grouping,
Expand All @@ -63,27 +60,22 @@ In a conventionnal empirical quantile mapping (EQM), this will compute the quant
passed, the adjustment factors will always be interpolated to the largest range of day of the years but this can
lead to strange values, so we recommend converting the data beforehand to a common calendar.


Application in multivariate settings
====================================

When applying univariate adjustment methods to multiple variables, some strategies are recommended to avoid introducing unrealistic artifacts in adjusted outputs.

Minimum and maximum temperature
-------------------------------

When adjusting both minimum and maximum temperature, adjustment factors sometimes yield minimum temperatures larger than the maximum temperature on the same day, which of course, is nonsensical.
One way to avoid this is to first adjust maximum temperature using an additive adjustment, then adjust the diurnal temperature range (DTR) using a multiplicative adjustment, and then determine minimum temperature by subtracting DTR from the maximum temperature :cite:p:`thrasher_technical_2012,agbazo_characterizing_2020`.

Relative and specific humidity
------------------------------

When adjusting both relative and specific humidity, we want to preserve the relationship between both.
To do this, :cite:t:`grenier_two_2018` suggests to first adjust the relative humidity using a multiplicative factor, ensure values are within 0-100%, then apply an additive adjustment factor to the surface pressure before estimating the specific humidity from thermodynamic relationships.

Radiation and precipitation
---------------------------

^^^^^^^^^^^^^^^^^^^^^^^^^^^
In theory, short wave radiation should be capped when precipitation is not zero, but there is as of yet no mechanism proposed to do that, see :cite:t:`hoffmann_meteorologically_2012`.

Usage examples
Expand All @@ -92,7 +84,6 @@ The usage of this module is documented in two example notebooks: `SDBA <notebook

Discussion topics
=================

Some issues were also discussed on the Github repository. Most of these are still open questions, feel free to participate to the discussion!

* Number quantiles to use in quantile mapping methods: :issue:`1162`
Expand Down Expand Up @@ -125,81 +116,11 @@ See the `sdba-advanced` notebook for more info on the reasons for this move.
Other restrictions : ``map_blocks`` will remove any "auxiliary" coordinates before calling the wrapped function and will
add them back on exit.

.. _sdbauserapi:

SDBA User API
=============

.. automodule:: xclim.sdba.adjustment
:members:
:exclude-members: BaseAdjustment
:special-members:
:show-inheritance:
:noindex:

.. automodule:: xclim.sdba.processing
:members:
:noindex:

.. automodule:: xclim.sdba.detrending
:members:
:show-inheritance:
:exclude-members: BaseDetrend
:noindex:

.. automodule:: xclim.sdba.utils
:members:
:noindex:

.. autoclass:: xclim.sdba.base.Grouper
:members:
:class-doc-from: init
:noindex:

.. automodule:: xclim.sdba.nbutils
:members:
:noindex:

.. automodule:: xclim.sdba.loess
:members:
:noindex:

.. automodule:: xclim.sdba.properties
:members:
:exclude-members: StatisticalProperty
:noindex:

.. automodule:: xclim.sdba.measures
:members:
:exclude-members: StatisticalMeasure
:noindex:

Developer tools
===============

.. automodule:: xclim.sdba.base
:members:
:show-inheritance:
:exclude-members: Grouper
:noindex:

.. autoclass:: xclim.sdba.detrending.BaseDetrend
:members:
:noindex:

.. autoclass:: xclim.sdba.adjustment.TrainAdjust
:members:
:noindex:

.. autoclass:: xclim.sdba.adjustment.Adjust
:members:
:noindex:

.. autofunction:: xclim.sdba.properties.StatisticalProperty
:noindex:

.. autofunction:: xclim.sdba.measures.StatisticalMeasure
:noindex:
User API
========

See: :ref:`sdba-user-api`


.. only:: html or text

Expand Down
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ dependencies:
- pytest-cov
- pytest-xdist>=3.2
- sphinx
- sphinx-autodoc-typehints
- sphinx-codeautolink
- sphinx-copybutton
- sphinx-rtd-theme>=1.0
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ dev = [
"netCDF4 >=1.4",
"pooch",
"sphinx",
"sphinx-autodoc-typehints",
"sphinx-codeautolink",
"sphinx-copybutton",
"sphinx-rtd-theme >=1.0",
Expand Down
Loading