Downloading with PC

[1]:
# install with
# !pip install terragon-downloader[pc]
[1]:
import terragon
import geopandas as gpd
import xarray as xr
from utils import visualize_sat_images, list_of_dicts_to_tree
[3]:
# we will use the sample data to download a minicube
# other datasets can be found here: https://planetarycomputer.microsoft.com/catalog
gdf = gpd.read_file("data/TUM_OTN.geojson")
gdf = gdf.to_crs("EPSG:32632")
arguments = dict(
    shp=gdf,
    collection="sentinel-2-l2a",
    start_date="2021-01-01",
    end_date="2021-01-05",
    bands=["B02", "B03", "B04"],
    resolution=10,
    download_folder="tests/download/",
)
gdf.crs
[3]:
<Projected CRS: EPSG:32632>
Name: WGS 84 / UTM zone 32N
Axis Info [cartesian]:
- E[east]: Easting (metre)
- N[north]: Northing (metre)
Area of Use:
- name: Between 6°E and 12°E, northern hemisphere between equator and 84°N, onshore and offshore. Algeria. Austria. Cameroon. Denmark. Equatorial Guinea. France. Gabon. Germany. Italy. Libya. Liechtenstein. Monaco. Netherlands. Niger. Nigeria. Norway. Sao Tome and Principe. Svalbard. Sweden. Switzerland. Tunisia. Vatican City State.
- bounds: (6.0, 0.0, 12.0, 84.0)
Coordinate Operation:
- name: UTM zone 32N
- method: Transverse Mercator
Datum: World Geodetic System 1984 ensemble
- Ellipsoid: WGS 84
- Prime Meridian: Greenwich
[2]:
tg = terragon.init("pc")  # credentials are not needed for public datasets
# tg = terragon.init("pc", credentials={"api_key": "<your_api_key>"})

Finding collections

[3]:
# explore the PC data on their website: https://planetarycomputer.microsoft.com/catalog
collections = tg.retrieve_collections(
    query={"id": "Sentinel.1.*"}, fields=["id", "title"]
)  # filter field with regex and only return wished fields
list_of_dicts_to_tree(collections)
[3]:

download

[5]:
# planetary computer is accessed via the stac catalog
ds = tg.create(**arguments)
# or
# items = tg.search(**arguments)
# ds = tg.download(items)
ds
[5]:
<xarray.Dataset> Size: 12kB
Dimensions:      (y: 18, x: 28, time: 2)
Coordinates:
  * y            (y) float64 144B 5.326e+06 5.326e+06 ... 5.326e+06 5.326e+06
  * x            (x) float64 224B 6.976e+05 6.976e+05 ... 6.979e+05 6.979e+05
  * time         (time) datetime64[ns] 16B 2021-01-01T10:23:29.024000 2021-01...
    spatial_ref  int64 8B 0
Data variables:
    B02          (time, y, x) float32 4kB nan nan nan 798.0 ... nan nan nan
    B03          (time, y, x) float32 4kB nan nan nan 779.0 ... nan nan nan
    B04          (time, y, x) float32 4kB nan nan nan 857.0 ... nan nan nan
Attributes:
    crs:          EPSG:32632
    data_source:  PC
    collection:   sentinel-2-l2a
[6]:
visualize_sat_images(ds, gdf, list(reversed(arguments["bands"])))
../_images/demo_files_demo_pc_9_0.png
[7]:
# the ouptut of the search is a collection of items
tg.search(**arguments)
[7]:

Filtering the meta data

[8]:
ds = tg.create(**arguments, filter={"eo:cloud_cover": {"lt": 95}})
visualize_sat_images(ds, gdf, list(reversed(arguments["bands"])))
../_images/demo_files_demo_pc_12_0.png