12

I want to be able to automate or batch download Sentinel data (in particular S2).

I am trying to use the OData protocol as described in the Sentinels Scientific Data Hub user-guide on APIs and batch scripting. As an example I try to download a complete product using wget:

wget --no-check-certificate --user=username --password=usrpass "https://scihub.copernicus.eu/apihub/odata/v1/Products('18f7993d-eae1-4f7f-9d81-d7cf19c18378')/$value"

(With a registered username and password) but I just receive the index.html:

<?xml version='1.0' encoding='utf-8'?><entry xmlns="http://www.w3.org/2005/Atom" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xml:base="https://scihub.copernicus.eu/dhus/odata/v1/"><id>https://scihub.copernicus.eu/dhus/odata/v1/Products('18f7993d-eae1-4f7f-9d81-d7cf19c18378')</id><title type="text">S1A_IW_SLC__1SDV_20141023T172123_20141023T172150_002960_0035D1_9743</title><updated>2014-12-07T17:06:00.324Z</updated><category term="DHuS.Product" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/><link href="Products('18f7993d-eae1-4f7f-9d81-d7cf19c18378')" rel="edit" title="Product"/><link href="Products('18f7993d-eae1-4f7f-9d81-d7cf19c18378')/$value" rel="edit-media" type="application/octet-stream"/><link href="Products('18f7993d-eae1-4f7f-9d81-d7cf19c18378')/Products" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Products" title="Products" type="application/atom+xml;type=feed"/><link href="Products('18f7993d-eae1-4f7f-9d81-d7cf19c18378')/Nodes" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Nodes" title="Nodes" type="application/atom+xml;type=feed"/><link href="Products('18f7993d-eae1-4f7f-9d81-d7cf19c18378')/Attributes" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Attributes" title="Attributes" type="application/atom+xml;type=feed"/><link href="Products('18f7993d-eae1-4f7f-9d81-d7cf19c18378')/Class" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Class" title="Class" type="application/atom+xml;type=entry"/><content type="application/octet-stream" src="Products('18f7993d-eae1-4f7f-9d81-d7cf19c18378')/$value"/><m:properties><d:Id>18f7993d-eae1-4f7f-9d81-d7cf19c18378</d:Id><d:Name>S1A_IW_SLC__1SDV_20141023T172123_20141023T172150_002960_0035D1_9743</d:Name><d:ContentType>application/octet-stream</d:ContentType><d:ContentLength>8544532822</d:ContentLength><d:ChildrenNumber>2</d:ChildrenNumber><d:Value m:null="true"/><d:CreationDate>2014-12-07T17:06:00.324</d:CreationDate><d:IngestionDate>2014-12-07T17:06:00.324</d:IngestionDate><d:EvictionDate m:null="true"/><d:ContentDate m:type="DHuS.TimeRange"><d:Start>2014-10-23T17:21:23.23</d:Start><d:End>2014-10-23T17:21:50.495</d:End></d:ContentDate><d:Checksum m:type="DHuS.Checksum"><d:Algorithm>MD5</d:Algorithm><d:Value>C4415763B3198B7A2874C2A60B2CDCDC</d:Value></d:Checksum><d:ContentGeometry>&lt;gml:Polygon srsName="http://www.opengis.net/gml/srs/epsg.xml#4326" xmlns:gml="http://www.opengis.net/gml">
   &lt;gml:outerBoundaryIs>
      &lt;gml:LinearRing>
         &lt;gml:coordinates>41.289764,6.891860 41.685265,9.900283 40.048470,10.244140 39.652199,7.311233 41.289764,6.891860&lt;/gml:coordinates>
      &lt;/gml:LinearRing>
   &lt;/gml:outerBoundaryIs>
&lt;/gml:Polygon></d:ContentGeometry><d:Metalink>&lt;metalink xmlns="urn:ietf:params:xml:ns:metalink">&lt;file name ="S1A_IW_SLC__1SDV_20141023T172123_20141023T172150_002960_0035D1_9743.zip">&lt;url>https://scihub.copernicus.eu/dhus/odata/v1/Products('18f7993d-eae1-4f7f-9d81-d7cf19c18378')/$value&lt;/url>&lt;/file>&lt;/metalink></d:Metalink></m:properties></entry>

However, if I put the URI query https://scihub.copernicus.eu/dhus/odata/v1/Products%28'18f7993d-eae1-4f7f-9d81-d7cf19c18378'%29/$value directly into the browser it does download the product zip file.

I have also tried using curl as described in an answer to this question

curl -u username:usrpass -JO "https://scihub.copernicus.eu/dhus/odata/v1/Products('18f7993d-eae1-4f7f-9d81-d7cf19c18378')/$value"

but I get the error

Warning: Remote filename has no length!

I can't yet access the APIhub, only the science hub, (although a colleague with APIhub access has tried that too and had the same problem). I am able to use the science hub gui to interactively download data but would like to be able to automate the process. There are third party python scripts and shell scripts around, but many use the API hub, and I would like to understand what I am doing so I can develop specific scripts.

3
  • Did you use a wget version that is compiled with ssl support? Otherwise ssl won´t work.
    – Matte
    Apr 20, 2016 at 12:17
  • I'm not sure, I think it's the default with ubuntu 14. (wget -V GNU Wget 1.15 built on linux-gnu. +digest +https +ipv6 +iri +large-file +nls +ntlm +opie +ssl/openssl) (Compile: gcc -DHAVE_CONFIG_H -DSYSTEM_WGETRC="/etc/wgetrc" -DLOCALEDIR="/usr/share/locale" -I. -I../../src -I../lib -I../../lib -D_FORTIFY_SOURCE=2 -I/usr/include -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -DNO_SSLv2 -D_FILE_OFFSET_BITS=64 -g -Wall)
    – Colabean
    Apr 20, 2016 at 13:40
  • Thats not the problem then as you have the +ssl/openssl.
    – Matte
    Apr 20, 2016 at 16:25

3 Answers 3

11

I received help from an application developer at JNCC. I will post their answer here to help others.

My problem was that I needed to escape the $ character before value. so the wget command should read (using the apihub, which you could replace with dhus):

wget --no-check-certificate --user=username --password=usrpass "https://scihub.copernicus.eu/apihub/odata/v1/Products('18f7993d-eae1-4f7f-9d81-d7cf19c18378')/\$value"

Or to use curl his suggested command was:

curl -u username:password -LkJO "https://scihub.copernicus.eu/dhus/odata/v1/Products('13e66985-7d1f-4a7c-be58-925e7ed7889d')/\$value"

Note the escaped $ at the end. Without this the URL being sent is https://scihub.copernicus.eu/dhus/odata/v1/Products('13e66985-7d1f-4a7c-be58-925e7ed7889d')/ If you try this url in a browser you will get an html description of the product.

2
  • The curl method is working for me, but I'm getting an authentication error when using wget. Apr 3, 2019 at 8:14
  • When I use this approach, I get a file saved as $value.. When I go to this location on the scihub it is just a blank page. Any suggestions?
    – Clouseau
    Jun 30, 2022 at 17:38
7

A good alternative to the official Scihub is the mirrored Sentinel-2 data on Amazon Web Services.

Sentinel-2 on AWS

This has the advantage of better uptime and the products are already saved in their MGRS tiles, which makes downloading a lot faster.

The data is stored in a public bucket with the scheme tiles/[UTM code]/latitude band/square/[year]/[month]/[day]/[sequence]/DATA. This makes iterative, scripted downloading of all available scenes over an area very easy.

If you are interested in programmatic search and download of data from the Scihub you could also use the Python tool Sentinelsat.

3

I would suggest using the sentinelsat Python API for this. Especially if your goal is batch download.

Please see below for some example code for Sentinel- 2 download (Code run from Spyder)

#First, import this library (sentinelsat)
from sentinelsat import SentinelAPI, read_geojson, geojson_to_wkt
from datetime import date

api = SentinelAPI('user', 'password', 'https://scihub.copernicus.eu/dhus')

# search by polygon, time, and SciHub query keywords
footprint = geojson_to_wkt(read_geojson(r'/path/to/map.geojson'))
products = api.query(footprint,
                     date=('20151219', date(2015, 12, 29)),
                     platformname='Sentinel-2',
                     cloudcoverpercentage=(0, 30))

#Download all products 
api.download_all(products)

FYI, if you're looking for countrywide data, split the AOI up into smaller shapefiles as i had this issue where it returned no results when my AOI was too large.

Have a read of this for more info: https://buildmedia.readthedocs.org/media/pdf/sentinelsat/master/sentinelsat.pdf

There are also options for Sentinel-1 batch download too.

1
  • Did this work for you?
    – Rhodri_22
    Jul 31, 2019 at 8:50

Your Answer

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

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