6

Can you suggest the code to select only January data from year 2000 to 2010 of Landsat 5 and calculate its mean?

Mean of the all Januray image from 2000 to 2010.

closed as off-topic by PolyGeo Apr 22 at 10:11

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "When seeking help to debug/write/improve code always provide the desired behavior, a specific problem/error and the shortest code (as formatted text, not pictures) needed to reproduce it in the question body. Providing a clear problem statement and a code attempt helps others to help you." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    What did you try and what was the result? – lynxlynxlynx Sep 22 '17 at 12:35
  • Actually i just checked filter method, but i was only able to select all images between to dates(e.g between 2000 to 2010, i get all images ). I need only january month images between 2000 to 2010. – P_P Sep 22 '17 at 14:48
7

You need to use ee.Filter.calendarRange(start,end,field) to filter by all Januaries from 2000 to 2010.

field could be:

  • field (String, default: "day_of_year"): The calendar field to filter over. Options are: 'year', 'month', 'hour', 'minute', 'day_of_year', 'day_of_month', and 'day_of_week'.

So, the code is:

var imageCollection = ee.ImageCollection("LANDSAT/LT05/C01/T1_TOA");

// Use ee.Filter.calendarRange to filter by year and month

var img = imageCollection.filter(ee.Filter.calendarRange(2000,2010,'year'))
.filter(ee.Filter.calendarRange(1,1,'month'));

// reduce image collection with mean()
var mean = img.mean();

// Set visualization parameters
var vizParams = {
  bands: ['B3', 'B2', 'B1'],
  min: 0,
  max: 0.5,
  gamma: [0.95, 1.1, 1]
};

// add layer
Map.addLayer(mean,vizParams);

This code process specifically fits your task description, but doesn't consider cloud mask or a cloud coverage filter.

  • Thank You for your valuable answer. Thanks a lot, but i have a question here, var img = imageCollection.filter(ee.Filter.calendarRange(2000,2010,'year')) .filter(ee.Filter.calendarRange(1,1,'month')); It is taking only January 2000 and January 2010, – P_P Sep 23 '17 at 9:11
  • var img = imageCollection.filter(ee.Filter.calendarRange(2000,2010,'year')) .filter(ee.Filter.calendarRange(1,1,'month')); It is filtering all images from January 2000 to January2010. I need only january from every year. Thank you – P_P Sep 23 '17 at 9:34
  • @P_P weird, I test it and takes every year. Try with .filterDate(“2000-01-01” , “2010-01-31”) instead of first filter. – aldo_tapia Sep 23 '17 at 12:02
  • Thank You for your kind reply. I started with this .filterDate(“2000-01-01” , “2010-01-31”) but its is taking all images between these dates. – P_P Sep 24 '17 at 5:24
  • @P_P yes, but I said as remplace of first filter (year filter), you need to keep the second filter (month filter). – aldo_tapia Sep 24 '17 at 11:15

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