Subset an image on a ROI#

In this example, we’ll configure pygeodes to use CNES S3, search an item and subset data to process it on a ROI

Fix a ROI#

[1]:
import geopandas as gpd
import folium
from shapely.geometry import Polygon

pyr_geom = {"type":"Polygon","coordinates":[[[1,42.9],[1.1,42.9],[1.1,42.8],[1,42.8],[1,42.9]]]}
pyr_gpd = gpd.GeoDataFrame(geometry=[Polygon(pyr_geom['coordinates'][0])], crs="EPSG:4326")

f = folium.Figure(width='100%', height=300)
m = folium.Map(location=[43.2, 1.05], zoom_start=8, tiles='OpenStreetMap').add_to(f)

folium.GeoJson(
    pyr_gpd,
    style_function=lambda feature: {
        'color': 'red',
        'weight': 2,
        'fillOpacity': 0
    }
).add_to(m)
m
[1]:

Searching products from a specific collection on ROI¶#

Now, let’s look for products from THEIA_REFLECTANCE_SENTINEL2_L2A collection, that intersect the area of interest for January 2020. To learn more about how to search items, see the docs.

[2]:
from pygeodes import Geodes
geodes = Geodes()

query = {
    "start_datetime":{"gte":"2020-01-01T00:00:00Z"},
    "end_datetime":{"lte":"2020-01-31T23:59:59Z"}
}
items,dataframe = geodes.search_items(intersects=pyr_geom, query=query, collections=["THEIA_REFLECTANCE_SENTINEL2_L2A"], get_all=True)
item = items[0]
/home/qt/robertm/Documents/pygeodes_user/pygeodes_env_user/lib/python3.10/site-packages/urllib3/connectionpool.py:1097: InsecureRequestWarning: Unverified HTTPS request is being made to host 'geodes-portal.cnes.fr'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings
  warnings.warn(
Found 10 items matching your query

10 item(s) found for query : {'start_datetime': {'gte': '2020-01-01T00:00:00Z'}, 'end_datetime': {'lte': '2020-01-31T23:59:59Z'}}


Display quicklook#

[3]:
import requests
from IPython.display import Image, display

for file in item.assets:
    if item.assets[file].roles == ['overview'] and item.assets[file].title.split('.')[-1] != 'xml':
        quicklook_url = item.assets[file].href
response = requests.get(quicklook_url)
display(Image(response.content))
../_images/examples_s3_subset_6_0.jpg