fbp
Field boundary prediction post-processing in Python.
fbp turns background, field, and boundary predictions into field instances. It
includes BoundaryVote, the method behind the FTW Global Data 2nd Edition, along with
watershed, connected-component, and published split-and-merge baselines.
Install
pip install ftw-fbp
The package imports as fbp.
For development:
git clone https://github.com/fieldsoftheworld/fbp.git
cd fbp
uv sync --extra dev
Use
A method takes a (H, W) class map and a (3, H, W) array of background, field,
and boundary probabilities, and returns int32 instance labels with 0 as background.
Each method is a frozen dataclass, so its settings can be written out and loaded
again as plain data.
from fbp import BoundaryVote
method = BoundaryVote(
foreground="not_background",
seed_depth=0.01,
min_line_support=0.3,
min_area_m2=900,
)
instances = method(segmentation, probabilities, pixel_area_m2=9.0)
This method takes every pixel where field or boundary wins as foreground and floods 1 - p(boundary) from seeds at least 0.01 deep. It keeps a proposed split when at least 30% of the pixels on the dividing line favor boundary, and drops fields under 900 m². The class docstrings describe every option.
For rasters too large for one call, run_windowed processes core-sized windows
with halo pixels of context on each side. The window whose core holds a field's
centroid keeps that field, and copies of a field that crosses a window boundary are
merged into one instance.
from fbp import run_windowed
instances = run_windowed(
method,
segmentation,
probabilities,
pixel_area_m2=9.0,
core=8192,
halo=512,
)
Only one window of the inputs is read at a time. segmentation and probabilities
can be any objects with a .shape whose numpy-style slices are arrays, such as a
reader of raster windows, so the whole raster never has to be in memory. The labels
are int32 and are relabelled in row strips; pass out= to write them into a
preallocated int32 array or memmap. A 40,032 x 40,032 raster then needs the 6.4 GB
label array plus one window's working memory.
FTW Global Data 2nd Edition
fbp.FTW_2E is the setting used for the 2nd Edition field boundaries, run on 2.5 m
probabilities:
from fbp import FTW_2E
instances = FTW_2E(segmentation, probabilities, pixel_area_m2=6.25)
Besides the BoundaryVote settings above (with min_line_support=0.5), it drops
fields whose mean field probability is under 0.25. It then splits the looser
foreground of pixels with field probability above 0.10 and adds each resulting field
that the first pass covers less than half of, which recovers fields whose field
probability rarely wins the argmax. That second pass is skipped when less than 2% of
the looser foreground is uncovered. With fast=True, the probabilities are rounded
to the 1/255 grid of the published uint8 rasters, and the watershed runs on integer
levels. This needs the fast extra (SimpleITK and numba):
pip install 'ftw-fbp[fast]'
On the published probability rasters, FTW_2E reproduces the published raw outlines.
It matches all 112 fields pixel for pixel on a 10 km window of tile 15TVG_0_0
(Iowa), and 647 of 648 fields (99.7% pixel for pixel) on tile 35MRT_0_0 (Rwanda).
Layout
src/fbp/core/ geometry and post-processing building blocks
src/fbp/methods/ the methods, one module each
tests/ package tests
A new method subclasses fbp.Method and implements split. Keep paper-specific
evaluation, results, figures, and LaTeX outside this package.
Development
uv run ruff format --check .
uv run ruff check .
uv run ty check
uv run pytest
Metadata
Release files for ftw-fbp 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ftw_fbp-0.2.0.tar.gz | 36.3 kB | Without provenance | Details for ftw_fbp-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ftw_fbp-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for ftw_fbp-0.2.0-py3-none-any.whl |
Total release size: 65.9 kB
Release files / ftw_fbp-0.2.0.tar.gz
| Download URL | ftw_fbp-0.2.0.tar.gz |
|---|---|
| Size | 36.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
84969176a087eb214f2c438b701c1ca099aa448a46c82d52ce9c02458ba8a464
|
|
BLAKE2b-256 checksum How to use checksums |
375f24f37a50434c85cba429cbc0bb35aea47bafbad5406fa0c29311e4b19454
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / ftw_fbp-0.2.0-py3-none-any.whl
| Download URL | ftw_fbp-0.2.0-py3-none-any.whl |
|---|---|
| Size | 29.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c4acf3e9c460973050b4c74c8f3da6bdf181405b6dbdf560519c465c7f106e7a
|
|
BLAKE2b-256 checksum How to use checksums |
bd174ff4c57a895a72afe135023bfb33d2bc2e69e547369826c6fa55894f0939
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for ftw-fbp 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.