2

I'm trying to extract from the MODIS collection MOD11A1006 band "LST_Day_1km" at one point coordinates the value of each image in the collection together with the date, and hour of the image and export this data to a CSV file. However, if I'm not mistaken, the code bellow gets the the "date" and "hour" when the image was taken, but for some reason I could not extract the "LST_Day_1km" band value at the point coordinates. How this could be extracted?

// Site coords
var siteCoords_features = [
ee.Feature(ee.Geometry.Point( -69.282000066708,-12.831999897556432), {name: 'site'})];

// Creates a FeatureCollection from coords
var pt_collection = ee.FeatureCollection(siteCoords_features);
print('Point', pt_collection)
Map.addLayer(pt_collection)
Map.centerObject(pt_collection, 10)

// Modis Collection
var startDate = ee.Date.fromYMD(2015,1,1);
var endDate = ee.Date.fromYMD(2020,12,31);
var dataset = ee.ImageCollection('MODIS/006/MOD11A1')
                  .filterDate(startDate, endDate)
                  .filterBounds(pt_collection.geometry())
                   .select('LST_Day_1km');
 print("Collection",dataset)                 

// Extracted band Scale to Kelvin and convert to Celsius
var modLSTc = dataset.map(function(img) {
  return img
    .multiply(0.02)
    .subtract(273.15)
   .copyProperties(img, ['system:time_start']);
});
print('Modis Image Colection processed:', modLSTc);
//Map.addLayer(modLSTc)

var geometry = pt_collection.geometry();
var extractData = function(img){
    var stats = img.reduceRegion({
      geometry: geometry,
      scale: 30,
      reducer: ee.Reducer.first()})
    return ee.Feature(geometry, {
      value: img.get('LST_Day_1km'), 
      hourStart: img.get('system:time_start'),
      hourEnd : img.get('system:time_start'),
      date: img.get('system:index'),
      lat: geometry.coordinates().get(0),
      lon: geometry.coordinates().get(1),
      })
    
}
var outputData = modLSTc.map(extractData)
print('output',outputData)


/*
// Export
Export.table.toDrive({
  collection: outputData,
  folder: 'GEE_results',
  fileNamePrefix: 'MODIS_LST_2015_2020',
  fileFormat: 'CSV',
  selectors: ['date', 'hourStart','hourEnd' ,'value', 'lat', 'lon']})
*/        

1 Answer 1

0

When you are working with these time series collections, you have to be sure that they are not empty at considered geometry. First of all, I "added" as layer first image of modLSTc without any result. So, afterward, I could add modLSTc mean indicating this Image Collection is not empty. Now, I could corroborate that you didn't extract the "LST_Day_1km" band value at the point coordinates because value is in the new created variable stats; not in img. So, I modified your code as follows for retrieving 2182 corresponding values (including nulls) for 'LST_Day_1km' and correct value for 'system:time_end'.

// Site coords
var siteCoords_features = [
ee.Feature(ee.Geometry.Point(-69.282000066708,-12.831999897556432 ), {name: 'site'})];

// Creates a FeatureCollection from coords
var pt_collection = ee.FeatureCollection(siteCoords_features);
print('Point', pt_collection);
Map.addLayer(pt_collection);
Map.centerObject(pt_collection, 10);

// Modis Collection
var startDate = ee.Date.fromYMD(2015,1,1);
var endDate = ee.Date.fromYMD(2020,12,31);
var dataset = ee.ImageCollection('MODIS/006/MOD11A1')
                  .filterDate(startDate, endDate)
                  .filterBounds(pt_collection.geometry())
                   .select('LST_Day_1km');

print("Collection",dataset);               

//Map.addLayer(dataset.first());

// Extracted band Scale to Kelvin and convert to Celsius
var modLSTc = dataset.map(function(img) {
  return img
    .multiply(0.02)
    .subtract(273.15)
   .copyProperties(img, ['system:time_start', 'system:time_end']);
});

print('Modis Image Colection processed:', modLSTc);
//Map.addLayer(modLSTc.mean());

var geometry = pt_collection.geometry();
var extractData = function(img){
    var stats = img.reduceRegion({
      geometry: geometry,
      scale: 30,
      reducer: ee.Reducer.first()});

    return ee.Feature(geometry, {
      value: stats.get('LST_Day_1km'), 
      hourStart: img.get('system:time_start'),
      hourEnd : img.get('system:time_end'),
      date: img.get('system:index'),
      lat: geometry.coordinates().get(0),
      lon: geometry.coordinates().get(1),
      });
    
};

var outputData = modLSTc.map(extractData);
print('output',outputData);

// Export
Export.table.toDrive({
  collection: outputData,
  folder: 'GEE_results',
  fileNamePrefix: 'MODIS_LST_2015_2020',
  fileFormat: 'CSV'});

After running above code in GEE code editor, an extract of obtained CSV can be observed as follows.

enter image description here

It can also be observed there are many missing values for temperature (column highlighted with red rectangle).

4
  • Thanks a lot for the clear explanation !!!
    – Gab
    Nov 29, 2021 at 8:12
  • I have a question I wanted the night band results for the same code so I have changed where say in the code "LST_Day_1km" to "LST_Night_1km" however in the output the hour is still the same. What could be the problem ? Thanks.
    – Gab
    Nov 30, 2021 at 17:19
  • None, it is OK. You have to use 'Night_view_time' (scaled by 0.1) for considering hours night range for each pixel. More information here: developers.google.com/earth-engine/datasets/catalog/… .
    – xunilk
    Dec 1, 2021 at 14:50
  • I could do it, but in two separated CSV files. One for the LST value and the other for its hour at : code.earthengine.google.com/daa003540e309044ef250fa70f2188d8 How can I get in one solely CSV file: the LST value from "LST_Night_1km" band and its correspondent hour from "Night_view_time" band for the point of interest?
    – Gab
    Dec 3, 2021 at 8:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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