如何使用 Python 计算多光谱植被指数
How to calculate Multispectral Vegetation Indices using Python
我正在尝试使用 Python 从多光谱照片计算多光谱植被指数。
到目前为止,我已经成功计算出NDVI,这很容易实现,因为网上有很多例子。
#Read the image file
image_file = "my_tif_image.tif"
with rasterio.open(image_file) as src:
band_red = src.read(3)
with rasterio.open(image_file) as src:
band_nir = src.read(4)
# Allow division by zero
numpy.seterr(divide='ignore', invalid='ignore')
band_nir = numpy.array(band_nir)
band_red = numpy.array(band_red)
NDVI = (band_nir.astype(float) - band_red.astype(float)) / (band_nir + band_red)
fig1, ax = plt.subplots(figsize=(12, 12))
fig1 = plt.gcf()
ep.plot_bands(NDVI,
cmap='PiYG',
scale=False,
cbar = False, #Change this to TRUE to display the color bar
ax=ax,
vmin=-1, vmax=1,
title="NDVI")
plt.show()
fig1.savefig('NDVI.png',bbox_inches='tight')
但是,除了上述指标外,我无法在任何地方找到有关如何计算其他指标(至少是我感兴趣的指标)的示例。
例如,我尝试使用燃烧面积指数的公式代替 NDVI 指数:
BIR = 1.0 / (((0.1 + band_red) ** 2) + ((0.06 + band_nir) ** 2))
但我得到一个空图并且计算出的数组数非常小(在 10^-9 的数字中)。
我的问题是,为什么很难找到计算和绘制 NDVI 以外的指数的示例?最后,如果我不能用 python 做到这一点,是否有任何其他编程方式可以做到这一点?
要使用燃烧面积指数,必须将数据校准为反射率。
还有其他植被指数:
- Kauth-Thomas 变形(流苏帽)http://web.pdx.edu/~jduh/courses/Archive/geog481w07/Students/Marcello_TasselledCap.pdf
- NDMI 或 NDWI https://www.usgs.gov/core-science-systems/nli/landsat/normalized-difference-moisture-index
- SAVI https://www.usgs.gov/core-science-systems/nli/landsat/landsat-soil-adjusted-vegetation-index
- 这里还有其他例子https://www.usgs.gov/core-science-systems/nli/landsat/landsat-surface-reflectance-derived-spectral-indices?qt-science_support_page_related_con=0#qt-science_support_page_related_con
您可以在 python 或 R 中应用不同的索引(其中包含用于操作的预建立包)。其他选项是 QGIS、PCI Geomatica(需要许可证)和 ArcMAP(需要许可证)。
我正在尝试使用 Python 从多光谱照片计算多光谱植被指数。
到目前为止,我已经成功计算出NDVI,这很容易实现,因为网上有很多例子。
#Read the image file
image_file = "my_tif_image.tif"
with rasterio.open(image_file) as src:
band_red = src.read(3)
with rasterio.open(image_file) as src:
band_nir = src.read(4)
# Allow division by zero
numpy.seterr(divide='ignore', invalid='ignore')
band_nir = numpy.array(band_nir)
band_red = numpy.array(band_red)
NDVI = (band_nir.astype(float) - band_red.astype(float)) / (band_nir + band_red)
fig1, ax = plt.subplots(figsize=(12, 12))
fig1 = plt.gcf()
ep.plot_bands(NDVI,
cmap='PiYG',
scale=False,
cbar = False, #Change this to TRUE to display the color bar
ax=ax,
vmin=-1, vmax=1,
title="NDVI")
plt.show()
fig1.savefig('NDVI.png',bbox_inches='tight')
但是,除了上述指标外,我无法在任何地方找到有关如何计算其他指标(至少是我感兴趣的指标)的示例。
例如,我尝试使用燃烧面积指数的公式代替 NDVI 指数:
BIR = 1.0 / (((0.1 + band_red) ** 2) + ((0.06 + band_nir) ** 2))
但我得到一个空图并且计算出的数组数非常小(在 10^-9 的数字中)。
我的问题是,为什么很难找到计算和绘制 NDVI 以外的指数的示例?最后,如果我不能用 python 做到这一点,是否有任何其他编程方式可以做到这一点?
要使用燃烧面积指数,必须将数据校准为反射率。 还有其他植被指数:
- Kauth-Thomas 变形(流苏帽)http://web.pdx.edu/~jduh/courses/Archive/geog481w07/Students/Marcello_TasselledCap.pdf
- NDMI 或 NDWI https://www.usgs.gov/core-science-systems/nli/landsat/normalized-difference-moisture-index
- SAVI https://www.usgs.gov/core-science-systems/nli/landsat/landsat-soil-adjusted-vegetation-index
- 这里还有其他例子https://www.usgs.gov/core-science-systems/nli/landsat/landsat-surface-reflectance-derived-spectral-indices?qt-science_support_page_related_con=0#qt-science_support_page_related_con
您可以在 python 或 R 中应用不同的索引(其中包含用于操作的预建立包)。其他选项是 QGIS、PCI Geomatica(需要许可证)和 ArcMAP(需要许可证)。