Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
spatialthoughts opened this issue Oct 31, 2023 · 0 comments · May be fixed by #91
Closed

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

spatialthoughts opened this issue Oct 31, 2023 · 0 comments · May be fixed by #91
Assignees

Comments

@spatialthoughts
Copy link

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

@naschmitz naschmitz self-assigned this Jan 16, 2024
copybara-service bot pushed a commit that referenced this issue Apr 11, 2024
Add a new `fast_time_slicing` parameter. If True, Xee performs an optimization that makes slicing an ImageCollection across time faster. This optimization loads EE images in a slice by ID, so any modifications to images in a computed ImageCollection will not be reflected.

For those familiar with the code before, the else flow in `_slice_collection` was only entered when images in the collection didn't have IDs. Clearing the image IDs triggered the else block.

Also adds several new warnings:

- if a user enables `fast_time_slicing` but there are no image IDs, and
- if a user is indexing into a very large ImageCollection.

Fixes #88 and #145.

PiperOrigin-RevId: 623280839
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants