{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "--------\n", "\n", "# Create custom water or vegetation index\n", "\n", "--------\n", "\n", "**Short description**\n", "\n", "This notebook demonstrates a general usecase for the SpaceSense library.\n", "\n", "In this notebook, you will search for, select, and obtain a Sentinel-2 image. We want the selected data needs to be cloud-free in order to better analyze the index. Custom indices can then be calculated over the area. This example examines several water quality indices. \n", "\n", "--------" ] }, { "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\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "import json\n", "\n", "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": [ "### 2 - Define AOI and output options\n", "\n", "The GeoJSON of this AOI, containing a small portion of Lake Matano and coastline in Indonesia, can be downloaded [here](../resources/aois/lake_matano.geojson)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "# Define the AOI\n", "with open(\"../resources/aois/lake_matano.geojson\", mode=\"r\") as file:\n", " aoi = json.load(file)\n", "\n", "# Get an instance of the SpaceSense Client object\n", "client = Client(id=\"s2_custom_index\")\n", "\n", "# Enable to save data in local files\n", "client.enable_local_output()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 3 - Search S2" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\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", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "S2B_51MUT_20210501_0_L2A | \n", "2021-05-01 | \n", "51MUT | \n", "100.0 | \n", "sentinel-2b | \n", "060 | \n", "S2B_MSIL2A_20210501T021339_N0300_R060_T51MUT_2... | \n", "2021-05-01T02:18:15Z | \n", "100.0 | \n", "0.0 | \n", "0.0 | \n", "26.02 | \n", "0.0 | \n", "72.95 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "
<xarray.Dataset>\n", "Dimensions: (time: 1, y: 2357, x: 327)\n", "Coordinates:\n", " * time (time) datetime64[ns] 2021-05-01\n", " * y (y) float32 -2.487 -2.487 -2.487 -2.487 ... -2.504 -2.504 -2.504\n", " * x (x) float64 121.3 121.3 121.3 121.3 ... 121.3 121.3 121.3 121.3\n", "Data variables:\n", " S2_B01 (time, y, x) float32 0.0 0.0 0.0 0.0 0.0 ... 0.0477 0.0477 0.0 0.0\n", " S2_B02 (time, y, x) float32 0.0 0.0 0.0 0.0 ... 0.0401 0.0442 0.0442 0.0\n", " S2_B03 (time, y, x) float32 0.0 0.0 0.0 0.0 ... 0.0257 0.0273 0.0263 0.0\n", " S2_B04 (time, y, x) float32 0.0 0.0 0.0 0.0 ... 0.0139 0.0128 0.0135 0.0\n", " S2_B08 (time, y, x) float32 0.0 0.0 0.0 0.0 ... 0.0071 0.0091 0.0096 0.0\n", " S2_SCL (time, y, x) float32 0.0 0.0 0.0 0.0 0.0 ... 6.0 6.0 6.0 6.0 6.0\n", "Attributes:\n", " crs: +init=epsg:4326\n", " transform: [ 8.98315284e-05 0.00000000e+00 1.21303645e+02 0.000...\n", " res: [8.98315284e-05 7.00728646e-06]\n", " ulx, uly: [121.30364507 -2.48706115]\n", " s2_data_lineage: {"Data origin": "S3 bucket (ARN=arn:aws:s3:::sentinel-c...\n", " additional_info: {'Info': 'You can put any additional information, such ...
<xarray.Dataset>\n", "Dimensions: (time: 1, y: 2357, x: 327)\n", "Coordinates:\n", " * time (time) datetime64[ns] 2021-05-01\n", " * y (y) float32 -2.487 -2.487 -2.487 -2.487 ... -2.504 -2.504 -2.504\n", " * x (x) float64 121.3 121.3 121.3 121.3 ... 121.3 121.3 121.3 121.3\n", "Data variables:\n", " S2_B01 (time, y, x) float32 0.0 0.0 0.0 0.0 0.0 ... 0.0477 0.0477 0.0 0.0\n", " S2_B02 (time, y, x) float32 0.0 0.0 0.0 0.0 ... 0.0401 0.0442 0.0442 0.0\n", " S2_B03 (time, y, x) float32 0.0 0.0 0.0 0.0 ... 0.0257 0.0273 0.0263 0.0\n", " S2_B04 (time, y, x) float32 0.0 0.0 0.0 0.0 ... 0.0139 0.0128 0.0135 0.0\n", " S2_B08 (time, y, x) float32 0.0 0.0 0.0 0.0 ... 0.0071 0.0091 0.0096 0.0\n", " S2_SCL (time, y, x) float32 0.0 0.0 0.0 0.0 0.0 ... 6.0 6.0 6.0 6.0 6.0\n", " CHL_A (time, y, x) float32 nan nan nan nan nan ... 0.3699 0.4693 nan nan\n", " SPM (time, y, x) float32 0.0 0.0 0.0 0.0 0.0 ... 6.8 9.212 9.835 0.0\n", "Attributes:\n", " crs: +init=epsg:4326\n", " transform: [ 8.98315284e-05 0.00000000e+00 1.21303645e+02 0.000...\n", " res: [8.98315284e-05 7.00728646e-06]\n", " ulx, uly: [121.30364507 -2.48706115]\n", " s2_data_lineage: {"Data origin": "S3 bucket (ARN=arn:aws:s3:::sentinel-c...\n", " additional_info: {'Info': 'You can put any additional information, such ...