Skip to main content

Tools & CLI for interacting with CDSE product APIs

Project description

CDSETool

About CDSETool

This script downloads copernicus data from the Copernicus Data Space Ecosystem

Usage

Querying features

Querying is always done in batches, returning len(results) <= maxRecords records each time. a local buffer is filled and gradually emptied as results are yielded. When the buffer is empty, more results will be requested and the process repeated until no more results are available, or the iterator is discarded.

from cdse.query import query_features

collection = "Sentinel2"
search_terms = {
    "maxRecords": "100", # batch size, between 1 and 2000 (default 50).
    "startDate": "1999-01-01",
    "processingLevel": "S2MSI1C"
}

# wait for a single batch to finish, yield results immediately
for feature in query_features(collection, search_terms):
    # do something with feature

# wait for all batch requests to complete, returning list
features = list(query_features(collection, search_terms))

# manually iterate
iter = query_features(collection, search_terms)

featureA = next(iter)
featureB = next(iter)
# ...

Querying by shapes

To query by shapes, you must first convert your shape to Well Known Text (WKT). The included shape_to_wkt can solve this.

from cdse.query import query_features, shape_to_wkt

geometry = shape_to_wkt("path/to/shape.shp")

features = query_features("Sentinel3", {"geometry": geometry})

Querying by lists of parameters

Most search terms only accept a single argument. To query by a list of arguments, loop the arguments and pass them one by one to the query function.

from cdse.query import query_features

tile_ids = ["32TPT", "32UPU", "32UPU", "31RFL", "37XDA"]

for tile_id in tile_ids:
    features = query_features("Sentinel2", {"tileId": tile_id})
    for feature in features:
        # do things with feature

Listing search terms

To get a list of all search terms for a given collection, you may either use the describe_collection function or use the CLI:

from cdsetool.query import describe_collection

search_terms = describe_collection("Sentinel2").keys()
print(search_terms)

And the CLI:

$ cdsetool query search-terms Sentinel2

Downloading features

Authenticating

An account is required to download features from the Copernicus distribution service.

To authenticate using an account, instantiate Credentials and pass your username and password

from cdsetool.credentials import Credentials

username = "konata@izumi.com"
password = "password123"
credentials = Credentials(username, password)

Alternatively, Credentials can pull from ~/.netrc when username and password are left blank.

# ~/.netrc
machine https://identity.dataspace.copernicus.eu/auth/realms/CDSE/protocol/openid-connect/token
login konata@izumi.com
password password123

# main.py
from cdsetool.credentials import Credentials

credentials = Credentials()

The credentials object may then be passed to a download function. If left out, the download functions will default to using .netrc.

credentials = Credentials()

download_features(features, "/some/download/path", {"credentials": credentials})

Concurrently downloading features

CDSETool provides a method for concurrently downloading features. The concurrency level should match your accounts privileges

The downloaded feature ids are yielded, so its required to await the results.

from cdsetool.query import query_features
from cdsetool.download import download_features

features = query_features("Sentinel2")

download_path = "/path/to/download/folder"
downloads = download_features(features, download_path, {"concurrency": 4})

for id in downloads:
    print(f"feature {id} downloaded")

# or

list(downloads)

Sequentially downloading features

Its possible to download features sequentially in a single thread if desired.

from cdsetool.query import query_features
from cdsetool.download import download_feature

features = query_features("Sentinel2")

download_path = "/path/to/download/folder"
for feature in features:
    download_feature(feature, download_path)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cdsetool-0.0.1.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cdsetool-0.0.1-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file cdsetool-0.0.1.tar.gz.

File metadata

  • Download URL: cdsetool-0.0.1.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for cdsetool-0.0.1.tar.gz
Algorithm Hash digest
SHA256 e598ac34953f7dfb7fe0cc5e260f83e15a0216fb8b08c42607402585a41e1905
MD5 8e65535d1fd51f6998f436f8130b3a63
BLAKE2b-256 a279234549e5543bd1cdb3e3f681c69bbf15c8e46ee8d62888e25ae99c932719

See more details on using hashes here.

File details

Details for the file cdsetool-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: cdsetool-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for cdsetool-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dfe27e557182bded66cad7d295f5938b2031a9768cc1b7922f33f63552fd9c34
MD5 241f129e1ea761a8ea58685f0230ab99
BLAKE2b-256 50ce0daab0cde8c16fce4937ace3dcaec7b78942489791466bed6728f27efcf6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page