我有一个栅格数据,其中包含 NaN 值作为无数据。我想从中计算新的栅格,例如 if raster==0 do statement1,if raster==1 do statement2,如果 raster 介于 0 和 1 之间,则 do statement3,否则不要更改值。如何使用 numpy.where() 函数来做到这一点?
这是我的代码:
import os
import rasterio
from rasterio import plot
import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline
os.listdir('../NDVI_output')
ndvi1 = rasterio.open("../NDVI_output/NDVI.tiff")
min_value = ndvi_s = np.nanmin(ndvi) #NDVI of Bare soil
max_value = ndvi_v = np.nanmax(ndvi) #NDVI of full vegetation cover
fvc = (ndvi-ndvi_s)/(ndvi_v-ndvi_s) #fvc: Fractional Vegetation Cover
band4 = rasterio.open('../TOAreflectance_output/TOAref_B4.tiff')
toaRef_red = band4.read(1).astype('float64')
emiss = np.where((fvc == 1.).any(), 0.99,
(np.where((fvc == 0.).any(), 0.979-0.046*toaRef_red,
(np.where((0.<fvc<1.).any(), 0.971*(1-fvc)+0.987*fvc, fvc)))))
饮歌长啸
相关分类