Export_sequence_image
unknown
plain_text
2 years ago
1.9 kB
6
Indexable
import ee
import os
# Authenticate to your Earth Engine account
ee.Authenticate()
ee.Initialize(project='ee-davari2023')
# Define the Area of Interest (AOI) as a geometry (e.g., a point)
aoi = ee.Geometry.Point([-122.08412, 37.42189]) #ee.Geometry.Point([-7.547798, 38.653770]).buffer(1000) # Longitude, Latitude
# Define the time period of interest
start_date = '2022-06-01'
end_date = '2022-06-30'
# Create an ImageCollection based on your criteria
##'COPERNICUS/S2 refers to the Sentinel-2 satellite imagery dataset
image_collection = ee.ImageCollection('COPERNICUS/S2') \
.filterBounds(aoi) \
.filterDate(start_date, end_date) \
.sort('CLOUDY_PIXEL_PERCENTAGE')
# Specify the folder where you want to save the images
download_folder = 'images_Portugal_1'
# Create the download folder if it doesn't exist
os.makedirs(download_folder, exist_ok=True)
# Loop through the images in the ImageCollection and download them
image_list = image_collection.toList(image_collection.size())
for i in range(2): #image_list.size().getInfo()
image = ee.Image(image_list.get(i))
image_id = image.id().getInfo()
#image = image.toUint16()
name = image.get('system:index').getInfo()
#image_filename = os.path.join(download_folder, f'image_{image_id}.png')
# Export the image to your local folder
## Bands 4, 3, and 2 are often used for RGB images
task = ee.batch.Export.image.toDrive(image=image.select(['B4', 'B3', 'B2']), description=image_id, folder=download_folder, scale= 30)
# Check the task status
task_status = task.status()
has_retries = task_status["state"] == "FAILED" and task_status["error_message"] is not None
# Print the result
if has_retries:
print("The task has been retried.")
else:
print("The task has not been retried.")
task.start()
print(i)Editor is loading...