I am trying to calculate multiple NDVI files from multiple red band files and NIR band files in 2 separated folders with the following code using python:
import arcpy
from arcpy.sa import *
# set workspace
arcpy.env.workspace = r"F:/..."
# set folder paths
folder1 = r"F:/..."
folder2 = r"F:/..."
# loop through each raster in folder1 and folder2
for raster1 in arcpy.ListRasters("TIF", folder1):
for raster2 in arcpy.ListRasters("TIF", folder2):
# create raster objects
ras1 = Raster(folder1 + "/" + raster1)
ras2 = Raster(folder2 + "/" + raster2)
# calculate NDVI
ndvi = ((ras2 - ras1) / (ras2 + ras1))
# save NDVI raster
ndvi.save(r"F:/..." + raster1[:-4] + "_ndvi.tif")
The code runs successfully but returns an empty output folder. What could be the reason?