BEEPAS / indices.py
youl's picture
New application
d37b207
raw
history blame
6.85 kB
import numpy as np
def indices(X):
# Calculate vegetation indices
#S2REP
#OTHERS
X["MTCI"] = (X["B06"]-X["B05"])/(X["B05"]-X["B04"])
X["AWEInsh"] = 4.0*(X["B03"]-X["B11"])-0.25*X["B08"]+2.75*X["B12"]
X["NBSIMS"] = 0.36*(X["B03"]+X["B04"]+X["B08"]) - (((X["B02"]+X["B12"])/X["B03"])+X["B11"])
X["MuWIR"] = -4.0*((X["B02"]-X["B03"])/(X["B02"]+X["B03"]))+2.0*((X["B03"]-X["B08"])/(X["B03"]+X["B08"]))+2.0*((X["B03"]-X["B12"])/(X["B03"]+X["B12"]))-((X["B03"]-X["B11"])/(X["B03"]+X["B11"]))
X["VARI700"] = (X["B05"]-1.7*X["B04"]+0.7*X["B02"])/(X["B05"]+1.3*X["B04"]-1.3*X["B02"])
X["S2WI"] = (X["B05"]-X["B12"])/(X["B05"]+X["B12"])
X["NBAI"] = ((X["B12"]-X["B11"])/X["B03"])/((X["B12"]+X["B11"])/X["B03"])
X["TCARI"] = 3*((X["B05"]-X["B04"]))-0.2*(X["B05"]-X["B03"])*(X["B05"]/X["B04"])
X["WI2015"] = 1.7204+171*X["B03"]+3*X["B04"]-70*X["B08"]-45*X["B11"]-71*X["B12"]
X["BAIM"] = 1.0/((0.05-X["B08"])**2.0)+((0.2-X["B12"])**2.0)
X["NDDI"] = (( (X["B08"]-X["B04"])/(X["B08"]+X["B04"])-((X["B03"]-X["B08"])/(X["B03"]+X["B08"])))/((X["B08"]-X["B04"])/(X["B08"]+X["B04"]))+((X["B03"]-X["B08"])/(X["B03"]+X["B08"])))
X["BCC"] = X["B02"]/(X["B04"]+X["B03"]+X["B02"])
X["RCC"] = X["B04"]/(X["B04"]+X["B03"]+X["B02"])
X["IKAW"] = (X["B08"]-X["B02"])/(X["B08"]+X["B02"])
X["ARI"] = (1/X["B03"])-(1/X["B05"])
X["MIRBI"] = 10.0*X["B12"]-9.8*X["B11"]+2.0
X["NMDI2"] = (X["B08"]-(X["B11"]-X["B12"]))/(X["B08"]+(X["B11"]-X["B12"]))
X["TTVI"] = 0.5*((865.0-740.0)*(X["B8A"]-X["B06"]-(X["B07"]-X["B06"])*(783.0-740)))
X["NHFD"] = (X["B05"]-X["B01"])/(X["B05"]+X["B01"])
X["NDSWIR"] = (X["B11"]-X["B8A"])/(X["B11"]+X["B8A"])
X["NBRSWIR"] = (X["B12"]-X["B11"]-0.02)/(X["B12"]+X["B11"]+0.1)
X["NBR"] = (X["B12"]-X["B8A"])/(X["B12"]+X["B8A"])
X["NBRplus"] = (X["B12"]-X["B8A"]-X["B03"]-X["B02"])/(X["B12"]+X["B8A"]+X["B03"]+X["B02"])
X["NDWI2"] = (X["B02"]-X["B08"])/(X["B02"]+X["B08"])
X["NDWI2"] = (X["B01"]-X["B08"])/(X["B01"]+X["B08"])
X["S2REP"] = 705 + 35 * ((((X["B07"] + X["B04"])/2) - X["B05"])/(X["B06"] - X["B05"]))
#S2REP = 705 + 35 * ((((X[:, 6, :] + X[:, 3, :])/2) - X[:, 4, :])/(X[:, 5, :] - X[:, 4, :]))
X["CCCI"] = ((X["B08"] - X["B05"]) / (X["B08"] + X["B05"])) / ((X["B08"] - X["B04"]) / (X["B08"] + X["B04"]))
#CCCI = ((X[:, 7, :] - X[:, 4, :]) / (X[:, 7, :] + X[:, 4, :])) / ((X[:, 7, :] - X[:, 3, :]) / (X[:, 7, :] + X[:, 3, :]))
X["MCARI"] = ((X["B05"] - X["B04"]) - 2 * (X["B05"] - X["B03"])) * (X["B05"] / X["B04"])
#MCARI = ((X[:, 4, :] - X[:, 3, :]) - 2 * (X[:, 4, :] - X[:, 2, :])) * (X[:, 4, :] / X[:, 3, :])
X["TCARI"] = 3 * ((X["B05"] - X["B04"]) - 0.2 * (X["B05"] - X["B03"]) * (X["B05"] / X["B04"]))
#TCARI = 3 * ((X[:, 4, :] - X[:, 3, :]) - 0.2 * (X[:, 4, :] - X[:, 2, :]) * (X[:, 4, :] / X[:, 3, :]))
X["PVI"] = (X["B08"] - 0.3 * X["B04"] - 0.5) / ((1 + 0.3 * 2) ** (1/2.0))
#PVI = (X[:, 7, :] - 0.3 * X[:, 3, :] - 0.5) / ((1 + 0.3 * 2) ** (1/2.0))
X["ndvi"] = (X["B08"] - X["B04"]) / (X["B08"] + X["B04"])
#ndvi = (X[:, 7, :] - X[:, 3, :]) / (X[:, 7, :] + X[:, 3, :])
X["evi"] = 2.5 * (X["B08"] - X["B04"]) / (X["B08"] + 6 * X["B04"] - 7.5 * X["B02"] + 1)
#evi = 2.5 * (X[:, 7, :] - X[:, 3, :]) / (X[:, 7, :] + 6 * X[:, 3, :] - 7.5 * X[:, 1, :] + 1)
X["savi"] = (X["B08"] - X["B04"]) / (X["B08"] + X["B04"] + 0.5)
#savi = (X[:, 7, :] - X[:, 3, :]) / (X[:, 7, :] + X[:, 3, :] + 0.5)
X["mndwi"] = (X["B03"] - X["B08"]) / (X["B03"] + X["B08"])
#mndwi = (X[:, 2, :] - X[:, 7, :]) / (X[:, 2, :] + X[:, 7, :])
X["ARVI"] = (X["B08"] - (2 * X["B04"]) + X["B02"]) / (X["B08"] + (2 * X["B04"]) + X["B02"])
#ARVI = (X[:, 7, :] - (2 * X[:, 3, :]) + X[:, 1, :]) / (X[:, 7, :] + (2 * X[:, 3, :]) + X[:, 1, :])
X["SIPI"] = (X["B08"] - X["B02"]) / (X["B08"] - X["B04"])
#SIPI = (X[:, 7, :] - X[:, 1, :]) / (X[:, 7, :] - X[:, 3, :])
X["RENDVI"] = (X["B06"] - X["B05"]) / (X["B06"] + X["B05"])
#RENDVI = (X[:, 5, :] - X[:, 4, :]) / (X[:, 5, :] + X[:, 4, :])
X["MRESR"] = (X["B06"] - X["B01"]) / (X["B05"] - X["B01"])
#MRESR = (X[:, 5, :] - X[:, 0, :]) / (X[:, 4, :] - X[:, 0, :])
# CANOLA
X["RYI"] = X["B03"] / X["B02"]
#RYI = X[:, 2, :] / X[:, 1, :]
X["NDYI"] = (X["B03"] - X["B02"]) / (X["B03"] + X["B02"])
#NDYI = (X[:, 2, :] - X[:, 1, :]) / (X[:, 2, :] + X[:, 1, :])
X["DYI"] = X["B03"] - X["B02"]
#DYI = X[:, 2, :] - X[:, 1, :]
X["ACI"] = X["B08"] * (X["B04"] + X["B03"])
#ACI = X[:, 7, :] * (X[:, 3, :] + X[:, 2, :])
# WEED
X["CVI"] = (X["B08"] / X["B03"]) * (X["B04"] / X["B03"])
#CVI = (X[:, 7, :] / X[:, 2, :]) * (X[:, 3, :] / X[:, 2, :])
X["AVI"] = (X["B08"] * (1 - X["B04"]) * (X["B08"] - X["B04"]))
#AVI = (X[:, 7, :] * (1 - X[:, 3, :]) * (X[:, 7, :] - X[:, 3, :]))
X["SI"] = ((1 - X["B02"]) * (1 - X["B03"]) * (1 - X["B04"]))
#SI= ((1 - X[:, 1, :]) * (1 - X[:, 2, :]) * (1 - X[:, 3, :]))
X["BSI"] = ((X["B11"] + X["B04"]) - (X["B08"] + X["B02"])) / ((X["B11"] + X["B04"]) + (X["B08"] + X["B02"]))
#BSI= ((X[:, 10, :] + X[:, 3, :]) - (X[:, 7, :] + X[:, 1, :])) / ((X[:, 10, :] + X[:, 3, :]) + (X[:, 7, :] + X[:, 1, :]))
# WINE GRAPES
X["MTCI"] = (X["B06"] - X["B05"])/(X["B05"] - X["B04"])
#MTCI = (X[:, 5, :] - X[:, 4, :])/(X[:, 4, :] - X[:, 3, :])
X["NPCRI"] = (X["B04"] - X["B02"]) / (X["B04"] + X["B02"])
#NPCRI = (X[:, 3, :] - X[:, 1, :]) / (X[:, 3, :] + X[:, 1, :])
# ROOIBOS
X["BAI"] = 1/((0.1 - X["B04"]) ** 2 + (0.06 - X["B08"]) ** 2)
#BAI = 1/((0.1 - X[:, 3, :]) ** 2 + (0.06 - X[:, 7, :]) ** 2)
#MTVI2 = list(1.5*(1.2 * (i - j) - 2.5 * (k - j))* ((2 * i + 1)**2-(6 * i - 5 * k ** (1/2.0)) - 0.5)**(1/2.0) for i, j, k in zip(X[:, 7, :], X[:, 2, :], X[:, 3, :]))
MTVI2 = list(1.5*(1.2 * (i - j) - 2.5 * (k - j))* ((2 * i + 1)**2-(6 * i - 5 * k ** (1/2.0)) - 0.5)**(1/2.0) for i, j, k in zip(X["B08"], X["B03"], X["B04"]))
X["MTVI2"] = np.array(MTVI2)
X["NDSI"] = (X["B03"] - X["B11"]) / (X["B03"] + X["B11"])
#NDSI = (X[:, 2, :] - X[:, 10, :]) / (X[:, 2, :] + X[:, 10, :])
# DRYNESS / DROUGHT
X["NDMI"] = (X["B08"] - X["B11"])/(X["B08"] + X["B11"])
#NDMI = (X[:, 7, :] - X[:, 10, :])/(X[:, 7, :] + X[:, 10, :])
TNDVI = [(x)**(1/2.0) for x in ((X["B08"] - X["B04"]) / (X["B08"] + X["B04"]) + 0.5)]
X["TNDVI"] = np.array(TNDVI)
# GENERAL
X["TVI"] = (120 * (X["B06"] - X["B03"]) - 200 * (X["B04"] - X["B03"])) / 2
#TVI = (120 * (X[:, 5, :] - X[:, 2, :]) - 200 * (X[:, 3, :] - X[:, 2, :])) / 2
X["EXG"] = 2 * X["B03"] - X["B04"] - X["B02"]
#EXG = 2 * X[:, 2, :] - X[:, 3, :] - X[:, 1, :]
X["PSRI"] = (X["B04"] - X["B02"]) / X["B06"]
#PSRI = (X[:, 3, :] - X[:, 1, :]) / X[:, 5, :]
return X