Para compor imagens em um ImageCollection
, use
imageCollection.reduce()
. Isso vai compor todas as imagens da
coleção em uma única imagem que representa, por exemplo, o desvio mínimo, máximo, médio ou padrão
das imagens.
Consulte a seção "Reducers"
para mais informações sobre redutores. Por exemplo, para criar uma imagem de valor mediano de uma
coleção:
Editor de código (JavaScript)
// Load a Landsat 8 collection for a single path-row. var collection = ee.ImageCollection('LANDSAT/LC08/C02/T1_TOA') .filter(ee.Filter.eq('WRS_PATH', 44)) .filter(ee.Filter.eq('WRS_ROW', 34)) .filterDate('2014-01-01', '2015-01-01'); // Compute a median image and display. var median = collection.median(); Map.setCenter(-122.3578, 37.7726, 12); Map.addLayer(median, {bands: ['B4', 'B3', 'B2'], max: 0.3}, 'Median');
import ee import geemap.core as geemap
Colab (Python)
# Load a Landsat 8 collection for a single path-row. collection = ( ee.ImageCollection('LANDSAT/LC08/C02/T1_TOA') .filter(ee.Filter.eq('WRS_PATH', 44)) .filter(ee.Filter.eq('WRS_ROW', 34)) .filterDate('2014-01-01', '2015-01-01') ) # Compute a median image and display. median = collection.median() m = geemap.Map() m.set_center(-122.3578, 37.7726, 12) m.add_layer(median, {'bands': ['B4', 'B3', 'B2'], 'max': 0.3}, 'Median') m
Em cada local da imagem de saída, em cada banda, o valor do pixel é a mediana de todos os pixels sem máscara na imagem de entrada (as imagens na coleção). No exemplo
anterior, median()
é um método de conveniência para a seguinte chamada:
Editor de código (JavaScript)
// Reduce the collection with a median reducer. var median = collection.reduce(ee.Reducer.median()); // Display the median image. Map.addLayer(median, {bands: ['B4_median', 'B3_median', 'B2_median'], max: 0.3}, 'Also median');
import ee import geemap.core as geemap
Colab (Python)
# Reduce the collection with a median reducer. median = collection.reduce(ee.Reducer.median()) # Display the median image. m.add_layer( median, {'bands': ['B4_median', 'B3_median', 'B2_median'], 'max': 0.3}, 'Also median', ) m
Os nomes das bandas são diferentes devido ao uso de reduce()
em vez do
método de conveniência. Especificamente, os nomes do redutor foram anexados aos
nomes das bandas.
Também é possível fazer reduções mais complexas usando reduce()
. Por exemplo, para calcular a tendência linear de longo prazo em uma coleção, use um dos redutores de regressão linear. O código a seguir calcula a tendência linear do índice de vegetação aprimorado (EVI, na sigla em inglês) do MODIS:
Editor de código (JavaScript)
// This function adds a band representing the image timestamp. var addTime = function(image) { return image.addBands(image.metadata('system:time_start') // Convert milliseconds from epoch to years to aid in // interpretation of the following trend calculation. .divide(1000 * 60 * 60 * 24 * 365)); }; // Load a MODIS collection, filter to several years of 16 day mosaics, // and map the time band function over it. var collection = ee.ImageCollection('MODIS/006/MYD13A1') .filterDate('2004-01-01', '2010-10-31') .map(addTime); // Select the bands to model with the independent variable first. var trend = collection.select(['system:time_start', 'EVI']) // Compute the linear trend over time. .reduce(ee.Reducer.linearFit()); // Display the trend with increasing slopes in green, decreasing in red. Map.setCenter(-96.943, 39.436, 5); Map.addLayer( trend, {min: 0, max: [-100, 100, 10000], bands: ['scale', 'scale', 'offset']}, 'EVI trend');
import ee import geemap.core as geemap
Colab (Python)
# This function adds a band representing the image timestamp. def add_time(image): return image.addBands( image.metadata('system:time_start') # Convert milliseconds from epoch to years to aid in # interpretation of the following trend calculation. .divide(1000 * 60 * 60 * 24 * 365) ) # Load a MODIS collection, filter to several years of 16 day mosaics, # and map the time band function over it. collection = ( ee.ImageCollection('MODIS/006/MYD13A1') .filterDate('2004-01-01', '2010-10-31') .map(add_time) ) # Select the bands to model with the independent variable first. trend = collection.select(['system:time_start', 'EVI']).reduce( # Compute the linear trend over time. ee.Reducer.linearFit() ) # Display the trend with increasing slopes in green, decreasing in red. m.set_center(-96.943, 39.436, 5) m = geemap.Map() m.add_layer( trend, { 'min': 0, 'max': [-100, 100, 10000], 'bands': ['scale', 'scale', 'offset'], }, 'EVI trend', ) m
A saída da redução neste exemplo é uma imagem com duas faixas,
uma para a inclinação de uma regressão linear (scale
) e outra para a interseção (offset
). Confira a documentação da API para ver uma lista dos
redutores disponíveis para reduzir um ImageCollection
a um único
Image
.
Os compostos não têm projeção
As imagens compostas criadas pela redução de uma coleção de imagens podem produzir pixels
em qualquer projeção solicitada e, portanto, não têm uma projeção de saída fixa.
Em vez disso, os compostos têm
a projeção
padrão do WGS-84 com pixels de resolução de 1 grau. Os compostos com a projeção padrão serão computados em qualquer projeção de saída solicitada. Uma solicitação
ocorre ao mostrar o composto no Editor de código. Saiba como o Editor de código
define escala e
projeção. Também é possível especificar explicitamente uma
projeção/escala como em uma agregação, como
ReduceRegion
ou Export
.