{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "kOn6Dorgx2wk"
},
"source": [
"--------\n",
"\n",
"# Search S1 and S2\n",
"\n",
"--------\n",
"\n",
"**Short description**\n",
"\n",
"This notebook introduces spacesense Search functionality for catalog datasets.\n",
"\n",
"In this notebook, you will search for specific Sentinel-1 and Sentinel-2 images over a specified area and time.\n",
"\n",
"--------\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "o4gN2FtIx2wl"
},
"source": [
"### 0 - Install Spacesense Client Library and dependencies"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Please follow the [installation process](../gettingstarted/installation.rst) and use the virtual environment in this notebook."
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "keC_14irx2wq"
},
"source": [
"### 1 - Import spacesense object(s) and other dependencies"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "l1WpZ6RSx2wr"
},
"outputs": [],
"source": [
"from spacesense import Client"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 2 - Configure the API Key by setting the `SS_API_KEY` environment variable"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"if \"SS_API_KEY\" not in os.environ:\n",
" from getpass import getpass\n",
" api_key = getpass('Enter your api key : ')\n",
" os.environ[\"SS_API_KEY\"] = api_key"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 3 - Define AOI and output options"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"# Define the AOI\n",
"aoi = {\n",
" \"type\": \"FeatureCollection\",\n",
" \"features\": [\n",
" {\n",
" \"id\": \"0\",\n",
" \"type\": \"Feature\",\n",
" \"properties\": {},\n",
" \"geometry\": {\n",
" \"type\": \"Polygon\",\n",
" \"coordinates\": [\n",
" [\n",
" [\n",
" 8.622499,\n",
" 39.831038\n",
" ],\n",
" [\n",
" 8.622499,\n",
" 39.827197\n",
" ],\n",
" [\n",
" 8.630311,\n",
" 39.827197\n",
" ],\n",
" [\n",
" 8.630311,\n",
" 39.831038\n",
" ],\n",
" [\n",
" 8.622499,\n",
" 39.831038\n",
" ]\n",
" ]\n",
" ]\n",
" }\n",
" }\n",
" ]\n",
"}\n",
"\n",
"# Get an instance of the SpaceSense Client object\n",
"client = Client(id=\"search_s1_s2\")\n",
"\n",
"# Enable to save data in local files\n",
"client.enable_local_output()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 4 - Search S1\n",
"\n",
"More information about query_filters for S1 and S2 can be found at the [s1_search](../apidocs/client.html#client.Client.s1_search) and [s2_search](../apidocs/client.html#client.Client.s1_search) functions"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" title | \n",
" date | \n",
" swath_coverage_percentage | \n",
" relativeorbitnumber | \n",
" lastrelativeorbitnumber | \n",
" producttype | \n",
" sensoroperationalmode | \n",
" acquisitiontype | \n",
" polarisationmode | \n",
" beginposition | \n",
" platformname | \n",
" missiondatatakeid | \n",
" orbitdirection | \n",
" orbitnumber | \n",
" instrumentname | \n",
" lastorbitnumber | \n",
" endposition | \n",
" ingestiondate | \n",
" slicenumber | \n",
" platformidentifier | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" S1A_IW_GRDH_1SDV_20210101T052857_20210101T0529... | \n",
" 2021-01-01 | \n",
" 100.0 | \n",
" 168.0 | \n",
" 168.0 | \n",
" GRD | \n",
" IW | \n",
" NOMINAL | \n",
" VV VH | \n",
" 2021-01-01T05:28:57.811000 | \n",
" Sentinel-1 | \n",
" 275881.0 | \n",
" DESCENDING | \n",
" 35940.0 | \n",
" Synthetic Aperture Radar (C-band) | \n",
" 35940.0 | \n",
" 2021-01-01T05:29:22.811000 | \n",
" 2021-01-01T09:42:44.752000 | \n",
" 24.0 | \n",
" 2014-016A | \n",
"
\n",
" \n",
" 1 | \n",
" S1B_IW_GRDH_1SDV_20210107T052818_20210107T0528... | \n",
" 2021-01-07 | \n",
" 100.0 | \n",
" 168.0 | \n",
" 168.0 | \n",
" GRD | \n",
" IW | \n",
" NOMINAL | \n",
" VV VH | \n",
" 2021-01-07T05:28:18.784000 | \n",
" Sentinel-1 | \n",
" 195358.0 | \n",
" DESCENDING | \n",
" 25044.0 | \n",
" Synthetic Aperture Radar (C-band) | \n",
" 25044.0 | \n",
" 2021-01-07T05:28:53.839000 | \n",
" 2021-01-07T10:54:44.856000 | \n",
" 11.0 | \n",
" 2016-025A | \n",
"
\n",
" \n",
" 2 | \n",
" S1A_IW_GRDH_1SDV_20210113T052859_20210113T0529... | \n",
" 2021-01-13 | \n",
" 100.0 | \n",
" 168.0 | \n",
" 168.0 | \n",
" GRD | \n",
" IW | \n",
" NOMINAL | \n",
" VV VH | \n",
" 2021-01-13T05:28:59.422000 | \n",
" Sentinel-1 | \n",
" 277466.0 | \n",
" DESCENDING | \n",
" 36115.0 | \n",
" Synthetic Aperture Radar (C-band) | \n",
" 36115.0 | \n",
" 2021-01-13T05:29:24.421000 | \n",
" 2021-01-13T10:04:56.375000 | \n",
" 5.0 | \n",
" 2014-016A | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" title date \\\n",
"0 S1A_IW_GRDH_1SDV_20210101T052857_20210101T0529... 2021-01-01 \n",
"1 S1B_IW_GRDH_1SDV_20210107T052818_20210107T0528... 2021-01-07 \n",
"2 S1A_IW_GRDH_1SDV_20210113T052859_20210113T0529... 2021-01-13 \n",
"\n",
" swath_coverage_percentage relativeorbitnumber lastrelativeorbitnumber \\\n",
"0 100.0 168.0 168.0 \n",
"1 100.0 168.0 168.0 \n",
"2 100.0 168.0 168.0 \n",
"\n",
" producttype sensoroperationalmode acquisitiontype polarisationmode \\\n",
"0 GRD IW NOMINAL VV VH \n",
"1 GRD IW NOMINAL VV VH \n",
"2 GRD IW NOMINAL VV VH \n",
"\n",
" beginposition platformname missiondatatakeid orbitdirection \\\n",
"0 2021-01-01T05:28:57.811000 Sentinel-1 275881.0 DESCENDING \n",
"1 2021-01-07T05:28:18.784000 Sentinel-1 195358.0 DESCENDING \n",
"2 2021-01-13T05:28:59.422000 Sentinel-1 277466.0 DESCENDING \n",
"\n",
" orbitnumber instrumentname lastorbitnumber \\\n",
"0 35940.0 Synthetic Aperture Radar (C-band) 35940.0 \n",
"1 25044.0 Synthetic Aperture Radar (C-band) 25044.0 \n",
"2 36115.0 Synthetic Aperture Radar (C-band) 36115.0 \n",
"\n",
" endposition ingestiondate slicenumber \\\n",
"0 2021-01-01T05:29:22.811000 2021-01-01T09:42:44.752000 24.0 \n",
"1 2021-01-07T05:28:53.839000 2021-01-07T10:54:44.856000 11.0 \n",
"2 2021-01-13T05:29:24.421000 2021-01-13T10:04:56.375000 5.0 \n",
"\n",
" platformidentifier \n",
"0 2014-016A \n",
"1 2016-025A \n",
"2 2014-016A "
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"start_date = \"2021-01-01\"\n",
"end_date = \"2021-01-17\"\n",
"# Retrieves all S1 images corresponding to the aoi, start date, end date, and query_filters\n",
"res_S1 = client.s1_search(aoi=aoi, start_date=start_date, end_date=end_date, query_filters = {\"orbitdirection\" : \"DESCENDING\"})\n",
"res_S1.dataframe"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 5 - Search S2\n"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" id | \n",
" date | \n",
" tile | \n",
" valid_pixel_percentage | \n",
" platform | \n",
" relative_orbit_number | \n",
" product_id | \n",
" datetime | \n",
" swath_coverage_percentage | \n",
" no_data | \n",
" cloud_shadows | \n",
" vegetation | \n",
" not_vegetated | \n",
" water | \n",
" cloud_medium_probability | \n",
" cloud_high_probability | \n",
" thin_cirrus | \n",
" snow | \n",
"
\n",
" \n",
" \n",
" \n",
" 1 | \n",
" S2B_32TMK_20210108_0_L2A | \n",
" 2021-01-08 | \n",
" 32TMK | \n",
" 50.73 | \n",
" sentinel-2b | \n",
" 022 | \n",
" S2B_MSIL2A_20210108T101319_N0214_R022_T32TMK_2... | \n",
" 2021-01-08T10:19:47Z | \n",
" 100.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.00 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 49.27 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
"
\n",
" \n",
" 0 | \n",
" S2A_32TMK_20210116_0_L2A | \n",
" 2021-01-16 | \n",
" 32TMK | \n",
" 100.00 | \n",
" sentinel-2a | \n",
" 065 | \n",
" S2A_MSIL2A_20210116T102351_N0214_R065_T32TMK_2... | \n",
" 2021-01-16T10:29:44Z | \n",
" 100.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 97.56 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.00 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" id date tile valid_pixel_percentage \\\n",
"1 S2B_32TMK_20210108_0_L2A 2021-01-08 32TMK 50.73 \n",
"0 S2A_32TMK_20210116_0_L2A 2021-01-16 32TMK 100.00 \n",
"\n",
" platform relative_orbit_number \\\n",
"1 sentinel-2b 022 \n",
"0 sentinel-2a 065 \n",
"\n",
" product_id datetime \\\n",
"1 S2B_MSIL2A_20210108T101319_N0214_R022_T32TMK_2... 2021-01-08T10:19:47Z \n",
"0 S2A_MSIL2A_20210116T102351_N0214_R065_T32TMK_2... 2021-01-16T10:29:44Z \n",
"\n",
" swath_coverage_percentage no_data cloud_shadows vegetation \\\n",
"1 100.0 0.0 0.0 0.00 \n",
"0 100.0 0.0 0.0 97.56 \n",
"\n",
" not_vegetated water cloud_medium_probability cloud_high_probability \\\n",
"1 0.0 0.0 49.27 0.0 \n",
"0 0.0 0.0 0.00 0.0 \n",
"\n",
" thin_cirrus snow \n",
"1 0.0 0.0 \n",
"0 0.0 0.0 "
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"start_date = \"2021-01-08\"\n",
"end_date = \"2021-01-17\"\n",
"# Retrieves all S2 images corresponding to the aoi, start date, end date, and query_filters\n",
"res_S2 = client.s2_search(aoi=aoi, start_date=start_date, end_date=end_date, query_filters = {\"valid_pixel_percentage\" : {\">=\": 50}, \"cloud_medium_probability\" : {\"<=\": 50}})\n",
"res_S2.dataframe"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 6 - S2 search results can be viewed using a calendar"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 2021 \n",
"\n",
" January February March \n",
"Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su\n",
" 1 2 3 1 2 3 4 5 6 7 1 2 3 4 5 6 7 \n",
" 4 5 6 7 \u001b[41m 8\u001b[0m 9 10 8 9 10 11 12 13 14 8 9 10 11 12 13 14 \n",
"11 12 13 14 15 \u001b[42m16\u001b[0m 17 15 16 17 18 19 20 21 15 16 17 18 19 20 21 \n",
"18 19 20 21 22 23 24 22 23 24 25 26 27 28 22 23 24 25 26 27 28 \n",
"25 26 27 28 29 30 31 29 30 31 \n",
"\n",
"\u001b[41msentinel-2b (1)\u001b[0m\n",
"\u001b[42msentinel-2a (1)\u001b[0m\n",
"2 total dates\n"
]
}
],
"source": [
"print(res_S2.item_collection.calendar())"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.7.5 ('venv': venv)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.5"
},
"orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "e1ad9e0bf6960974dd8425f76aaa88b32de1b03d6f54bb6bf7fb6a0ca773e449"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}