gee-community / geetools

A collection of tools to work with Google Earth Engine Python API
https://geetools.readthedocs.io/en/stable/
MIT License
530 stars 122 forks source link

Problem with export of ImageCollection #263

Open tabea-schultestrathaus opened 7 months ago

tabea-schultestrathaus commented 7 months ago

Hi there,

I have some issues with downloading an ImageCollection and I would appreciate any help! I'm following an earlier tutorial from this community.

Here's my code:

import ee
import random
from geetools import batch

ee.Authenticate(auth_mode='localhost')
ee.Initialize(project='ee-user')

seed = random.randint(0, 10000)

collection = (ee.ImageCollection('COPERNICUS/S2_SR_HARMONIZED')
              .filterDate('2023-01-01', '2023-01-31')
              .filter(ee.Filter.stringContains('MGRS_TILE', '20M'))
              .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 10))
              .randomColumn('randomKey', seed)
              .sort('randomKey')
              .limit(3)
              .select(['B2', 'B3', 'B4', 'B8']))

print('Number of images', collection.size().getInfo())

size = collection.size().getInfo()
clist = collection.toList(size)
for i in range(size):
    image = ee.Image(clist.get(i))
    iid = image.id().getInfo()
    name = 'jan_'+iid
    print('downloading '+ name)
    batch.image.toLocal(image, name)

And here's the error:

(user) [user"user]$ /user/export.py
Number of images 3
downloading jan_20230126T144729_20230126T145426_T20MKU
Traceback (most recent call last):
  File "/user/data.py", line 402, in _execute_cloud_call
    return call.execute(num_retries=num_retries)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/user/lib/python3.12/site-packages/googleapiclient/_helpers.py", line 130, in positional_wrapper
    return wrapped(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/user/lib/python3.12/site-packages/googleapiclient/http.py", line 938, in execute
    raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 400 when requesting https://earthengine.googleapis.com/v1/projects/ee-user/value:compute?prettyPrint=false&alt=json returned "Image.bandNames, argument 'image': Invalid type.
Expected type: Image<unknown bands>.
Actual type: Feature.". Details: "Image.bandNames, argument 'image': Invalid type.
Expected type: Image<unknown bands>.
Actual type: Feature.">

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/user/export.py", line 28, in <module>
    batch.image.toLocal(image, name)
  File "/user/lib/python3.12/site-packages/geetools/batch/image.py", line 37, in toLocal
    scale = scale if scale else int(tools.image.minscale(image).getInfo())
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/user/lib/python3.12/site-packages/ee/computedobject.py", line 107, in getInfo
    return data.computeValue(self)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/user/lib/python3.12/site-packages/ee/data.py", line 1107, in computeValue
    return _execute_cloud_call(
           ^^^^^^^^^^^^^^^^^^^^
  File "/user/lib/python3.12/site-packages/ee/data.py", line 404, in _execute_cloud_call
    raise _translate_cloud_exception(e)  # pylint: disable=raise-missing-from
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ee.ee_exception.EEException: Image.bandNames, argument 'image': Invalid type.
Expected type: Image<unknown bands>.
Actual type: Feature.
12rambau commented 7 months ago

This script is not compatible with version 1.0 of the lib as exportation has not been refactored yet. Could you try using 0.6.14 ? Alternatively can you look at my answer in https://github.com/gee-community/geetools/issues/256 ?

tabea-schultestrathaus commented 7 months ago

Hi, thanks for your reply! I already downgraded to 0.6.14. Is it really a problem with batch?

12rambau commented 7 months ago

I think yes, maybe the latest changes to the tools module have conflict in the batch context, or the collection you have is a featureCollection nwhich sounds strange.

The problem is that there was no tests before so I'm building them on the spot every time I refactor an existing method. There are many cases where I need multiple iteration to cover all the edge cases. The v1 of the lib will eventually be more stable but i still need to work on batch