On-demand ortho images from Sentinel-2 L1B#
A Sentinel-2 L1B granule is raw detector imagery: not orthorectified, not corrected for the atmosphere. With this feature, a catalog record of an L1B granule offers an ortho product. When a client asks for it, the server calibrates, orthorectifies and atmospherically corrects the requested window on a GPU, and returns it. Nothing is saved: every response is computed from the original granule when it is requested.
To set this up with your own L1B data, together with Clay embeddings of the same granules, follow Serve your L1B data as ortho images and embeddings.
Route under |
Returns |
|---|---|
|
The granule’s 10 m UTM grid (CRS, transform, size) and its ten bands |
|
A float32 GeoTIFF of that window, deflate-compressed |
|
A stretched JPEG, true color (B04, B03, B02) by default |
Windows are in pixels of the grid, 16 to 4096 on a side; without one, the whole grid.
reduce (1 to 64) averages the valid pixels of each block on the GPU, for a coarser
grid; a preview picks it from its size, so only about the image’s own pixels move.
Bands are any of B02, B03, B04, B05, B06, B07, B08, B8A, B11 and B12. GeoTIFF values are
surface reflectance times 10000; zero marks pixels with no valid source sample. Responses
carry X-GeoNemo-Media-Product: l1b-ortho-surface-reflectance and
X-GeoNemo-L1B-Granule. A request may correct at most 128 M values on the GPU (bands
times window pixels, before reduce), so all ten bands fit a window of up to about
3600 x 3600. A GeoTIFF is also limited to 64 MiB of raw values and to the media response
limit (GEONEMO_MAX_MEDIA_RESPONSE_BYTES, 20 MiB by default): ask for fewer bands or a
smaller window when the API answers 413. The service renders one request at a time and
queues at most four; beyond that the API answers 503 with Retry-After: 2.
How it works#
client ── GET l1b-ortho ──▶ services-api ── POST /v1/render ──▶ l1b-ortho
│ │ one GPU
GeoTIFF / JPEG ◀───┘ encodes float32 planes ◀──┘ cuGeo
services-apilooks up the record, which names its granule inl1b_granule, and sends the window and bands to the ortho service.The ortho service (
cugeo-pipeline ortho-service) runs in the L1B image on one GPU. It uses the same correction as L1B batch ingestion (sentinel_l1b.correct_bands): cuGeo’s physical model and warp from the worker’s cuGeo checkout, then Sen2Cor-table atmospheric correction with terrain illumination. It runs one request at a time on one thread and returns the planes in memory.services-apiencodes the GeoTIFF or JPEG. GDAL stays out of the GPU runtime.
The service has no host port; only the API reaches it. Without
GEONEMO_L1B_ORTHO_ENDPOINT, or with the media gateway off, the routes answer 404 and
discovery reports l1b_ortho unavailable.
What it is, and is not#
The atmosphere is an explicit Sen2Cor preset and a fixed visibility, chosen when the granule is prepared. Nothing is retrieved per scene, and there is no cloud mask. This is not ESA’s operational L2A.
On one inland granule (tile 14SQD, 6.4 million pixels), the result correlated with the official L2A at 0.993 to 0.996 per band, on the same 10 m grid. Medians were 2 to 11% lower, most in blue, as expected from a fixed 40 km visibility against L2A’s retrieved aerosol. This checks registration and radiometric consistency on one scene; it is not a qualification.
Prepare granules#
The service reads a private L1B index and, for each granule, ten cuGeo band inputs.
packs/sentinel/scripts/prepare_l1b_ortho.py writes them for a
single-acquisition corpus (worklists/ortho.jsonl and
worklists/surface.jsonl, original granule and datastrip archives, matching L1C SAFEs,
Copernicus DEM tiles, a geoid and the GIPP). Run it with the server environment, which has
rasterio:
python packs/sentinel/scripts/prepare_l1b_ortho.py \
--dataset <corpus-dir> \
--work <work-dir>/ortho \
--lut-library <sen2cor-dir>/lib/python2.7/site-packages/sen2cor/lib_S2B \
--limit 20
Step |
Detail |
|---|---|
Extract |
The granule and datastrip archives, once, under |
Grid |
The L1C tile whose 10 m grid contains the whole footprint, with the widest margin. A granule that no single tile contains is skipped |
DEM |
The footprint’s one-degree cells plus a one-cell halo, resampled from Copernicus GLO-30 to SRTM-1 |
Atmosphere |
|
Output |
|
The Sen2Cor LUTs are in the Sen2Cor installer; sh Sen2Cor-02.12.04-Linux64.run --noexec --target DIR unpacks it. Everything the index names must be readable by UID
10001, the image’s user.
Run it on a development stack#
Build the L1B image once with
packs/sentinel/examples/l1b-similarity/build-l1b-image.sh, then:
deploy/development/dev.sh up --build \
--l1b-ortho <work-dir>/ortho/l1b.json \
--l1b-ortho-data <data-dir> --l1b-ortho-gpu 0
Option |
Effect |
|---|---|
|
Adds |
|
Mounts |
|
The GPU index or UUID the service reserves; default 0 |
It combines with --retrieval, and the stack keeps these options until dev.sh down.
Then register the granules (below) and request images, with the granule name as
GRANULE:
curl -o window.tif "http://127.0.0.1:8101/v1/media/records/sentinel-2-l1b/GRANULE/l1b-ortho?bands=B04,B03,B02&x=1000&y=1000&width=1024&height=1024"
curl -o preview.jpg "http://127.0.0.1:8101/v1/media/records/sentinel-2-l1b/GRANULE/l1b-ortho/preview"
Register the granules#
packs/sentinel/scripts/register_l1b_granules.py creates one
catalog record per prepared granule, once the stack is running, through the public catalog API, in collection
sentinel-2-l1b by default. It sends only public facts: footprint, sensing time,
detector and l1b_granule. Each record’s ID is the granule name.
python packs/sentinel/scripts/register_l1b_granules.py \
<work-dir>/ortho/granules.json \
--api http://127.0.0.1:8101
Limits#
One request at a time per service and GPU. A whole granule takes a few seconds; the first request after start is slower.
Each window is computed from the whole source granule’s decode and physical model; a small window is not proportionally cheaper.
Granules that cross an L1C tile edge are not prepared yet.
The image is built locally; it is not published.