0

I´m trying to make an overview in a table or graph of the available images in Landsat, Sentinel and Modis series for a certain area of interest. Although I could solve it as follows, this is obviously very inefficient.

Does anyone have an advice how to write this more efficiently?

// ------INPUT------------------------------------------------------------------------------------------------------------
// define a year of classification
var year_start = 1970;
var year_end = 2018;
var date_start = ee.Date.fromYMD(year_start,1,1);
var date_end = ee.Date.fromYMD(year_end,12,31);
var cloud_cover_100 = 100;
var cloud_cover_90 = 90;
var cloud_cover_80 = 80;
var cloud_cover_70 = 70;
var cloud_cover_60 = 60;
var cloud_cover_50 = 50;
var cloud_cover_40 = 40;
var cloud_cover_30 = 30;
var cloud_cover_20 = 20;
var cloud_cover_10 = 10;
var cloud_cover_5 = 5;
//     ------LANDSAT------------------------------------------------------------------------------------------------------------
var size_l8 = l8.filterBounds(aoi).filterDate(date_start,date_end).toList(1000000).length();
print('Total number of images in l8 in current time frame: ', size_l8);

l8 = l8.filterBounds(aoi).filterDate(date_start,date_end).filter(ee.Filter.lt('CLOUD_COVER_LAND',cloud_cover_100));
var size = l8;
print(size);
l8 = l8.filterBounds(aoi).filterDate(date_start,date_end).filter(ee.Filter.lt('CLOUD_COVER_LAND',cloud_cover_90));
var size = l8;
print(size);
l8 = l8.filterBounds(aoi).filterDate(date_start,date_end).filter(ee.Filter.lt('CLOUD_COVER_LAND',cloud_cover_80));
var size = l8;
print(size);
etc...
  • Is the code running slow or what do you mean by making it more efficient? – Kersten Apr 26 '18 at 9:30
  • In the end the goal would be to make an overview of the cloud cover over time with 3 variables: 1. the amount of cloud cover, 2. the start and end date, 3. the selected satellites. Therefore I was planning to write out all these options manually, but it would take a whole lot of time and most of all is not very convenient. I was thinking if something like a function could solve this, but I´m not sure how to set it up. – Wouter Neisingh Apr 30 '18 at 5:56
1

You can write a function to create a histogram of an image metadata (i.e. CLOUD_COVER_LAND) values, and run the function for each combination of year and image collection.

var get_cloudcover_histogram = function(collection, start, end) {
  var images_in_period = collection.filterBounds(aoi)
                                  .filterDate(start, end);
  var cloudcover_histogram = images_in_period
                             .reduceColumns({
                               reducer:ee.Reducer.fixedHistogram(0,110,11),
                               selectors:['CLOUD_COVER_LAND']
                             });
  return cloudcover_histogram;
};

// Define a sample Area-of-Interest.
var aoi = ee.Geometry.Polygon(
        [[[-106.82, 36.56],
          [-106.89, 36.43],
          [-106.54, 36.43]]]);

// Define a set of years.
var years = [];
for (var i = 1970; i <= 2018; i++) {
   years.push(i);
}

// Define a set of image collections.
var collections = [
  'LANDSAT/LC08/C01/T1_SR',
  'LANDSAT/LE07/C01/T1_SR',
  'LANDSAT/LT05/C01/T1_SR'
];

for (var i_collection = 0; i_collection < collections.length; i_collection++) { 
  var collection_name = collections[i_collection];
  var collection = ee.ImageCollection(collection_name);
  for (var i_year = 0; i_year < years.length; i_year++) { 
    var year = years[i_year];
    var start = ee.Date.fromYMD(year, 1, 1);
    var end = start.advance(1, 'year');
    print(collection_name, year, get_cloudcover_histogram (collection, start, end).get('histogram'));
  }
}

Note that the metadata 'CLOUD_COVER_LAND' may not be set for all Landsat images.

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.