gee逐月计算ndvi的代码
时间: 2023-09-08 08:08:19 浏览: 264
以下是Python中用于逐月计算NDVI的示例代码:
```
import rasterio
import numpy as np
import glob
# 读取所有的红光波段和近红外波段
red_bands = glob.glob('path/to/red/bands/*.tif')
nir_bands = glob.glob('path/to/nir/bands/*.tif')
# 定义计算NDVI的函数
def calc_ndvi(red_band, nir_band):
with rasterio.open(red_band) as red_src, rasterio.open(nir_band) as nir_src:
red = red_src.read(1).astype('float32')
nir = nir_src.read(1).astype('float32')
ndvi = (nir - red) / (nir + red)
return ndvi
# 遍历所有的红光波段和近红外波段,计算NDVI并保存结果
for red_band, nir_band in zip(red_bands, nir_bands):
ndvi = calc_ndvi(red_band, nir_band)
month = red_band.split('/')[-1].split('_')[-2]
with rasterio.open(f'path/to/ndvi/{month}_ndvi.tif', 'w', **red_src.profile) as dst:
dst.write(ndvi, 1)
```
这个代码通过遍历所有的红光波段和近红外波段,计算NDVI并保存结果。在每个月份的NDVI图像中,NDVI值表示该月份该地区的植被生长情况。
阅读全文
相关推荐
















