Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
1832f94
Radius computation improved (#22)
pjtys Jan 14, 2025
7e1f84a
Add nodata value to hillshade output (#23)
pjtys Jan 31, 2025
58f1079
docs: start review documentation
cadauxe Oct 30, 2024
70be9b2
refactor: replacing argparse by click in main.py
cadauxe Nov 5, 2024
eb3e4a5
refactor: WIP click
cadauxe Nov 6, 2024
d5aa77c
refactor: replaced argparse by click
cadauxe Nov 8, 2024
6dd23f7
refactor: working tests in all directories
cadauxe Nov 12, 2024
bc2b88b
docs: Docstrings of the click cli functions
cadauxe Nov 14, 2024
2357604
refactor: began setup.py
cadauxe Nov 14, 2024
d1bf785
install: update setup.py
cadauxe Nov 15, 2024
07902b0
feat: add vsimem_to_rasterio function
Nov 29, 2024
ac54e93
refactor: cleaning
cadauxe Dec 2, 2024
48723f6
refactor: suppress vsimem_to_rasterio
cadauxe Dec 4, 2024
51dc6fa
refactor: fixing --compare test
cadauxe Dec 5, 2024
92e737f
refactor: cleaned code
cadauxe Dec 5, 2024
071a31f
refactor: setup w/ rasterio
cadauxe Dec 6, 2024
82f3011
refactor: test --compare modifications
cadauxe Dec 6, 2024
371a214
CI: add CI/CD workflows
Dec 9, 2024
7555591
CD: from test.pypi to pypi
Dec 17, 2024
58777c8
docs : added georastertools tuto
cadauxe Jan 22, 2025
5c0120c
docs : improving georastertools tuto
cadauxe Jan 30, 2025
024465b
docs : improving georastertools tuto
cadauxe Jan 31, 2025
1f95bb2
docs : changing tuto_data
cadauxe Jan 31, 2025
f3b7642
fix : restored "with" data opening
cadauxe Apr 10, 2025
a749d87
feat : removed additionnal stats computation
cadauxe Apr 14, 2025
f73973a
feat : modified ci.yml to test with CI
cadauxe Apr 14, 2025
cc1fced
feat : centralized sys.exit()
cadauxe Apr 17, 2025
4645b22
feat : launch CI when PR into main
cadauxe Apr 17, 2025
de3d234
feat : restored tiling valueError
cadauxe Apr 18, 2025
857e623
feat : tests modifs for CI
cadauxe Apr 18, 2025
0a6d5cf
feat : WIP test tiling
cadauxe Apr 23, 2025
ba1e66f
feat : corrected DHM by DEM
cadauxe May 5, 2025
f9fd5ad
feat : removed duplicated numpy import
cadauxe May 5, 2025
9ff50ea
docs: updated install doc
cadauxe May 5, 2025
c751879
feat : small docs corrections
cadauxe May 6, 2025
3f7eee0
Rasterio plugin and Pip install rasterio (#20)
cadauxe May 6, 2025
ae69738
feat : corrected version in setup.py
cadauxe May 6, 2025
834e4b4
feat : added files for ReadTheDocs
cadauxe May 6, 2025
3381fff
feat : changed DHM by DEM
cadauxe May 6, 2025
8aabe2d
feat : added CI tests time computations
cadauxe May 12, 2025
7a1b5bc
feat : wip Rtd
cadauxe May 12, 2025
a6f56f6
docs : updated tutorial
cadauxe May 12, 2025
eb3c27e
feat : upgraded ci to python 3.10
cadauxe May 5, 2025
088853e
feat : upgraded ci to python 3.10
cadauxe May 5, 2025
c0cc618
feat : upgraded ci to python 3.10
cadauxe May 5, 2025
40133ce
rebased with rasterio_plugin_vsimem
cadauxe May 5, 2025
237c2a7
feat : upgraded cd to python 3.10
cadauxe May 5, 2025
36976af
remove .readthedocs.yaml
cadauxe May 19, 2025
4f1447c
Merge branch 'main' into python310_upgrade
cadauxe May 19, 2025
f85fa28
feat : restricted click version to avoid test fails
cadauxe May 19, 2025
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
42 changes: 42 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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.10
uses: actions/setup-python@v3
with:
python-version: "3.10"

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

- name: Build package
shell: bash -l {0}
run: |
conda create -n deploy_env python=3.10 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.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- 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.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Setup Miniconda
uses: conda-incubator/setup-miniconda@v2
with:
python-version: '3.10'
auto-activate-base: false
- name: Create test env
shell: bash -l {0}
run: |
conda create -n test_env python=3.10 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 --durations=0
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 Elevation 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 georastertools
conda activate
conda install python=3.10 libgdal=3.5.2
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 Elevation Model...
hs Execute the hillshade subcommand on a Digital Elevation 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 Elevation...
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