{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Sentinel-1 processing for ship detection (SNAP)\n", "\n", "In this tutorial we will employ `eodag` for ship detection (marine surveillance) in the Gulf of Trieste using Sentinel-1 satellite-borne Synthetic Aperture Radar (SAR).\n", "\n", "Marine surveillance can be done using different technologies. A first option consists of cooperative system in which ships themselves report their identities and positions. The three most common options are Automatic Identification System (AIS), Long Range Identification and Tracking (LRIT) and Vessel Monitoring System. These systems most commonly use cameras and radars located on a variety of platforms (ship, airplanes, satellites, etc.) (source: [ESA RUS](https://rus-copernicus.eu/) tutorials).\n", "\n", "Ship detection with Sentinel-1 falls into the non-cooperative category and enables detection of vessels not carrying AIS or other tracking system on board such as smaller fishing ships or ships that are in the surveyed area illegally (illegal fishing, piracy etc.). Moreover, SAR is not reliant on solar illumination and is rather independent of weather conditions, therefore enabling frequent monitoring.\n", "\n", "\n", "To be able to follow this tutorial, you will need to:\n", "\n", "* [SNAP](http://step.esa.int/main/download/snap-download/) to use its `gpt` command. This particular command is used to execute *SNAP* raster data operators in batch-mode based on XML Graph files (see more info about the [Graph Processing Framework](https://senbox.atlassian.net/wiki/spaces/SNAP/pages/70503590/Creating+a+GPF+Graph) of *SNAP*). You need to have the `bin` folder of *SNAP* in your system *PATH*. The version used in this tutorial is the 8.0.\n", " \n", " > **Note:** If you need support to install or configure SNAP, please refer to https://forum.step.esa.int/c/snap.\n", "\n", "* Download the auxiliary files [here](https://github.com/CS-SI/eodag/tree/master/docs/notebooks/tutos/auxdata/) which contain the appropriate shapefiles.\n", "* The following Python packages: [Folium](https://python-visualization.github.io/folium/installing.html), [imageio](https://imageio.readthedocs.io/en/stable/installation.html), [Matplotlib](https://matplotlib.org/3.3.3/users/installing.html), [NumPy](https://numpy.org/install/) and [rasterio](https://rasterio.readthedocs.io/en/latest/installation.html).\n", "\n", "## Configuration\n", "\n", "Let's start by setting your personal credentials to access [PEPS service](https://peps.cnes.fr/rocket/) by filling your username and password below:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import os\n", "os.environ[\"EODAG__PEPS__AUTH__CREDENTIALS__USERNAME\"] = \"PLEASE_CHANGE_ME\"\n", "os.environ[\"EODAG__PEPS__AUTH__CREDENTIALS__PASSWORD\"] = \"PLEASE_CHANGE_ME\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If you don't have the `bin` folder of *SNAP* in your system *PATH* uncomment the following lines of code, adapt the path to your installation and run it to check whether the path was correctly prepended to your *PATH*." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "# Add absolute path to SNAP bin folder to make the gpt command available \n", "#os.environ[\"PATH\"] = \"PLEASE_CHANGE_ME\" + \":\" + os.environ[\"PATH\"]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's check that the Python packages required to run this notebook are available:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "import folium\n", "import imageio\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "import rasterio" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Then we create a workspace directory where all our files and configuration will live:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2021-01-11 21:29:05,764-15s eodag.config [INFO ] Loading user configuration from: /home/maxime/TRAVAIL/06_EODAG/eodag/examples/eodag_workspace_shipdetection/eodag_conf.yml\n", "2021-01-11 21:29:06,075-15s eodag.core [INFO ] Locations configuration loaded from /home/maxime/.config/eodag/locations.yml\n" ] } ], "source": [ "from eodag.api.core import EODataAccessGateway\n", "from eodag import setup_logging\n", "\n", "setup_logging(verbose=2)\n", "\n", "# Create the workspace folder.\n", "workspace = 'eodag_workspace_shipdetection'\n", "if not os.path.isdir(workspace):\n", " os.mkdir(workspace)\n", "\n", "# Save the PEPS configuration file.\n", "yaml_content = \"\"\"\n", "peps:\n", " download:\n", " outputs_prefix: \"{}\"\n", " extract: true\n", "\"\"\".format(os.path.abspath(workspace))\n", "\n", "with open(os.path.join(workspace, 'eodag_conf.yml'), \"w\") as f_yml:\n", " f_yml.write(yaml_content.strip())\n", "\n", "dag = EODataAccessGateway(os.path.join(workspace, 'eodag_conf.yml'))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Search and download with `eodag`\n", "\n", "We define the type of product we want to work on and the search area." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "product_type = 'S1_SAR_GRD'\n", "extent = {\n", " 'lonmin': 13.054504,\n", " 'lonmax': 13.808441,\n", " 'latmin': 45.475540,\n", " 'latmax': 45.762733\n", "}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We make a search centered on the ninth of October 2016 via `eodag` and display the returned products on an interactive map:" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "scrolled": false }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2021-01-11 21:29:10,041-15s eodag.core [INFO ] Searching product type 'S1_SAR_GRD' on provider: peps\n", "2021-01-11 21:29:10,043-15s eodag.plugins.search.qssearch [INFO ] Sending count request: https://peps.cnes.fr/resto/api/collections/S1/search.json?startDate=2017-05-01&completionDate=2017-05-02&geometry=POLYGON ((13.0545 45.4755, 13.0545 45.7627, 13.8084 45.7627, 13.8084 45.4755, 13.0545 45.4755))&productType=GRD&maxRecords=1&page=1\n", "2021-01-11 21:29:10,742-15s eodag.plugins.search.qssearch [INFO ] Sending search request: https://peps.cnes.fr/resto/api/collections/S1/search.json?startDate=2017-05-01&completionDate=2017-05-02&geometry=POLYGON ((13.0545 45.4755, 13.0545 45.7627, 13.8084 45.7627, 13.8084 45.4755, 13.0545 45.4755))&productType=GRD&maxRecords=20&page=1\n", "2021-01-11 21:29:11,546-15s eodag.core [INFO ] Found 2 result(s) on provider 'peps'\n" ] }, { "data": { "text/plain": [ "[EOProduct(id=S1A_IW_GRDH_1SDV_20170501T165831_20170501T165856_016391_01B235_1399, provider=peps), EOProduct(id=S1A_IW_GRDH_1SDV_20170501T165806_20170501T165831_016391_01B235_9CD1, provider=peps)]" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "products, estimated_nbr_of_results = dag.search(\n", " productType=product_type, \n", " start='2017-05-01', \n", " end='2017-05-02',\n", " geom=extent\n", ")\n", "products" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ "