Metadata-Version: 2.5
Name: mgmradar
Version: 0.39.0
Summary: Calibrated MGM radar composite API with explicit confidence and a durable archive
Project-URL: Homepage, https://mgm-radar.velosophic.life
Project-URL: Repository, https://github.com/Velosophic-Life/mgm-radar
Author: MGM Radar
License: Proprietary
Requires-Python: >=3.12
Requires-Dist: fastapi<1,>=0.115
Requires-Dist: httpx<1,>=0.27
Requires-Dist: mcp<3,>=2.3
Requires-Dist: numpy<3,>=1.26
Requires-Dist: pillow<12,>=10.4
Requires-Dist: pydantic-settings<3,>=2.3
Requires-Dist: pydantic<3,>=2.7
Requires-Dist: pyyaml<7,>=6.0
Requires-Dist: rasterio<2,>=1.3
Requires-Dist: scipy<2,>=1.11
Requires-Dist: sqlalchemy<3,>=2.0
Requires-Dist: uvicorn[standard]<1,>=0.30
Provides-Extra: dev
Requires-Dist: boto3-stubs[s3]>=1.34; extra == 'dev'
Requires-Dist: build<2,>=1.2; extra == 'dev'
Requires-Dist: jsonschema<5,>=4.21; extra == 'dev'
Requires-Dist: mypy==1.20.2; extra == 'dev'
Requires-Dist: pytest-cov<7,>=5; extra == 'dev'
Requires-Dist: pytest<9,>=8.2; extra == 'dev'
Requires-Dist: ruff==0.17.4; extra == 'dev'
Requires-Dist: types-pyyaml>=6.0; extra == 'dev'
Provides-Extra: postgres
Requires-Dist: psycopg[binary]<4,>=3.1; extra == 'postgres'
Provides-Extra: redis
Requires-Dist: redis<7,>=5.0; extra == 'redis'
Provides-Extra: s3
Requires-Dist: boto3<2,>=1.34; extra == 's3'
Provides-Extra: spike
Requires-Dist: matplotlib<4,>=3.8; extra == 'spike'
Description-Content-Type: text/markdown

# MGM Radar

A clean, standalone API for Turkey's national radar composite: ingest the MGM
image, turn it into calibrated rain data, and serve it to app developers and
hobbyists.

> **Status: launched.** Ingest, processing, live serving, access and metering,
> archive/exports, operations, tests, and deployment assets are in place and
> running in production. The design and specs live in
> [`openspec/changes/archive/2026-11-20-bootstrap-mgm-radar-api/`](openspec/changes/archive/2026-11-20-bootstrap-mgm-radar-api/).
> The independent reference comparison is complete
> ([report](docs/reference-comparison.md)), as are the two-week soak
> ([report](docs/soak-report.md)) and the paid-listing decision
> ([record](docs/paid-listing-decision.md)); remaining follow-ups are tracked in
> [the validation plan](docs/validation-plan.md).

## What it does

```mermaid
flowchart LR
    SRC["MGM compmax1..15<br/>(10-min JPEG)"]
    ING["Ingest<br/>raw + archive"]
    PROC["Process<br/>dBZ, rain, confidence"]
    SERVE["Serve<br/>live API + history"]

    SRC --> ING --> PROC --> SERVE
```

- **Ingest** the full rolling set of MGM composite frames, not just the latest.
- **Process** each frame into a georeferenced reflectivity grid, a rain-rate
  grid, and an explicit confidence mask.
- **Serve** a versioned REST API: metadata, frames, images, snapshots, tiles, point
  queries, and historical series/exports.
- **Archive** every frame so history is queryable for forecasting and ML users.

## What it is not

- Not a forecast model. It serves observations.
- Not a multi-source platform in this change. The source sits behind an adapter
  so it can be replaced later.
- Not a general-purpose weather UI. The product surface is the API, the account
  portal, and the documentation.

## Architecture

```mermaid
flowchart TD
    SRC["MGM compmax1..15 (HTTPS)"]
    ING["INGEST<br/>poller → downloader → hash/dedupe → raw → index"]
    PROC["PROCESS<br/>decode → georef → legend → classify → dBZ → rain<br/>→ confidence → derived store → render"]
    SERVE["SERVE<br/>/v1: meta · frames · image · tiles · point · batch<br/>archive: series · exports · jobs · signed URLs<br/>edge: auth · quotas · rate limits · usage"]

    SRC -- "conditional GET" --> ING
    ING -- "new frame" --> PROC
    PROC -- "indexed artifacts" --> SERVE
```

## Repository layout

```
src/mgmradar/
  ingest/      source adapter, poller, downloader, dedupe, raw storage
  process/     decode, calibration, classification, rain rate, renders
  store/       object storage and frame/export index
  api/         FastAPI routes, schemas, auth, quotas
  ops/         health, metrics, alerts
tests/         offline fixtures and golden-frame tests
deploy/        compose/runbook, CDN notes (image: root Dockerfile)
docs/          source, calibration, API, archive, operations, licensing
openspec/      proposal, specs, design, tasks
```

## API at a glance

| Method | Path                                           | Purpose                                           |
| ------ | ---------------------------------------------- | ------------------------------------------------- |
| GET    | `/v1/meta`                                     | source, coverage, bounds, units, legend, versions (public on the first-party host) |
| GET    | `/v1/frames`                                   | list frames                                       |
| GET    | `/v1/frames/{scan_time}`                       | one frame's metadata                              |
| GET    | `/v1/frames/{scan_time}/image.png`             | full-frame Web Mercator overlay                   |
| GET    | `/v1/frames/{scan_time}/tiles/{z}/{x}/{y}.png` | XYZ tile                                          |
| GET    | `/v1/snapshot`                                 | focused bbox/place radar snapshot                 |
| GET    | `/v1/frames/latest/image.png`                  | newest complete frame                             |
| GET    | `/v1/point`                                    | one coordinate observation                        |
| POST   | `/v1/points`                                   | bounded batch observations                        |
| GET    | `/v1/series`                                   | one coordinate over time                          |
| POST   | `/v1/exports`                                  | create a bbox/time export job                     |
| GET    | `/v1/exports/{id}`                             | export status + signed URL                        |
| GET    | `/v1/coverage.geojson`                         | radar footprint (public on the first-party host)  |
| GET    | `/v1/status`                                   | freshness and processing health (public on the first-party host) |
| GET    | `/v1/health`                                   | liveness/readiness (no auth)                      |
| GET    | `/v1/health/ready`                             | 503 unless dependencies and data are fresh        |
| GET    | `/ops`                                         | operations dashboard (Cloudflare Access SSO)      |
| POST   | `/mcp`                                         | remote MCP server (Streamable HTTP)               |

`/v1` uses `X-API-Key`. The five MCP tools are available from a first-party
local stdio package (`uvx mgmradar-mcp`, with the key in `MGM_API_KEY`) and from
the remote `/mcp` endpoint over Streamable HTTP. The remote server accepts the
same `X-API-Key` from header-capable clients, and OAuth 2.1 from OAuth-only hosts
such as ChatGPT, which discover the authorization server, register themselves,
and ask the customer to approve the `radar:read` scope. OAuth is accepted only
on `/mcp`, never on `/v1`. MCP `place` inputs resolve Turkish neighborhoods and
villages as well as provinces and districts, and every observation returns a
nullable tri-state answer (`rain_detected`, `no_rain_detected`, `indeterminate`)
with an explicit freshness band. See [MCP server](docs/mcp.md) for setup and
troubleshooting, and [MCP listings](docs/mcp-listings.md) for the official
registry and developer directories that cover both the hosted and local
transports. The
[`evals/`](evals/README.md) directory holds the provider-independent
tool-selection benchmark.

## Plans

The **Basic** tier is permanent and card-free: 5,000 requests per month, 150 per
day, 1 request per second, and the newest frame only. It includes no timestamped
images, tiles, batch requests, history, or exports.

| Plan | Price | Requests / month | History | Includes |
| ---- | ----: | ---------------: | ------- | -------- |
| Basic | $0 | 5,000 | live only | meta, frames, latest frame/image, point |
| Pro | $9 | 150,000 | 7 days | + images, batch, history |
| Ultra | $29 | 500,000 | 90 days | + tiles, exports (1/day) |
| Mega | $89 | 1,500,000 | full archive | + exports (10/day) |
| Enterprise | Custom | Custom | full archive | SLA, bulk export, dedicated support |

Rain threshold alerts are included in Pro and above with no per-alert charge in
version one. Basic has no alert rules. The configured limits match
`config/plans.yaml`:

| Plan | Alert rules | Deliveries / day | Deliveries / month |
| --- | ---: | ---: | ---: |
| Basic | 0 | 0 | 0 |
| Pro | 10 | 100 | 2,000 |
| Ultra | 50 | 500 | 10,000 |
| Mega | 200 | 2,000 | 50,000 |
| Enterprise | 1,000 | 10,000 | 250,000 |

A downgrade disables rules above the new limit without deleting them and
cancels their pending deliveries; an upgrade does not re-enable them
automatically. See [rain-alerts.md](docs/rain-alerts.md) for the customer guide
and [runbook-rain-alerts.md](docs/runbook-rain-alerts.md) for operations.

Sign up at `/signup`, verify the email, and the key is shown once. Paid plans
are self-serve through the portal; Polar handles checkout. There is no overage:
a quota rejection returns `429` until the reset or a plan change. See
[pricing.md](docs/pricing.md) for the full rules.

## Documentation

- [Quickstart](docs/quickstart.md) — the customer path from signup to the first call
- [Self-hosting](docs/self-hosting.md) — install and run the service locally
- [Architecture](docs/architecture.md)
- [Source contract](docs/source.md)
- [Calibration and confidence](docs/calibration.md)
- [API reference](docs/api.md) and [OpenAPI 3.1](docs/openapi.json)
- [Rain alerts](docs/rain-alerts.md) and the [operator runbook](docs/runbook-rain-alerts.md)
- [Agent quickstart](docs/agents.md) and the served `/llms.txt`
- [MCP server](docs/mcp.md)
- [MCP listings](docs/mcp-listings.md) — registry and directory discovery surfaces
- [Integration examples](docs/integrations/README.md) — MCP host, Home Assistant,
  and Python/JavaScript
- [Authentication and plans](docs/authentication.md)
- [Historical archive](docs/archive.md)
- [Operations, dashboard, and alerts](docs/operations.md)
- [Performance and freshness](docs/performance.md)
- [Accuracy and limitations](docs/accuracy.md)
- [Independent reference comparison](docs/reference-comparison.md)
- [Backup and retention](docs/retention.md)
- [Two-week soak report](docs/soak-report.md)
- [Paid-listing decision](docs/paid-listing-decision.md)
- [Release and deploy pipeline](docs/releasing.md)
- [Pricing and plans](docs/pricing.md)
- [Pricing decision](docs/pricing-decision.md)
- [Billing lifecycle, access policy, and the Polar account](docs/billing.md)
- [FAQ](docs/faq.md)
- [Ansible deployment](ANSIBLE.md)
- [Remaining validation plan](docs/validation-plan.md)
- [Licensing and attribution](docs/licensing.md)

## Known risks

- **Upstream has no SLA.** MGM can change the image layout, palette, cadence, or
  URL without notice. The service detects drift, quarantines bad frames, and
  reports staleness.
- **Licensing.** The source is publicly reachable but its terms assert all
  rights reserved. The owner has accepted the redistribution risk; the position
  is recorded in [docs/licensing.md](docs/licensing.md). This is not legal
  advice.
- **Coarse product.** The composite is roughly 2.4 km/px and column-maximum, not
  a surface rain measurement. The API must say so.

## Naming

**MGM Radar** is the product name. The repository directory is `mgm-radar`; the
Python package, distribution, CLI command, environment-variable prefix, and
metric prefix use the single-token form `mgmradar`.

The name references the upstream source (MGM, the Turkish State Meteorological
Service) but does not imply affiliation. MGM Radar is an independent product,
not an official MGM service.

## Development

```bash
python3.12 -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
ruff check src tests
mypy src
pytest
```

Run the service with `mgmradar serve`, the ingest loop with `mgmradar poll`,
and the export worker with `mgmradar export-worker --cleanup`. See the
[self-hosting guide](docs/self-hosting.md) and [deployment runbook](deploy/README.md).

## License

Proprietary. All rights reserved. The upstream data is subject to its own terms;
see [docs/licensing.md](docs/licensing.md).
