0

I did not receive any data from change temperature CSV from my code. How can I correct it?

I need to export monthly yearly change temperature in single CSV but I did not receive any data in my CSV.

How can I solve it?

//var regions = table.filterBounds(geometry);
var regionNames = ee.List([
  '1','2','3','4','5','6','7','8','9','10','11','12','13'
  ,'14','15','16','17','18','19','20','21','22'
]);
var regions = table.filterBounds(geometry)
  .map(function (region) {
    var index = region.getNumber('FID_1');
    return ee.Feature(region.geometry(), {
      'Region ID': index,
      'Region Name': regionNames.get(index)
    });
  });
  
Map.addLayer(regions);
var clipToCol = function(image){
  return image.clip(regions);
};
var change_c = ee.ImageCollection('MODIS/061/MOD11A2')
.filterDate(ee.Date('2001-01-01'), ee.Date('2022-01-01'))
.filterBounds(geometry)
.map(clipToCol);


var months = ee.List.sequence(1, 12);
var years = ee.List.sequence(2001, 2022);

var change= change_c.map(function(image) {
  return image.multiply(0.02).copyProperties(image,['system:time_start']);
});

var changeByMonthYear = ee.ImageCollection.fromImages(
  years.map(function(y) {
    return months.map(function (m) {
       var median = change
      return change
        .filter(ee.Filter.calendarRange(y, y, 'year'))
        .filter(ee.Filter.calendarRange(m, m, 'month'))
        .median()
        .set('month', m).set('year', y);
         return median
        .set('empty',  median.bandNames().size().eq(0));
  });
}).flatten());
var selectors = ['Region ID', 'Region Name', 'year', 'month', 'ndvi'];

var byRegion = changeByMonthYear
  .filter(ee.Filter.eq('empty', 0)) // Remove year/month without imagery
  .map(function(yearMonthchange) {
    return yearMonthchange
      .reduceRegions({
        collection: regions,
        reducer: ee.Reducer.median().setOutputs(['changetemp']), 
        scale: 500
        
      })
      .map(function (feature) {
        return feature
          .copyProperties(yearMonthchange, yearMonthchange.propertyNames());
      });
  })
  .flatten()
  .select(selectors);
Export.table.toDrive({
  collection: byRegion,
  description: 'changetemp',
  selectors: ['region', 'year', 'month', 'changetemp']
});

This is my link code: https://code.earthengine.google.com/13515dc5d295ecd2a3e3bdf2e495adab

1 Answer 1

0

The problem is that the empty property isn't set on the median images, but it's still used to filter out images. That leads to all images being filtered out. You probably want it to look like this:

  var median = change
    .filter(ee.Filter.calendarRange(y, y, 'year'))
    .filter(ee.Filter.calendarRange(m, m, 'month'))
    .median()
    .set('month', m).set('year', y)
  return median
    .set('empty', median.bandNames().size().eq(0))

https://code.earthengine.google.com/8767a223b0a8f6dc67042122c860762d

3
  • @ Daniel Wiell thank you for your answer but again this code doesen't have any data in this CSV
    – sadaf
    Sep 20, 2022 at 12:07
  • selectors in your export doesn't name the actual properties in byRegion. Run print(byRegion.first().propertyNames()) and include the property names you want to include in your CSV in selectors. Sep 20, 2022 at 13:42
  • @ Daniel Wiell i got another error where is my mistake sir?code.earthengine.google.com/79d986b36035815b510bf025b27aa04b
    – sadaf
    Sep 20, 2022 at 18:04

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.