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

Extended methods for the ee.Image class cannot be thrown to map #65

Closed
FeiYao-Edinburgh opened this issue Apr 26, 2022 · 4 comments
Closed
Labels
bug Something isn't working

Comments

@FeiYao-Edinburgh
Copy link

FeiYao-Edinburgh commented Apr 26, 2022

Hi @davemlz ! I recently want to combine part of the extended methods for the ee.Image class into my personal image processing workflow. However, I found that those methods cannot be thrown into map. As a simple illustration, the following code excerpt will prompts the error of A mapped function's arguments cannot be used in client-side operations.

import ee, eemont
ee.Initialize()

def user_process(image):
    return image.scaleAndOffset()

image_coll = ee.ImageCollection("COPERNICUS/S2_SR").limit(3).map(user_process)

I definitely understand that the above stupid example can be simply resolved by:

image_coll = ee.ImageCollection("COPERNICUS/S2_SR").limit(3).scaleAndOffset()

However, won't you think it would be great if extended methods for the ee.Image class can be used as identically as standard methods for the ee.Image class? For instance, the following another stupid example would work perfectly:

import ee, eemont
ee.Initialize()

def user_process(image):
    return image.add(1).subtract(1)

image_coll = ee.ImageCollection("COPERNICUS/S2_SR").limit(3).map(user_process)

I also checked that eemont is powered by eeExtra and throwing to ee_extra.STAC.core.scaleAndOffset(image) to map would cause the same issue. As such, I am not sure if it would be too complicated to have this feature which although may be helpful at some cases.

All the best,
Fei

@FeiYao-Edinburgh FeiYao-Edinburgh added the bug Something isn't working label Apr 26, 2022
@FeiYao-Edinburgh FeiYao-Edinburgh changed the title Extended methods for the ee.Image class cannot be applied within map Extended methods for the ee.Image class cannot be thrown to map Apr 26, 2022
@davemlz
Copy link
Owner

davemlz commented Apr 26, 2022

Hi @FeiYao-Edinburgh!

I understand what you're trying to do. I ran into this problem a long time ago (#11), but unfortunately there is no actual way to solve it since I have to maintain the core STAC function on the client-side: this in order to keep all datasets updated autimatically.

@FeiYao-Edinburgh
Copy link
Author

Hi @davemlz !

Thanks for your quick reply. I now see the root of evil is the use of getInfo() which is not allowed in map. In this sense, I will choose to use extended methods of eemont simply before and outside my personal user_process:

def user_process(image):
    # Do some stuff
    return image

# For a single image:
image = image.maskClouds()
image = image.scaleAndOffset()
image = user_process(image)

# For an image collection:
image_coll = image_coll.maskClouds()
image_coll = image_coll.scaleAndOffset()
image_coll = image_coll.map(user_process)

Not ideal but still doable. Hopefully all can be thrown into the user_process() function in the future with the improvement of earthengine-api capability.

Slightly deviated from but similar to this topic, it is weird that ee.Image() does not accept ee.String() as input, e.g..

All the best,
Fei

@FeiYao-Edinburgh
Copy link
Author

Alternatively:

def user_process_coll(image):
    # Do some stuff
    return image

def user_process(image):
    image = image.maskClouds()
    image = image.scaleAndOffset()
    image = user_process_coll(image)
    return image

# For a single image:
image = user_process(image)

# For an image collection:
image_coll = image_coll.maskClouds()
image_coll = image_coll.scaleAndOffset()
image_coll = image_coll.map(user_process_coll)

@davemlz
Copy link
Owner

davemlz commented Apr 26, 2022

Yes!

Also, you can go:

image_col.preprocess().map(user_process_coll)

The preprocess() method calls all available pre-processing steps, including maskClouds() and scaleAndOffset()

@davemlz davemlz closed this as completed Jul 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants