I am trying to calculate EVI from MODIS data in Arc. I know how to run one raster group of 3 bands but don't know how to tell it to move on to the next group of 3 bands in that directory. Here is the formula EVI = 2.5 * (NIR-Red)/(NIR+6*Red-7.5*Blue+1). So ideally I would like it to run a directory of many tiles with their bands in order from 1-3.
The following assumes you have ArcGIS 10.2 and the Spatial Analyst extension. If you have the Spatial Analyst extension available to you, I'm pretty sure the ArcPy.sa Raster Object can be used to apply the *EVI = 2.5 * (NIR-Red)/(NIR+6*Red-7.5*Blue+1)* formula across all MODIS rasters in your directory. I'm thinking we need these steps:
- Get a list of all of the MODIS raster datasets in the directory (the trickery shown below with the paths here is a poor hack, there is probably a better way)
- For each MODIS raster identify NIR, BLUE, and RED bands. Create a Raster Object for each.
- Use math expressions on the Raster Objects to get the EVI output raster
The code may look something like:
import arcpy from arcpy import env arcpy.CheckOutExtension("Spatial") from arcpy.sa import * env.workspace = "The\\Modis\\Rasters\\Directory" RasterList = arcpy.ListRasters() counter = 1 for Rasteroo in RasterList: RedBand = arcpy.Raster(env.workspace + "\\" + Rasteroo + "\\" + "Band_1") # here, we can create raster objects from single bands in a raster dataset BlueBand = arcpy.Raster(env.workspace + "\\" + Rasteroo + "\\" + "Band_2") NIRBand = arcpy.Raster(env.workspace + "\\" + Rasteroo + "\\" + "Band_3") EVI_Raster = 2.5 * (NIRBand - RedBand)/(NIRBand + (6 * RedBand) - (7.5 * BlueBand) + 1) # Is this math correct to your EVI formula? EVI_Raster.save(env.workspace + "\\" + "EVI_Raster_" + str(counter)) counter +=1
Best Luck with this.
Just use model builder.
Step 1 iterate your rasters.
Select the folder or Geodatabase of all your rasters on the left.
Step 2. would be (many options here but I would use map algebra) put your math into the Single Map Algebra Function. Remember to specify the bands.
Then use this for the output name EVI%Name%
This will result in one output file in your output geodatabase or folder named EVIinputname with the EVI result. You can do hundreds overnight.
HINT -- if your inputs are Integer and you want decimals in the output (I think this will be the case, it almost always is) they just add a FLOAT command between the Iterator and the Raster Calculator (I process EVI often...). Otherwise you get zero for everyone.