1

I'm having trouble with exporting images from NASA/HLS/HLSL30/v002 image collection to Drive.

This produces a map of the image I want to make:

# Applies scaling factors.
def apply_scale_factors(image):
  thermal_bands = image.select('B10').multiply(0.00341802).add(149.0)
  return image.addBands(
      thermal_bands, None, True
  )

visualization = {
    'bands': ['B4', 'B3', 'B2'],
    'min': 0.0,
    'max': 0.3,
}
m = geemap.Map()
m.set_center(-78.405278, 35.647222, 16)

dataset = ee.ImageCollection('NASA/HLS/HLSL30/v002').filterDate('2020-01-21', '2020-02-20').filter(ee.Filter.lt('CLOUD_COVERAGE',70))
dataset = dataset.map(apply_scale_factors)
m.add_layer(dataset.mean(), visualization, 'True Color (321)')
m

Is there a way to export images from this image collection at this location over many dates (from 2014 to 2024, perhaps)?

And is there a way to download them directly to your machine?

I tried this, but it uses a deprecated geometry tool

roi = ee.Geometry.Rectangle([-78.41, 35.65, -78.40, 35.64])
collection = (ee.ImageCollection('NASA/HLS/HLSL30/v002')
                .filterDate('2020-01-01', '2020-03-01')
                .filter(ee.Filter.lt('CLOUD_COVERAGE', 70))
                .filterBounds(roi))
# Export the ImageCollection
tasks = geetools.batch.Export.imagecollection.toDrive(
    collection=collection,
    folder='gee_images',
    region=roi,
    namePattern='{id}',
    scale=30,
    dataType='uint32',
    verbose=True,
    maxPixels=int(1e13)
)

returns error

/usr/local/lib/python3.10/dist-packages/geetools/tools/_deprecated_geometry.py in getRegion(eeobject, bounds, error)
     12 def getRegion(eeobject, bounds=False, error=1):
     13     """Gets the region of a given geometry to use in exporting tasks."""
---> 14     return eeobject.geometry()
     15 
     16 

AttributeError: 'Geometry' object has no attribute 'geometry'

2 Answers 2

0

You can convert an ee.ImageCollection to an ee.List using the .toList() method and then for loop over that list and exporting each image. Note that you will need to get the length of the list client-side using .getInfo() for use in the for loop. Basic example script would be:

collection_size = collection.size().getInfo() # Get size of collection client-side
collection_ls = collection.toList(collection_size) # Convert collection to a list

# Loop over list, extract image to an ee.Image object, then export it
for i in range(collection_size): 
    image = ee.Image(collection_ls.get(i))
    
    task = ee.batch.Export.image.toDrive(image)
    task.start()

Make sure you edit any other parameters in the export function, but otherwise this should work.

0

Hi @catahua I'm the maintainer of geetools, the first option you tried in your example. The solution you tried is the old implementation of the tool and starting from 1.0 you should do the following instead:

tasks = geetools.batch.Export.imagecollection.toDrive(
    imagecollection =collection.map(lambdaa i: i.clip(roi)),
    folder='gee_images',
    index_property = "system:id",
    scale=30,
)
[t.start() for t in tasks]

you can find more information about the function parameters in the documentation.

As the method have been recently refactored please report any bug in our issue tracker

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.