Skip to content

dhanushs403-blip/LST-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

// ================================================================================= // PART 1: SETUP - AOI, DATE & LANDSAT COLLECTION // =================================================================================

// Define Area of Interest (AOI) for Bengaluru var aoi = ee.Geometry.Polygon([[ [77.498, 13.032], [77.498, 13.117], [77.652, 13.117], [77.652, 13.032], [77.498, 13.032] ]]);

// Date range for the analysis var startDate = '2025-01-07'; var endDate = '2025-01-09';

// Define the Landsat 8 Collection 2, Tier 1, Level 2 dataset var datasetID = 'LANDSAT/LC08/C02/T1_L2'; print('Using Landsat Dataset:', datasetID);

// Center the map on the Area of Interest Map.centerObject(aoi, 9); // Zoom out a bit to see the full scene

// ================================================================================= // PART 2: PRE-PROCESSING FUNCTIONS // =================================================================================

// Function to apply scaling factors to Landsat 8 bands function applyScaleFactors(image) { var optical = image.select('SR_B.').multiply(0.0000275).add(-0.2); var thermal = image.select('ST_B.*').multiply(0.00341802).add(149.0); return image.addBands(optical, null, true) .addBands(thermal, null, true); }

// Function to mask clouds and cloud shadows using the QA_PIXEL band function maskL8sr(image) { var qa = image.select('QA_PIXEL'); var cloudShadowBitMask = (1 << 5); var cloudsBitMask = (1 << 3); var mask = qa.bitwiseAnd(cloudShadowBitMask).eq(0) .and(qa.bitwiseAnd(cloudsBitMask).eq(0)); return image.updateMask(mask); }

// ================================================================================= // PART 3: LOAD AND PROCESS LANDSAT DATA // =================================================================================

var collection = ee.ImageCollection(datasetID) .filterDate(startDate, endDate) .filterBounds(aoi) .map(applyScaleFactors) .map(maskL8sr);

var image = ee.Image(collection.sort('CLOUD_COVER').first()); var acquisitionDate = ee.Date(image.get('system:time_start')); // Keep as ee.Date object print('Image Acquisition Date:', acquisitionDate.format('YYYY-MM-dd'));

// ================================================================================= // PART 4: CALCULATE LST AND SPECTRAL INDICES // =================================================================================

// --- LST CALCULATION --- var ndvi = image.normalizedDifference(['SR_B5', 'SR_B4']).rename('NDVI'); var fv = ndvi.subtract(0.2).divide(0.5 - 0.2).clamp(0, 1).rename('FV'); var em = fv.multiply(0.004).add(0.986).rename('EM'); var thermal = image.select('ST_B10').rename('thermal'); var lst = thermal.expression( '(BT / (1 + ((LAMBDA * BT / RHO) * log(EM)))) - 273.15', { 'BT': thermal, 'EM': em, 'LAMBDA': 1.0895e-5, 'RHO': 1.438e-2 } ).rename('LST');

// --- ADDED: SPECTRAL INDICES CALCULATION --- // NDBI (Built-up): (SWIR1 - NIR) / (SWIR1 + NIR) var ndbi = image.normalizedDifference(['SR_B6', 'SR_B5']).rename('NDBI');

// NDWI (Water): (Green - NIR) / (Green + NIR) var ndwi = image.normalizedDifference(['SR_B3', 'SR_B5']).rename('NDWI');

// ================================================================================= // PART 5: DISPLAY LANDSAT LST RESULTS // =================================================================================

var lstStats = lst.reduceRegion({ reducer: ee.Reducer.minMax().combine(ee.Reducer.mean(), '', true), geometry: aoi, scale: 30, maxPixels: 1e9 }); print('--- Landsat LST Results (for the small AOI) ---'); print('LST Min (°C):', lstStats.get('LST_min')); print('LST Max (°C):', lstStats.get('LST_max')); print('LST Mean (°C):', lstStats.get('LST_mean'));

var lstVis = { min: 25, max: 45, palette: [ '040274','0602ff','307ef3','30c8e2','3ff38f','86e26f','b5e22e', 'ffd611','ff8b13','ff6e08','ff0000','a71001' ]};

Map.addLayer(lst, lstVis, 'Landsat LST (°C) - Full Scene');

// ================================================================================= // PART 6: PREPARE DATA FOR EXPORT AND VALIDATION // =================================================================================

// Define the boundary of the Landsat image to use for the export region var landsat_boundary = image.geometry();

var startDateMODIS = acquisitionDate.advance(-4, 'day'); var endDateMODIS = acquisitionDate.advance(4, 'day'); var modisCollection = ee.ImageCollection('MODIS/061/MOD11A1').filterDate(startDateMODIS, endDateMODIS);

// ================================================================================= // PART 7: EXPORT RASTER FILES TO GOOGLE DRIVE AND PRINT MODIS STATS // =================================================================================

print('--- Preparing Export Tasks ---'); print('Go to the "Tasks" tab in the right panel to run the exports.');

// --- EXPORT 1: High-Resolution LST from Landsat --- Export.image.toDrive({ image: lst, description: 'Export_LST_from_Landsat', folder: 'GEE_Exports', fileNamePrefix: 'LST_Landsat_30m_20210129', region: landsat_boundary, scale: 30, maxPixels: 1e13, fileFormat: 'GeoTIFF' });

// --- ADDED: EXPORT SPECTRAL INDICES --- Export.image.toDrive({ image: ndvi, description: 'Export_NDVI', folder: 'GEE_Exports', fileNamePrefix: 'NDVI_30m_20210129', region: landsat_boundary, scale: 30, maxPixels: 1e13, fileFormat: 'GeoTIFF' });

Export.image.toDrive({ image: ndbi, description: 'Export_NDBI', folder: 'GEE_Exports', fileNamePrefix: 'NDBI_30m_20210129', region: landsat_boundary, scale: 30, maxPixels: 1e13, fileFormat: 'GeoTIFF' });

Export.image.toDrive({ image: ndwi, description: 'Export_NDWI', folder: 'GEE_Exports', fileNamePrefix: 'NDWI_30m_20210129', region: landsat_boundary, scale: 30, maxPixels: 1e13, fileFormat: 'GeoTIFF' });

// Check if there is MODIS data before trying to process or export it if (modisCollection.size().gt(0)) { var modisMean = modisCollection.mean(); var modis_lst = modisMean.select('LST_Day_1km').multiply(0.02).subtract(273.15);

var modisStats = modis_lst.reduceRegion({ reducer: ee.Reducer.mean(), geometry: landsat_boundary, scale: 1000, maxPixels: 1e10 });

print('--- MODIS Validation ---'); print('MODIS 8-Day Mean LST for Full Landsat Scene (°C):', modisStats.get('LST_Day_1km'));

// --- EXPORT 2: Low-Resolution LST from MODIS --- Export.image.toDrive({ image: modis_lst, description: 'Export_LST_from_MODIS', folder: 'GEE_Exports', fileNamePrefix: 'LST_MODIS_1km_Composite_20210129', region: landsat_boundary, scale: 1000, maxPixels: 1e13, fileFormat: 'GeoTIFF' });

print('MODIS export task has been prepared.');

} else { print('No MODIS images found. MODIS LST was not exported.'); }

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors