0

I'm using the following code to download satellite imagery for the given polygon. The script runs successfully, but I don't get the files downloaded in the drive. What could be the reason?

 import ee
 import os
 from datetime import datetime

 try:
     ee.Initialize()
 except Exception as e:
     ee.Authenticate()
     ee.Initialize()


 def download_satellite_images(region_coords, start_date, end_date, download_folder, cloud_cover=10):


roi = ee.Geometry.Polygon(region_coords)


collection = (
    ee.ImageCollection("COPERNICUS/S2")
    .filterBounds(roi)
    .filterDate(start_date, end_date)
 .filter(ee.Filter.lt("CLOUDY_PIXEL_PERCENTAGE", cloud_cover))
)


image_list = collection.toList(collection.size())
image_count = image_list.size().getInfo()

if image_count == 0:
    print("No images found for the specified criteria.")
    return

print(f"Found {image_count} images. Starting download...")


os.makedirs(download_folder, exist_ok=True)


for i in range(image_count):
    image = ee.Image(image_list.get(i))
    image_id = image.id().getInfo()
    image_date = image.date().format("YYYY-MM-dd").getInfo()
    filename = f"{image_date}_{image_id}.tif"
    filepath = os.path.join(download_folder, filename)

    
    task= ee.batch.Export.image.toDrive(
        image=image.clip(roi),
        description=filename,
        folder=download_folder,
        scale=10,  
        region=roi.getInfo()["coordinates"],
        fileFormat="GeoTIFF",
    )

    task.start()
    print(f"Started download task for {filename}")

 if __name__ == "__main__":

     region_coordinates = [
    [78.547606, 11.670881],
    [78.583869, 11.670881],
    [78.583869, 11.649485],
    [78.547606, 11.649485],
    [78.547606, 11.670881],
] 

start_date = "2024-06-01"
end_date = "2024-12-01"
download_dir = "satellite_images"

download_satellite_images(
    region_coords=region_coordinates,
    start_date=start_date,
    end_date=end_date,
    download_folder=download_dir,
    cloud_cover=10,
)

The output: Found 11 images. Starting download... Started download task for 2024-06-01_20240601T050649_20240601T051727_T44PKU.tif Started download task for 2024-06-16_20240616T050701_20240616T051417_T43PHN.tif... so on

2
  • please specify your python versions, OS (windows/linux/mac/....) name a version (i can't reproduce this on python 3.12.2 and the ee version has references to pre python 3 modules (StringIO for starters). ..... tks Commented Dec 14, 2024 at 2:12
  • if you didn't see any error when running your code it means that the computation have indeed started, can you add the results you see in the earthengine task monitor ? Commented Jan 20 at 12:52

0

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.