I am a newbie to using Sentinel and scihub. I have come across SentinelSat and it looked convenient than directly using copernicus to download the data. Yet I am running into the following error when I run api.download_all(products)
StopIteration Traceback (most recent call last)
<ipython-input-29-1da24c759dfe> in <module>()
1 # download all results from the search
----> 2 api.download_all(products)
/usr/local/lib/python3.6/dist-packages/sentinelsat/sentinel.py in download_all(self, products, directory_path, max_attempts, checksum, n_concurrent_dl, lta_retry_delay)
806 if len(failed_prods) == len(product_ids):
--> 807 raise next(iter(x.exception() for x in dl_tasks if x.exception()))
809 return downloaded_prods, retrieval_scheduled, failed_prods
This is the request I used:
from sentinelsat.sentinel import SentinelAPI, read_geojson, geojson_to_wkt
from datetime import date
# connect to the API
api = SentinelAPI('user', 'password', 'https://scihub.copernicus.eu/dhus')
# search by polygon, time, and Hub query keywords
footprint = geojson_to_wkt(read_geojson('./Bizerte_BoundaryMap/smaller_region.geojson'))
products = api.query(footprint,
date = ('20190625', date(2019, 6, 25)),
platformname = 'Sentinel-2',
processinglevel = 'Level-2A',
cloudcoverpercentage = (0, 10))
I think that may be because there are no products covering that footprint on those dates. If you change the end date to ‘20190630’ there should be 11 available products to download (according to my copy of your code). Let me know if that is enough to start the download.
OK. I thought that would have fixed it. There are some other things you could try.
If you print len(products)
do you get a number larger than 0?
If so, that suggests that api.query()
is working fine. In which case, there could be something amiss with the products. You could try to check if one of the products you are requesting is online. Something like:
list_of_items = list(products.items()) # items from ordered dictionary product_ID = list_of_items # item corresponding to product id product_info = api.get_product_odata(product_ID) # info for given product ID print(product_info['Online']) # True/false check for online
would check the first product in the dictionary called “products” and print “True” if that product is online.
I would imagine that is saves the files to the working directory, probably in the same folder where your Python script is. I prefer to specify a path to download the products to, since the files can be quite large. You can do this simply in the download_all function with: api.download_all(products,directory_path=download_path)
where download_path is a string of the path to the folder you wish to download the products to.
Ok, thanks for the help. It works now I believe the error was instead of using 'Malta_Sicily.json' I used './'Malta_Sicily.json'.
One more question, is the number of images =len(products)? because in my case len(products)=5 and I got 5 L2A and 6 L2B despite that I specified processinglevel = 'Level-2A'
Good question. I believe that the output of api.query() is a dictionary with one entry for each product that satisfies the specifications provided to the query function. Hence the length of the dictionary should be the same as the number of products. However, there is probably a more sensible way to find out the number of products. I have only used SentinelSat for level 1 and level 2 Sentinel 3 products and it’s worked very well for that so far.