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:
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:
Or calculate a per-pixel median or mean of the complete collection: