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);
    landSurfaceTemperature, landSurfaceTemperatureVis,
    'Land Surface Temperature');

var temperature = landSurfaceTemperature * 0.02 - 273.15

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.


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();
| improve this answer | |
  • I am still confused. When I look in the console, I see the data printed in the script, but I don't know which part of the data is the temperature data. Can I get a temperature for a given 1 km square? – GGamer Dec 23 '18 at 4:46
  • In the 'inspector' tab you can click on individual pixels to obtain temperatures per pixel. You can also apply reduceRegion over an area of interest and calculate for example to mean temperature in that area. – Kuik Dec 23 '18 at 8:50
  • Thank you; I am able to get the temperature of a given pixel. How could I turn the temperatures of a group of pixels on a given day into a Python array that has the respective coordinates of each pixel? For example, given an area in California, I could generate a dataset that has the temperature of each pixel in the area on December 20. – GGamer Dec 24 '18 at 6:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.