Skip to main content

Download Sentinel-2 data from Microsoft Planetary Computer

Project description

sen2p

sen2p is a lightweight Python library to search and download Sentinel-2 imagery from Microsoft Planetary Computer. No API keys required.

Installation

pip install sen2p

Dependencies are installed automatically: planetary-computer, pystac-client, rioxarray, xarray, geopandas, shapely, rasterio, tqdm.

Requirements

  • Python >= 3.9

Features

  • 🔍 Search Sentinel-2 data by date, location, and cloud cover
  • 🛰️ Download selected bands or all available bands
  • 🗂️ Auto-merge bands into a single GeoTIFF (with resampling)
  • ☁️ Cloud cover filtering
  • ♻️ Skip already-downloaded files
  • 🔄 Retry on network failures
  • 🖥️ CLI tool: sen2p search, sen2p download, sen2p meta

Quick Start

Python API

from sen2p import search, download, show_meta

# Search (preview without downloading)
items = search(
    start_date="2023-06-01",
    end_date="2023-06-10",
    location=[172.1, -43.5],  # [lon, lat]
    cloud_max=20,
)
for item in items:
    print(item['item_id'], item['cloud_cover'])

# Download
results = download(
    start_date="2023-06-01",
    end_date="2023-06-10",
    location=[172.1, -43.5],
    bands=["B02", "B03", "B04", "B08"],
    output_dir="output",
    cloud_max=20,
)

for r in results:
    print(r["merged"])
    show_meta(r["merged"])

CLI

# Search for items
sen2p search --start 2023-06-01 --end 2023-06-10 --location "172.1,-43.5" --cloud-max 20

# Download bands
sen2p download --start 2023-06-01 --end 2023-06-10 --location "172.1,-43.5" \
    --bands B02,B03,B04,B08 --output output --cloud-max 20

# Show raster metadata
sen2p meta output/S2B_..._merged.tif

Location Formats

All functions accept flexible location inputs:

# Point [lon, lat]
location = [172.1, -43.5]

# Bounding box [min_lon, min_lat, max_lon, max_lat]
location = [172.0, -43.6, 172.5, -43.3]

# Path to shapefile / GeoJSON
location = "study_area.shp"
location = "area.geojson"

# GeoJSON dict
location = {"type": "Polygon", "coordinates": [[[172, -43.6], [172.5, -43.6], [172.5, -43.3], [172, -43.3], [172, -43.6]]]}

Functions

Function Description
search(start_date, end_date, location, ...) Search for items without downloading
download(start_date, end_date, location, bands, ...) Download bands and optionally merge
show_meta(file_path) Display raster metadata

download() Parameters

Parameter Type Default Description
start_date str required Start date (YYYY-MM-DD)
end_date str required End date (YYYY-MM-DD)
location list/dict/str required Point, bbox, GeoJSON, or shapefile path
bands list None Band names (e.g., ["B02", "B03"]). None = all
output_dir str None Output directory
cloud_max float None Max cloud cover %
max_items int None Max items to download
merge_bands bool True Merge bands into single GeoTIFF
cell_size float None Target resolution (meters). None = auto
overwrite bool False Overwrite existing files
collection str "sentinel-2-l2a" STAC collection ID

Sentinel-2 Band Reference

Band Name Resolution
B01 Coastal aerosol 60m
B02 Blue 10m
B03 Green 10m
B04 Red 10m
B05 Vegetation Red Edge 20m
B06 Vegetation Red Edge 20m
B07 Vegetation Red Edge 20m
B08 NIR 10m
B8A Narrow NIR 20m
B09 Water vapour 60m
B11 SWIR 20m
B12 SWIR 20m

Contributing

License

MIT License

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

sen2p-0.1.0.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

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

sen2p-0.1.0-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file sen2p-0.1.0.tar.gz.

File metadata

  • Download URL: sen2p-0.1.0.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for sen2p-0.1.0.tar.gz
Algorithm Hash digest
SHA256 dfe2c0ca5f6f995d8ae979b9e4d7d2375584bda802268ad2270783c840ca1134
MD5 96b5439aae2fb9597fa9ff0c96fbc3c8
BLAKE2b-256 d00c0b52dcfbbcb455fe6fd567d4274af109d82d29a0fe71ee25680530bc3212

See more details on using hashes here.

File details

Details for the file sen2p-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: sen2p-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for sen2p-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cbe481e7dfd29805fb926c97c5dba47f22965eb5df83e02a5f0f6153961f5d76
MD5 06234624c8a0d82142189fa9d2fffd3b
BLAKE2b-256 b21235401a7985037251778588e1da35680312afdc557338640239dedce7d98e

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