1

I want to download an image collection with 36 images from my script in GEE and select the three bands from each image ('NDVI_mean','LST_mean',FV_mean'). I have tried many solutions which are posted on gis.stackexchange but it is not working. Is it possible to export all the images in an image collection? or we have to download each image separately? the error is :

Error: Image.clipToBoundsAndScale, argument 'input': Invalid type.
Expected: Image<unknown bands>. Actual: ImageCollection.

The code is here

Map.centerObject(Scotty, 13);

//cloud mask landsat7,landsat5, and landsat8 based on the pixel_qa band of Landsat SR data.
// function for cloud masking on three types of lan dsat

var LC8_BANDS = ['B4',  'B5', 'B10','pixel_qa']; //Landsat 8
var LC7_BANDS = ['B3',  'B4','B6','pixel_qa']; //Landsat 7
var LC5_BANDS = [ 'B3',  'B4','B6','pixel_qa']; //Llandsat 5
var STD_NAMES = ['red', 'nir', 'temp','qa'];

var cloudmasklandsat7and5and8= function(image){
    var Qlandsat5and7= image.select('qa');
    var cloudShadowBitMask = (1 << 3);
    var cloudsBitMask = (1 << 5);
    var mask5and7=Qlandsat5and7.clip(Scotty).bitwiseAnd(cloudShadowBitMask).eq(0)
                                   .and(Qlandsat5and7.bitwiseAnd(cloudsBitMask).eq(0));
    return image.updateMask(mask5and7);
};




var landsat8 = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR').select(LC8_BANDS, STD_NAMES)
                  .filterDate('2013-01-01', '2019-12-31')
                  .filterBounds(Scotty)
                  .filter(ee.Filter.lt('CLOUD_COVER', 25))
                 .map(cloudmasklandsat7and5and8);

var landsat7 = ee.ImageCollection('LANDSAT/LE07/C01/T1_SR').select(LC7_BANDS, STD_NAMES)
                  .filterDate('1984-01-01', '2012-12-31')
                  .filterBounds(Scotty)
                  .filter(ee.Filter.lt('CLOUD_COVER', 25))
                 .map(cloudmasklandsat7and5and8);

var landsat5 = ee.ImageCollection('LANDSAT/LT05/C01/T1_SR').select(LC7_BANDS, STD_NAMES)
                  .filterDate('1984-01-01', '2012-12-31')
                  .filterBounds(Scotty)
                  .filter(ee.Filter.lt('CLOUD_COVER', 25))
                 .map(cloudmasklandsat7and5and8);

var landsatcolor={
  min: 0,
  max: 3000,
  gamma: 1.4,
};
//Map.addLayer(landsat8,landsatcolor, 'Landsat8' );
//Map.addLayer(landsat7,landsatcolor, 'Landsat7' );
//Map.addLayer(landsat5,landsatcolor, 'Landsat5' );


  // totall image collection
var landsatimage = ee.ImageCollection(landsat5.merge(landsat7).merge(landsat8));
Map.addLayer(landsatimage,landsatcolor, 'Landsat' );

 //    NDVI

 var setNdviMinMax=function (img) {
  var minMax = img
    .select('NDVI')
    .reduceRegion({
      reducer: ee.Reducer.minMax(),
      scale: 30,
      maxPixels: 1e13
    })
    ;
  return img.set({
    'NDVI_min': minMax.get('NDVI_min'),
    'NDVI_max': minMax.get('NDVI_max'),
  }).toFloat();
};
var NDVI=function(image){
  var ndvi = image.addBands(image.normalizedDifference(['nir', 'red']).rename('NDVI'));
  return setNdviMinMax(ndvi).clip(Scotty).toFloat();
};

  var ndviParams = {
  min: -1,
  max: 1.0,
  palette: [
    'FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718', '74A901',
    '66A000', '529400', '3E8601', '207401', '056201', '004C00', '023B01',
    '012E01', '011D01', '011301'
  ],
};

var landsatwithndvi=landsatimage.map(NDVI).filter(ee.Filter.notNull(['NDVI_min', 'NDVI_max']));
print(landsatwithndvi);
Map.addLayer(landsatwithndvi.select('NDVI').filter(ee.Filter.notNull(['NDVI_min', 'NDVI_max'])), ndviParams, 'landsatNdvi');

var addMinMaxBands=function (img) {
  var minMaxBands = ee.Image.constant([
    img.get('NDVI_min'),
    img.get('NDVI_max')])
    .rename(['NDVImin', 'NDVImax']);
  return img.clip(Scotty).addBands(minMaxBands).toFloat();
};
 //2: map the min max function on collection
var landsatNdviminmax = landsatwithndvi.map(addMinMaxBands).filterBounds(Scotty);
print(landsatNdviminmax);

//fv 
var addFVband=function (img) {
  var ndvi = img.select('NDVI');
  var ndviMin = img.select('NDVImin');
  var ndviMax = img.select('NDVImax');
  var fvBand = ndvi
    .subtract(ndviMin)
    .divide(ndviMax.subtract(ndviMin))
    .rename('FV');
  return img.clip(Scotty).addBands(fvBand).toFloat();
};
//4: fv COLLECTION FOR LANDSAT
var landsatfv= landsatNdviminmax.map(addFVband);
print(landsatfv);

// Em

var addEMband=function (img){
  var FVb = img.select('FV');
  var a= ee.Number(0.004);
  var b= ee.Number(0.986);
  var EMBand = FVb
    .multiply(a).add(b).rename('EM');
  return img.addBands(EMBand).toFloat();
};

//5: EM COLLECTION FOR EACH LANDSAT

var landsatEM= landsatfv.map(addEMband);
print(landsatEM);

//6: Thermal landsat 
var LST=function(image){
  var Thermal = image.addBands(image.select('temp').multiply(0.1).rename('Thermal'));
  return Thermal};

var landsatthermal= landsatEM.map(LST);
print(landsatthermal);

var LStfunction = function(image){
  var LSTEQ=image.expression(
    '(Tb/(1 + (0.001145* (Tb / 1.438))*log(Ep)))-273.15', {
      'Tb': image.select('Thermal'),
      'Ep': image.select('EM')}).rename('LST');
 return  image.addBands(LSTEQ)};

var LST= landsatthermal.map(LStfunction);
print(LST);


/*Map.addLayer(LinearFit.select([0]), 
  {min:-0.03, max:0.03, palette:BlueToBrown}, 
  'Linear Trend',
  false);*/


Map.addLayer(LST.select('LST'),{min: -30, max: 32, palette: ['white','blue','green','yellow' ,'red']},'LST');

/////////////// End of LST calculation for each image







/// Annual mean LST

var years = ee.List.sequence(1984, 2019);
print (years);
var collectYear = ee.ImageCollection(years
  .map(function(y) {
    var start = ee.Date.fromYMD(y, 1, 1);
    var end = start.advance(12, 'month');
    return LST.filterDate(start, end).reduce(ee.Reducer.mean()).float();
}));
print (collectYear);

Map.addLayer(collectYear.select('LST_mean'),{min: -30, max: 32, palette: ['white','blue','green','yellow' ,'red']},'LST_Annual');



var finalCollection = collectYear.map(function(image){
  return image.visualize({bands: ['LST_mean', 'NDVI_mean'], min: -40, max: 40});
});
/*Export.video.toDrive({
  collection: finalCollection,
  description: 'yearly',
  dimensions: 1080,
  framesPerSecond: 1,
  region: Scotty
});*/


/// export mean anuual images from collectyear image collection
 Export.image.toDrive({
  image: collectYear.select('LST_mean').select('NDVI_mean').select('FV_mean'),
  description: 'LST_Mean',
  scale: 10,
  maxPixels: 3784216672400,
  region: Scotty,
  });
1
  • The function clipToBoundsAndScale is not in your code. Please scale your code down to the actual problem.
    – Kuik
    Commented Jan 27, 2020 at 22:34

1 Answer 1

3

You will have to export each image in the collection separately. You can trigger the exports with your script, but there will be a lot of manual "Run" button clicks.

collectYear
  .aggregate_array('system:index')
  .evaluate(function (indexes) {
    indexes.forEach(function (index) {
      var image = collectYear
        .filterMetadata('system:index', 'equals', index)
        .first()
      var description = 'LST_Mean-' + index.replace(/[^\w]/, '_')
      Export.image.toDrive({
        image: image.select('LST_mean'),
        description: description,
        scale: 10,
        maxPixels: 3784216672400,
        region: Scotty,
      });      
    })
})

https://code.earthengine.google.com/bd7e38caf3eadbb6b901fe683d9750db

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.