Skip to content

sudapy.rs.sentinel

Sentinel satellite scene search and download via sentinelsat.

Note

Requires pip install "sudapy[rs]" and Copernicus credentials set as environment variables.

sudapy.rs.sentinel

Sentinel satellite scene search and download via sentinelsat.

Requires the sudapy[rs] extra: pip install "sudapy[rs]"

Before first use, set your Copernicus Open Access Hub credentials:

export COPERNICUS_USER=your_username
export COPERNICUS_PASSWORD=your_password

Register at https://scihub.copernicus.eu/dhus/#/self-registration

search_scenes

search_scenes(*, lon: float, lat: float, start_date: str, end_date: str, platform_name: str = 'Sentinel-2', max_cloud: int = 30) -> list[dict]

Search for Sentinel scenes around a point.

Parameters:

Name Type Description Default
lon float

Center longitude.

required
lat float

Center latitude.

required
start_date str

Start date as YYYY-MM-DD.

required
end_date str

End date as YYYY-MM-DD.

required
platform_name str

Satellite platform (default Sentinel-2).

'Sentinel-2'
max_cloud int

Maximum cloud cover percentage (default 30).

30

Returns:

Type Description
list[dict]

List of dicts with keys: uuid, title, date, cloud_cover.

Source code in src\sudapy\rs\sentinel.py
def search_scenes(
    *,
    lon: float,
    lat: float,
    start_date: str,
    end_date: str,
    platform_name: str = "Sentinel-2",
    max_cloud: int = 30,
) -> list[dict]:
    """Search for Sentinel scenes around a point.

    Args:
        lon: Center longitude.
        lat: Center latitude.
        start_date: Start date as YYYY-MM-DD.
        end_date: End date as YYYY-MM-DD.
        platform_name: Satellite platform (default ``Sentinel-2``).
        max_cloud: Maximum cloud cover percentage (default 30).

    Returns:
        List of dicts with keys: ``uuid``, ``title``, ``date``, ``cloud_cover``.
    """
    from sentinelsat import geojson_to_wkt, read_geojson

    api = _get_api()

    # Create a small point footprint
    footprint = f"POINT({lon} {lat})"

    products = api.query(
        footprint,
        date=(start_date.replace("-", ""), end_date.replace("-", "")),
        platformname=platform_name,
        cloudcoverpercentage=(0, max_cloud),
    )

    results = []
    for uid, meta in products.items():
        results.append({
            "uuid": uid,
            "title": meta.get("title", ""),
            "date": str(meta.get("beginposition", ""))[:10],
            "cloud_cover": meta.get("cloudcoverpercentage", -1),
        })

    # Sort by date descending
    results.sort(key=lambda r: r["date"], reverse=True)
    logger.info("Found %d scenes", len(results))
    return results

download_scene

download_scene(*, uuid: str, out_dir: PathLike = '.') -> Path

Download a Sentinel scene by UUID.

Parameters:

Name Type Description Default
uuid str

Scene UUID from :func:search_scenes.

required
out_dir PathLike

Output directory (default: current directory).

'.'

Returns:

Type Description
Path

Path to the downloaded file.

Source code in src\sudapy\rs\sentinel.py
def download_scene(
    *,
    uuid: str,
    out_dir: PathLike = ".",
) -> Path:
    """Download a Sentinel scene by UUID.

    Args:
        uuid: Scene UUID from :func:`search_scenes`.
        out_dir: Output directory (default: current directory).

    Returns:
        Path to the downloaded file.
    """
    api = _get_api()
    out_dir = Path(out_dir)
    out_dir.mkdir(parents=True, exist_ok=True)

    logger.info("Downloading scene %s to %s ...", uuid, out_dir)
    result = api.download(uuid, directory_path=str(out_dir))

    downloaded_path = Path(result["path"])
    logger.info("Download complete: %s", downloaded_path)
    return downloaded_path