0

As a newbie to the google earth engine, I have been trying something (https://code.earthengine.google.com/6f45059a59b75757c88ce2d3869fc9fd) following a NASA tutorial (https://www.youtube.com/watch?v=JFvxudueT_k&ab_channel=NASAVideo). My last line (line 60) shows image.filter is not a function, while the one in the tutorial (line 34) is working. I am not sure what happened and how to sort this out?

//creating a new variable 'image' from the L8 collection data imported
var image = ee.Image (L8_tier1  //the details in the data will represent that the band resolution is 30m
          //the details in the data will represent that the band resolution is 30m
          //.filterDate ("2019-07-01","2021-10-03") //for a specific date range. maybe good to remove it for the function.
  //the details in the data will represent that the band resolution is 30m
 //the details in the data will represent that the band resolution is 30m
  //.filterDate ("2019-07-01","2021-10-03") //for a specific date range. maybe good to remove it for the function.
  .filterBounds (ROI) //for the region of interest we are interested in 
  //.sort ("COLUD_COVER") //for sorting the data between the range with a cloud cover, the metadata property we are interested in. Other way to do this is using the function below.
  //.first() //this will make the image choose the first image with the least amount of cloud cover for the area. Other way to do this is using the function below.
  );
  
//print ("Hague and Rotterdam", image); //printing the image in the console

//console on the right hand side will explain everything from the data
//id will show the image deatils and date of the image, for this case 29th July 2019
//under the properties tab cloud cover can be found, this is the least we can get for this area during this period

// //vizualisation of the data in the map with true color rendering
// var trueColour = {
//   bands:["SR_B4","SR_B3","SR_B2"],
//   min: 5000,
//   max: 12000
// };

// Map.centerObject (ROI, 12); //for the centering the area in the center of the map with required zoom level

// Map.addLayer (image, trueColour, "Hague and Rotterdam"); //for adding the image with the variable of bands we made and naming the image

//Alternate way
//Function to cloud mask from the qa_pixel band of Landsat 8 SR data. In this case bits 3 and 4 are clouds and cloud shadow respectively. This can be different for different image sets.
function maskL8sr(image) {
  var cloudsBitMask = 1 << 3; //remember to check this with the source
  var cloudshadowBitMask = 1 << 4; //remember to check this with the source
  
  var qa = image.select ('qa_pixel'); //creating the new variable from the band of the source image
  
  var mask = qa.bitwiseAnd(cloudsBitMask).eq(0) //making the cloud equal to zero to mask them out
      .and(qa.bitwiseAnd(cloudshadowBitMask).eq(0)); //making the cloud shadow equal to zero to mask them out
      
  return image.updateMask(mask).divide(10000)
    .select("SR_B[0-9]*")
    .copyProperties(image, ["system:time_start"]);
}

// print ("Hague and Rotterdam", image);// look into the console now. How many images the code have downloaded!!!

//filtering imagery for 2015 to 2021 summer date ranges
//creating joint filter and applying to image collection 
var sum21 = ee.Filter.date ('2021-06-01','2021-09-30');
var sum20 = ee.Filter.date ('2020-06-01','2020-09-30');
var sum19 = ee.Filter.date ('2019-06-01','2019-09-30');
var sum18 = ee.Filter.date ('2018-06-01','2018-09-30');
var sum17 = ee.Filter.date ('2017-06-01','2017-09-30');
var sum16 = ee.Filter.date ('2016-06-01','2016-09-30');
var sum15 = ee.Filter.date ('2015-06-01','2015-09-30');

var SumFilter = ee.Filter.or(sum21, sum20, sum19, sum18, sum17, sum16, sum15);

var allsum = image.filter(SumFilter);
Kevin Reid
  • 37,492
  • 13
  • 80
  • 108
  • Unfortunately your code link isn't public so we can't view it and help you, but also, Stack Overflow questions need to have the code in the question and not at external locations, for posterity. Please include code that demonstrates the problem **in the question**. – Kevin Reid May 12 '22 at 00:39
  • Hi Kevin!!! Thanks for your help. I guess this link should work now: https://code.earthengine.google.com/c3be6fac4f7bc0ae51e8ac615d696ed2 – Tahmid Towsif Ahmed May 12 '22 at 10:34
  • Yes, that link works, but you must **include the code in the question** not just a link. I've now done the edit for you. – Kevin Reid May 12 '22 at 14:44

1 Answers1

1

Filtering is an operation you can do on ImageCollections, not individual Images, because all filtering does is choose a subset of the images. Then, in your script, you have (with the comments removed):

var image = ee.Image (L8_tier1
  .filterBounds (ROI)
  );

The result of l8_tier1.filterBounds(ROI) is indeed an ImageCollection. But in this case, you have told the Earth Engine client that it should be treated as an Image, and it believed you. So, then, the last line

var allsum = image.filter(SumFilter);

fails with the error you saw because there is no filter() on ee.Image.

The script will successfully run if you change ee.Image(...) to ee.ImageCollection(...), or even better, remove the cast because it's not necessary — that is,

var image = L8_tier1.filterBounds(ROI);

You should probably also change the name of var image too, since it is confusing to call an ImageCollection by the name image. Naming things accurately helps avoid mistakes, while you are working on the code and also when others try to read it or build on it.

Kevin Reid
  • 37,492
  • 13
  • 80
  • 108