0

I have calculated from Landsat images monthly maximum NDVI values for a period of time. Now I want to calculate the seasonal values for this same variable but I don't know how to do it since I want it to be winter December - February, spring March - May, summer June - August and summer September - November.

var mycollection = ee.ImageCollection('LANDSAT/LC08/C02/T1_L2')
                  .filterBounds(geometry)
                  .filter(ee.Filter.date('2014-12-01', '2021-11-30'))
                  .map(calcularNDVI)

print(mycollection, 'NDVI 2015 2022');

//NDVI 
function calcularNDVI(image) {
  var ndvi = image.normalizedDifference(['SR_B5','SR_B4']).rename('NDVI')
  return image.addBands(ndvi);
}

// monthly NDVI calculation
var start = ee.Date('2014-12-01');
var end = ee.Date('2021-11-30');
var numbmonthly = end.difference(start, 'month').divide(1).ceil();

// make a composite image for every month
var monthlyImages = ee.ImageCollection.fromImages(
            ee.List.sequence(1, numbmonthly).map(
              function(monthly){
              var startTemp = start.advance(
                              ee.Number(monthly).subtract(1).multiply(1), 'month');
              var endTemp = start.advance(ee.Number(monthly).multiply(1), 'month');
              var image = mycollection.filterDate(startTemp, endTemp)
                                    .filterBounds(geometry)
                                    .mean()
                                    .clip(geometry)
                                    .select('NDVI');
              return image.set('system:time_start', startTemp.millis(),
                               'system:time_end', endTemp.millis());
            }));
print(monthlyImages, "Monthly Images");

Map.addLayer(monthlyImages.first());

2 Answers 2

0

Olá @SBARRAO, estava buscando algumas informações para o meu projeto quando me deparei com essa situção que talvez lhe atenda:

var winter = Landsat8lst.filter(ee.Filter.calendarRange(2013,2019,'year'))
.filter(ee.Filter.calendarRange(12,2,'month'));

var spring = Landsat8lst.filter(ee.Filter.calendarRange(2013,2019,'year'))
.filter(ee.Filter.calendarRange(3,5,'month'));

var summer = Landsat8lst.filter(ee.Filter.calendarRange(2013,2019,'year'))
.filter(ee.Filter.calendarRange(6,8,'month'));

var fall = Landsat8lst.filter(ee.Filter.calendarRange(2013,2019,'year'))
.filter(ee.Filter.calendarRange(9,11,'month'));

var ndvimax_spring = ee.Number(spring .reduceRegion({
      reducer: ee.Reducer.max(),
      geometry: geometry,
      scale: 30,
      maxPixels: 1e10
    }).values().get(0))

Mas é claro que se faz necessário alterar para a sua image.collection e o período de interesse.

4
  • 1
    As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Oct 26, 2022 at 5:57
  • Thanks for your answer, but what I'm looking for is to calculate the maximum for each station, the code you are telling me only filters the collection of images. I want to obtain for each year a maximum value of ndvi for each station.
    – SBARRAO
    Oct 27, 2022 at 8:39
  • @SBARRAO fiz uma alteração. Você pode utilizar ee.Reducer.max() para selecionar o máximo ou o ee.Reducer.min() para o mínimo. Espero que isso lhe atenda. Oct 28, 2022 at 19:30
  • @DarlanTelesdaSilva this is an English language site. Please use English.
    – Padmanabha
    Aug 13 at 7:19
0

Calculating Seasonal NDVI can be accomplished by mapping over a list of dates. Each date in the list represents the first date of the season. In the mapped function you filter the image collection to all images within the season, calculate Maximum NDVI for the season and return it as a new image.

Below is code that demonstrates this approach. You can also find the code here - https://code.earthengine.google.com/759c017e5a4e970f5e22415b0fbb6c4a.

// Specify your start date as the start of a season
// Winter (December 1), Spring (March 1), Summer (June 1) or Autumn (September 1)
var start = '2014-03-01'
// Also, specify the number of three-month seasons to collect data on.
var numSeasons = 2

// Calculate the end date and the index of the last month in the sequence
var end = ee.Date(start).advance(3 * numSeasons, 'month')
var lastStartingMonth = (numSeasons - 1) * 3

// Create a list where each item of the list is the start date for a season
var seasonStartMonths = ee.List.sequence(0, lastStartingMonth, 3).map(function(n){
  return ee.Date(start).advance(n, 'month')
})

// Add NDVI and remove all other bands
function calculateNDVI(image) {
  var ndvi = image.normalizedDifference(['SR_B5','SR_B4']).rename('NDVI')
  return image.select().addBands(ndvi);
}

var mycollection = ee.ImageCollection('LANDSAT/LC08/C02/T1_L2')
                  .filterBounds(geometry)
                  .filterDate(start, end)
                  .map(calculateNDVI)

// Map over the list of seasons
var result = seasonStartMonths.map(function(d) {
  var startDate = ee.Date(d)
  return mycollection.filterDate(startDate, startDate.advance(3, 'month'))
    .max()
    .set({
      'system:id': startDate.format("YYYYMMdd"),
      'system:time_start': startDate.millis()
    })
})

print(ee.ImageCollection(result))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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