Search and filter S1 and S2 data#


Short description

This notebook introduces the Search and Filter functionality for SpaceSense catalog entries.

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


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_filter_s1_s2")

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

4 - Search S1#

[4]:
start_date = "2021-01-01"
end_date = "2021-01-17"
# Retrieves all S1 images corresponding to the aoi, start date, and end date
res_S1 = client.s1_search(aoi=aoi, start_date=start_date, end_date=end_date)
res_S1.dataframe
[4]:
title date swath_coverage_percentage relativeorbitnumber lastrelativeorbitnumber producttype sensoroperationalmode acquisitiontype polarisationmode beginposition platformname missiondatatakeid orbitdirection orbitnumber instrumentname lastorbitnumber endposition ingestiondate slicenumber platformidentifier
0 S1B_IW_GRDH_1SDV_20210101T172105_20210101T1721... 2021-01-01 100.0 88.0 88.0 GRD IW NOMINAL VV VH 2021-01-01T17:21:05.249000 Sentinel-1 194718.0 ASCENDING 24964.0 Synthetic Aperture Radar (C-band) 24964.0 2021-01-01T17:21:30.248000 2021-01-01T21:41:44.626000 10.0 2016-025A
1 S1A_IW_GRDH_1SDV_20210101T052857_20210101T0529... 2021-01-01 100.0 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
2 S1A_IW_GRDH_1SDV_20210107T172154_20210107T1722... 2021-01-07 100.0 88.0 88.0 GRD IW NOMINAL VV VH 2021-01-07T17:21:54.456000 Sentinel-1 276727.0 ASCENDING 36035.0 Synthetic Aperture Radar (C-band) 36035.0 2021-01-07T17:22:19.456000 2021-01-08T19:10:51.074000 7.0 2014-016A
3 S1B_IW_GRDH_1SDV_20210107T052818_20210107T0528... 2021-01-07 100.0 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
4 S1B_IW_GRDH_1SDV_20210113T172104_20210113T1721... 2021-01-13 100.0 88.0 88.0 GRD IW NOMINAL VV VH 2021-01-13T17:21:04.721000 Sentinel-1 196160.0 ASCENDING 25139.0 Synthetic Aperture Radar (C-band) 25139.0 2021-01-13T17:21:29.719000 2021-01-14T12:43:29.264000 10.0 2016-025A
5 S1A_IW_GRDH_1SDV_20210113T052859_20210113T0529... 2021-01-13 100.0 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-01"
end_date = "2021-01-31"
# Retrieves all S2 images corresponding to the aoi, start date, and end date
res_S2 = client.s2_search(aoi=aoi, start_date=start_date, end_date=end_date)
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
12 S2B_32TMK_20210101_0_L2A 2021-01-01 32TMK 0.00 sentinel-2b 065 S2B_MSIL2A_20210101T102329_N0214_R065_T32TMK_2... 2021-01-01T10:29:42Z 100.0 0.0 0.0 0.00 0.00 0.0 0.00 100.00 0.00 0.0
11 S2A_32TMK_20210103_0_L2A 2021-01-03 32TMK 0.00 sentinel-2a 022 S2A_MSIL2A_20210103T101411_N0214_R022_T32TMK_2... 2021-01-03T10:19:48Z 100.0 0.0 0.0 0.00 0.00 0.0 0.00 100.00 0.00 0.0
10 S2A_32TMK_20210106_0_L2A 2021-01-06 32TMK 0.00 sentinel-2a 065 S2A_MSIL2A_20210106T102411_N0214_R065_T32TMK_2... 2021-01-06T10:29:44Z 100.0 0.0 0.0 0.00 0.00 0.0 0.00 100.00 0.00 0.0
9 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.00 0.0 49.27 0.00 0.00 0.0
8 S2B_32TMK_20210111_0_L2A 2021-01-11 32TMK 5.08 sentinel-2b 065 S2B_MSIL2A_20210111T102309_N0214_R065_T32TMK_2... 2021-01-11T10:29:43Z 100.0 0.0 0.0 0.00 0.00 0.0 16.69 77.53 0.70 0.0
7 S2A_32TMK_20210113_0_L2A 2021-01-13 32TMK 0.00 sentinel-2a 022 S2A_MSIL2A_20210113T101401_N0214_R022_T32TMK_2... 2021-01-13T10:19:48Z 100.0 0.0 0.0 0.00 0.00 0.0 0.00 100.00 0.00 0.0
6 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.00 0.0 0.00 0.00 0.00 0.0
5 S2B_32TMK_20210118_0_L2A 2021-01-18 32TMK 100.00 sentinel-2b 022 S2B_MSIL2A_20210118T101249_N0214_R022_T32TMK_2... 2021-01-18T10:19:47Z 100.0 0.0 0.0 96.59 0.49 0.0 0.00 0.00 0.00 0.0
4 S2B_32TMK_20210121_0_L2A 2021-01-21 32TMK 0.00 sentinel-2b 065 S2B_MSIL2A_20210121T102239_N0214_R065_T32TMK_2... 2021-01-21T10:29:43Z 100.0 0.0 0.0 0.00 0.00 0.0 61.38 0.00 38.62 0.0
3 S2A_32TMK_20210123_0_L2A 2021-01-23 32TMK 100.00 sentinel-2a 022 S2A_MSIL2A_20210123T101321_N0214_R022_T32TMK_2... 2021-01-23T10:19:48Z 100.0 0.0 0.0 97.40 0.00 0.0 0.00 0.00 0.00 0.0
2 S2A_32TMK_20210126_0_L2A 2021-01-26 32TMK 100.00 sentinel-2a 065 S2A_MSIL2A_20210126T102311_N0214_R065_T32TMK_2... 2021-01-26T10:29:44Z 100.0 0.0 0.0 97.40 0.00 0.0 0.00 0.00 0.00 0.0
1 S2B_32TMK_20210128_0_L2A 2021-01-28 32TMK 0.00 sentinel-2b 022 S2B_MSIL2A_20210128T101159_N0214_R022_T32TMK_2... 2021-01-28T10:19:47Z 100.0 0.0 0.0 0.00 0.00 0.0 0.00 100.00 0.00 0.0
0 S2B_32TMK_20210131_0_L2A 2021-01-31 32TMK 0.00 sentinel-2b 065 S2B_MSIL2A_20210131T102149_N0214_R065_T32TMK_2... 2021-01-31T10:29:43Z 100.0 0.0 0.0 0.00 0.00 0.0 0.00 100.00 0.00 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)
13 total dates

7 - Filter and select only the S1 and S2 images you require#

There are many ways to select the data you need, as it is simply manipulating the Pandas Dataframe object. Here is a link to the Pandas documentation for DataFrames, and there are introductory tutorials available to teach the basics of DataFrame structure and manipulation here and here

So experiment and find the best way that suits your use case!

This same process works for both S1 and S2 search results. The following examples simply display the result after filtering. To apply the filters, set them equal to a new or existing variable.

[7]:
# Select only the first (0) and second (1) elements of the Sentinel-1 results by their index (using "iloc")
res_S1.dataframe.iloc[[0,1]]
[7]:
title date swath_coverage_percentage relativeorbitnumber lastrelativeorbitnumber producttype sensoroperationalmode acquisitiontype polarisationmode beginposition platformname missiondatatakeid orbitdirection orbitnumber instrumentname lastorbitnumber endposition ingestiondate slicenumber platformidentifier
0 S1B_IW_GRDH_1SDV_20210101T172105_20210101T1721... 2021-01-01 100.0 88.0 88.0 GRD IW NOMINAL VV VH 2021-01-01T17:21:05.249000 Sentinel-1 194718.0 ASCENDING 24964.0 Synthetic Aperture Radar (C-band) 24964.0 2021-01-01T17:21:30.248000 2021-01-01T21:41:44.626000 10.0 2016-025A
1 S1A_IW_GRDH_1SDV_20210101T052857_20210101T0529... 2021-01-01 100.0 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
[8]:
# Filter the Sentinel-2 search results by the "valid_pixel_percentage" column
# This filter takes only those results with more than 80% of pixels considered valid
res_S2.dataframe[res_S2.dataframe["valid_pixel_percentage"] > 80]
[8]:
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
6 S2A_32TMK_20210116_0_L2A 2021-01-16 32TMK 100.0 sentinel-2a 065 S2A_MSIL2A_20210116T102351_N0214_R065_T32TMK_2... 2021-01-16T10:29:44Z 100.0 0.0 0.0 97.56 0.00 0.0 0.0 0.0 0.0 0.0
5 S2B_32TMK_20210118_0_L2A 2021-01-18 32TMK 100.0 sentinel-2b 022 S2B_MSIL2A_20210118T101249_N0214_R022_T32TMK_2... 2021-01-18T10:19:47Z 100.0 0.0 0.0 96.59 0.49 0.0 0.0 0.0 0.0 0.0
3 S2A_32TMK_20210123_0_L2A 2021-01-23 32TMK 100.0 sentinel-2a 022 S2A_MSIL2A_20210123T101321_N0214_R022_T32TMK_2... 2021-01-23T10:19:48Z 100.0 0.0 0.0 97.40 0.00 0.0 0.0 0.0 0.0 0.0
2 S2A_32TMK_20210126_0_L2A 2021-01-26 32TMK 100.0 sentinel-2a 065 S2A_MSIL2A_20210126T102311_N0214_R065_T32TMK_2... 2021-01-26T10:29:44Z 100.0 0.0 0.0 97.40 0.00 0.0 0.0 0.0 0.0 0.0

Learn more about what “valid_pixel_percentage” is here

[9]:
# Filter S2 on specific dates or date ranges
res_S2.dataframe[res_S2.dataframe.date >= "2021-01-13"]
[9]:
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
7 S2A_32TMK_20210113_0_L2A 2021-01-13 32TMK 0.0 sentinel-2a 022 S2A_MSIL2A_20210113T101401_N0214_R022_T32TMK_2... 2021-01-13T10:19:48Z 100.0 0.0 0.0 0.00 0.00 0.0 0.00 100.0 0.00 0.0
6 S2A_32TMK_20210116_0_L2A 2021-01-16 32TMK 100.0 sentinel-2a 065 S2A_MSIL2A_20210116T102351_N0214_R065_T32TMK_2... 2021-01-16T10:29:44Z 100.0 0.0 0.0 97.56 0.00 0.0 0.00 0.0 0.00 0.0
5 S2B_32TMK_20210118_0_L2A 2021-01-18 32TMK 100.0 sentinel-2b 022 S2B_MSIL2A_20210118T101249_N0214_R022_T32TMK_2... 2021-01-18T10:19:47Z 100.0 0.0 0.0 96.59 0.49 0.0 0.00 0.0 0.00 0.0
4 S2B_32TMK_20210121_0_L2A 2021-01-21 32TMK 0.0 sentinel-2b 065 S2B_MSIL2A_20210121T102239_N0214_R065_T32TMK_2... 2021-01-21T10:29:43Z 100.0 0.0 0.0 0.00 0.00 0.0 61.38 0.0 38.62 0.0
3 S2A_32TMK_20210123_0_L2A 2021-01-23 32TMK 100.0 sentinel-2a 022 S2A_MSIL2A_20210123T101321_N0214_R022_T32TMK_2... 2021-01-23T10:19:48Z 100.0 0.0 0.0 97.40 0.00 0.0 0.00 0.0 0.00 0.0
2 S2A_32TMK_20210126_0_L2A 2021-01-26 32TMK 100.0 sentinel-2a 065 S2A_MSIL2A_20210126T102311_N0214_R065_T32TMK_2... 2021-01-26T10:29:44Z 100.0 0.0 0.0 97.40 0.00 0.0 0.00 0.0 0.00 0.0
1 S2B_32TMK_20210128_0_L2A 2021-01-28 32TMK 0.0 sentinel-2b 022 S2B_MSIL2A_20210128T101159_N0214_R022_T32TMK_2... 2021-01-28T10:19:47Z 100.0 0.0 0.0 0.00 0.00 0.0 0.00 100.0 0.00 0.0
0 S2B_32TMK_20210131_0_L2A 2021-01-31 32TMK 0.0 sentinel-2b 065 S2B_MSIL2A_20210131T102149_N0214_R065_T32TMK_2... 2021-01-31T10:29:43Z 100.0 0.0 0.0 0.00 0.00 0.0 0.00 100.0 0.00 0.0
[10]:
# Filter the Sentinel-2 search results by the "cloud_high_probability" column
# This filter takes only those results with less than 5% of pixels classificed as "cloud_high_probability"
res_S2.dataframe[res_S2.dataframe["cloud_high_probability"] < 5]
[10]:
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
9 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.00 0.0 49.27 0.0 0.00 0.0
6 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.00 0.0 0.00 0.0 0.00 0.0
5 S2B_32TMK_20210118_0_L2A 2021-01-18 32TMK 100.00 sentinel-2b 022 S2B_MSIL2A_20210118T101249_N0214_R022_T32TMK_2... 2021-01-18T10:19:47Z 100.0 0.0 0.0 96.59 0.49 0.0 0.00 0.0 0.00 0.0
4 S2B_32TMK_20210121_0_L2A 2021-01-21 32TMK 0.00 sentinel-2b 065 S2B_MSIL2A_20210121T102239_N0214_R065_T32TMK_2... 2021-01-21T10:29:43Z 100.0 0.0 0.0 0.00 0.00 0.0 61.38 0.0 38.62 0.0
3 S2A_32TMK_20210123_0_L2A 2021-01-23 32TMK 100.00 sentinel-2a 022 S2A_MSIL2A_20210123T101321_N0214_R022_T32TMK_2... 2021-01-23T10:19:48Z 100.0 0.0 0.0 97.40 0.00 0.0 0.00 0.0 0.00 0.0
2 S2A_32TMK_20210126_0_L2A 2021-01-26 32TMK 100.00 sentinel-2a 065 S2A_MSIL2A_20210126T102311_N0214_R065_T32TMK_2... 2021-01-26T10:29:44Z 100.0 0.0 0.0 97.40 0.00 0.0 0.00 0.0 0.00 0.0
[11]:
# Filter S1 on orbit number
res_S1.dataframe[res_S1.dataframe.orbitnumber == 25044]
[11]:
title date swath_coverage_percentage relativeorbitnumber lastrelativeorbitnumber producttype sensoroperationalmode acquisitiontype polarisationmode beginposition platformname missiondatatakeid orbitdirection orbitnumber instrumentname lastorbitnumber endposition ingestiondate slicenumber platformidentifier
3 S1B_IW_GRDH_1SDV_20210107T052818_20210107T0528... 2021-01-07 100.0 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
[12]:
# Filter S2 on satellite platform (S2A or S2B)
res_S2.dataframe[res_S2.dataframe.platform == "sentinel-2a"]
[12]:
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
11 S2A_32TMK_20210103_0_L2A 2021-01-03 32TMK 0.0 sentinel-2a 022 S2A_MSIL2A_20210103T101411_N0214_R022_T32TMK_2... 2021-01-03T10:19:48Z 100.0 0.0 0.0 0.00 0.0 0.0 0.0 100.0 0.0 0.0
10 S2A_32TMK_20210106_0_L2A 2021-01-06 32TMK 0.0 sentinel-2a 065 S2A_MSIL2A_20210106T102411_N0214_R065_T32TMK_2... 2021-01-06T10:29:44Z 100.0 0.0 0.0 0.00 0.0 0.0 0.0 100.0 0.0 0.0
7 S2A_32TMK_20210113_0_L2A 2021-01-13 32TMK 0.0 sentinel-2a 022 S2A_MSIL2A_20210113T101401_N0214_R022_T32TMK_2... 2021-01-13T10:19:48Z 100.0 0.0 0.0 0.00 0.0 0.0 0.0 100.0 0.0 0.0
6 S2A_32TMK_20210116_0_L2A 2021-01-16 32TMK 100.0 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.0 0.0 0.0 0.0
3 S2A_32TMK_20210123_0_L2A 2021-01-23 32TMK 100.0 sentinel-2a 022 S2A_MSIL2A_20210123T101321_N0214_R022_T32TMK_2... 2021-01-23T10:19:48Z 100.0 0.0 0.0 97.40 0.0 0.0 0.0 0.0 0.0 0.0
2 S2A_32TMK_20210126_0_L2A 2021-01-26 32TMK 100.0 sentinel-2a 065 S2A_MSIL2A_20210126T102311_N0214_R065_T32TMK_2... 2021-01-26T10:29:44Z 100.0 0.0 0.0 97.40 0.0 0.0 0.0 0.0 0.0 0.0