Weather Data Access in Search
Contents
Weather Data Access in Search#
Short description
This notebook introduces the Weather access and refinement.
1 - Import spacesense object(s) and other dependencies#
[1]:
from spacesense import Client
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import json
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 TOI#
[2]:
# 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
]
]
]
}
}
]
}
# Define TOI
start_date = "2021-02-01"
end_date = "2021-04-15"
# Get an instance of the SpaceSense Client object
client = Client(id="weather_search")
3 - Search Weather#
[3]:
# Retrieves specified weather variables corresponding to the aoi, start date, and end date
weather_variables = ["LAILOW", "PREC", "UWIND", "VWIND"]
res_weather = client.weather_search(aoi, start_date, end_date, variables=weather_variables)
df = res_weather.dataframe
df
[3]:
date | lailow | prec | uwind | vwind | |
---|---|---|---|---|---|
0 | 2021-02-01 | 1.725094 | 7.116849 | 4.864336 | -2.266004 |
1 | 2021-02-02 | 1.726089 | 1.581512 | 3.563660 | -2.541020 |
2 | 2021-02-03 | 1.727094 | 0.004455 | -0.781930 | 2.039700 |
3 | 2021-02-04 | 1.728088 | 0.000006 | -1.836714 | 1.226246 |
4 | 2021-02-05 | 1.729092 | 0.000006 | -1.827159 | 1.178977 |
... | ... | ... | ... | ... | ... |
69 | 2021-04-11 | 1.930440 | 1.614441 | -2.829541 | 2.599476 |
70 | 2021-04-12 | 1.933740 | 6.214283 | 2.196791 | -2.096936 |
71 | 2021-04-13 | 1.937054 | 0.000000 | 4.891191 | -3.295530 |
72 | 2021-04-14 | 1.940352 | 0.043861 | 0.547026 | -0.059496 |
73 | 2021-04-15 | 1.940711 | 0.046124 | -0.063789 | -0.383259 |
74 rows × 5 columns
4 - Plot time series of LAI#
[4]:
df.plot(x="date", y=["lailow"])
[4]:
<AxesSubplot:xlabel='date'>

5 - Search S2#
[5]:
# 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, query_filters = {"valid_pixel_percentage" : {">=": 95}})
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 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
11 | S2A_32TMK_20210205_0_L2A | 2021-02-05 | 32TMK | 100.00 | sentinel-2a | 065 | S2A_MSIL2A_20210205T102221_N0214_R065_T32TMK_2... | 2021-02-05T10:29:43Z | 100.0 | 0.0 | 0.00 | 97.40 | 0.16 | 0.0 | 0.00 | 0.00 | 0.0 | 0.0 |
10 | S2A_32TMK_20210215_0_L2A | 2021-02-15 | 32TMK | 100.00 | sentinel-2a | 065 | S2A_MSIL2A_20210215T102121_N0214_R065_T32TMK_2... | 2021-02-15T10:29:42Z | 100.0 | 0.0 | 0.00 | 97.86 | 0.00 | 0.0 | 0.00 | 0.00 | 0.0 | 0.0 |
9 | S2B_32TMK_20210217_0_L2A | 2021-02-17 | 32TMK | 100.00 | sentinel-2b | 022 | S2B_MSIL2A_20210217T101029_N0214_R022_T32TMK_2... | 2021-02-17T10:19:45Z | 100.0 | 0.0 | 0.00 | 97.97 | 0.00 | 0.0 | 0.00 | 0.00 | 0.0 | 0.0 |
8 | S2B_32TMK_20210220_0_L2A | 2021-02-20 | 32TMK | 100.00 | sentinel-2b | 065 | S2B_MSIL2A_20210220T101939_N0214_R065_T32TMK_2... | 2021-02-20T10:29:41Z | 100.0 | 0.0 | 0.00 | 97.86 | 0.00 | 0.0 | 0.00 | 0.00 | 0.0 | 0.0 |
7 | S2A_32TMK_20210225_0_L2A | 2021-02-25 | 32TMK | 100.00 | sentinel-2a | 065 | S2A_MSIL2A_20210225T102021_N0214_R065_T32TMK_2... | 2021-02-25T10:29:43Z | 100.0 | 0.0 | 0.00 | 97.80 | 0.00 | 0.0 | 0.00 | 0.00 | 0.0 | 0.0 |
6 | S2A_32TMK_20210307_0_L2A | 2021-03-07 | 32TMK | 99.00 | sentinel-2a | 065 | S2A_MSIL2A_20210307T102021_N0214_R065_T32TMK_2... | 2021-03-07T10:29:43Z | 100.0 | 0.0 | 0.00 | 68.59 | 0.00 | 0.0 | 1.00 | 0.00 | 0.0 | 0.0 |
5 | S2B_32TMK_20210322_0_L2A | 2021-03-22 | 32TMK | 97.78 | sentinel-2b | 065 | S2B_MSIL2A_20210322T101649_N0214_R065_T32TMK_2... | 2021-03-22T10:29:43Z | 100.0 | 0.0 | 0.00 | 92.87 | 0.98 | 0.0 | 2.22 | 0.00 | 0.0 | 0.0 |
4 | S2B_32TMK_20210329_0_L2A | 2021-03-29 | 32TMK | 100.00 | sentinel-2b | 022 | S2B_MSIL2A_20210329T100609_N0214_R022_T32TMK_2... | 2021-03-29T10:19:46Z | 100.0 | 0.0 | 0.00 | 97.86 | 0.16 | 0.0 | 0.00 | 0.00 | 0.0 | 0.0 |
3 | S2B_32TMK_20210401_0_L2A | 2021-04-01 | 32TMK | 100.00 | sentinel-2b | 065 | S2B_MSIL2A_20210401T101559_N0300_R065_T32TMK_2... | 2021-04-01T10:29:42Z | 100.0 | 0.0 | 0.00 | 97.97 | 0.00 | 0.0 | 0.00 | 0.00 | 0.0 | 0.0 |
2 | S2A_32TMK_20210406_0_L2A | 2021-04-06 | 32TMK | 100.00 | sentinel-2a | 065 | S2A_MSIL2A_20210406T102021_N0300_R065_T32TMK_2... | 2021-04-06T10:29:40Z | 100.0 | 0.0 | 0.00 | 98.56 | 0.00 | 0.0 | 0.00 | 0.00 | 0.0 | 0.0 |
1 | S2B_32TMK_20210408_0_L2A | 2021-04-08 | 32TMK | 100.00 | sentinel-2b | 022 | S2B_MSIL2A_20210408T100549_N0300_R022_T32TMK_2... | 2021-04-08T10:19:45Z | 100.0 | 0.0 | 0.00 | 98.13 | 0.00 | 0.0 | 0.00 | 0.00 | 0.0 | 0.0 |
0 | S2A_32TMK_20210413_0_L2A | 2021-04-13 | 32TMK | 96.34 | sentinel-2a | 022 | S2A_MSIL2A_20210413T101021_N0300_R022_T32TMK_2... | 2021-04-13T10:19:42Z | 100.0 | 0.0 | 0.49 | 89.35 | 3.12 | 0.0 | 3.01 | 0.16 | 0.0 | 0.0 |
6 - Filter weather dates matching S2 dates#
[6]:
res_weather.dataframe = res_weather.dataframe[[date in list(res_S2.dataframe["date"]) for date in list(res_weather.dataframe["date"])]]
res_weather.dataframe
[6]:
date | lailow | prec | uwind | vwind | |
---|---|---|---|---|---|
4 | 2021-02-05 | 1.729092 | 0.000006 | -1.827159 | 1.178977 |
14 | 2021-02-15 | 1.740311 | 0.000006 | -0.302282 | -1.600299 |
16 | 2021-02-17 | 1.747522 | 0.000006 | -0.037975 | -0.273452 |
19 | 2021-02-20 | 1.758355 | 0.004262 | -2.808861 | 0.954008 |
24 | 2021-02-25 | 1.776382 | 0.028380 | 0.015086 | -0.116508 |
34 | 2021-03-07 | 1.812463 | 0.682086 | -2.230686 | 1.315975 |
49 | 2021-03-22 | 1.864313 | 0.125496 | -0.026054 | -4.197672 |
56 | 2021-03-29 | 1.887462 | 0.009414 | -0.267097 | -0.117241 |
59 | 2021-04-01 | 1.897375 | 0.000000 | -0.250064 | -0.198988 |
64 | 2021-04-06 | 1.913904 | 0.299103 | 5.917795 | -2.332012 |
66 | 2021-04-08 | 1.920513 | 0.000000 | -0.086882 | -0.620076 |
71 | 2021-04-13 | 1.937054 | 0.000000 | 4.891191 | -3.295530 |
7 - Filter S2 dates with U-wind<1#
[7]:
res_S2_df_no_wind = res_S2.dataframe[list(res_weather.dataframe["uwind"]<1)]
res_S2_df_no_wind
[7]:
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_20210205_0_L2A | 2021-02-05 | 32TMK | 100.00 | sentinel-2a | 065 | S2A_MSIL2A_20210205T102221_N0214_R065_T32TMK_2... | 2021-02-05T10:29:43Z | 100.0 | 0.0 | 0.0 | 97.40 | 0.16 | 0.0 | 0.00 | 0.0 | 0.0 | 0.0 |
10 | S2A_32TMK_20210215_0_L2A | 2021-02-15 | 32TMK | 100.00 | sentinel-2a | 065 | S2A_MSIL2A_20210215T102121_N0214_R065_T32TMK_2... | 2021-02-15T10:29:42Z | 100.0 | 0.0 | 0.0 | 97.86 | 0.00 | 0.0 | 0.00 | 0.0 | 0.0 | 0.0 |
9 | S2B_32TMK_20210217_0_L2A | 2021-02-17 | 32TMK | 100.00 | sentinel-2b | 022 | S2B_MSIL2A_20210217T101029_N0214_R022_T32TMK_2... | 2021-02-17T10:19:45Z | 100.0 | 0.0 | 0.0 | 97.97 | 0.00 | 0.0 | 0.00 | 0.0 | 0.0 | 0.0 |
8 | S2B_32TMK_20210220_0_L2A | 2021-02-20 | 32TMK | 100.00 | sentinel-2b | 065 | S2B_MSIL2A_20210220T101939_N0214_R065_T32TMK_2... | 2021-02-20T10:29:41Z | 100.0 | 0.0 | 0.0 | 97.86 | 0.00 | 0.0 | 0.00 | 0.0 | 0.0 | 0.0 |
7 | S2A_32TMK_20210225_0_L2A | 2021-02-25 | 32TMK | 100.00 | sentinel-2a | 065 | S2A_MSIL2A_20210225T102021_N0214_R065_T32TMK_2... | 2021-02-25T10:29:43Z | 100.0 | 0.0 | 0.0 | 97.80 | 0.00 | 0.0 | 0.00 | 0.0 | 0.0 | 0.0 |
6 | S2A_32TMK_20210307_0_L2A | 2021-03-07 | 32TMK | 99.00 | sentinel-2a | 065 | S2A_MSIL2A_20210307T102021_N0214_R065_T32TMK_2... | 2021-03-07T10:29:43Z | 100.0 | 0.0 | 0.0 | 68.59 | 0.00 | 0.0 | 1.00 | 0.0 | 0.0 | 0.0 |
5 | S2B_32TMK_20210322_0_L2A | 2021-03-22 | 32TMK | 97.78 | sentinel-2b | 065 | S2B_MSIL2A_20210322T101649_N0214_R065_T32TMK_2... | 2021-03-22T10:29:43Z | 100.0 | 0.0 | 0.0 | 92.87 | 0.98 | 0.0 | 2.22 | 0.0 | 0.0 | 0.0 |
4 | S2B_32TMK_20210329_0_L2A | 2021-03-29 | 32TMK | 100.00 | sentinel-2b | 022 | S2B_MSIL2A_20210329T100609_N0214_R022_T32TMK_2... | 2021-03-29T10:19:46Z | 100.0 | 0.0 | 0.0 | 97.86 | 0.16 | 0.0 | 0.00 | 0.0 | 0.0 | 0.0 |
3 | S2B_32TMK_20210401_0_L2A | 2021-04-01 | 32TMK | 100.00 | sentinel-2b | 065 | S2B_MSIL2A_20210401T101559_N0300_R065_T32TMK_2... | 2021-04-01T10:29:42Z | 100.0 | 0.0 | 0.0 | 97.97 | 0.00 | 0.0 | 0.00 | 0.0 | 0.0 | 0.0 |
1 | S2B_32TMK_20210408_0_L2A | 2021-04-08 | 32TMK | 100.00 | sentinel-2b | 022 | S2B_MSIL2A_20210408T100549_N0300_R022_T32TMK_2... | 2021-04-08T10:19:45Z | 100.0 | 0.0 | 0.0 | 98.13 | 0.00 | 0.0 | 0.00 | 0.0 | 0.0 | 0.0 |
8 - Merge dataframes#
[8]:
global_df = pd.merge(res_weather.dataframe, res_S2.dataframe, on="date", how="outer")
global_df = global_df[["date", "lailow", "prec", "product_id"]]
global_df
[8]:
date | lailow | prec | product_id | |
---|---|---|---|---|
0 | 2021-02-05 | 1.729092 | 0.000006 | S2A_MSIL2A_20210205T102221_N0214_R065_T32TMK_2... |
1 | 2021-02-15 | 1.740311 | 0.000006 | S2A_MSIL2A_20210215T102121_N0214_R065_T32TMK_2... |
2 | 2021-02-17 | 1.747522 | 0.000006 | S2B_MSIL2A_20210217T101029_N0214_R022_T32TMK_2... |
3 | 2021-02-20 | 1.758355 | 0.004262 | S2B_MSIL2A_20210220T101939_N0214_R065_T32TMK_2... |
4 | 2021-02-25 | 1.776382 | 0.028380 | S2A_MSIL2A_20210225T102021_N0214_R065_T32TMK_2... |
5 | 2021-03-07 | 1.812463 | 0.682086 | S2A_MSIL2A_20210307T102021_N0214_R065_T32TMK_2... |
6 | 2021-03-22 | 1.864313 | 0.125496 | S2B_MSIL2A_20210322T101649_N0214_R065_T32TMK_2... |
7 | 2021-03-29 | 1.887462 | 0.009414 | S2B_MSIL2A_20210329T100609_N0214_R022_T32TMK_2... |
8 | 2021-04-01 | 1.897375 | 0.000000 | S2B_MSIL2A_20210401T101559_N0300_R065_T32TMK_2... |
9 | 2021-04-06 | 1.913904 | 0.299103 | S2A_MSIL2A_20210406T102021_N0300_R065_T32TMK_2... |
10 | 2021-04-08 | 1.920513 | 0.000000 | S2B_MSIL2A_20210408T100549_N0300_R022_T32TMK_2... |
11 | 2021-04-13 | 1.937054 | 0.000000 | S2A_MSIL2A_20210413T101021_N0300_R022_T32TMK_2... |