Measuring crop health
Products used: s2_l2a
Keywords: data used; sentinel-2, band index; NDVI, interactive, analysis; time series, agriculture
While crops are growing, fields may look visually similar. However, health or growth rates from these fields can be quite different, leading to variability and unpredictability in revenue. Identifying underperforming crops can have two benefits:
Ability to scout for disease damage.
Ability to investigate poor performing fields and undertake management action such as soil testing or targeted fertilising to improve yield.
Digital Earth Africa use case
Satellite imagery can be used to measure plant health over time and identify any changes in growth patterns between otherwise similar fields. Sentinel-2’s 20-metre resolution makes it ideal for understanding the health of large fields.
The Normalised Difference Vegetation Index (NDVI) describes the difference between visible and near-infrared reflectance of vegetation cover. This index estimates the density of green on an area of land and can be used to track the health and growth of crops as they mature. Comparing the NDVI of two similar planting areas will help to identify any anomalies in growth patterns.
In this example, data from Sentinel-2 is used to assess crop growing patterns for the last two years. The worked example below takes users through the code required to:
Create a time series data cube over croplands.
Select multiple areas for comparison.
Create graphs to identify crop performance trends over the last two years.
Interpret the results.
To run this analysis, run all the cells in the notebook, starting with the “Load packages and apps” cell.
Load packages and apps
This notebook works via two functions, which are referred to as apps:
run_crophealth_app. The apps allow the majority of the analysis code to be stored in another file, making the notebook easy to use and run. To view the code behind the apps, open the notebookapp_crophealth.py file.
%matplotlib inline import sys import datacube sys.path.append("../Scripts") from notebookapp_crophealth import load_crophealth_data from notebookapp_crophealth import run_crophealth_app
/env/lib/python3.6/site-packages/geopandas/_compat.py:88: UserWarning: The Shapely GEOS version (3.7.2-CAPI-1.11.0 ) is incompatible with the GEOS version PyGEOS was compiled with (3.9.1-CAPI-1.14.2). Conversions between both will be slow. shapely_geos_version, geos_capi_version_string
The following cell sets important parameters for the analysis. There are three parameters that control where the data will be loaded:
lat: The central latitude to analyse (e.g.
lon: The central longitude to analyse (e.g.
buffer: The number of square degrees to load around the central latitude and longitude. For reasonable loading times, set this as
These can be changed in the cell below, noting that the DE Africa Explorer can be used to check whether Sentinel-2 data is available over the selected area.
Here are some suggestions for areas to look at. To view one of these areas, copy and paste the parameter values into the cell below, then run the notebook.
lat = 14.789064 lon = -17.065202 buffer = 0.005
Aviv Coffee Farm, Tanzania
lat = -10.6979 lon = 35.2635 buffer = 0.003
Croplands, Western Kenya
lat = -0.483689 lon = 34.193792 buffer = 0.005
# Define the area of interest for the analysis lat = 14.789064 lon = -17.065202 buffer = 0.005
Load the data
load_crophealth_data() command performs several key steps:
identify all available Sentinel-2 data in the case-study area over the last two years
remove any bad quality pixels
keep images where more than half of the image contains good quality pixels
calculate the NDVI from the red and near infrared bands
return the collated data for analysis
The cleaned and collated data is stored in the
dataset object. As the command runs, feedback will be provided below the cell, including information on the number of cleaned images loaded from the satellite.
The function takes three arguments:
buffer. These determine the area of interest that the function loads, and can be changed in the previous cell.
Please be patient. The load is complete when the cell status goes from
dataset = load_crophealth_data(lat, lon, buffer)
Using pixel quality parameters for Sentinel 2 Finding datasets s2_l2a Counting good quality pixels for each time step Filtering to 97 out of 146 time steps with at least 50.0% good quality pixels Applying pixel quality/cloud mask Loading 97 time steps
Run the crop health app
run_crophealth_app() command launches an interactive map. Drawing polygons within the red boundary (which represents the area covered by the loaded data) will result in plots of the average NDVI in that area. Draw polygons by clicking the ⬟ symbol in the app.
The function works by taking the loaded data
dataset as an argument, as well as the
buffer parameters used to define the spatial extent.
Note: data points will only appear for images where more than 50% of the pixels were classified as good quality. This may cause trend lines on the average NDVI plot to appear disconnected. Available data points will be marked with the
run_crophealth_app(dataset, lat, lon, buffer)
Here are some questions to think about:
What are some factors that might explain differences or similarities across different sections of the study area?
Are there any noticable patterns across the two years of data? Could these correspond to specific events such as planting or harvesting?
Contact: If you need assistance, please post a question on the Open Data Cube Slack channel or on the GIS Stack Exchange using the
open-data-cube tag (you can view previously asked questions here). If you would like to report an issue with this notebook, you can file one on
Compatible datacube version:
from datetime import datetime datetime.today().strftime('%Y-%m-%d')