Skip to main content

Trufl

Trufl helps you decide where to sample next in a survey that runs over several rounds. At each round, it ranks areas, such as administrative units, by how much they need more samples. It then splits your sampling budget across the areas according to their rank. The ranking uses multiple-criteria decision-making (MCDM) on criteria that you choose, computed from the measurements collected so far and from prior knowledge such as an airborne survey.

Trufl was built to plan soil surveys of farmland contaminated after a nuclear accident. The same approach works for any phenomenon you monitor over time against several criteria, such as legacy contaminants.

trufl is part of the ecosystem of DSS4NAFA, a decision support system for nuclear emergencies affecting food and agriculture. Where trufl comes from describes the research behind trufl and how it works with DSS4NAFA.

Why trufl

Sampling theory and the research literature already cover multi-stage and adaptive spatial sampling well. Their methods rest on assumptions, such as a planned probability sampling design or a known model of spatial variation. In a nuclear emergency, the data rarely meet those assumptions. Measurements arrive over time from many sources, such as airborne surveys, laboratory analyses and samples taken where it was convenient to take them. They cover different locations at different resolutions. Sound statistical inference from such data is difficult. Decisions still have to be made, and you can’t ignore the data you have. trufl takes a pragmatic approach and uses all of it.

The reasons to sample one area before another also vary, and they change during an emergency. They include the levels measured so far, the uncertainty that remains, prior knowledge, land use and population. trufl ranks areas on criteria that you choose, with weights that you set. You can change both from one round to the next.

Like DSS4NAFA, trufl is not a black box. Each rank follows from the state of the area, the criteria, the weights and the scoring method. You can inspect each of them, and adjust them as the situation develops.

You can also use trufl to prepare for an emergency. Simulate a campaign over several rounds on a map of a possible contamination, and compare sampling strategies before you need them.

Install

pip install trufl

Example

This example plans one sampling round over a simulated contamination map, split into a 10 x 10 grid of areas:

import pandas as pd
import geopandas as gpd

from trufl.utils import gridder
from trufl.callbacks import State, PriorCB
from trufl.optimizer import Optimizer
from trufl.sampler import Sampler, rank_to_sample
fname_raster = './files/ground-truth-01-4326-simulated.tif'
gdf_grid = gridder(fname_raster, nrows=10, ncols=10)

Before any measurement, the state of each area is its prior: the mean of the map over the area. Calling a State computes it:

no_samples = gpd.GeoDataFrame(index=pd.Index([], name='loc_id'), geometry=None, data={'value': None})
state = State(no_samples, gdf_grid, cbs=[PriorCB(fname_raster)])()
state.head()
<style scoped> .dataframe tbody tr th:only-of-type { vertical-align: middle; } .dataframe tbody tr th { vertical-align: top; } .dataframe thead th { text-align: right; } </style>
Prior
loc_id
0 0.102492
1 0.125727
2 0.161802
3 0.184432
4 0.201405

With the prior as the only criterion, an area with a higher prior gets a higher sampling priority. Rank 1 is the highest:

ranks = Optimizer(state).get_rank(is_benefit_x=[True], w_vector=[1], s_method='CP')
ranks.head()
<style scoped> .dataframe tbody tr th:only-of-type { vertical-align: middle; } .dataframe tbody tr th { vertical-align: top; } .dataframe thead th { text-align: right; } </style>
rank
loc_id
92 1
93 2
91 3
94 4
82 5

rank_to_sample splits a budget of 600 samples across the areas by rank, with at least one sample in each area (min=1). A Sampler then picks the sample locations in each area:

n = rank_to_sample(ranks['rank'].sort_index().values, budget=600, min=1, policy='quantiles')
sample_locs = Sampler(gdf_grid).sample(n, method='uniform')
sample_locs.head()
<style scoped> .dataframe tbody tr th:only-of-type { vertical-align: middle; } .dataframe tbody tr th { vertical-align: top; } .dataframe thead th { text-align: right; } </style>
geometry
loc_id
0 MULTIPOINT ((-1.20861 43.26337))
1 MULTIPOINT ((-1.21204 43.27385))
2 MULTIPOINT ((-1.21957 43.28701))
3 MULTIPOINT ((-1.22048 43.28873))
4 MULTIPOINT ((-1.21362 43.30199))

In the next round, you compute the state from the values measured at these locations, and rank the areas again.

Documentation

Acknowledgements

trufl started within the IAEA Coordinated Research Project D15019, “Monitoring and Predicting Radionuclide Uptake and Dynamics for Optimizing Remediation of Radioactive Contamination in Agriculture”, led by the Joint FAO/IAEA Centre of Nuclear Techniques in Food and Agriculture. It is actively maintained.

It builds on the PhD research of Floris Abrams at SCK CEN and KU Leuven. Floris Abrams and Franck Albinet wrote the package. Where trufl comes from describes the research and how trufl works with DSS4NAFA.

Metadata

Release files for trufl 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for trufl 0.2.1
File Size Uploaded Provenance Actions
trufl-0.2.1.tar.gz 24.6 kB Without provenance Details for trufl-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for trufl 0.2.1
File Interpreter ABI Platform Actions
trufl-0.2.1-py3-none-any.whl Python 3 none any Details for trufl-0.2.1-py3-none-any.whl

Total release size: 49.3 kB

Release files / trufl-0.2.1.tar.gz

Download URL trufl-0.2.1.tar.gz
Size 24.6 kB
Tags Source
SHA-256 checksum
How to use checksums
8075db8775f1846debd8b86e5039a66304e89b67267c56fc1522fa60217ee8f6
BLAKE2b-256 checksum
How to use checksums
e02613d225a501e9fdca36c1c8e757e654e59fe55e12c1701484a40209ab353f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release files / trufl-0.2.1-py3-none-any.whl

Download URL trufl-0.2.1-py3-none-any.whl
Size 24.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
39a46be5c656f85f6197601975cf62d87af686743dc252b56e90e4e3f0364182
BLAKE2b-256 checksum
How to use checksums
b17b77d5f0a6b5fade3d23d2011c8878c891e68a4f71e3597d164d6ca542be9b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Security for trufl 0.2.1

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page