Skip to content

XEE doesn't recognize new bands added to existing images #88

@spatialthoughts

Description

@spatialthoughts

Discovered this serious issue with how XEE deals with image bands. A typical GEE workflow is to add new bands to existing images after computing indices or for other dependent vairables for classificaiton. When one adds a new band, the 'system:id' doesn't change and XEE uses that to fetch the list of bands for further processing. For example, consider the following snippet

def addNDVI(image):
  ndvi = image.normalizedDifference(['B8', 'B4']).rename('ndvi')
  return image.addBands(ndvi)

# Map the function over the collection
withNdvi = filtered.map(addNDVI)

This results in errors such as

EEException: Image.addBands: Cannot add band 'ndvi' because it doesn't appear in srcImg.

If one modifies the image in any way, the system:id gets overwritten and this problem doesn't arise. See example below

# Modify the function to create a 'new' image
def addNDVI(image):
  ndvi = image.normalizedDifference(['B8', 'B4']).rename('ndvi')
  return image.multiply(0.0001).addBands(ndvi).copyProperties(image, ['system:time_start'])

# Map the function over the collection
withNdvi = filtered.map(addNDVI)

My guess is due to the fact that XEE gets the metadata based on 'system:id'. This behavior is problematic and can cause a lot of very hard-to-debug errors.

Here's a full notebook that reproduces this error https://colab.research.google.com/drive/1MvayipJAwiYWWyMfGwiRiPy8RmUaCqc6?usp=sharing

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions