MODIS LST Data – How to Calculate Temperature of Given Area Using MODIS LST Data

google-earth-enginejavascriptmodis

I am using Google Earth Engine and the MODIS Land Surface Temperature data to try and calculate the temperature of a square of land.

Here is my code so far:

var dataset = ee.ImageCollection('MODIS/006/MOD11A1')
              .filter(ee.Filter.date('2018-12-01', '2018-12-10'));
var landSurfaceTemperature = dataset.select('LST_Day_1km');
var landSurfaceTemperatureVis = {
  min: 13000.0,
  max: 16500.0,
  palette: [
    '040274', '040281', '0502a3', '0502b8', '0502ce', '0502e6',
    '0602ff', '235cb1', '307ef3', '269db1', '30c8e2', '32d3ef',
    '3be285', '3ff38f', '86e26f', '3ae237', 'b5e22e', 'd6e21f',
    'fff705', 'ffd611', 'ffb613', 'ff8b13', 'ff6e08', 'ff500d',
    'ff0000', 'de0101', 'c21301', 'a71001', '911003'
  ],
};
Map.setCenter(6.746, 46.529, 2);
Map.addLayer(
    landSurfaceTemperature, landSurfaceTemperatureVis,
    'Land Surface Temperature');

var temperature = landSurfaceTemperature * 0.02 - 273.15
print(temperature)

As you can see, I am trying to calculate the temperature using the formula T = DN * 0.02 - 273.15 (I found this formula in the following thread How do I convert the LST values on the MODIS LST Image to degree celsius
).

When run, the program produces an output of 'NaN'. I believe I am trying to use the data in the wrong format, but I do not know the correct one.

Best Answer

You should improve two things:

First, the GEE requires server side function, which you can read here.

Secondly, you should apply this per pixel formula of temperature on images, instead of on a image collection (which temperature is). That can be achieved by mapping the collection over its images.

This is how I would apply your function on the images:

// map over the image collection and use server side functions
var tempToDegrees = landSurfaceTemperature.map(function(image){
  return image.multiply(0.02).subtract(273.15);
});
// print and add to the map
print('image collection in temp in degrees', tempToDegrees);
Map.addLayer(tempToDegrees, {min: -20, max: 40, palette: landSurfaceTemperatureVis.palette}, 'temp in degrees');

You can find the full script here Be aware that you are now adding an image collection to the map. I would advice to add single image to the map, for example like this:

var firstImage = tempToDegrees.first();

Or calculate a per-pixel median or mean of the complete collection:

var meanCollection = tempToDegrees.mean();
Related Question