From a3fba377b5fdc2a446f9cd1c1cb46f48243f3ec7 Mon Sep 17 00:00:00 2001 From: Gajanan Kothawade Date: Wed, 14 Feb 2018 00:37:42 +0530 Subject: [PATCH] Function for NDVI NDVI is used as a base calculation in vegetation analysis --- yatsm/vegetation_indices.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/yatsm/vegetation_indices.py b/yatsm/vegetation_indices.py index 2eccb14c..807603a1 100644 --- a/yatsm/vegetation_indices.py +++ b/yatsm/vegetation_indices.py @@ -31,3 +31,27 @@ def EVI(red, nir, blue): """ return 2.5 * (nir - red) / (nir + 6 * red - 7.5 * blue + 1) + +def NDVI(red, nir): + """ Return the Normalized Difference Vegetation Index for a set of np.ndarrays + + NDVI is calculated as: + + .. math:: + \\frac{(NIR - RED)}{(NIR + RED )} + + where: + - :math:`RED` is the red band + - :math:`NIR` is the near infrared band + + Note: bands must be given in float datatype from [0, 1] + + Args: + red (np.ndarray): red band + nir (np.ndarray): NIR band + + Returns: + np.ndarray: NDVI + + """ + return (nir - red) / (nir + red)