# Calculate annual EVI vegetation index in Google Earth Engine

The code use for calculate annual EVI vegetation index in Google Earth Engine but there's a problem not define getEVI8

``````// Define Study Area -- MainProject
var west = 21.691531038847305;
var east = 21.691531038847305; //-103;
var north = 30.563767723564865;
var south = 30.563767723564865;
var resolution = 30;
var projection = "EPSG:5070"; //" "EPSG:4269";                   // max 65336
var MainProject = ee.Geometry.Rectangle(west,north,east,south);
Map.setCenter(30.563767723564865, 21.691531038847305, 8);

image = image.select('B1','B3', 'B4');
};

image = image.select('B2','B4', 'B5');
};

var pixel_qa = image.select('pixel_qa');

var pixel_qa = image.select('pixel_qa');
};

/*For Landsat 5 and 7, the ‘sr_atmos_opacity’ band was used to find and mask hazy pixels.*/

//ATMOS OPACITY MASK (L5/L7) -to get rid of haze
//Select band and multiply by scaling factor
var atmos_qa = image.select('sr_atmos_opacity').multiply(0.0010);
//Mask for non-hazy pixels and remove fill vals
};

/*For Landsat 8’s aerosol band, this function was used to remove pixels labelled as hazy.*/
var aero_qa = image.select('sr_aerosol');

};

// EVI Functions
/*These 2 functions are used to calculate the NDVI for Landsat 5/7 and Landsat 8, respectively.*/
// For L5 and L7
var getEVI57 = function(image){
//Apply saturate function
};

var evi = getEVI8.expression(
'2.5 * ((NIR-RED) / (NIR + 6 * RED - 7.5* BLUE +1))', {
NIR:getEVI57.select('B4'),
RED:getEVI57.select('B3'),
BLUE:getEVI57.select('B1')

});
//.rename('nd');
//return(evi);

// For L8
var getEVI8 = function(image){
//Apply saturate function
};

var evi = getEVI8.expression(
'2.5 * ((NIR-RED) / (NIR + 6 * RED - 7.5* BLUE +1))', {
NIR:getEVI8.select('B5'),
RED:getEVI8.select('B4'),
BLUE:getEVI8.select('B2')
});
//.rename('nd');
//return(evi);

// Sensor calibration functions
//Coefficient Function (L5)
var applyCoefficientL5 = function(image){

}

//Coefficient Function (L8)
var applyCoefficientL8 = function(image){

}

// Main function
var createEVI_Composite_ = function(){
//Set year range
var yearrangeStart = 1985;
var yearrangeStop = 2019;

// Moving into the loop, the next variables of importance are:
for(var loopYear = yearrangeStart; loopYear <= yearrangeStop; loopYear +=1){
//Set years date range
var start = ee.Date.fromYMD(loopYear, 1, 1);
var end = ee.Date.fromYMD(loopYear, 12, 31);

//Landsat 8
var l8 = ee.ImageCollection("LANDSAT/LC08/C01/T1_SR")
//Filter AOI (imported at the top)
.filterBounds(MainProject)
//July and August only
.filterDate(start, end)
//Filter CLOUD_COVER
//Calculate EVI
.map(getEVI8)
//Apply Sensor Callibration Coefficient
.map(applyCoefficientL8);

//Landsat7
var l7 = ee.ImageCollection("LANDSAT/LE07/C01/T1_SR")
//Filter AOI (imported at the top)
.filterBounds(MainProject)
//July and August only
.filterDate(start, end)
//Filter CLOUD_COVER
//Calculate EVI
.map(getEVI57);

//Landsat5
var l5 = ee.ImageCollection("LANDSAT/LT05/C01/T1_SR")
//Filter AOI (imported at the top)
.filterBounds(MainProject)
//July and August only
.filterDate(start, end)
//Filter CLOUD_COVER
//Calculate EVI
.map(getEVI57)
//Apply Sensor Callibration Coefficient
.map(applyCoefficientL5);

//Merge collections
var mergedCollection = ee.ImageCollection(l8.merge(l7).merge(l5)).reduce(ee.Reducer.percentile([90]));
var finalOutput = mergedCollection.reduce(ee.Reducer.median()).clip(MainProject).rename(loopYear.toString());

//Generate filename for export
var filename = ("EVI_Composite_").concat(loopYear.toString());

Export.image.toDrive({
image: finalOutput,
description: filename,
scale: 30,
region: MainProject,
crs: projection,
maxPixels: 800000000

});
}
};

//-----------------------------------//
// 5. MAIN FUNCTION EXECUTION //
//-----------------------------------//
var comp = createEVIComposite();
``````

`getEVI8` is called before it is defined. Move the following section of code around so that `var getEVI8 = function(image){...` comes before `var evi = getEVI8.expression(...`. You are also defining two `evi` variables using different expressions; you probably intended to name the vars differently(?)

Fix this section of code per above recommendation:

``````var evi = getEVI8.expression(
'2.5 * ((NIR-RED) / (NIR + 6 * RED - 7.5* BLUE +1))', {
NIR:getEVI57.select('B4'),
RED:getEVI57.select('B3'),
BLUE:getEVI57.select('B1')

});
//.rename('nd');
//return(evi);

// For L8
var getEVI8 = function(image){
//Apply saturate function
• There are many thing wrong with your script. The `getEVI57` function does not return anything. When it is called, you are not providing an image input, you are calling is multiple times when it could be called just once, etc. You script is sort of complex - I recommend going back and learning EE basics and breaking your script into small sections to simplify implementation and debugging. Jun 26, 2020 at 18:17