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#
[ ]:
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 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | S2A_30TYN_20200101_0_L2A | 2020-01-01 | 30TYN | 57.44 | sentinel-2a | 051 | S2A_MSIL2A_20200101T105441_N0213_R051_T30TYN_2... | 2020-01-01T10:59:11.266000Z | 100.0 | 0.0 | 0.81 | 0.85 | 1.96 | 7.56 | 0.14 | 0.63 | 0.01 | 40.97 |
1 | S2B_30TYN_20200106_0_L2A | 2020-01-06 | 30TYN | 57.35 | sentinel-2b | 051 | S2B_MSIL2A_20200106T105339_N0213_R051_T30TYN_2... | 2020-01-06T10:59:11.633000Z | 100.0 | 0.0 | 1.06 | 0.93 | 2.48 | 7.28 | 0.18 | 0.74 | 0.00 | 40.67 |
2 | S2B_30TYN_20200116_0_L2A | 2020-01-16 | 30TYN | 56.64 | sentinel-2b | 051 | S2B_MSIL2A_20200116T105309_N0213_R051_T30TYN_2... | 2020-01-16T10:59:10.849000Z | 100.0 | 0.0 | 1.39 | 1.02 | 5.01 | 6.09 | 0.17 | 0.98 | 0.00 | 40.82 |
3 | S2A_30TYN_20200131_0_L2A | 2020-01-31 | 30TYN | 44.26 | sentinel-2a | 051 | S2A_MSIL2A_20200131T105251_N0213_R051_T30TYN_2... | 2020-01-31T10:59:09.147000Z | 100.0 | 0.0 | 0.14 | 0.35 | 0.33 | 4.15 | 0.09 | 0.12 | 0.00 | 55.39 |
4 | S2B_30TYN_20200205_0_L2A | 2020-02-05 | 30TYN | 46.62 | sentinel-2b | 051 | S2B_MSIL2A_20200205T105129_N0214_R051_T30TYN_2... | 2020-02-05T10:59:10.605000Z | 100.0 | 0.0 | 1.02 | 1.26 | 2.69 | 3.76 | 0.28 | 0.64 | 0.00 | 51.44 |
5 | S2A_30TYN_20200210_0_L2A | 2020-02-10 | 30TYN | 46.31 | sentinel-2a | 051 | S2A_MSIL2A_20200210T105201_N0214_R051_T30TYN_2... | 2020-02-10T10:59:09.328000Z | 100.0 | 0.0 | 1.30 | 1.54 | 4.71 | 3.05 | 0.05 | 0.53 | 0.00 | 51.81 |
6 | S2B_30TYN_20200215_0_L2A | 2020-02-15 | 30TYN | 44.75 | sentinel-2b | 051 | S2B_MSIL2A_20200215T105029_N0214_R051_T30TYN_2... | 2020-02-15T10:59:12.451000Z | 100.0 | 0.0 | 1.48 | 1.72 | 5.96 | 2.40 | 0.28 | 0.93 | 0.00 | 52.56 |
7 | S2A_30TYN_20200220_0_L2A | 2020-02-20 | 30TYN | 43.54 | sentinel-2a | 051 | S2A_MSIL2A_20200220T105051_N0214_R051_T30TYN_2... | 2020-02-20T10:59:11.040000Z | 100.0 | 0.0 | 1.58 | 2.65 | 7.58 | 1.83 | 0.27 | 1.01 | 0.00 | 53.60 |
8 | 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:12.233000Z | 100.0 | 0.0 | 0.00 | 0.00 | 0.14 | 0.00 | 4.44 | 6.32 | 0.00 | 89.09 |
9 | S2A_30TYN_20200311_0_L2A | 2020-03-11 | 30TYN | 20.12 | sentinel-2a | 051 | S2A_MSIL2A_20200311T105021_N0214_R051_T30TYN_2... | 2020-03-11T10:59:12.935000Z | 100.0 | 0.0 | 0.48 | 0.91 | 0.48 | 0.65 | 0.16 | 0.09 | 0.00 | 79.15 |
10 | S2A_30TYN_20200321_0_L2A | 2020-03-21 | 30TYN | 32.54 | sentinel-2a | 051 | S2A_MSIL2A_20200321T105021_N0214_R051_T30TYN_2... | 2020-03-21T10:59:13.094000Z | 100.0 | 0.0 | 0.68 | 2.09 | 13.14 | 0.35 | 0.96 | 0.57 | 0.00 | 65.25 |
11 | S2A_30TYN_20200410_0_L2A | 2020-04-10 | 30TYN | 24.51 | sentinel-2a | 051 | S2A_MSIL2A_20200410T105031_N0214_R051_T30TYN_2... | 2020-04-10T10:59:15.012000Z | 100.0 | 0.0 | 1.52 | 6.31 | 8.57 | 0.50 | 1.63 | 9.43 | 0.00 | 62.91 |
12 | S2A_30TYN_20200520_0_L2A | 2020-05-20 | 30TYN | 53.59 | sentinel-2a | 051 | S2A_MSIL2A_20200520T105031_N0214_R051_T30TYN_2... | 2020-05-20T10:59:22.363000Z | 100.0 | 0.0 | 0.04 | 32.70 | 16.82 | 0.16 | 0.82 | 1.63 | 0.00 | 43.92 |
13 | S2A_30TYN_20200530_0_L2A | 2020-05-30 | 30TYN | 58.84 | sentinel-2a | 051 | S2A_MSIL2A_20200530T105031_N0214_R051_T30TYN_2... | 2020-05-30T10:59:22.967000Z | 100.0 | 0.0 | 1.30 | 37.21 | 16.90 | 0.43 | 1.23 | 4.62 | 0.00 | 34.01 |
14 | S2B_30TYN_20200624_0_L2A | 2020-06-24 | 30TYN | 68.59 | sentinel-2b | 051 | S2B_MSIL2A_20200624T104629_N0214_R051_T30TYN_2... | 2020-06-24T10:59:19.327000Z | 100.0 | 0.0 | 0.75 | 46.88 | 17.58 | 0.13 | 1.64 | 4.30 | 0.00 | 24.72 |
15 | S2B_30TYN_20200704_0_L2A | 2020-07-04 | 30TYN | 78.01 | sentinel-2b | 051 | S2B_MSIL2A_20200704T104619_N0214_R051_T30TYN_2... | 2020-07-04T10:59:18.977000Z | 100.0 | 0.0 | 0.28 | 51.04 | 22.23 | 0.04 | 2.51 | 3.77 | 0.00 | 15.43 |
16 | S2A_30TYN_20200709_0_L2A | 2020-07-09 | 30TYN | 71.72 | sentinel-2a | 051 | S2A_MSIL2A_20200709T105031_N0214_R051_T30TYN_2... | 2020-07-09T10:59:20.829000Z | 100.0 | 0.0 | 2.88 | 46.20 | 19.82 | 0.20 | 4.15 | 9.84 | 0.00 | 11.41 |
17 | S2B_30TYN_20200714_0_L2A | 2020-07-14 | 30TYN | 80.75 | sentinel-2b | 051 | S2B_MSIL2A_20200714T104619_N0214_R051_T30TYN_2... | 2020-07-14T10:59:18.200000Z | 100.0 | 0.0 | 0.47 | 51.60 | 23.56 | 0.02 | 4.07 | 5.65 | 0.00 | 9.06 |
18 | S2A_30TYN_20200719_0_L2A | 2020-07-19 | 30TYN | 83.64 | sentinel-2a | 051 | S2A_MSIL2A_20200719T105031_N0214_R051_T30TYN_2... | 2020-07-19T10:59:21.847000Z | 100.0 | 0.0 | 0.61 | 51.86 | 25.36 | 0.14 | 3.41 | 7.26 | 0.00 | 5.08 |
19 | S2A_30TYN_20200729_0_L2A | 2020-07-29 | 30TYN | 86.56 | sentinel-2a | 051 | S2A_MSIL2A_20200729T105031_N0214_R051_T30TYN_2... | 2020-07-29T10:59:22.508000Z | 100.0 | 0.0 | 0.80 | 50.94 | 28.15 | 0.02 | 4.25 | 5.34 | 0.00 | 3.05 |
20 | S2B_30TYN_20200803_0_L2A | 2020-08-03 | 30TYN | 88.60 | sentinel-2b | 051 | S2B_MSIL2A_20200803T104629_N0214_R051_T30TYN_2... | 2020-08-03T10:59:19.827000Z | 100.0 | 0.0 | 0.69 | 49.25 | 30.00 | 0.02 | 4.82 | 4.16 | 0.00 | 1.73 |
21 | S2A_30TYN_20200808_0_L2A | 2020-08-08 | 30TYN | 82.34 | sentinel-2a | 051 | S2A_MSIL2A_20200808T105031_N0214_R051_T30TYN_2... | 2020-08-08T10:59:22.783000Z | 100.0 | 0.0 | 1.42 | 42.16 | 27.86 | 0.02 | 7.62 | 7.12 | 0.00 | 1.50 |
22 | S2B_30TYN_20200823_0_L2A | 2020-08-23 | 30TYN | 94.13 | sentinel-2b | 051 | S2B_MSIL2A_20200823T104629_N0214_R051_T30TYN_2... | 2020-08-23T10:59:20.275000Z | 100.0 | 0.0 | 1.24 | 49.92 | 33.75 | 0.05 | 2.34 | 1.56 | 0.00 | 0.73 |
23 | S2B_30TYN_20200902_0_L2A | 2020-09-02 | 30TYN | 91.56 | sentinel-2b | 051 | S2B_MSIL2A_20200902T104629_N0214_R051_T30TYN_2... | 2020-09-02T10:59:23.832000Z | 100.0 | 0.0 | 2.27 | 48.39 | 29.37 | 0.08 | 2.18 | 3.04 | 0.00 | 0.95 |
24 | S2B_30TYN_20200912_0_L2A | 2020-09-12 | 30TYN | 81.66 | sentinel-2b | 051 | S2B_MSIL2A_20200912T104629_N0214_R051_T30TYN_2... | 2020-09-12T10:59:18.972000Z | 100.0 | 0.0 | 7.71 | 35.06 | 28.57 | 0.06 | 4.27 | 6.24 | 0.00 | 0.12 |
25 | S2A_30TYN_20200927_0_L2A | 2020-09-27 | 30TYN | 19.93 | sentinel-2a | 051 | S2A_MSIL2A_20200927T105031_N0214_R051_T30TYN_2... | 2020-09-27T10:59:22.256000Z | 100.0 | 0.0 | 0.43 | 6.84 | 0.18 | 0.39 | 0.52 | 0.05 | 0.00 | 79.07 |
26 | S2B_30TYN_20201012_0_L2A | 2020-10-12 | 30TYN | 26.37 | sentinel-2b | 051 | S2B_MSIL2A_20201012T104909_N0214_R051_T30TYN_2... | 2020-10-12T10:59:20.517000Z | 100.0 | 0.0 | 1.59 | 6.85 | 0.70 | 1.14 | 0.77 | 9.61 | 0.00 | 61.66 |
27 | S2A_30TYN_20201017_0_L2A | 2020-10-17 | 30TYN | 40.44 | sentinel-2a | 051 | S2A_MSIL2A_20201017T105041_N0214_R051_T30TYN_2... | 2020-10-17T10:59:22.444000Z | 100.0 | 0.0 | 2.79 | 9.11 | 6.41 | 0.83 | 2.38 | 2.35 | 0.06 | 51.98 |
28 | S2B_30TYN_20201101_0_L2A | 2020-11-01 | 30TYN | 69.02 | sentinel-2b | 051 | S2B_MSIL2A_20201101T105209_N0214_R051_T30TYN_2... | 2020-11-01T10:59:19.525000Z | 100.0 | 0.0 | 6.70 | 12.90 | 22.01 | 0.84 | 1.59 | 2.62 | 0.86 | 19.21 |
29 | S2B_30TYN_20201111_0_L2A | 2020-11-11 | 30TYN | 75.63 | sentinel-2b | 051 | S2B_MSIL2A_20201111T105259_N0214_R051_T30TYN_2... | 2020-11-11T10:59:17.920000Z | 100.0 | 0.0 | 4.41 | 14.45 | 17.83 | 2.60 | 0.42 | 1.38 | 0.00 | 18.16 |
30 | S2B_30TYN_20201121_0_L2A | 2020-11-21 | 30TYN | 78.80 | sentinel-2b | 051 | S2B_MSIL2A_20201121T105349_N0214_R051_T30TYN_2... | 2020-11-21T10:59:17.294000Z | 100.0 | 0.0 | 4.08 | 11.19 | 19.89 | 3.74 | 4.11 | 2.82 | 0.00 | 10.19 |
31 | S2A_30TYN_20201216_0_L2A | 2020-12-16 | 30TYN | 46.75 | sentinel-2a | 051 | S2A_MSIL2A_20201216T105441_N0214_R051_T30TYN_2... | 2020-12-16T10:59:14.504000Z | 100.0 | 0.0 | 0.40 | 0.16 | 0.24 | 5.98 | 0.33 | 0.14 | 0.51 | 51.87 |
32 | S2A_30TYN_20201226_0_L2A | 2020-12-26 | 30TYN | 52.46 | sentinel-2a | 051 | S2A_MSIL2A_20201226T105451_N0214_R051_T30TYN_2... | 2020-12-26T10:59:16.273000Z | 100.0 | 0.0 | 0.09 | 0.11 | 0.47 | 7.33 | 2.82 | 0.57 | 0.03 | 44.03 |
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 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | S2A_30TYN_20200101_0_L2A | 2020-01-01 | 30TYN | 57.44 | sentinel-2a | 051 | S2A_MSIL2A_20200101T105441_N0213_R051_T30TYN_2... | 2020-01-01T10:59:11.266000Z | 100.0 | 0.0 | 0.81 | 0.85 | 1.96 | 7.56 | 0.14 | 0.63 | 0.01 | 40.97 |
1 | S2B_30TYN_20200106_0_L2A | 2020-01-06 | 30TYN | 57.35 | sentinel-2b | 051 | S2B_MSIL2A_20200106T105339_N0213_R051_T30TYN_2... | 2020-01-06T10:59:11.633000Z | 100.0 | 0.0 | 1.06 | 0.93 | 2.48 | 7.28 | 0.18 | 0.74 | 0.00 | 40.67 |
2 | S2B_30TYN_20200116_0_L2A | 2020-01-16 | 30TYN | 56.64 | sentinel-2b | 051 | S2B_MSIL2A_20200116T105309_N0213_R051_T30TYN_2... | 2020-01-16T10:59:10.849000Z | 100.0 | 0.0 | 1.39 | 1.02 | 5.01 | 6.09 | 0.17 | 0.98 | 0.00 | 40.82 |
3 | S2A_30TYN_20200131_0_L2A | 2020-01-31 | 30TYN | 44.26 | sentinel-2a | 051 | S2A_MSIL2A_20200131T105251_N0213_R051_T30TYN_2... | 2020-01-31T10:59:09.147000Z | 100.0 | 0.0 | 0.14 | 0.35 | 0.33 | 4.15 | 0.09 | 0.12 | 0.00 | 55.39 |
4 | S2B_30TYN_20200205_0_L2A | 2020-02-05 | 30TYN | 46.62 | sentinel-2b | 051 | S2B_MSIL2A_20200205T105129_N0214_R051_T30TYN_2... | 2020-02-05T10:59:10.605000Z | 100.0 | 0.0 | 1.02 | 1.26 | 2.69 | 3.76 | 0.28 | 0.64 | 0.00 | 51.44 |
5 | S2A_30TYN_20200210_0_L2A | 2020-02-10 | 30TYN | 46.31 | sentinel-2a | 051 | S2A_MSIL2A_20200210T105201_N0214_R051_T30TYN_2... | 2020-02-10T10:59:09.328000Z | 100.0 | 0.0 | 1.30 | 1.54 | 4.71 | 3.05 | 0.05 | 0.53 | 0.00 | 51.81 |
6 | S2B_30TYN_20200215_0_L2A | 2020-02-15 | 30TYN | 44.75 | sentinel-2b | 051 | S2B_MSIL2A_20200215T105029_N0214_R051_T30TYN_2... | 2020-02-15T10:59:12.451000Z | 100.0 | 0.0 | 1.48 | 1.72 | 5.96 | 2.40 | 0.28 | 0.93 | 0.00 | 52.56 |
7 | S2A_30TYN_20200220_0_L2A | 2020-02-20 | 30TYN | 43.54 | sentinel-2a | 051 | S2A_MSIL2A_20200220T105051_N0214_R051_T30TYN_2... | 2020-02-20T10:59:11.040000Z | 100.0 | 0.0 | 1.58 | 2.65 | 7.58 | 1.83 | 0.27 | 1.01 | 0.00 | 53.60 |
8 | 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:12.233000Z | 100.0 | 0.0 | 0.00 | 0.00 | 0.14 | 0.00 | 4.44 | 6.32 | 0.00 | 89.09 |
9 | S2A_30TYN_20200311_0_L2A | 2020-03-11 | 30TYN | 20.12 | sentinel-2a | 051 | S2A_MSIL2A_20200311T105021_N0214_R051_T30TYN_2... | 2020-03-11T10:59:12.935000Z | 100.0 | 0.0 | 0.48 | 0.91 | 0.48 | 0.65 | 0.16 | 0.09 | 0.00 | 79.15 |
10 | S2A_30TYN_20200321_0_L2A | 2020-03-21 | 30TYN | 32.54 | sentinel-2a | 051 | S2A_MSIL2A_20200321T105021_N0214_R051_T30TYN_2... | 2020-03-21T10:59:13.094000Z | 100.0 | 0.0 | 0.68 | 2.09 | 13.14 | 0.35 | 0.96 | 0.57 | 0.00 | 65.25 |
11 | S2A_30TYN_20200410_0_L2A | 2020-04-10 | 30TYN | 24.51 | sentinel-2a | 051 | S2A_MSIL2A_20200410T105031_N0214_R051_T30TYN_2... | 2020-04-10T10:59:15.012000Z | 100.0 | 0.0 | 1.52 | 6.31 | 8.57 | 0.50 | 1.63 | 9.43 | 0.00 | 62.91 |
12 | S2A_30TYN_20200520_0_L2A | 2020-05-20 | 30TYN | 53.59 | sentinel-2a | 051 | S2A_MSIL2A_20200520T105031_N0214_R051_T30TYN_2... | 2020-05-20T10:59:22.363000Z | 100.0 | 0.0 | 0.04 | 32.70 | 16.82 | 0.16 | 0.82 | 1.63 | 0.00 | 43.92 |
13 | S2A_30TYN_20200530_0_L2A | 2020-05-30 | 30TYN | 58.84 | sentinel-2a | 051 | S2A_MSIL2A_20200530T105031_N0214_R051_T30TYN_2... | 2020-05-30T10:59:22.967000Z | 100.0 | 0.0 | 1.30 | 37.21 | 16.90 | 0.43 | 1.23 | 4.62 | 0.00 | 34.01 |
14 | S2B_30TYN_20200624_0_L2A | 2020-06-24 | 30TYN | 68.59 | sentinel-2b | 051 | S2B_MSIL2A_20200624T104629_N0214_R051_T30TYN_2... | 2020-06-24T10:59:19.327000Z | 100.0 | 0.0 | 0.75 | 46.88 | 17.58 | 0.13 | 1.64 | 4.30 | 0.00 | 24.72 |
15 | S2B_30TYN_20200704_0_L2A | 2020-07-04 | 30TYN | 78.01 | sentinel-2b | 051 | S2B_MSIL2A_20200704T104619_N0214_R051_T30TYN_2... | 2020-07-04T10:59:18.977000Z | 100.0 | 0.0 | 0.28 | 51.04 | 22.23 | 0.04 | 2.51 | 3.77 | 0.00 | 15.43 |
16 | S2A_30TYN_20200709_0_L2A | 2020-07-09 | 30TYN | 71.72 | sentinel-2a | 051 | S2A_MSIL2A_20200709T105031_N0214_R051_T30TYN_2... | 2020-07-09T10:59:20.829000Z | 100.0 | 0.0 | 2.88 | 46.20 | 19.82 | 0.20 | 4.15 | 9.84 | 0.00 | 11.41 |
17 | S2B_30TYN_20200714_0_L2A | 2020-07-14 | 30TYN | 80.75 | sentinel-2b | 051 | S2B_MSIL2A_20200714T104619_N0214_R051_T30TYN_2... | 2020-07-14T10:59:18.200000Z | 100.0 | 0.0 | 0.47 | 51.60 | 23.56 | 0.02 | 4.07 | 5.65 | 0.00 | 9.06 |
18 | S2A_30TYN_20200719_0_L2A | 2020-07-19 | 30TYN | 83.64 | sentinel-2a | 051 | S2A_MSIL2A_20200719T105031_N0214_R051_T30TYN_2... | 2020-07-19T10:59:21.847000Z | 100.0 | 0.0 | 0.61 | 51.86 | 25.36 | 0.14 | 3.41 | 7.26 | 0.00 | 5.08 |
19 | S2A_30TYN_20200729_0_L2A | 2020-07-29 | 30TYN | 86.56 | sentinel-2a | 051 | S2A_MSIL2A_20200729T105031_N0214_R051_T30TYN_2... | 2020-07-29T10:59:22.508000Z | 100.0 | 0.0 | 0.80 | 50.94 | 28.15 | 0.02 | 4.25 | 5.34 | 0.00 | 3.05 |
20 | S2B_30TYN_20200803_0_L2A | 2020-08-03 | 30TYN | 88.60 | sentinel-2b | 051 | S2B_MSIL2A_20200803T104629_N0214_R051_T30TYN_2... | 2020-08-03T10:59:19.827000Z | 100.0 | 0.0 | 0.69 | 49.25 | 30.00 | 0.02 | 4.82 | 4.16 | 0.00 | 1.73 |
22 | S2B_30TYN_20200823_0_L2A | 2020-08-23 | 30TYN | 94.13 | sentinel-2b | 051 | S2B_MSIL2A_20200823T104629_N0214_R051_T30TYN_2... | 2020-08-23T10:59:20.275000Z | 100.0 | 0.0 | 1.24 | 49.92 | 33.75 | 0.05 | 2.34 | 1.56 | 0.00 | 0.73 |
23 | S2B_30TYN_20200902_0_L2A | 2020-09-02 | 30TYN | 91.56 | sentinel-2b | 051 | S2B_MSIL2A_20200902T104629_N0214_R051_T30TYN_2... | 2020-09-02T10:59:23.832000Z | 100.0 | 0.0 | 2.27 | 48.39 | 29.37 | 0.08 | 2.18 | 3.04 | 0.00 | 0.95 |
25 | S2A_30TYN_20200927_0_L2A | 2020-09-27 | 30TYN | 19.93 | sentinel-2a | 051 | S2A_MSIL2A_20200927T105031_N0214_R051_T30TYN_2... | 2020-09-27T10:59:22.256000Z | 100.0 | 0.0 | 0.43 | 6.84 | 0.18 | 0.39 | 0.52 | 0.05 | 0.00 | 79.07 |
26 | S2B_30TYN_20201012_0_L2A | 2020-10-12 | 30TYN | 26.37 | sentinel-2b | 051 | S2B_MSIL2A_20201012T104909_N0214_R051_T30TYN_2... | 2020-10-12T10:59:20.517000Z | 100.0 | 0.0 | 1.59 | 6.85 | 0.70 | 1.14 | 0.77 | 9.61 | 0.00 | 61.66 |
27 | S2A_30TYN_20201017_0_L2A | 2020-10-17 | 30TYN | 40.44 | sentinel-2a | 051 | S2A_MSIL2A_20201017T105041_N0214_R051_T30TYN_2... | 2020-10-17T10:59:22.444000Z | 100.0 | 0.0 | 2.79 | 9.11 | 6.41 | 0.83 | 2.38 | 2.35 | 0.06 | 51.98 |
29 | S2B_30TYN_20201111_0_L2A | 2020-11-11 | 30TYN | 75.63 | sentinel-2b | 051 | S2B_MSIL2A_20201111T105259_N0214_R051_T30TYN_2... | 2020-11-11T10:59:17.920000Z | 100.0 | 0.0 | 4.41 | 14.45 | 17.83 | 2.60 | 0.42 | 1.38 | 0.00 | 18.16 |
30 | S2B_30TYN_20201121_0_L2A | 2020-11-21 | 30TYN | 78.80 | sentinel-2b | 051 | S2B_MSIL2A_20201121T105349_N0214_R051_T30TYN_2... | 2020-11-21T10:59:17.294000Z | 100.0 | 0.0 | 4.08 | 11.19 | 19.89 | 3.74 | 4.11 | 2.82 | 0.00 | 10.19 |
31 | S2A_30TYN_20201216_0_L2A | 2020-12-16 | 30TYN | 46.75 | sentinel-2a | 051 | S2A_MSIL2A_20201216T105441_N0214_R051_T30TYN_2... | 2020-12-16T10:59:14.504000Z | 100.0 | 0.0 | 0.40 | 0.16 | 0.24 | 5.98 | 0.33 | 0.14 | 0.51 | 51.87 |
32 | S2A_30TYN_20201226_0_L2A | 2020-12-26 | 30TYN | 52.46 | sentinel-2a | 051 | S2A_MSIL2A_20201226T105451_N0214_R051_T30TYN_2... | 2020-12-26T10:59:16.273000Z | 100.0 | 0.0 | 0.09 | 0.11 | 0.47 | 7.33 | 2.82 | 0.57 | 0.03 | 44.03 |
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.44 | sentinel-2a | 051 | S2A_MSIL2A_20200101T105441_N0213_R051_T30TYN_2... | 2020-01-01T10:59:11.266000Z | 100.0 | 0.0 | 0.81 | 0.85 | 1.96 | 7.56 | 0.14 | 0.63 | 0.01 | 40.97 |
2020-02-29 | S2B_30TYN_20200205_0_L2A | 30TYN | 46.62 | sentinel-2b | 051 | S2B_MSIL2A_20200205T105129_N0214_R051_T30TYN_2... | 2020-02-05T10:59:10.605000Z | 100.0 | 0.0 | 1.02 | 1.26 | 2.69 | 3.76 | 0.28 | 0.64 | 0.00 | 51.44 |
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:12.233000Z | 100.0 | 0.0 | 0.00 | 0.00 | 0.14 | 0.00 | 4.44 | 6.32 | 0.00 | 89.09 |
2020-04-30 | S2A_30TYN_20200410_0_L2A | 30TYN | 24.51 | sentinel-2a | 051 | S2A_MSIL2A_20200410T105031_N0214_R051_T30TYN_2... | 2020-04-10T10:59:15.012000Z | 100.0 | 0.0 | 1.52 | 6.31 | 8.57 | 0.50 | 1.63 | 9.43 | 0.00 | 62.91 |
2020-05-31 | S2A_30TYN_20200520_0_L2A | 30TYN | 53.59 | sentinel-2a | 051 | S2A_MSIL2A_20200520T105031_N0214_R051_T30TYN_2... | 2020-05-20T10:59:22.363000Z | 100.0 | 0.0 | 0.04 | 32.70 | 16.82 | 0.16 | 0.82 | 1.63 | 0.00 | 43.92 |
2020-06-30 | S2B_30TYN_20200624_0_L2A | 30TYN | 68.59 | sentinel-2b | 051 | S2B_MSIL2A_20200624T104629_N0214_R051_T30TYN_2... | 2020-06-24T10:59:19.327000Z | 100.0 | 0.0 | 0.75 | 46.88 | 17.58 | 0.13 | 1.64 | 4.30 | 0.00 | 24.72 |
2020-07-31 | S2B_30TYN_20200704_0_L2A | 30TYN | 78.01 | sentinel-2b | 051 | S2B_MSIL2A_20200704T104619_N0214_R051_T30TYN_2... | 2020-07-04T10:59:18.977000Z | 100.0 | 0.0 | 0.28 | 51.04 | 22.23 | 0.04 | 2.51 | 3.77 | 0.00 | 15.43 |
2020-08-31 | S2B_30TYN_20200803_0_L2A | 30TYN | 88.60 | sentinel-2b | 051 | S2B_MSIL2A_20200803T104629_N0214_R051_T30TYN_2... | 2020-08-03T10:59:19.827000Z | 100.0 | 0.0 | 0.69 | 49.25 | 30.00 | 0.02 | 4.82 | 4.16 | 0.00 | 1.73 |
2020-09-30 | S2B_30TYN_20200902_0_L2A | 30TYN | 91.56 | sentinel-2b | 051 | S2B_MSIL2A_20200902T104629_N0214_R051_T30TYN_2... | 2020-09-02T10:59:23.832000Z | 100.0 | 0.0 | 2.27 | 48.39 | 29.37 | 0.08 | 2.18 | 3.04 | 0.00 | 0.95 |
2020-10-31 | S2B_30TYN_20201012_0_L2A | 30TYN | 26.37 | sentinel-2b | 051 | S2B_MSIL2A_20201012T104909_N0214_R051_T30TYN_2... | 2020-10-12T10:59:20.517000Z | 100.0 | 0.0 | 1.59 | 6.85 | 0.70 | 1.14 | 0.77 | 9.61 | 0.00 | 61.66 |
2020-11-30 | S2B_30TYN_20201111_0_L2A | 30TYN | 75.63 | sentinel-2b | 051 | S2B_MSIL2A_20201111T105259_N0214_R051_T30TYN_2... | 2020-11-11T10:59:17.920000Z | 100.0 | 0.0 | 4.41 | 14.45 | 17.83 | 2.60 | 0.42 | 1.38 | 0.00 | 18.16 |
2020-12-31 | S2A_30TYN_20201216_0_L2A | 30TYN | 46.75 | sentinel-2a | 051 | S2A_MSIL2A_20201216T105441_N0214_R051_T30TYN_2... | 2020-12-16T10:59:14.504000Z | 100.0 | 0.0 | 0.40 | 0.16 | 0.24 | 5.98 | 0.33 | 0.14 | 0.51 | 51.87 |
Please note, the value of the “date” column changes to account for the grouper function assigning only one value per month. However, the true value of the Sentinel-2 images are kept, and are viewable and accessible in the final result.
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
2023-06-22 12:50:43,988 INFO spacesense.core : created everything
[7]:
<xarray.Dataset> Dimensions: (time: 12, y: 678, x: 722) 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) float32 -0.07177 -0.07165 -0.07152 ... 0.019 0.01913 0.01925 Data variables: S2_B02 (time, y, x) float32 0.9697 0.9752 0.9456 ... 0.666 0.6728 nan S2_B03 (time, y, x) float32 0.9881 1.017 0.9744 1.058 ... 0.6882 0.696 nan S2_B04 (time, y, x) float32 0.9375 0.9807 0.9945 ... 0.6836 0.6948 nan Attributes: transform: [ 1.26249832e-04 0.00000000e+00 -7.18361548e-02 0.000... crs: +init=epsg:4326 res: [1.26249832e-04 8.68139450e-05] descriptions: ['B02', 'B03', 'B04'] AREA_OR_POINT: Area _FillValue: nan s2_data_lineage: {"Data origin": "S3 bucket (ARN=arn:aws:s3:::sentinel-c... ulx, uly: [-0.07183615 42.73798515] 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)
2023-06-22 12:50:44,238 WARNING matplotlib.image : Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
2023-06-22 12:50:44,274 WARNING matplotlib.image : Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
2023-06-22 12:50:44,309 WARNING matplotlib.image : Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
2023-06-22 12:50:44,344 WARNING matplotlib.image : Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
2023-06-22 12:50:44,380 WARNING matplotlib.image : Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
2023-06-22 12:50:44,415 WARNING matplotlib.image : Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
2023-06-22 12:50:44,451 WARNING matplotlib.image : Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
2023-06-22 12:50:44,488 WARNING matplotlib.image : Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
2023-06-22 12:50:44,526 WARNING matplotlib.image : Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
2023-06-22 12:50:44,563 WARNING matplotlib.image : Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
2023-06-22 12:50:44,606 WARNING matplotlib.image : Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
2023-06-22 12:50:44,652 WARNING matplotlib.image : Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
