Grab satellite data with Python

petercour profile image petercour ・2 min read

You can use Python to download satellite data. Lets try that. First you need to create tha username and password for the API. This is from the Senitel satellites.

Then install the senital module. You can type

pip install senitel

I got this working for Python 2.x, not Python 3. Maybe just an install issue.

It needs a search polygon as input (cities.geojson). You can download that file from here.

Change the username and password below, then run the code.

from sentinelsat import SentinelAPI, read_geojson, geojson_to_wkt
from datetime import date

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

# search by polygon, time, and SciHub query keywords
footprint = geojson_to_wkt(read_geojson(r'cities.geojson'))
products = api.query(footprint,
                     date=('20151219', date(2015, 12, 29)),
                     cloudcoverpercentage=(0, 30))

#Download all products 

It will download a zip file with lots of data. Extract that zip file and enter the directory:

cd /S2A_MSIL1C_20151221T140112_N0201_R024_T21HVB_20151221T140113.SAFE/GRANULE/L1C_T21HVB_A002595_20151221T140113/IMG_DATA/

Great, but all the image format is in jp2 format. Ever heard of that? Me neither. You can convert these images online. Seems that after that step need to merge the color channels.

Related links:

Posted on by:


markdown guide

You can use QGIS (qgis.org) to view the imagery in a GUI environment or if you prefer the command line look at GDAL (gdal.org) which also has python bindings. There is also Rasterio (rasterio.readthedocs.io/en/latest/...) as a python raster data processing and viewing system.