WaterDetect

Water Detect Algorithm

https://github.com/cordmaur/WaterDetect

Science Score: 49.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 6 DOI reference(s) in README
  • Academic publication links
    Links to: zenodo.org
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (10.0%) to scientific vocabulary
Last synced: 7 months ago · JSON representation

Repository

Water Detect Algorithm

Basic Info
  • Host: GitHub
  • Owner: cordmaur
  • License: apache-2.0
  • Language: Jupyter Notebook
  • Default Branch: master
  • Size: 968 KB
Statistics
  • Stars: 210
  • Watchers: 5
  • Forks: 40
  • Open Issues: 1
  • Releases: 10
Created over 6 years ago · Last pushed 11 months ago
Metadata Files
Readme License

README.md

WaterDetect

DOI

Synopsis

WaterDetect is an end-to-end algorithm to generate open water cover mask, specially conceived for L2A Sentinel 2 imagery from MAJA1 processor, without any a priori knowledge on the scene. It can also be used for Landsat 8 images and for other multispectral clustering/segmentation tasks.

The water masks produced by WaterDetect were primarily designed for water quality product computation (Obs2Co processing chain) and are also used for multi-temporal water maps (Surfwater processing chain). Both chains are supported by the "SWOT-Downstream" and TOSCA programs by CNES. Products are provided by the THEIA / Hydroweb-NG platform.

The WaterDetect algorithm uses a multidimensional agglomerative clustering technique on a subsample of the scene's pixels, to group them in classes, and a naive bayes classifier to generalize the results for the whole scene, as summarized in the following picture:

Screenshot

All the details and tests has been described in the article Automatic Water Detection from Multidimensional Hierarchical Clustering for Sentinel-2 Images and a Comparison with Level 2A Processors, under revision by the journal Remote Sensing of Environment.

How to cite

Cordeiro, M. C. R.; Martinez, J.-M.; Peña-Luque, S. Automatic Water Detection from Multidimensional Hierarchical Clustering for Sentinel-2 Images and a Comparison with Level 2A Processors. Remote Sensing of Environment 2021, 253, 112209. https://doi.org/10.1016/j.rse.2020.112209.

Changelog

Release 1.5.15

  • Corrected PyPDF2 deprecation error.

Release 1.5.13

  • Code updated to comply with Sen2Cor processing baseline 04.00, that started in January, 25th 2022.
    BoA offset was added to the Sen2Cor workflow to deal with negative values. Oficial release: https://sentinels.copernicus.eu/documents/247904/4830984/OMPC.CS.DQR.002.07-2022%20-%20i52r0%20-%20MSI%20L2A%20DQR%20August%202022.pdf/36edbb04-0c6c-fba3-5c34-0ba3be82e91c

Release 1.5.12

  • Minor updates to make it compatible with the waterquality package. For more information, check the waterquality package here: https://github.com/cordmaur/WaterQuality

Release 1.5.11

  • Bug fix when loading L1C and S2COR images, from MacOS.

Release 1.5.9

  • Added external mask processing through the command process_ext_masks. It prepares an external mask (ex. created by FMask) to be used by WaterDetect.

Release 1.5.8

  • correct GlintMode to work on S2_THEIA images
  • Add calculation of MBWI index inside DWImageClustering class

Release 1.5.7

  • new entry point runWaterDetect.py
  • Namespace correction for different versions of sklearn package
  • New treatment for negative reflectance values (individual pixel correction)
  • Added regularization option to avoid extreme values on Normalized Difference indices.
  • New water cluster detection method based on lowest Nir reflectance ("minnir")
  • Updated reporting. Invalid mask is superimposed to the RGB scene representation
  • Added support for Sen2Cor internal masks
  • GLINT mode (For entire scenes only). Creates a Glint heatmap based on viewing and solar angles and updates the thresholds to include waters with sun glint in the final mask

Tutorial

The following topics have the first steps to install and run the library. For a more comprehensive tutorial with code samples and results please refer to this tutorial https://cordmaur.medium.com/water-detection-in-high-resolution-satellite-images-using-the-waterdetect-python-package-7c5a031e3d16.

Supported Formats

The algorithm has been developed taking into account atmospherically corrected images from MAJA, as described in the paper. However other image formats are also supported. To the present, the following image formats are supported: * Sentinel 2 - L2A from MAJA: the products can be downloaded from (https://www.theia-land.fr/en/product/sentinel-2-surface-reflectance/) * Sentinel 2 - L2A from Sen2Cor: The L2A processed by Sen2Cor are available at Copernicus SciHub (https://scihub.copernicus.eu/) * Sentinel 2 - L1C: L1C Sentinel 2 images can be downloaded from Copernicus SciHub (https://scihub.copernicus.eu/) * Landsat 8 - To be validated

Dependencies

The required libraries are: GDAL>=3.0.2 matplotlib>=3.1.2 PyPDF2>=1.26.0 scipy>=1.3.2 scikit-learn>=0.22 scikit-image>=0.16.2 numpy>=1.17 PIL>=8.0 lxml>=4.5

Note 1:

GDAL is required to open the satellite images. It's still possible to use without GDAL, from a python console or jupyter notebook, loading the rasters manually and passing all the necessary bands to the DWImageClustering class. Check the topic "Usage from Console" for more information.

Note 2:

Scikit-Image is only necessary to run Otsu threshold method.

The test_dependencies.py can be used to check if all libraries are loading correctly. Simply run:

Instalation

The easiest way to install waterdetect package is with pip command:
pip install waterdetect

Alternatively, you can clone the repository and install from its root throught the following commands: git clone https://github.com/cordmaur/WaterDetect.git cd WaterDetect pip install .

Once installed, a waterdetect entry point is created in the path of the environment. One can check the installation and options by running waterdetect --help. If GDAL is not found, a message will raise indicating that waterdetect will only run from a console. ``` usage: waterdetect [-h] [-GC] [-i INPUT] [-o OUT] [-s SHP] [-p PRODUCT] [-c CONFIG]

The waterdetect is a high speed water detection algorithm for satellite images. It will loop through all images available in the input folder and write results for every combination specified in the .ini file to the output folder. It can also run for single images from Python console or Jupyter notebook. Refer to the onlinedocumentation

optional arguments: -h, --help show this help message and exit -GC, --GetConfig Copy the WaterDetect.ini from the package into the specifieddirectory and skips the processing. Once copied you can edit the .ini file and launch the waterdetect without -c option. -i INPUT, --input INPUT The products input folder. Required. -o OUT, --out OUT Output directory. Required. -s SHP, --shp SHP SHP file. Optional. -p PRODUCT, --product PRODUCT The product to be processed (S2THEIA, L8USGS, S2L1C or S2S2COR) -c CONFIG, --config CONFIG Configuration .ini file. If not specified WaterDetect.ini from current dir and used as default

To copy the package's default .ini file into the current directory, type: waterdetect -GC . without other arguments and it will copy WaterDetect.ini into the current directory. ```

Config File

The waterdetect needs a config file that specifies the bands used in the clustering process as well as other parameters. To obtain the default version of this file, one can use waterdetec -GC and the file WaterDetect.ini will be copied into the current working folder.

Usage as Script

The basic usage for the waterdetect is:
waterdetect -i c:/input_folder -o -c:/output_folder -p S2_THEIA

The input directory should contain the uncompressed folders for the images. The script will loop through all folders in the input directory and save the water masks, graphs and reports to the output folder. The output folder must be created beforehand.

If the config file is not specified, the script will search for WaterDetect.ini in the current folder.

Usage from Console

Once properly installed, the WaterDetect can be run from a console or a Jupyter Notebook, by importing the package and calling DWDetectWater.

```

import waterdetect as wd !waterdetect -GC wd.DWWaterDetect.runwaterdetect(inputfolder='D:\Images\Input\', outputfolder='D:\Images\Output', shapefile='D:\Shp\SomeShapefile.shp', singlemode=False, product=wd.DWProducts.Sentinel2THEIA, configfile='WaterDetect.ini' ) ``` For more information on how to use it from jupyter notebook, in batch or single mode or to use it with other satellite images or without GDAL, please refer to the tutorial available here https://towardsdatascience.com/water-detection-in-high-resolution-satellite-images-using-the-waterdetect-python-package-7c5a031e3d16.

Contributors

Author: Maurício Cordeiro (ANA/GET)
Supervisor: Jean-Michel Martinez (IRD/GET)
Validation dataset: Santiago Pena Luque (CNES)

Institutions

  • ANA - Agência Nacional de Águas (https://www.gov.br/ana/en/)
  • GET - Géosciences Environnement Toulouse (https://www.get.omp.eu/)
  • IRD - Institut de Recherche pour le Développement (https://en.ird.fr/)
  • CNES - Centre National d'Études Spatiales (https://cnes.fr/fr)

License

This code is licensed under the GNU General Public License v3.0 license. Please, refer to GNU's webpage (https://www.gnu.org/licenses/gpl-3.0.en.html) for details.

Reference

(1) Hagolle, O.; Huc, M.; Pascual, D. V.; Dedieu, G. A Multi-Temporal Method for Cloud Detection, Applied to FORMOSAT-2, VENµS, LANDSAT and SENTINEL-2 Images. Remote Sensing of Environment 2010, 114 (8), 1747–1755. https://doi.org/10.1016/j.rse.2010.03.002.

(2) Cordeiro, M. C. R.; Martinez, J.-M.; Peña-Luque, S. Automatic Water Detection from Multidimensional Hierarchical Clustering for Sentinel-2 Images and a Comparison with Level 2A Processors. Remote Sensing of Environment 2021, 253, 112209. https://doi.org/10.1016/j.rse.2020.112209.

Owner

  • Name: Mauricio Cordeiro
  • Login: cordmaur
  • Kind: user
  • Location: Toulouse

Data scientist specialized in geosciences and remote sensing for environment. Deep learning practitioner. More info: http://cordmaur.carrd.co

GitHub Events

Total
  • Watch event: 15
  • Push event: 1
  • Fork event: 2
Last Year
  • Watch event: 15
  • Push event: 1
  • Fork event: 2

Committers

Last synced: 7 months ago

All Time
  • Total Commits: 185
  • Total Committers: 9
  • Avg Commits per committer: 20.556
  • Development Distribution Score (DDS): 0.405
Past Year
  • Commits: 1
  • Committers: 1
  • Avg Commits per committer: 1.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Mauricio Cordeiro c****r@g****m 110
rebellm m****o@a****r 34
David Franca d****f@g****m 16
MH m****2@g****m 14
David Guimaraes 3****a@u****m 5
unknown a****c@t****l 3
Mauricio Cordeiro c****r@M****l 1
Parthiban Marimuthu 6****e@u****m 1
hybam-dev h****v@g****m 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 7 months ago

All Time
  • Total issues: 21
  • Total pull requests: 8
  • Average time to close issues: 3 months
  • Average time to close pull requests: 9 days
  • Total issue authors: 21
  • Total pull request authors: 3
  • Average comments per issue: 3.0
  • Average comments per pull request: 0.0
  • Merged pull requests: 6
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • Krish-newbie (1)
  • jshermeyer (1)
  • cmorenoUCB2021 (1)
  • HEGIT2018 (1)
  • Digdgeo (1)
  • souvik0306 (1)
  • fede1608 (1)
  • DevAlvaroF (1)
  • VaasuDevanS (1)
  • Dave0178 (1)
  • scantle (1)
  • andreabenedetti (1)
  • mazingaro (1)
  • amangupta2303 (1)
  • haozhen315 (1)
Pull Request Authors
  • cordmaur (5)
  • daviguima (2)
  • partheee (1)
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 3
  • Total downloads:
    • pypi 92 last-month
  • Total dependent packages: 0
    (may contain duplicates)
  • Total dependent repositories: 1
    (may contain duplicates)
  • Total versions: 37
  • Total maintainers: 1
proxy.golang.org: github.com/cordmaur/waterdetect
  • Versions: 8
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent packages count: 5.4%
Average: 5.6%
Dependent repos count: 5.8%
Last synced: 7 months ago
proxy.golang.org: github.com/cordmaur/WaterDetect
  • Versions: 8
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent packages count: 5.4%
Average: 5.6%
Dependent repos count: 5.8%
Last synced: 7 months ago
pypi.org: waterdetect

WaterDetect generates open water cover mask for L2A Sentinel 2 imagery without any a priori knowledge on the scene. It can also be used for Landsat 8 images and for other multispectral clustering/segmentation tasks.

  • Versions: 21
  • Dependent Packages: 0
  • Dependent Repositories: 1
  • Downloads: 92 Last month
Rankings
Stargazers count: 5.6%
Forks count: 6.8%
Dependent packages count: 7.3%
Average: 13.6%
Dependent repos count: 22.1%
Downloads: 26.1%
Maintainers (1)
Last synced: 7 months ago

Dependencies

requirements.txt pypi
  • PyPDF2 >=1.26
  • lxml *
  • matplotlib >=3.3
  • numpy >=1.14
  • packaging *
  • pillow >=7.0.0
  • scikit-image >=0.13
  • scikit_learn >=0.19
setup.py pypi
  • PyPDF2 >=1.26
  • lxml >=4.5.0
  • matplotlib >=3.3
  • numpy >=1.17
  • packaging *
  • pillow >=7.0.0
  • scikit-image >=0.13
  • scikit_learn >=0.19