Metadata-Version: 2.4
Name: sen2p
Version: 0.1.0
Summary: Download Sentinel-2 data from Microsoft Planetary Computer
Home-page: https://github.com/tnmthai/sen2p
Author: Thai Tran
Author-email: ThaiTran@outlook.co.nz
License: MIT
Project-URL: Homepage, https://github.com/tnmthai/sen2p
Project-URL: Issues, https://github.com/tnmthai/sen2p/issues
Project-URL: PyPI, https://pypi.org/project/sen2p/
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Intended Audience :: Science/Research
Classifier: Topic :: Scientific/Engineering :: GIS
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Requires-Dist: planetary-computer
Requires-Dist: pystac-client
Requires-Dist: rioxarray
Requires-Dist: xarray
Requires-Dist: tqdm
Requires-Dist: geopandas
Requires-Dist: shapely
Requires-Dist: rasterio
Dynamic: author-email
Dynamic: home-page
Dynamic: requires-python

# sen2p

**sen2p** is a lightweight Python library to search and download Sentinel-2 imagery from [Microsoft Planetary Computer](https://planetarycomputer.microsoft.com/). No API keys required.

## Installation

```bash
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

```python
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

```bash
# 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:

```python
# 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

- **Repository**: [github.com/tnmthai/sen2p](https://github.com/tnmthai/sen2p)
- **Issues**: [github.com/tnmthai/sen2p/issues](https://github.com/tnmthai/sen2p/issues)
- **PyPI**: [pypi.org/project/sen2p](https://pypi.org/project/sen2p/)

## License

MIT License
