DEV Community

petercour
petercour

Posted on

Grab satellite data with Python

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.

#!/usr/bin/python3
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)),
                     platformname='Sentinel-2',
                     cloudcoverpercentage=(0, 30))

#Download all products 
api.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:

Top comments (1)

Collapse
 
ianturton profile image
Ian Turton

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.