/*=========================================================================================== Agriculture Drought Monitoring and Hazard Assessment Temperature Condition Index (TCI) =========================================================================================== Within this script MODIS data is used to calculate the Temperature Condition Index (TCI) for a specific time and location. Land surface temperature (LST) derived from thermal radiance bands is a good indicator of the energy balance of the Earth’s surface, because temperatures can rise quickly under water stress. The TCI is an initial indicator of water stress and drought. =========================================================================================== ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: RUN A DEMO (optional) If you would like to run an example, you can use the predefined geometry below as well as the other predefined parameter settings. The code will take you to the Sindh Province, Pakistan, looking at the drought situation in March 2019. --> Remove the comment-symbol (//) below so Earth Engine recognizes the polygon.*/ // var geometry = ee.Geometry.Polygon([[[67.0438497, 24.74674177],[67.3075216, 28.323637774435067],[70.6913106898558, 28.594081948857962],[70.3836935023558, 24.666896799718423]]]); /* Now hit Run to start the demo! Do not forget to delete/outcomment this geometry before creating a new one! ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */ //******************************************************************************************* // USER INPUT // 1. Import the shapefile of your study area, or draw a polygon in the map window below. // // 2. At the top, change the name of the import or drawn polygon to AOI. // a) If a shapefile import is used, remove // symbols in next line: // var geometry = AOI.geometry(); // b) If a polygon was drawn in Google Earth Engine Map, remove // symbols in next line: // var geometry = AOI; // 3. Set variable for which month (format 'MM'), and year (format 'YYYY') you want to // calculate the index: var month = '03'; var year = '2019'; /******************************************************************************************** ---->>> DO NOT EDIT THE SCRIPT PAST THIS POINT! (unless you know what you are doing) <<<--- ------------------>>> now hit the'RUN' at the top of the script! <<<----------------------- ----> The final flood product will be ready for download on the right (under Console) <---- ******************************************************************************************/ // Zoom to AOI Map.centerObject(geometry,5); // Transformations for dates var monthn = +month; //numerical var yearn = +year; //numerical var monthn1 = monthn+1; if (monthn1 == 13) { var monthn1 = 01; } var month1 = padLeadingZeros(monthn1,2); //Visualization Palette var vis = ['d7191c', 'fdae61', 'ffffc0', 'a6d96a', '1a9641']; // Filterout Specific Month for analysis var imageFilter = ee.Filter.calendarRange(monthn,monthn,'month'); //selection of Historical datasets var startDate = ee.String('2000-').cat(month); var endDate = ee.String((yearn-1).toString()).cat('-').cat(month1); if (monthn1 == 1) { var endDate = ee.String((yearn).toString()).cat('-').cat(month1); } // Specific month time to see the drought like condition var imageStartDate = year.concat('-',month); var imageEndDate = ee.String((yearn).toString()).cat('-').cat(month1); if (monthn1 == 1) { var imageEndDate = ee.String((yearn+1).toString()).cat('-').cat(month1); } //Load collection for TCI var collection = ee.ImageCollection('MODIS/006/MOD11A2').filterDate(startDate, endDate).filter(imageFilter); var factor_NDVI = function(image){ return image.multiply(0.02); }; var lst = collection.select('LST_Day_1km'); //minimum and maximum LST var minLST = lst.min(); var maxLST = lst.max(); var image = ee.ImageCollection('MODIS/006/MOD11A2').filterDate(imageStartDate, imageEndDate).filter(imageFilter).max(); var imageLST = image.select('LST_Day_1km'); // TCI calculation and Clipping according to the AOI var TCI = (maxLST.subtract(imageLST)).divide(maxLST.subtract(minLST)).clip(geometry); Map.addLayer(TCI,{ min: -1, max: 1, palette: vis}, 'TCI',false); //Applying classifying Criteria var image02 = ee.Image(TCI.lt(0.1).and(TCI.gte(-1))); var image04 = ee.Image(((TCI.gte(0.1)).and(TCI.lt(0.2))).multiply(2)); var image06 = ((TCI.gte(0.2)).and(TCI.lt(0.3))).multiply(3); var image08 = ((TCI.gte(0.3)).and(TCI.lt(0.4))).multiply(4); var image10 = (TCI.gte(0.4)).multiply(5); var Drought_Index = (image02.add(image04).add(image06).add(image08).add(image10)); var Drought_Index = Drought_Index.float(); // Export to Google Drive Export.image.toDrive({ image: Drought_Index, description: 'Drought_Index_TCI', fileNamePrefix: 'Drought_Index_TCI', region: geometry, scale: 1000, crs: 'EPSG:4326', skipEmptyTiles: true }); Map.addLayer(Drought_Index,{ min: 1, max: 5, palette: vis}, 'Drought Index'); /////////////////////////////////////////////////////////////////////////////// //Creation of Classification Legend /////////////////////////////////////////////////////////////////////////////// var legend = ui.Panel({ style: { position: 'bottom-left', padding: '8px 15px' } }); // Create and add the legend title. var legendTitle = ui.Label({ value: 'Drought Index (TCI)', style: { fontWeight: 'bold', fontSize: '18px', margin: '0 0 4px 0', padding: '0' } }); legend.add(legendTitle); // Creates and styles 1 row of the legend. var makeRow = function(color, name) { // Create the label that is actually the colored box. var colorBox = ui.Label({ style: { backgroundColor: '#' + color, // Use padding to give the box height and width. padding: '8px', margin: '0 0 4px 0' } }); // Create the label filled with the description text. var description = ui.Label({ value: name, style: {margin: '0 0 4px 6px'} }); return ui.Panel({ widgets: [colorBox, description], layout: ui.Panel.Layout.Flow('horizontal') }); }; legend.add(makeRow('d7191c', 'Extreme'));//1 legend.add(makeRow('fdae61', 'Severe'));//2 legend.add(makeRow('ffffc0', 'Moderate'));//3 legend.add(makeRow('a6d96a', 'Mild'));//4 legend.add(makeRow('1a9641', 'No Drought'));//5 Map.add(legend); // Function used for transforming dates to string and having leading 0, if necessary function padLeadingZeros(num, size) { var s = num+""; while (s.length < size) s = "0" + s; return s; }