English | Deutsch
Contributing¶
This page is for people who change the package: how the code is organised, how to run the tests, how to build this documentation, and what to do when you add a data type.
Set up¶
pip install -e ".[test,docs]"
How the code is organised¶
src/cdec/eo/
ndvi.py, evi.py, tci.py, ... one module per data type, one download_* function each
scl.py Sentinel-2 SCL classes: names, hints, ready-made selections
util.py login, download + Cloud Optimized GeoTIFF
postprocessing.py colour / contrast enhancement of RGB composites
src/cdec/plot/
products.py one plot_* function per data type (colour map, range, labels)
raster.py the drawing itself, and plot_raster for any GeoTIFF
docs/ this documentation (conf.py, *.rst, _ext/ for the class tables)
Every download_* function reads from top to bottom in the same way: check the arguments, connect, describe the
data as an openEO data cube (load_collection -> mask -> mean_time -> index), then hand the cube to
download_raster_cube (How a download works). Start with ndvi.py; the other modules are
variations of it. The short alias of each function is the last line of its module. The helpers are in the
developer reference.
Run the tests¶
pytest # offline tests only, a few seconds: no internet, no login
pytest --live # additionally download every data type for real
pytest --live -k ndvi
File |
What it tests |
|---|---|
|
what every |
|
colour enhancement (including: same reflectance, same colour), SCL table and validation, helper functions, the public interface (aliases, argument order) |
|
the plot functions: colour maps and ranges, no-data pixels, colour pictures from reflectance, land-cover legend,
axes in degrees or metres, |
|
the documentation: every public name is documented, every data type has a page, the pages build without a warning (the build tests are skipped if Sphinx is not installed) |
|
real downloads of every data type for Bremen (see |
The live tests need internet and a Copernicus Data Space account. The first run asks you to log in. The downloaded
rasters are kept in tests/output/ (ignored by git) so you can open them in QGIS.
Look at the plots¶
tests/plot_gallery.py is not a test. It draws all plot functions into one picture so that you can look at them
(and check a change of a plot function with your own eyes):
python tests/plot_gallery.py # a made-up landscape, works offline
python tests/plot_gallery.py --real # the files that `pytest --live` downloaded to tests/output/
python tests/plot_gallery.py --no-show # do not open a window, only write tests/output/plot_gallery_*.png
Build this documentation¶
python docs/_scripts/build_docs.py
This builds the English and the German version into docs/_build/html/en and docs/_build/html/de. Then open
docs/_build/html/index.html in a browser: it forwards you to the language of your browser (docs/_build/ is
ignored by git). Every build uses -W, which turns every warning into an error. hatch run docs:build does the
same. While you write, one language is quicker:
sphinx-build -W --keep-going -b html docs docs/_build/html/en
sphinx-build -W --keep-going -b html -D language=de docs docs/_build/html/de
The pages follow the Diátaxis scheme: tutorial/ (learning), howto/ (goals),
explanation/ (understanding) and reference/ (look-up), plus one page for each data type in data/.
The pictures on the data type pages are real data. They are made from the files in tests/output/ (after a
pytest --live run) and saved in docs/_static/figures/. After a change of a plot function make them again and
commit them:
python docs/_scripts/make_figures.py
The code examples on the data type pages and the how-to pages are complete: each one defines the
spatial_extent and the temporal_extent it uses (Bremen, June 2024), so that a student can copy it into an empty
file and run it. tests/test_docs.py checks this, and runs the example of every data type page with the made-up
backend. Keep it that way when you write a new page.
Translate the documentation¶
The pages are written in English and translated with Sphinx’s gettext system: the German texts are in
docs/locale/de/LC_MESSAGES/*.po (one file for each folder of docs/). The .rst files exist only once, so
both languages have the same pages, the same pictures and the same code. The .po files also translate the
documentation of the functions (their docstrings); the docstrings in the code stay English.
When you change an English text, the German page shows the new English text until you translate it. To find the texts that changed:
pip install sphinx-intl
sphinx-build -b gettext docs docs/_build/gettext
sphinx-intl -c docs/conf.py update -p docs/_build/gettext -l de
Open the .po files in a text editor or in Poedit and fill in every msgstr that is empty or marked #, fuzzy
(remove the fuzzy line when the translation is right). Do not translate code between double back-ticks and keep
the roles such as :doc: and :func:: Sphinx warns about broken markup, and tests/test_docs.py compares the
code and the roles of every German text with the English one. It also fails while a German text is missing.
For a third language add its code to LANGUAGES in docs/conf.py and run sphinx-intl update with -l and
that code.
Add a data type¶
Write
src/cdec/eo/<name>.pywith thedownload_<long_name>function and a short alias as its last line; copyndvi.pyand change what is different. Export both names insrc/cdec/eo/__init__.py.Write the matching
plot_<long_name>function insrc/cdec/plot/products.pyand export it insrc/cdec/plot/__init__.py.Add the page
docs/data/<name>.rst(copy a page of a similar data type) with a line.. autofunction:: cdec.download_<long_name>and.. autofunction:: cdec.plot_<long_name>, and list it indocs/data/index.rstanddocs/reference/functions.rst. The short alias needs no line: the documentation of the long name shows it automatically.Add the function to the tests (
tests/test_download_offline.py,tests/test_plot.py,tests/test_package.py) and to the live tests.tests/test_docs.pyfails until the documentation is complete.Translate the new texts of the page and of the docstrings into German (see above).
Make a release¶
uv build # or: python -m build
twine check dist/*
Raise __version__ in src/cdec/__about__.py first.