1st: The exact code you posted (https://code.earthengine.google.com/ce1a151ce06497b20cf1793715cb0120) did export the image correctly. So the error cannot be reproduced. May be, you changed the 'ROI' to a place where the filtered collection had no images.
2nd: There are no images because you filtered by cloud percentage, and so, it found images that suited the condition only in the left part of the ROI. If you comment like:
//.filter(ee.Filter.lte('CLOUDY_PIXEL_PERCENTAGE', 5))
you'll see that there are more images and you get the whole ROI (of course you get a part of the image plenty of clouds).
3rd: if automated exporting is your goal, maybe you should migrate to Python, but if you don't mind clicking the run button over and over, this would be one approach to download images only if the filtered collection has images (don't blame me on the getInfo
=):
//Define date range
var startDate = ee.Date.fromYMD(2017,7,1);
var endDate = ee.Date.fromYMD(2017,7,31);
//Load Sentinel-2 image collections
var coll_s2 = ee.ImageCollection("COPERNICUS/S2");
//Filter Sentinel-2 collection for ROI and cloud-coverage.
//Keep only images with less than 5% clouds
var coll_s2_filtered = coll_s2.filterDate(startDate, endDate)
.filter(ee.Filter.lte('CLOUDY_PIXEL_PERCENTAGE', 5))
.sort('system:time_start',false);
// Define the FeatureCollection!
var fc = ee.FeatureCollection(LIST_OF_POINT_FEATURES)
// Iterate over the FeatureCollection to create a List
// with images where there is data avialable
var listn = ee.List(fc.iterate(function(elem, ini){
var rectangle = ee.Feature(elem.buffer(20000).bounds());
var roi = rectangle.geometry();
var col = coll_s2_filtered.filterBounds(roi);
return ee.Algorithms.If(col.size(),
ee.List(ini).add(coll_s2_filtered.select(['B4','B3','B2']).mosaic().clip(roi)),
ee.List(ini))
}, ee.List([])))
listn = ee.List(listn)
print(listn)
// As Export is a Client-side function, you have to iterate the list
// in a client-side way
for (var n = 0; n<listn.size().getInfo(); n++) {
var i = ee.Image(listn.get(n))
Export.image.toDrive({
image: i,
description: 'image_'+n.toString(),
scale: 10,
folder: "tests",
region: i.geometry()
});
}
But if you want to change the filter regarding on whether it finds or not images, that would be different.
you will find documentation on this page : https://developers.google.com/earth-engine/python_install
I propose you to go through the native export tool of Earth Engine instead of geetools.
import ee
from google.colab import drive
Authenticate and mount your drive into your project
ee.Authenticate()
ee.Initialize()
drive.mount('/content/drive')
You can export images using a thread.
I've never tried to export a whole collection but it seems to me that you can do it by replacing the 'image=image' attribute by 'collection=yourCollection' (not sure of that). In general, I prefer to transform my collection into an images list and then to upload images one by one.
imagesList = collection.toList(collection.size())
for i in range(0,imagesList.size().getInfo()):
image= ee.Image(imagesList.get(i))
#Process the export for you image into the folder of your choice into Drive
task = ee.batch.Export.image.toDrive(image= image,
description='Exported from EarthEngine',
fileNamePrefix='filename.tif',
scale= scale,
folder='repertoryOfYourChoice/',
fileFormat='GeoTIFF')
task.start()
Then you can follow the status of the last uploaded image in your list (you can upgrade this code by storing all the tasks in a list to track the status of all the images in your list) :
print(task.status())
Otherwise, about the scale it allows you to reproject an image to have a different resolution and speed up the export time. So it can be useful to use a large scale when working on very large areas. However, be careful not to scale it too large because the calculation time of the reprojection could sometimes be too greedy and exceed the maximum memory size allowed.
Best Answer
There is one batch tool https://github.com/gee-hydro/gee_monkey, but it did not work very well for me. Or consider stacking all the images into one following the instructions at Layer stacking images in Earth Engine? using a loop, and exporting just that one image.