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

Add Continuous Integration (CI) #21

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
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
43 changes: 43 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: CD Workflow

on:
push:
branches:
- "main"

permissions:
contents: read
id-token: write

jobs:
deploy:
runs-on: ubuntu-latest
environment:
name: pypi
steps:
- uses: actions/checkout@v4

- name: Setup Python 3.8.13
uses: actions/setup-python@v3
with:
python-version: "3.8.13"

- name: Setup Miniconda
uses: conda-incubator/setup-miniconda@v2
with:
python-version: 3.8.13
auto-activate-base: false

- name: Build package
shell: bash -l {0}
run: |
conda create -n deploy_env python=3.8.13 libgdal=3.5.2 build -c conda-forge -y
conda activate deploy_env
python -m build -C--global-option=bdist_wheel -C--global-option=--build-number=0 --wheel

- name: Publish package
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
verbose: true
password: ${{ secrets.PYPI_PASSWORD }}
53 changes: 53 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: CI Workflow

on:
pull_request:
branches:
- "main"
permissions:
contents: read

jobs:
quality:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Python 3.8.13
uses: actions/setup-python@v3
with:
python-version: "3.8.13"
- name: Create test env
shell: bash -l {0}
run: |
pip install pylint mccabe
- name: code quality
shell: bash -l {0}
run: |
pylint --disable=all --fail-under=10 --enable=too-many-statements src/eolab/georastertools/
pylint --disable=all --fail-under=10 --enable=too-many-nested-blocks src/eolab/georastertools/
./continuous_integration/scripts/check_mccabe_complexity.sh 25 src/eolab/georastertools
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Python 3.8.13
uses: actions/setup-python@v3
with:
python-version: "3.8.13"
- name: Setup Miniconda
uses: conda-incubator/setup-miniconda@v2
with:
python-version: 3.8.13
auto-activate-base: false
- name: Create test env
shell: bash -l {0}
run: |
conda create -n test_env python=3.8.13 libgdal=3.5.2 -c conda-forge -c defaults -y
conda activate test_env
PIP_NO_BINARY=rasterio pip install .
pip install pylint mccabe
- name: test
shell: bash -l {0}
run: |
conda activate test_env
pytest --cov-fail-under=65 --compare
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
# Distribution / packaging
.Python build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
Expand All @@ -15,10 +14,11 @@ parts/
sdist/
var/
wheels/
*.whl
dist/
*.egg-info/
.installed.cfg
*.egg
*.whl
*.manifest
*.spec

150 changes: 73 additions & 77 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
Raster tools
============

This project provides a command line named **rastertools** that enables various calculation tools:
This project provides a command line named **georastertools** that enables various calculation tools:


- the calculation of radiometric indices on satellite images
- the calculation of the Compute the Sky View Factor (SVF) of a Digital Height Model (DHM).
- the calculation of the hillshades of a Digital Elevation / Surface / Height Model
- the calculation of the speed of evolution of radiometry from images between two dates
- the calculation of zonal statistics of the bands of a raster, that is to say statistics such as min, max, average, etc.
on subareas (defined by a vector file) of the area of interest.

The **rastertools** project also aims to make the handling of the following image products transparent:
The **georastertools** project also aims to make the handling of the following image products transparent:

- Sentinel-2 L1C PEPS (https://peps.cnes.fr/rocket/#/search)
- Sentinel-2 L2A PEPS (https://peps.cnes.fr/rocket/#/search)
Expand All @@ -21,7 +23,7 @@ The **rastertools** project also aims to make the handling of the following imag
It is thus possible to input files in the command line in any of the formats above.
It is also possible to specify your own product types by providing a JSON file as a parameter of the command line (cf. docs/usage.rst)

Finally, **rastertools** offers an API for calling these different tools in Python and for extending its capabilities, for example by defining new radiometric indices.
Finally, **georastertools** offers an API for calling these different tools in Python and for extending its capabilities, for example by defining new radiometric indices.

Installation
============
Expand All @@ -30,100 +32,94 @@ Create a conda environment by typing the following:

.. code-block:: bash

conda env create -f environment.yml
conda env update -f env_update.yml

The following dependencies will be installed in the ``rastertools`` environment:

- pyscaffold
- geopandas
- scipy
- gdal
- rasterio
- tqdm

Install ``rastertools`` in the conda environment by typing the following:

.. code-block:: bash

conda activate rastertools
pip install -e .

.. note::

Note: Installing in a *virtualenv* does not work properly for this project. For unexplained reasons,
the VRTs that are created in memory by rastertools to handle image products are not properly managed
with an installation in a virtualenv.

For more details, including installation as a Docker or Singularity image, please refer to the documentation. : `Installation <docs/install.rst>`_
conda env create -n rastertools
conda activate
conda install python=3.8.13 libgdal
pip install georastertools --no-binary rasterio

For more details, including installation as a Docker or Singularity image, please refer to the documentation. : docs/install.rst

Usage
=====

rastertools
^^^^^^^^^^^
The rastertools command line is the high-level command for activating the various tools.
georastertools
^^^^^^^^^^^^^^
The georastertools command line is the high-level command for activating the various tools.

.. code-block:: console

$ rastertools --help
usage: rastertools [-h] [-t RASTERTYPE] [--version] [-v] [-vv]
{filter,fi,radioindice,ri,speed,sp,svf,hillshade,hs,zonalstats,zs,tiling,ti}
...

Collection of tools on raster data

optional arguments:
-h, --help show this help message and exit
-t RASTERTYPE, --rastertype RASTERTYPE
JSON file defining additional raster types of input
files
--version show program's version number and exit
-v, --verbose set loglevel to INFO
-vv, --very-verbose set loglevel to DEBUG

Commands:
{filter,fi,radioindice,ri,speed,sp,svf,hillshade,hs,zonalstats,zs,tiling,ti}
filter (fi) Apply a filter to a set of images
radioindice (ri) Compute radiometric indices
speed (sp) Compute speed of rasters
svf Compute Sky View Factor of a Digital Height Model
hillshade (hs) Compute hillshades of a Digital Height Model
zonalstats (zs) Compute zonal statistics
tiling (ti) Generate image tiles

Calling rastertools returns the following exit codes:
$ rio georastertools --help
Usage: rio georastertools [OPTIONS] COMMAND [ARGS]...

Main entry point for the `georastertools` Command Line Interface.

The `georastertools` CLI provides tools for raster processing and analysis
and allows configurable data handling, parallel processing, and debugging
support.

Logging:

- INFO level (`-v`) gives detailed step information.

- DEBUG level (`-vv`) offers full debug-level tracing.

Environment Variables:

- `RASTERTOOLS_NOTQDM`: If the log level is above INFO, sets this to
disable progress bars.

- `RASTERTOOLS_MAXWORKERS`: If `max_workers` is set, it defines the max
workers for georastertools.

Options:
-t, --rastertype PATH JSON file defining additional raster types of input
files
--max_workers INTEGER Maximum number of workers for parallel processing. If
not given, it will default to the number of
processors on the machine. When all processors are
not allocated to run georastertools, it is thus
recommended to set this option.
--debug Store to disk the intermediate VRT images that are
generated when handling the input files which can be
complex raster product composed of several band
files.
-v, --verbose set loglevel to INFO
-vv, --very-verbose set loglevel to DEBUG
--version Show the version and exit.
-h, --help Show this message and exit.

Commands:
fi Apply a filter to a set of images.
filter Apply a filter to a set of images.
hillshade Execute the hillshade subcommand on a Digital Height Model...
hs Execute the hillshade subcommand on a Digital Height Model...
radioindice Compute the requested radio indices on raster data.
ri Compute the requested radio indices on raster data.
sp Compute the speed of radiometric values for multiple...
speed Compute the speed of radiometric values for multiple...
svf Compute the Sky View Factor (SVF) of a Digital Height...
ti Generate tiles of an input raster image following the...
tiling Generate tiles of an input raster image following the...
timeseries Generate a timeseries of images (without gaps) from a set...
ts Generate a timeseries of images (without gaps) from a set...
zonalstats Compute zonal statistics of a raster image.
zs Compute zonal statistics of a raster image.

Calling georastertools returns the following exit codes:

.. code-block:: console

0: everything went well
1: processing error
2: incorrect invocation parameters

Details of the various subcommands are presented in the documentation : `Usage <docs/cli.rst>`_


Tests & documentation
=====================

To run tests and generate documentation, the following dependencies must be installed in the conda environment. :

- py.test et pytest-cov (tests execution)
- sphinx (documentation generation)

Pour cela, exécuter la commande suivante :

.. code-block:: console

conda env update -f env_test.yml

Details of the various subcommands are presented in the documentation : docs/cli.rst

Tests
^^^^^

The project comes with a suite of unit and functional tests. To run them,
launch the command ``pytest tests``. To run specific tests, execute ``pytest tests -k "<nom_du_test>"``.
launch the command ``pytest tests``. To run specific tests, execute ``pytest tests -k "<test_name>"``.

The tests may perform comparisons between generated files and reference files.
In this case, the tests depend on the numerical precision of the platforms.
Expand Down
36 changes: 36 additions & 0 deletions continuous_integration/scripts/check_mccabe_complexity.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

if [ -z "$1" ] || [ -z "$2" ]; then
echo "Error: You must specify a McCabe threshold and a directory to analyze."
echo "Usage: $0 <threshold> <directory>"
exit 1
fi

threshold=$1
directory=$2

if [ ! -d "$directory" ]; then
echo "Error: The directory '$directory' does not exist."
exit 1
fi

all_files_ok=true
for file in $(find "$directory" -name "*.py"); do
echo "Analyzing $file ..."
output=$(python -m mccabe --min "$threshold" "$file")

if [ -n "$output" ]; then
echo "Error: McCabe complexity too high in $file"
echo "$output"
all_files_ok=false
fi
done

if $all_files_ok; then
echo "✅ All files have McCabe scores less than or equal to $threshold. ✅"
else
echo "❌ Some files have a complexity higher than $threshold ❌"
exit 1
fi

exit 0
Loading