Skip to content

Converters

cdse.converters

Data format converters for CDSE Client.

This module provides functions to convert search results to various formats: - Pandas DataFrame - GeoPandas GeoDataFrame - GeoJSON FeatureCollection

These functions are designed to be compatible with sentinelsat's API.

to_geojson(products: list[Product]) -> dict[str, Any]

Convert products to GeoJSON FeatureCollection.

Parameters:

Name Type Description Default
products list[Product]

List of Product objects from search results

required

Returns:

Type Description
dict[str, Any]

GeoJSON FeatureCollection dictionary

Example

products = client.search(...) geojson = to_geojson(products) with open("footprints.geojson", "w") as f: ... json.dump(geojson, f)

to_dataframe(products: list[Product]) -> pd.DataFrame

Convert products to Pandas DataFrame.

Requires pandas to be installed: pip install pandas

Parameters:

Name Type Description Default
products list[Product]

List of Product objects from search results

required

Returns:

Type Description
DataFrame

pandas.DataFrame with product metadata

Raises:

Type Description
ImportError

If pandas is not installed

Example

products = client.search(...) df = to_dataframe(products) df_sorted = df.sort_values('cloud_cover') df.to_csv("products.csv")

to_geodataframe(products: list[Product]) -> gpd.GeoDataFrame

Convert products to GeoPandas GeoDataFrame.

Requires geopandas to be installed: pip install geopandas

Parameters:

Name Type Description Default
products list[Product]

List of Product objects from search results

required

Returns:

Type Description
GeoDataFrame

geopandas.GeoDataFrame with product metadata and geometries

Raises:

Type Description
ImportError

If geopandas is not installed

Example

products = client.search(...) gdf = to_geodataframe(products) gdf.plot() # Visualize footprints gdf.to_file("footprints.gpkg", driver="GPKG")

products_size(products: list[Product]) -> float

Calculate total size of products in GB.

Parameters:

Name Type Description Default
products list[Product]

List of Product objects

required

Returns:

Type Description
float

Total size in gigabytes

Example

products = client.search(...) print(f"Total size: {products_size(products):.2f} GB")

products_count(products: list[Product]) -> dict[str, int]

Count products by collection.

Parameters:

Name Type Description Default
products list[Product]

List of Product objects

required

Returns:

Type Description
dict[str, int]

Dictionary mapping collection names to counts

Example

products = client.search(...) counts = products_count(products) print(counts) # {'sentinel-2-l2a': 5, 'sentinel-2-l1c': 2}