Search S1 and S2#


Short description

This notebook introduces spacesense Search functionality for catalog datasets.

In this notebook, you will search for specific Sentinel-1 and Sentinel-2 images over a specified area and time.


0 - Install Spacesense Client Library and dependencies#

Please follow the installation process and use the virtual environment in this notebook.

1 - Import spacesense object(s) and other dependencies#

[1]:
from spacesense import Client

2 - Configure the API Key by setting the SS_API_KEY environment variable#

[2]:
import os
if "SS_API_KEY" not in os.environ:
    from getpass import getpass
    api_key = getpass('Enter your api key : ')
    os.environ["SS_API_KEY"] = api_key

3 - Define AOI and output options#

[3]:
# Define the AOI
aoi = {
  "type": "FeatureCollection",
  "features": [
    {
      "id": "0",
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [
            [
              8.622499,
              39.831038
            ],
            [
              8.622499,
              39.827197
            ],
            [
              8.630311,
              39.827197
            ],
            [
              8.630311,
              39.831038
            ],
            [
              8.622499,
              39.831038
            ]
          ]
        ]
      }
    }
  ]
}

# Get an instance of the SpaceSense Client object
client = Client(id="search_s1_s2")

# Enable to save data in local files
client.enable_local_output()

4 - Search S1#

More information about query_filters for S1 and S2 can be found at the s1_search and s2_search functions

[4]:
start_date = "2021-01-01"
end_date = "2021-01-17"
# Retrieves all S1 images corresponding to the aoi, start date, end date, and query_filters
res_S1 = client.s1_search(aoi=aoi, start_date=start_date, end_date=end_date, query_filters = {"orbitdirection" : "DESCENDING"})
res_S1.dataframe
[4]:
title date relativeorbitnumber lastrelativeorbitnumber producttype sensoroperationalmode acquisitiontype polarisationmode beginposition platformname missiondatatakeid orbitdirection orbitnumber instrumentname lastorbitnumber endposition ingestiondate slicenumber platformidentifier
0 S1A_IW_GRDH_1SDV_20210101T052857_20210101T0529... 2021-01-01 168.0 168.0 GRD IW NOMINAL VV VH 2021-01-01T05:28:57.811000 Sentinel-1 275881.0 DESCENDING 35940.0 Synthetic Aperture Radar (C-band) 35940.0 2021-01-01T05:29:22.811000 2021-01-01T09:42:44.752000 24.0 2014-016A
1 S1B_IW_GRDH_1SDV_20210107T052818_20210107T0528... 2021-01-07 168.0 168.0 GRD IW NOMINAL VV VH 2021-01-07T05:28:18.784000 Sentinel-1 195358.0 DESCENDING 25044.0 Synthetic Aperture Radar (C-band) 25044.0 2021-01-07T05:28:53.839000 2021-01-07T10:54:44.856000 11.0 2016-025A
2 S1A_IW_GRDH_1SDV_20210113T052859_20210113T0529... 2021-01-13 168.0 168.0 GRD IW NOMINAL VV VH 2021-01-13T05:28:59.422000 Sentinel-1 277466.0 DESCENDING 36115.0 Synthetic Aperture Radar (C-band) 36115.0 2021-01-13T05:29:24.421000 2021-01-13T10:04:56.375000 5.0 2014-016A

5 - Search S2#

[5]:
start_date = "2021-01-08"
end_date = "2021-01-17"
# Retrieves all S2 images corresponding to the aoi, start date, end date, and query_filters
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}})
res_S2.dataframe
[5]:
id date tile valid_pixel_percentage platform relative_orbit_number product_id datetime swath_coverage_percentage no_data cloud_shadows vegetation not_vegetated water cloud_medium_probability cloud_high_probability thin_cirrus snow
1 S2B_32TMK_20210108_0_L2A 2021-01-08 32TMK 50.73 sentinel-2b 022 S2B_MSIL2A_20210108T101319_N0214_R022_T32TMK_2... 2021-01-08T10:19:47Z 100.0 0.0 0.0 0.00 0.0 0.0 49.27 0.0 0.0 0.0
0 S2A_32TMK_20210116_0_L2A 2021-01-16 32TMK 100.00 sentinel-2a 065 S2A_MSIL2A_20210116T102351_N0214_R065_T32TMK_2... 2021-01-16T10:29:44Z 100.0 0.0 0.0 97.56 0.0 0.0 0.00 0.0 0.0 0.0

6 - S2 search results can be viewed using a calendar#

[6]:
print(res_S2.item_collection.calendar())
                              2021

      January               February               March
Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su
             1  2  3   1  2  3  4  5  6  7   1  2  3  4  5  6  7
 4  5  6  7  8  9 10   8  9 10 11 12 13 14   8  9 10 11 12 13 14
11 12 13 14 15 16 17  15 16 17 18 19 20 21  15 16 17 18 19 20 21
18 19 20 21 22 23 24  22 23 24 25 26 27 28  22 23 24 25 26 27 28
25 26 27 28 29 30 31                        29 30 31

sentinel-2a (1)
sentinel-2b (1)
2 total dates