Skip to content

Sample code downloading a GeoTIF image from Sentinel Hub and calculates the average NDVI on a certain area, which is provided by a polygon within the script

License

Notifications You must be signed in to change notification settings

lucalevi/NDVI-calculation

Repository files navigation

NDVI Data Retrieval and Analysis

This Python script retrieves and analyzes Normalized Difference Vegetation Index (NDVI) data for a specified region using the Sentinel Hub API provided by Copernicus, the Earth observation programme managed by the European Space Agency (ESA).

Overview

This script performs the following tasks:

  1. Authentication: Uses OAuth2 to authenticate with the Sentinel Hub API.
  2. Data Request: Sends a request to the Sentinel Hub API to retrieve NDVI data for a specified region and time range.
  3. Data Extraction: Downloads the data as a TAR file and extracts the contents.
  4. NDVI Calculation: Reads the extracted TIFF file and calculates the mean, minimum, and maximum NDVI values.
  5. JSON Export: Exports the NDVI statistics to a JSON file.

Requirements

  • Python 3.x
  • oauthlib
  • requests-oauthlib
  • rasterio
  • numpy
  • tarfile
  • os
  • json
  • logging

Installation

To install the required packages, run:

pip install oauthlib requests-oauthlib rasterio numpy

Usage

  1. Clone the repository
git clone https://github.com/lucalevi/NDVI-calculation.git
cd ndvi-data-retrieval
  1. Update the 'CLIENT_ID' and 'CLIENT_SECRET' in the script with your Sentinel Hub credentials. Look here for a detailed guide on how to get your own credentials.

  2. Run the script

    python ndvi_request_final.py

Configuration

Modify the evalscript and request_payload within the script to customize the data request (e.g. change time range, or data type).

Sentinel Hub API and Copernicus

This script utilizes the Sentinel Hub API, a powerful interface provided by Copernicus, the European Space Agency's Earth observation program. Sentinel Hub enables easy and efficient access to satellite data for a variety of applications, including agriculture, forestry, and environmental monitoring.

For more information about Sentinel Hub and Copernicus, visit:

License

This project is licensed under the MIT License. See the LICENSE file for details.

Original scripts

The script in this repository has been re-elaborated based on two main files:

The rest of the script is original. Warning: the programme has been submitted to models of artificial intelligence to better the overall performance and readibility of the script.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Contact

For any inquiries or issues, please contact iacolettig dot luca at gmail dot com, or submit an issue.

About

Sample code downloading a GeoTIF image from Sentinel Hub and calculates the average NDVI on a certain area, which is provided by a polygon within the script

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages