Monthly optical images
Contents
Monthly optical images#
Short description
This notebook demonstrates a general usecase for the SpaceSense library.
In this notebook, you will search for, select, and obtain Sentinel-2 data. The selected data will be cloud free and the expected result is to have a single image per month of the year.
1 - Import spacesense object(s) and other dependencies#
[1]:
from spacesense import Client
import json
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
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
2 - Define AOI and output options#
The GeoJSON of this AOI, containing the Cirque de Garvanie in the Pyrenees Mountains, can be downloaded here
[2]:
# Define the AOI
with open("../resources/aois/cirque_de_garvanie.geojson", mode="r") as file:
aoi = json.load(file)
# Get an instance of the SpaceSense Client object
client = Client(id="s2_optical_monthly")
# Enable to save data in local files
client.enable_local_output()
3 - Search S2#
[3]:
start_date = "2020-01-01"
end_date = "2021-01-01"
# Create a query filter, limiting cloud coverage to 10% or less, and only taking scenes with 100% swath coverage
query_filter = {"cloud_medium_probability" : {"<=": 10},
"cloud_high_probability" : {"<=": 10},
"cloud_shadows" : {"<=": 10},
"swath_coverage_percentage": {"==": 100}}
res_S2 = client.s2_search(aoi=aoi, start_date=start_date, end_date=end_date, query_filters = query_filter)
res_S2.filter_duplicate_dates()
res_S2.dataframe
[3]:
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 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
32 | S2A_30TYN_20200101_0_L2A | 2020-01-01 | 30TYN | 57.50 | sentinel-2a | 051 | S2A_MSIL2A_20200101T105441_N0213_R051_T30TYN_2... | 2020-01-01T10:59:11Z | 100.0 | 0.0 | 0.80 | 0.85 | 1.97 | 7.58 | 0.15 | 0.62 | 0.01 | 40.92 |
31 | S2B_30TYN_20200106_0_L2A | 2020-01-06 | 30TYN | 57.40 | sentinel-2b | 051 | S2B_MSIL2A_20200106T105339_N0213_R051_T30TYN_2... | 2020-01-06T10:59:11Z | 100.0 | 0.0 | 1.06 | 0.93 | 2.48 | 7.29 | 0.18 | 0.74 | 0.00 | 40.62 |
30 | S2B_30TYN_20200116_0_L2A | 2020-01-16 | 30TYN | 56.71 | sentinel-2b | 051 | S2B_MSIL2A_20200116T105309_N0213_R051_T30TYN_2... | 2020-01-16T10:59:10Z | 100.0 | 0.0 | 1.39 | 1.03 | 5.02 | 6.10 | 0.17 | 0.98 | 0.00 | 40.75 |
29 | S2A_30TYN_20200131_0_L2A | 2020-01-31 | 30TYN | 44.29 | sentinel-2a | 051 | S2A_MSIL2A_20200131T105251_N0213_R051_T30TYN_2... | 2020-01-31T10:59:09Z | 100.0 | 0.0 | 0.14 | 0.36 | 0.33 | 4.16 | 0.09 | 0.12 | 0.00 | 55.36 |
28 | S2B_30TYN_20200205_0_L2A | 2020-02-05 | 30TYN | 46.67 | sentinel-2b | 051 | S2B_MSIL2A_20200205T105129_N0214_R051_T30TYN_2... | 2020-02-05T10:59:10Z | 100.0 | 0.0 | 1.02 | 1.27 | 2.69 | 3.77 | 0.28 | 0.65 | 0.00 | 51.38 |
27 | S2A_30TYN_20200210_0_L2A | 2020-02-10 | 30TYN | 46.38 | sentinel-2a | 051 | S2A_MSIL2A_20200210T105201_N0214_R051_T30TYN_2... | 2020-02-10T10:59:09Z | 100.0 | 0.0 | 1.30 | 1.55 | 4.72 | 3.06 | 0.05 | 0.53 | 0.00 | 51.74 |
26 | S2B_30TYN_20200215_0_L2A | 2020-02-15 | 30TYN | 44.83 | sentinel-2b | 051 | S2B_MSIL2A_20200215T105029_N0214_R051_T30TYN_2... | 2020-02-15T10:59:12Z | 100.0 | 0.0 | 1.47 | 1.72 | 5.97 | 2.42 | 0.28 | 0.93 | 0.00 | 52.49 |
25 | S2A_30TYN_20200220_0_L2A | 2020-02-20 | 30TYN | 43.61 | sentinel-2a | 051 | S2A_MSIL2A_20200220T105051_N0214_R051_T30TYN_2... | 2020-02-20T10:59:11Z | 100.0 | 0.0 | 1.58 | 2.65 | 7.60 | 1.83 | 0.27 | 1.00 | 0.00 | 53.54 |
24 | S2A_30TYN_20200301_0_L2A | 2020-03-01 | 30TYN | 0.15 | sentinel-2a | 051 | S2A_MSIL2A_20200301T105021_N0214_R051_T30TYN_2... | 2020-03-01T10:59:12Z | 100.0 | 0.0 | 0.00 | 0.00 | 0.14 | 0.00 | 4.42 | 6.33 | 0.00 | 89.10 |
23 | S2A_30TYN_20200311_0_L2A | 2020-03-11 | 30TYN | 20.14 | sentinel-2a | 051 | S2A_MSIL2A_20200311T105021_N0214_R051_T30TYN_2... | 2020-03-11T10:59:12Z | 100.0 | 0.0 | 0.48 | 0.91 | 0.48 | 0.66 | 0.16 | 0.10 | 0.00 | 79.12 |
22 | S2A_30TYN_20200321_0_L2A | 2020-03-21 | 30TYN | 32.57 | sentinel-2a | 051 | S2A_MSIL2A_20200321T105021_N0214_R051_T30TYN_2... | 2020-03-21T10:59:13Z | 100.0 | 0.0 | 0.69 | 2.08 | 13.17 | 0.35 | 0.96 | 0.57 | 0.00 | 65.21 |
21 | S2A_30TYN_20200410_0_L2A | 2020-04-10 | 30TYN | 24.57 | sentinel-2a | 051 | S2A_MSIL2A_20200410T105031_N0214_R051_T30TYN_2... | 2020-04-10T10:59:15Z | 100.0 | 0.0 | 1.53 | 6.33 | 8.60 | 0.50 | 1.63 | 9.39 | 0.00 | 62.88 |
20 | S2A_30TYN_20200520_0_L2A | 2020-05-20 | 30TYN | 53.65 | sentinel-2a | 051 | S2A_MSIL2A_20200520T105031_N0214_R051_T30TYN_2... | 2020-05-20T10:59:22Z | 100.0 | 0.0 | 0.04 | 32.74 | 16.87 | 0.16 | 0.82 | 1.63 | 0.00 | 43.86 |
19 | S2A_30TYN_20200530_0_L2A | 2020-05-30 | 30TYN | 58.93 | sentinel-2a | 051 | S2A_MSIL2A_20200530T105031_N0214_R051_T30TYN_2... | 2020-05-30T10:59:22Z | 100.0 | 0.0 | 1.28 | 37.27 | 16.95 | 0.44 | 1.22 | 4.56 | 0.00 | 34.01 |
18 | S2B_30TYN_20200624_0_L2A | 2020-06-24 | 30TYN | 68.65 | sentinel-2b | 051 | S2B_MSIL2A_20200624T104629_N0214_R051_T30TYN_2... | 2020-06-24T10:59:19Z | 100.0 | 0.0 | 0.74 | 46.94 | 17.59 | 0.13 | 1.62 | 4.27 | 0.00 | 24.72 |
17 | S2B_30TYN_20200704_0_L2A | 2020-07-04 | 30TYN | 78.03 | sentinel-2b | 051 | S2B_MSIL2A_20200704T104619_N0214_R051_T30TYN_2... | 2020-07-04T10:59:18Z | 100.0 | 0.0 | 0.27 | 51.08 | 22.21 | 0.04 | 2.49 | 3.78 | 0.00 | 15.43 |
16 | S2A_30TYN_20200709_0_L2A | 2020-07-09 | 30TYN | 71.78 | sentinel-2a | 051 | S2A_MSIL2A_20200709T105031_N0214_R051_T30TYN_2... | 2020-07-09T10:59:20Z | 100.0 | 0.0 | 2.89 | 46.26 | 19.83 | 0.20 | 4.11 | 9.80 | 0.00 | 11.42 |
15 | S2B_30TYN_20200714_0_L2A | 2020-07-14 | 30TYN | 80.79 | sentinel-2b | 051 | S2B_MSIL2A_20200714T104619_N0214_R051_T30TYN_2... | 2020-07-14T10:59:18Z | 100.0 | 0.0 | 0.47 | 51.64 | 23.57 | 0.02 | 4.04 | 5.64 | 0.00 | 9.06 |
14 | S2A_30TYN_20200719_0_L2A | 2020-07-19 | 30TYN | 83.65 | sentinel-2a | 051 | S2A_MSIL2A_20200719T105031_N0214_R051_T30TYN_2... | 2020-07-19T10:59:21Z | 100.0 | 0.0 | 0.62 | 51.89 | 25.35 | 0.14 | 3.40 | 7.23 | 0.00 | 5.10 |
13 | S2A_30TYN_20200729_0_L2A | 2020-07-29 | 30TYN | 86.59 | sentinel-2a | 051 | S2A_MSIL2A_20200729T105031_N0214_R051_T30TYN_2... | 2020-07-29T10:59:22Z | 100.0 | 0.0 | 0.80 | 50.98 | 28.16 | 0.02 | 4.23 | 5.34 | 0.00 | 3.04 |
12 | S2B_30TYN_20200803_0_L2A | 2020-08-03 | 30TYN | 88.64 | sentinel-2b | 051 | S2B_MSIL2A_20200803T104629_N0214_R051_T30TYN_2... | 2020-08-03T10:59:19Z | 100.0 | 0.0 | 0.69 | 49.30 | 29.98 | 0.02 | 4.78 | 4.17 | 0.00 | 1.72 |
11 | S2A_30TYN_20200808_0_L2A | 2020-08-08 | 30TYN | 82.37 | sentinel-2a | 051 | S2A_MSIL2A_20200808T105031_N0214_R051_T30TYN_2... | 2020-08-08T10:59:22Z | 100.0 | 0.0 | 1.43 | 42.20 | 27.85 | 0.02 | 7.56 | 7.13 | 0.00 | 1.51 |
10 | S2B_30TYN_20200823_0_L2A | 2020-08-23 | 30TYN | 94.14 | sentinel-2b | 051 | S2B_MSIL2A_20200823T104629_N0214_R051_T30TYN_2... | 2020-08-23T10:59:20Z | 100.0 | 0.0 | 1.26 | 49.93 | 33.76 | 0.05 | 2.31 | 1.56 | 0.00 | 0.73 |
9 | S2B_30TYN_20200902_0_L2A | 2020-09-02 | 30TYN | 91.57 | sentinel-2b | 051 | S2B_MSIL2A_20200902T104629_N0214_R051_T30TYN_2... | 2020-09-02T10:59:23Z | 100.0 | 0.0 | 2.29 | 48.40 | 29.39 | 0.08 | 2.16 | 3.03 | 0.00 | 0.95 |
8 | S2B_30TYN_20200912_0_L2A | 2020-09-12 | 30TYN | 81.70 | sentinel-2b | 051 | S2B_MSIL2A_20200912T104629_N0214_R051_T30TYN_2... | 2020-09-12T10:59:18Z | 100.0 | 0.0 | 7.72 | 35.06 | 28.64 | 0.05 | 4.22 | 6.24 | 0.00 | 0.12 |
7 | S2A_30TYN_20200927_0_L2A | 2020-09-27 | 30TYN | 19.97 | sentinel-2a | 051 | S2A_MSIL2A_20200927T105031_N0214_R051_T30TYN_2... | 2020-09-27T10:59:22Z | 100.0 | 0.0 | 0.43 | 6.86 | 0.17 | 0.40 | 0.52 | 0.05 | 0.00 | 79.03 |
6 | S2B_30TYN_20201012_0_L2A | 2020-10-12 | 30TYN | 26.43 | sentinel-2b | 051 | S2B_MSIL2A_20201012T104909_N0214_R051_T30TYN_2... | 2020-10-12T10:59:20Z | 100.0 | 0.0 | 1.58 | 6.88 | 0.70 | 1.15 | 0.77 | 9.60 | 0.00 | 61.62 |
5 | S2A_30TYN_20201017_0_L2A | 2020-10-17 | 30TYN | 40.49 | sentinel-2a | 051 | S2A_MSIL2A_20201017T105041_N0214_R051_T30TYN_2... | 2020-10-17T10:59:22Z | 100.0 | 0.0 | 2.80 | 9.13 | 6.44 | 0.83 | 2.37 | 2.35 | 0.07 | 51.92 |
4 | S2B_30TYN_20201101_0_L2A | 2020-11-01 | 30TYN | 69.09 | sentinel-2b | 051 | S2B_MSIL2A_20201101T105209_N0214_R051_T30TYN_2... | 2020-11-01T10:59:19Z | 100.0 | 0.0 | 6.71 | 12.92 | 22.02 | 0.85 | 1.59 | 2.62 | 0.85 | 19.14 |
3 | S2B_30TYN_20201111_0_L2A | 2020-11-11 | 30TYN | 75.71 | sentinel-2b | 051 | S2B_MSIL2A_20201111T105259_N0214_R051_T30TYN_2... | 2020-11-11T10:59:17Z | 100.0 | 0.0 | 4.41 | 14.47 | 17.84 | 2.60 | 0.41 | 1.37 | 0.00 | 18.10 |
2 | S2B_30TYN_20201121_0_L2A | 2020-11-21 | 30TYN | 78.88 | sentinel-2b | 051 | S2B_MSIL2A_20201121T105349_N0214_R051_T30TYN_2... | 2020-11-21T10:59:17Z | 100.0 | 0.0 | 4.08 | 11.20 | 19.91 | 3.74 | 4.06 | 2.80 | 0.00 | 10.18 |
1 | S2A_30TYN_20201216_0_L2A | 2020-12-16 | 30TYN | 46.80 | sentinel-2a | 051 | S2A_MSIL2A_20201216T105441_N0214_R051_T30TYN_2... | 2020-12-16T10:59:14Z | 100.0 | 0.0 | 0.40 | 0.16 | 0.24 | 5.98 | 0.33 | 0.15 | 0.51 | 51.81 |
0 | S2A_30TYN_20201226_0_L2A | 2020-12-26 | 30TYN | 52.51 | sentinel-2a | 051 | S2A_MSIL2A_20201226T105451_N0214_R051_T30TYN_2... | 2020-12-26T10:59:16Z | 100.0 | 0.0 | 0.09 | 0.11 | 0.47 | 7.34 | 2.80 | 0.57 | 0.03 | 44.00 |
4 - Specify bands#
Only selecting blue, green, and red bands from S2
[4]:
res_S2.output_bands = ["B02","B03","B04"]
5 - Filter search results#
While we initially filtered the search results by 10% or less on cloud coverage, we may want to be more selective. We can then set a higher threshold for our monthly images, such as limiting some clouds to 5% or less as shown below.
[5]:
res_S2.dataframe = res_S2.dataframe[(res_S2.dataframe["cloud_medium_probability"] < 5) & (res_S2.dataframe["cloud_shadows"] < 5)]
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 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
32 | S2A_30TYN_20200101_0_L2A | 2020-01-01 | 30TYN | 57.50 | sentinel-2a | 051 | S2A_MSIL2A_20200101T105441_N0213_R051_T30TYN_2... | 2020-01-01T10:59:11Z | 100.0 | 0.0 | 0.80 | 0.85 | 1.97 | 7.58 | 0.15 | 0.62 | 0.01 | 40.92 |
31 | S2B_30TYN_20200106_0_L2A | 2020-01-06 | 30TYN | 57.40 | sentinel-2b | 051 | S2B_MSIL2A_20200106T105339_N0213_R051_T30TYN_2... | 2020-01-06T10:59:11Z | 100.0 | 0.0 | 1.06 | 0.93 | 2.48 | 7.29 | 0.18 | 0.74 | 0.00 | 40.62 |
30 | S2B_30TYN_20200116_0_L2A | 2020-01-16 | 30TYN | 56.71 | sentinel-2b | 051 | S2B_MSIL2A_20200116T105309_N0213_R051_T30TYN_2... | 2020-01-16T10:59:10Z | 100.0 | 0.0 | 1.39 | 1.03 | 5.02 | 6.10 | 0.17 | 0.98 | 0.00 | 40.75 |
29 | S2A_30TYN_20200131_0_L2A | 2020-01-31 | 30TYN | 44.29 | sentinel-2a | 051 | S2A_MSIL2A_20200131T105251_N0213_R051_T30TYN_2... | 2020-01-31T10:59:09Z | 100.0 | 0.0 | 0.14 | 0.36 | 0.33 | 4.16 | 0.09 | 0.12 | 0.00 | 55.36 |
28 | S2B_30TYN_20200205_0_L2A | 2020-02-05 | 30TYN | 46.67 | sentinel-2b | 051 | S2B_MSIL2A_20200205T105129_N0214_R051_T30TYN_2... | 2020-02-05T10:59:10Z | 100.0 | 0.0 | 1.02 | 1.27 | 2.69 | 3.77 | 0.28 | 0.65 | 0.00 | 51.38 |
27 | S2A_30TYN_20200210_0_L2A | 2020-02-10 | 30TYN | 46.38 | sentinel-2a | 051 | S2A_MSIL2A_20200210T105201_N0214_R051_T30TYN_2... | 2020-02-10T10:59:09Z | 100.0 | 0.0 | 1.30 | 1.55 | 4.72 | 3.06 | 0.05 | 0.53 | 0.00 | 51.74 |
26 | S2B_30TYN_20200215_0_L2A | 2020-02-15 | 30TYN | 44.83 | sentinel-2b | 051 | S2B_MSIL2A_20200215T105029_N0214_R051_T30TYN_2... | 2020-02-15T10:59:12Z | 100.0 | 0.0 | 1.47 | 1.72 | 5.97 | 2.42 | 0.28 | 0.93 | 0.00 | 52.49 |
25 | S2A_30TYN_20200220_0_L2A | 2020-02-20 | 30TYN | 43.61 | sentinel-2a | 051 | S2A_MSIL2A_20200220T105051_N0214_R051_T30TYN_2... | 2020-02-20T10:59:11Z | 100.0 | 0.0 | 1.58 | 2.65 | 7.60 | 1.83 | 0.27 | 1.00 | 0.00 | 53.54 |
24 | S2A_30TYN_20200301_0_L2A | 2020-03-01 | 30TYN | 0.15 | sentinel-2a | 051 | S2A_MSIL2A_20200301T105021_N0214_R051_T30TYN_2... | 2020-03-01T10:59:12Z | 100.0 | 0.0 | 0.00 | 0.00 | 0.14 | 0.00 | 4.42 | 6.33 | 0.00 | 89.10 |
23 | S2A_30TYN_20200311_0_L2A | 2020-03-11 | 30TYN | 20.14 | sentinel-2a | 051 | S2A_MSIL2A_20200311T105021_N0214_R051_T30TYN_2... | 2020-03-11T10:59:12Z | 100.0 | 0.0 | 0.48 | 0.91 | 0.48 | 0.66 | 0.16 | 0.10 | 0.00 | 79.12 |
22 | S2A_30TYN_20200321_0_L2A | 2020-03-21 | 30TYN | 32.57 | sentinel-2a | 051 | S2A_MSIL2A_20200321T105021_N0214_R051_T30TYN_2... | 2020-03-21T10:59:13Z | 100.0 | 0.0 | 0.69 | 2.08 | 13.17 | 0.35 | 0.96 | 0.57 | 0.00 | 65.21 |
21 | S2A_30TYN_20200410_0_L2A | 2020-04-10 | 30TYN | 24.57 | sentinel-2a | 051 | S2A_MSIL2A_20200410T105031_N0214_R051_T30TYN_2... | 2020-04-10T10:59:15Z | 100.0 | 0.0 | 1.53 | 6.33 | 8.60 | 0.50 | 1.63 | 9.39 | 0.00 | 62.88 |
20 | S2A_30TYN_20200520_0_L2A | 2020-05-20 | 30TYN | 53.65 | sentinel-2a | 051 | S2A_MSIL2A_20200520T105031_N0214_R051_T30TYN_2... | 2020-05-20T10:59:22Z | 100.0 | 0.0 | 0.04 | 32.74 | 16.87 | 0.16 | 0.82 | 1.63 | 0.00 | 43.86 |
19 | S2A_30TYN_20200530_0_L2A | 2020-05-30 | 30TYN | 58.93 | sentinel-2a | 051 | S2A_MSIL2A_20200530T105031_N0214_R051_T30TYN_2... | 2020-05-30T10:59:22Z | 100.0 | 0.0 | 1.28 | 37.27 | 16.95 | 0.44 | 1.22 | 4.56 | 0.00 | 34.01 |
18 | S2B_30TYN_20200624_0_L2A | 2020-06-24 | 30TYN | 68.65 | sentinel-2b | 051 | S2B_MSIL2A_20200624T104629_N0214_R051_T30TYN_2... | 2020-06-24T10:59:19Z | 100.0 | 0.0 | 0.74 | 46.94 | 17.59 | 0.13 | 1.62 | 4.27 | 0.00 | 24.72 |
17 | S2B_30TYN_20200704_0_L2A | 2020-07-04 | 30TYN | 78.03 | sentinel-2b | 051 | S2B_MSIL2A_20200704T104619_N0214_R051_T30TYN_2... | 2020-07-04T10:59:18Z | 100.0 | 0.0 | 0.27 | 51.08 | 22.21 | 0.04 | 2.49 | 3.78 | 0.00 | 15.43 |
16 | S2A_30TYN_20200709_0_L2A | 2020-07-09 | 30TYN | 71.78 | sentinel-2a | 051 | S2A_MSIL2A_20200709T105031_N0214_R051_T30TYN_2... | 2020-07-09T10:59:20Z | 100.0 | 0.0 | 2.89 | 46.26 | 19.83 | 0.20 | 4.11 | 9.80 | 0.00 | 11.42 |
15 | S2B_30TYN_20200714_0_L2A | 2020-07-14 | 30TYN | 80.79 | sentinel-2b | 051 | S2B_MSIL2A_20200714T104619_N0214_R051_T30TYN_2... | 2020-07-14T10:59:18Z | 100.0 | 0.0 | 0.47 | 51.64 | 23.57 | 0.02 | 4.04 | 5.64 | 0.00 | 9.06 |
14 | S2A_30TYN_20200719_0_L2A | 2020-07-19 | 30TYN | 83.65 | sentinel-2a | 051 | S2A_MSIL2A_20200719T105031_N0214_R051_T30TYN_2... | 2020-07-19T10:59:21Z | 100.0 | 0.0 | 0.62 | 51.89 | 25.35 | 0.14 | 3.40 | 7.23 | 0.00 | 5.10 |
13 | S2A_30TYN_20200729_0_L2A | 2020-07-29 | 30TYN | 86.59 | sentinel-2a | 051 | S2A_MSIL2A_20200729T105031_N0214_R051_T30TYN_2... | 2020-07-29T10:59:22Z | 100.0 | 0.0 | 0.80 | 50.98 | 28.16 | 0.02 | 4.23 | 5.34 | 0.00 | 3.04 |
12 | S2B_30TYN_20200803_0_L2A | 2020-08-03 | 30TYN | 88.64 | sentinel-2b | 051 | S2B_MSIL2A_20200803T104629_N0214_R051_T30TYN_2... | 2020-08-03T10:59:19Z | 100.0 | 0.0 | 0.69 | 49.30 | 29.98 | 0.02 | 4.78 | 4.17 | 0.00 | 1.72 |
10 | S2B_30TYN_20200823_0_L2A | 2020-08-23 | 30TYN | 94.14 | sentinel-2b | 051 | S2B_MSIL2A_20200823T104629_N0214_R051_T30TYN_2... | 2020-08-23T10:59:20Z | 100.0 | 0.0 | 1.26 | 49.93 | 33.76 | 0.05 | 2.31 | 1.56 | 0.00 | 0.73 |
9 | S2B_30TYN_20200902_0_L2A | 2020-09-02 | 30TYN | 91.57 | sentinel-2b | 051 | S2B_MSIL2A_20200902T104629_N0214_R051_T30TYN_2... | 2020-09-02T10:59:23Z | 100.0 | 0.0 | 2.29 | 48.40 | 29.39 | 0.08 | 2.16 | 3.03 | 0.00 | 0.95 |
7 | S2A_30TYN_20200927_0_L2A | 2020-09-27 | 30TYN | 19.97 | sentinel-2a | 051 | S2A_MSIL2A_20200927T105031_N0214_R051_T30TYN_2... | 2020-09-27T10:59:22Z | 100.0 | 0.0 | 0.43 | 6.86 | 0.17 | 0.40 | 0.52 | 0.05 | 0.00 | 79.03 |
6 | S2B_30TYN_20201012_0_L2A | 2020-10-12 | 30TYN | 26.43 | sentinel-2b | 051 | S2B_MSIL2A_20201012T104909_N0214_R051_T30TYN_2... | 2020-10-12T10:59:20Z | 100.0 | 0.0 | 1.58 | 6.88 | 0.70 | 1.15 | 0.77 | 9.60 | 0.00 | 61.62 |
5 | S2A_30TYN_20201017_0_L2A | 2020-10-17 | 30TYN | 40.49 | sentinel-2a | 051 | S2A_MSIL2A_20201017T105041_N0214_R051_T30TYN_2... | 2020-10-17T10:59:22Z | 100.0 | 0.0 | 2.80 | 9.13 | 6.44 | 0.83 | 2.37 | 2.35 | 0.07 | 51.92 |
3 | S2B_30TYN_20201111_0_L2A | 2020-11-11 | 30TYN | 75.71 | sentinel-2b | 051 | S2B_MSIL2A_20201111T105259_N0214_R051_T30TYN_2... | 2020-11-11T10:59:17Z | 100.0 | 0.0 | 4.41 | 14.47 | 17.84 | 2.60 | 0.41 | 1.37 | 0.00 | 18.10 |
2 | S2B_30TYN_20201121_0_L2A | 2020-11-21 | 30TYN | 78.88 | sentinel-2b | 051 | S2B_MSIL2A_20201121T105349_N0214_R051_T30TYN_2... | 2020-11-21T10:59:17Z | 100.0 | 0.0 | 4.08 | 11.20 | 19.91 | 3.74 | 4.06 | 2.80 | 0.00 | 10.18 |
1 | S2A_30TYN_20201216_0_L2A | 2020-12-16 | 30TYN | 46.80 | sentinel-2a | 051 | S2A_MSIL2A_20201216T105441_N0214_R051_T30TYN_2... | 2020-12-16T10:59:14Z | 100.0 | 0.0 | 0.40 | 0.16 | 0.24 | 5.98 | 0.33 | 0.15 | 0.51 | 51.81 |
0 | S2A_30TYN_20201226_0_L2A | 2020-12-26 | 30TYN | 52.51 | sentinel-2a | 051 | S2A_MSIL2A_20201226T105451_N0214_R051_T30TYN_2... | 2020-12-26T10:59:16Z | 100.0 | 0.0 | 0.09 | 0.11 | 0.47 | 7.34 | 2.80 | 0.57 | 0.03 | 44.00 |
6 - Select one image per month#
Here we use Pandas and its “groupby” function to select the first available image for each month. The frequency, “freq”, can be changed to a large number of time frequencies, called offset aliases. Among them are, daily (‘D’), weekly (‘W’), monthly (‘M’), quarterly (‘Q’), twice monthly (‘SM’) and yearly (‘A’ or ‘Y’). A full list can be found here.
Custom frequencies can be also made and applied using the general pd.Grouper function and/or pd.DateOffset and pd.cut.
[6]:
# Clone the search result so as to not need to re-run the search if our manipulation doesn't work as intended
new_S2 = res_S2
# Set the Dataframe index as the "date" column, in order to apply the grouper function
new_S2.dataframe.set_index('date', inplace=True)
# Group search result by taking only the first image of the month
new_S2.dataframe = new_S2.dataframe.groupby(pd.Grouper(freq='M')).first()
new_S2.dataframe
[6]:
id | 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 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
date | |||||||||||||||||
2020-01-31 | S2A_30TYN_20200101_0_L2A | 30TYN | 57.50 | sentinel-2a | 051 | S2A_MSIL2A_20200101T105441_N0213_R051_T30TYN_2... | 2020-01-01T10:59:11Z | 100.0 | 0.0 | 0.80 | 0.85 | 1.97 | 7.58 | 0.15 | 0.62 | 0.01 | 40.92 |
2020-02-29 | S2B_30TYN_20200205_0_L2A | 30TYN | 46.67 | sentinel-2b | 051 | S2B_MSIL2A_20200205T105129_N0214_R051_T30TYN_2... | 2020-02-05T10:59:10Z | 100.0 | 0.0 | 1.02 | 1.27 | 2.69 | 3.77 | 0.28 | 0.65 | 0.00 | 51.38 |
2020-03-31 | S2A_30TYN_20200301_0_L2A | 30TYN | 0.15 | sentinel-2a | 051 | S2A_MSIL2A_20200301T105021_N0214_R051_T30TYN_2... | 2020-03-01T10:59:12Z | 100.0 | 0.0 | 0.00 | 0.00 | 0.14 | 0.00 | 4.42 | 6.33 | 0.00 | 89.10 |
2020-04-30 | S2A_30TYN_20200410_0_L2A | 30TYN | 24.57 | sentinel-2a | 051 | S2A_MSIL2A_20200410T105031_N0214_R051_T30TYN_2... | 2020-04-10T10:59:15Z | 100.0 | 0.0 | 1.53 | 6.33 | 8.60 | 0.50 | 1.63 | 9.39 | 0.00 | 62.88 |
2020-05-31 | S2A_30TYN_20200520_0_L2A | 30TYN | 53.65 | sentinel-2a | 051 | S2A_MSIL2A_20200520T105031_N0214_R051_T30TYN_2... | 2020-05-20T10:59:22Z | 100.0 | 0.0 | 0.04 | 32.74 | 16.87 | 0.16 | 0.82 | 1.63 | 0.00 | 43.86 |
2020-06-30 | S2B_30TYN_20200624_0_L2A | 30TYN | 68.65 | sentinel-2b | 051 | S2B_MSIL2A_20200624T104629_N0214_R051_T30TYN_2... | 2020-06-24T10:59:19Z | 100.0 | 0.0 | 0.74 | 46.94 | 17.59 | 0.13 | 1.62 | 4.27 | 0.00 | 24.72 |
2020-07-31 | S2B_30TYN_20200704_0_L2A | 30TYN | 78.03 | sentinel-2b | 051 | S2B_MSIL2A_20200704T104619_N0214_R051_T30TYN_2... | 2020-07-04T10:59:18Z | 100.0 | 0.0 | 0.27 | 51.08 | 22.21 | 0.04 | 2.49 | 3.78 | 0.00 | 15.43 |
2020-08-31 | S2B_30TYN_20200803_0_L2A | 30TYN | 88.64 | sentinel-2b | 051 | S2B_MSIL2A_20200803T104629_N0214_R051_T30TYN_2... | 2020-08-03T10:59:19Z | 100.0 | 0.0 | 0.69 | 49.30 | 29.98 | 0.02 | 4.78 | 4.17 | 0.00 | 1.72 |
2020-09-30 | S2B_30TYN_20200902_0_L2A | 30TYN | 91.57 | sentinel-2b | 051 | S2B_MSIL2A_20200902T104629_N0214_R051_T30TYN_2... | 2020-09-02T10:59:23Z | 100.0 | 0.0 | 2.29 | 48.40 | 29.39 | 0.08 | 2.16 | 3.03 | 0.00 | 0.95 |
2020-10-31 | S2B_30TYN_20201012_0_L2A | 30TYN | 26.43 | sentinel-2b | 051 | S2B_MSIL2A_20201012T104909_N0214_R051_T30TYN_2... | 2020-10-12T10:59:20Z | 100.0 | 0.0 | 1.58 | 6.88 | 0.70 | 1.15 | 0.77 | 9.60 | 0.00 | 61.62 |
2020-11-30 | S2B_30TYN_20201111_0_L2A | 30TYN | 75.71 | sentinel-2b | 051 | S2B_MSIL2A_20201111T105259_N0214_R051_T30TYN_2... | 2020-11-11T10:59:17Z | 100.0 | 0.0 | 4.41 | 14.47 | 17.84 | 2.60 | 0.41 | 1.37 | 0.00 | 18.10 |
2020-12-31 | S2A_30TYN_20201216_0_L2A | 30TYN | 46.80 | sentinel-2a | 051 | S2A_MSIL2A_20201216T105441_N0214_R051_T30TYN_2... | 2020-12-16T10:59:14Z | 100.0 | 0.0 | 0.40 | 0.16 | 0.24 | 5.98 | 0.33 | 0.15 | 0.51 | 51.81 |
7 - Obtain S2 data through Fuse function#
We pass the filtered S2 search result object to the “fuse” function in order to download the organize the S2 result
[7]:
fusion = client.fuse(
catalogs_list=[new_S2],
additional_info={"Info": "You can put any additional information, such as custom non-raster or non-vector data, in this parameter"}
)
fusion.dataset
2022-11-28 10:14:08,114 INFO spacesense.core : created everything
[7]:
<xarray.Dataset> Dimensions: (time: 12, y: 651, x: 1014) Coordinates: * time (time) datetime64[ns] 2020-01-01 2020-02-05 ... 2020-12-16 * y (y) float32 42.74 42.74 42.74 42.74 ... 42.68 42.68 42.68 42.68 * x (x) float64 -0.07173 -0.07164 -0.07155 ... 0.01909 0.01918 0.01927 Data variables: S2_B02 (time, y, x) float32 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.668 0.6718 0.0 S2_B03 (time, y, x) float32 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.692 0.6976 0.0 S2_B04 (time, y, x) float32 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.6932 0.6968 0.0 Attributes: crs: +init=epsg:4326 transform: [ 8.98360017e-05 0.00000000e+00 -7.17789654e-02 0.000... res: [8.98360017e-05 9.04414549e-05] ulx, uly: [-0.07177897 42.73801908] s2_data_lineage: {"Data origin": "S3 bucket (ARN=arn:aws:s3:::sentinel-c... additional_info: {'Info': 'You can put any additional information, such ...
8 - Plot using matplotlib#
This code sets up and plots each time in the dataset. Because we had high cloud and swath requirements, only 9 of 12 months have valid images
[8]:
# Define a function to normalize reflectance from S2 bands
rgb = fusion.plot_rgb(all_dates = True, brightness_factor = 3)
2022-11-28 10:14:08,531 WARNING matplotlib.image : Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
2022-11-28 10:14:08,566 WARNING matplotlib.image : Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
2022-11-28 10:14:08,602 WARNING matplotlib.image : Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
2022-11-28 10:14:08,637 WARNING matplotlib.image : Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
2022-11-28 10:14:08,671 WARNING matplotlib.image : Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
2022-11-28 10:14:08,705 WARNING matplotlib.image : Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
2022-11-28 10:14:08,740 WARNING matplotlib.image : Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
2022-11-28 10:14:08,778 WARNING matplotlib.image : Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
2022-11-28 10:14:08,815 WARNING matplotlib.image : Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
2022-11-28 10:14:08,853 WARNING matplotlib.image : Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
2022-11-28 10:14:08,890 WARNING matplotlib.image : Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
2022-11-28 10:14:08,927 WARNING matplotlib.image : Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
