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

Exporting imageCollection #241

Open
aldotapia opened this issue Mar 5, 2024 · 4 comments
Open

Exporting imageCollection #241

aldotapia opened this issue Mar 5, 2024 · 4 comments

Comments

@aldotapia
Copy link

Hi,

I used to export image collections using this library (before version 1) and now I'm struggling to do the same task again. For instance:

import ee
from geetools import batch

region = ee.Geometry.Point(-71.5, -42.5).buffer(10000).bounds()
col = ee.ImageCollection('COPERNICUS/S2').filterBounds(region)

batch.Export.imagecollection.toDrive(collection = col, folder =  'S2', region = ee.Feature(region), scale=10, dataType='float')

The error message is the following:

EEException                               Traceback (most recent call last)
Cell In[12], line 7
      4 region = ee.Geometry.Point(-71.5, -42.5).buffer(10000).bounds()
      5 col = ee.ImageCollection('COPERNICUS/S2').filterBounds(region)
----> 7 batch.Export.imagecollection.toDrive(collection = col, folder =  'S2', namePattern='{PRODUCT_ID}',region = ee.Feature(region), scale=10, dataType='float')
      9 # batch.Export.imagecollection.toDrive(col, 'S2', region, scale=10, dataType='float')

File ~/miniforge3/envs/gee/lib/python3.10/site-packages/geetools/batch/imagecollection.py:101, in toDrive(collection, folder, namePattern, scale, dataType, region, datePattern, extra, verbose, **kwargs)
     99             break
    100         else:
--> 101             raise e
    103 return tasklist

File ~/miniforge3/envs/gee/lib/python3.10/site-packages/geetools/batch/imagecollection.py:71, in toDrive(collection, folder, namePattern, scale, dataType, region, datePattern, extra, verbose, **kwargs)
     68 try:
     69     img = ee.Image(img_list.get(n))
---> 71     name = makeName(img, namePattern, datePattern, extra)
     72     name = name.getInfo()
     73     description = utils.matchDescription(name)

File ~/miniforge3/envs/gee/lib/python3.10/site-packages/deprecated/classic.py:285, in deprecated.<locals>.wrapper_function(wrapped_, instance_, args_, kwargs_)
    283 else:
    284     warnings.warn(msg, category=category, stacklevel=_routine_stacklevel)
--> 285 return wrapped_(*args_, **kwargs_)

File ~/miniforge3/envs/gee/lib/python3.10/site-packages/geetools/_deprecated_utils.py:31, in makeName(img, pattern, date_pattern, extra)
     28 @deprecated(version="1.0.0", reason="Use ee.Image.format instead")
     29 def makeName(img, pattern, date_pattern=None, extra=None):
     30     """Make a name with the given pattern."""
---> 31     return ee.Image(img).geetools.format(pattern, date_pattern)

File ~/miniforge3/envs/gee/lib/python3.10/site-packages/geetools/Image/__init__.py:595, in ImageAccessor.format(self, string, dateFormat)
    568 def format(
    569     self,
    570     string: ee_str,
    571     dateFormat: ee_str = "yyyy-MM-dd",
    572 ) -> ee.String:
    573     """Create a string from using the given pattern and using the image properties.
    574 
    575     The ``system_date`` property is special cased to fit the dateFormat parameter.
   (...)
    593             print(string.getInfo())
    594     """
--> 595     dateFormat, string = ee.String(dateFormat), ee.String(string)
    597     patternList = string.match(r"\{([^}]+)\}", "g")
    599     def replaceProperties(p, s):

File ~/miniforge3/envs/gee/lib/python3.10/site-packages/ee/computedobject.py:28, in ComputedObjectMetaclass.__call__(cls, *args, **kwargs)
     26   return args[0]
     27 else:
---> 28   return type.__call__(cls, *args, **kwargs)

File ~/miniforge3/envs/gee/lib/python3.10/site-packages/ee/ee_string.py:46, in String.__init__(self, string)
     42     super().__init__(
     43         apifunction.ApiFunction(self.name()), {'input': string}
     44     )
     45 else:
---> 46   raise ee_exception.EEException(
     47       'Invalid argument specified for ee.String(): %s' % string)
     48 self._string = string

EEException: Invalid argument specified for ee.String(): None

I have tried different namePattern without success, even using image properties like '{PRODUCT_ID}'. Any hints?

@12rambau
Copy link
Member

12rambau commented Mar 5, 2024

Yes at the moment you need to stick to v0 unfortunately because I didn't had the time to completely back port the batch module. As the previous maintainer left it completely untested, I cannot check it yet. I'm planning on working on it very soon because it's a most wanted feature.

I'll leave this issue open until the batch module get reintegrated into the lib.

@aldotapia
Copy link
Author

Oh, no worries. I'll switch back to v0 then. Thank you!

@12rambau
Copy link
Member

12rambau commented Mar 6, 2024

i don't know what you are doing with you imageCollection afterward but in case you analyse it with Xarray, be aware that v1 has a to_xarray method based on Xee package.

@aldotapia
Copy link
Author

aldotapia commented Mar 6, 2024

You made my day. I didn't know about that package. Now, my workflow writes directly to my machine skipping the tedious Google Drive folder download step:

import ee
from geetools import batch
import xarray as rx
import rioxarray

region = ee.Geometry.Point(-71.5, -42.5).buffer(10000).bounds()
col = ee.ImageCollection('COPERNICUS/S2').filterBounds(region)

ds = col.geetools.to_xarray(n_images=20, mask_and_scale=False, crs='EPSG:32719', scale=10, geometry=region)
# save a test file
ds['B2'].transpose('time','Y','X').rename({'X': 'x', 'Y': 'y'}).isel(time=-1).rio.to_raster('test.tif')

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants