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).
This script performs the following tasks:
- Authentication: Uses OAuth2 to authenticate with the Sentinel Hub API.
- Data Request: Sends a request to the Sentinel Hub API to retrieve NDVI data for a specified region and time range.
- Data Extraction: Downloads the data as a TAR file and extracts the contents.
- NDVI Calculation: Reads the extracted TIFF file and calculates the mean, minimum, and maximum NDVI values.
- JSON Export: Exports the NDVI statistics to a JSON file.
- Python 3.x
- oauthlib
- requests-oauthlib
- rasterio
- numpy
- tarfile
- os
- json
- logging
To install the required packages, run:
pip install oauthlib requests-oauthlib rasterio numpy
- Clone the repository
git clone https://github.com/lucalevi/NDVI-calculation.git
cd ndvi-data-retrieval
-
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.
-
Run the script
python ndvi_request_final.py
Modify the evalscript and request_payload within the script to customize the data request (e.g. change time range, or data type).
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:
This project is licensed under the MIT License. See the LICENSE file for details.
The script in this repository has been re-elaborated based on two main files:
- Authentication script: see the Python Authentication of Sentinel Hub
- Process API script: see the script using NDVI data
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.
Contributions are welcome! Please feel free to submit a Pull Request.
For any inquiries or issues, please contact iacolettig dot luca at gmail dot com, or submit an issue.