4. Using sen1mosaic in Python

This is harder than the command line, but you may be interested in importing the sen1mosaic functions into Python in order to customise the processing chain.

To make sen1mosaic accesible in Python, edit your .bashrc file (located at ~/.bashrc) to contain the line:

export PYTHONPATH=$PYTHONPATH:/path/to/sen1mosaic/

You should now be able to import each of the four modules in Python as follows:

import sen1mosaic.download
import sen1mosaic.preprocess
import sen1mosaic.mosaic

Help for each function can be accessed interactively from Python. For example:

>>> help(sen1mosaic.download.connectToAPI)
        Help on function connectToAPI in module sen1mosaic.download:

        connectToAPI(username, password)
        Connect to the SciHub API with sentinelsat.

        Args:
            username: Scihub username. Sign up at https://scihub.copernicus.eu/.
            password: Scihub password.

On this page each of the functions from the download, preprocess, and mosaic modules are documented. Note that the main() function in each is what is driven by the command line tools, so in addition to it’s component parts you can call the entire processing chain from Python.

4.1. Download module

sen1mosaic.download.connectToAPI(username, password)[source]

Connect to the SciHub API with sentinelsat. Sign up at https://scihub.copernicus.eu/.

Parameters:
  • username – Scihub username.
  • password – Scihub password.
sen1mosaic.download.download(products_df, output_dir = os.getcwd())[source]

Downloads all images from a dataframe produced by sentinelsat.

Parameters:
  • products_df – Pandas dataframe from search() function.
  • output_dir – Optionally specify an output directory. Defaults to the present working directory.
sen1mosaic.download.removeDuplicates(products_df, data_dir = os.getcwd())[source]

Remove images from search results that have already been downloaded

Parameters:
  • products_df – Pandas dataframe from search() function.
  • data_dir – Directory containing Sentinel-1 data. Defaults to current working directory.
Returns:

A dataframe with duplicate files removed.

sen1mosaic.download.search(search_area, start = '20140403', end = datetime.datetime.today().strftime('%Y%m%d'), direction= '*')[source]

Searches for Sentinel-1 GRD IW images that meet conditions of date range and extent.

Parameters:
  • search_area – A list in the format [minlon, minlat, maxlon, maxlat]
  • start – Start date for search in format YYYYMMDD. Start date may not precede 20140403, the launch date of Sentinel1-. Defaults to 20140403.
  • end – End date for search in format YYYYMMDD. Defaults to today’s date.
Returns:

A pandas dataframe with details of scenes matching conditions.

4.2. Preprocessing module

4.3. Mosaicking module