1

Using Colab, I am trying to compute an index (e.g., NDVI), but I'd like to improve the selection of the bands from ee.ImageCollection.toBands(). I am using the exact names to call the bands from the stack, but I’d like to use the band's position in the stack or another way. Is there any possibility?

geometry = ee.Geometry.Polygon([-42.68383865527343,-14.294442457842383,-42.64263992480468,-14.294442457842383,-42.64263992480468,-14.259340569775649,-42.68383865527343,-14.259340569775649,-42.68383865527343,-14.294442457842383])

img_colec = ee.ImageCollection("COPERNICUS/S2_SR")\
  .filterDate("2019-03-07", "2019-03-17")\
  .select("B8","B4","B2")\
  .filterBounds(geometry)
 
composite = img_colec.toBands()

index = composite.normalizedDifference(['20190313T131241_20190313T131238_T23LQE_B2','20190313T131241_20190313T131238_T23LQE_B4'])

The composite is like that:

{'bands': [{'crs': 'EPSG:32723',
   'crs_transform': [10, 0, 699960, 0, -10, 8500000],
   'data_type': {'max': 65535,
    'min': 0,
    'precision': 'int',
    'type': 'PixelType'},
   'dimensions': [10980, 10980],
   'id': '20190308T131239_20190308T131240_T23LQE_B8'},
  {'crs': 'EPSG:32723',
   'crs_transform': [10, 0, 699960, 0, -10, 8500000],
   'data_type': {'max': 65535,
    'min': 0,
    'precision': 'int',
    'type': 'PixelType'},
   'dimensions': [10980, 10980],
   'id': '20190308T131239_20190308T131240_T23LQE_B4'},
  {'crs': 'EPSG:32723',
   'crs_transform': [10, 0, 699960, 0, -10, 8500000],
   'data_type': {'max': 65535,
    'min': 0,
    'precision': 'int',
    'type': 'PixelType'},
   'dimensions': [10980, 10980],
   'id': '20190308T131239_20190308T131240_T23LQE_B2'},
  {'crs': 'EPSG:32723',
   'crs_transform': [10, 0, 699960, 0, -10, 8500000],
   'data_type': {'max': 65535,
    'min': 0,
    'precision': 'int',
    'type': 'PixelType'},
   'dimensions': [10980, 10980],
   'id': '20190313T131241_20190313T131238_T23LQE_B8'},
  {'crs': 'EPSG:32723',
   'crs_transform': [10, 0, 699960, 0, -10, 8500000],
   'data_type': {'max': 65535,
    'min': 0,
    'precision': 'int',
    'type': 'PixelType'},
   'dimensions': [10980, 10980],
   'id': '20190313T131241_20190313T131238_T23LQE_B4'},
  {'crs': 'EPSG:32723',
   'crs_transform': [10, 0, 699960, 0, -10, 8500000],
   'data_type': {'max': 65535,
    'min': 0,
    'precision': 'int',
    'type': 'PixelType'},
   'dimensions': [10980, 10980],
   'id': '20190313T131241_20190313T131238_T23LQE_B2'}],
 'type': 'Image'}

0 Answers0