A Python toolkit for computing nutrition-sensitive food environment indicators from spatial and survey data.
Project description
๐ฆ NFEI โ Nutrition-Sensitive Food Environment Index (Python Package)
nfei is a Python package for computing nutrition-sensitive food environment indicators from vendor survey data, food availability data, and geospatial data. It provides reusable functions for building the indicator components used in the Nutrition-Sensitive Food Environment Index (N-FEI), including food diversity, produce color diversity, vendor availability, vendor density, spatial aggregation, scaling, and validation.
This package is designed for researchers, data scientists, public-health analysts, food-system practitioners, and policy teams who want to move from raw food environment data to transparent, reproducible indicators.
๐ง What is the Nutrition-Sensitive Food Environment Index?
The Nutrition-Sensitive Food Environment Index (N-FEI) is a composite food environment assessment framework developed to evaluate how the built food environment may support or constrain healthier diets and public-health outcomes. It is designed to assess food environments through a nutrition and public health lens, capturing how food availability, accessibility, infrastructure, and exposure to unhealthy foods interact to influence malnutrition risk.
It is grounded in the definition of food environments as:
โthe collective physical, economic, policy, and sociocultural surroundings, opportunities, and conditions that influence peopleโs food and beverage choices and nutritional status.โ
The N-FEI expands food environment measurement beyond affordability alone. The index is constructed from nine indicators, normalized and aggregated into a 0โ10 scale, where higher values indicate healthier food environments. It focuses on observable features of vendor environments, including:
- Vendor Healthy Food Diversity Score, using food groups aligned with the Minimum Dietary Diversity for Women framework.
- Vendor Environment Healthy Food Diversity Score, capturing what is available around vendors, not only at a single vendor.
- Vendor ProColor Diversity Score, Fruit and vegetable color diversity reflecting ProColor-style produce diversity.
- Vendor Environment ProColor Diversity Score, capturing the broader produce-color environment around vendors.
- Access to Water and Sanitation, especially relevant for informal and mobile food vendors.
- Vendor availability, measured through daily and weekly operating patterns.
- Vendor density per population, capturing vendor availability relative to population size.
- Vendor density per square kilometre, capturing geographic distribution.
- Unhealthy food count, capturing exposure to selected unhealthy beverages and snacks.
The N-FEI methodology was developed and validated using multi-country food environment data. The published paper describes the conceptual basis, indicator selection, spatial logic, sensitivity analysis, validation strategy, and policy relevance of the index.
Methodology paper:
https://doi.org/10.55845/jos-2025-1116
This package does not hide the index inside a black-box function. Instead, it exposes the building blocks used to compute the indicators, so users can adapt the workflow to their own study design, data structure, and policy context.
๐ฏ What this package does
nfei helps you:
- Compute vendor-level food diversity indicators.
- Compute produce color diversity indicators.
- Compute unhealthy beverage, snack, and total unhealthy food counts.
- Compute daily, weekly, and combined vendor availability.
- Estimate population covered by radius-based vendor mapping.
- Compute vendor density by population and land area.
- Aggregate food environment features within spatial buffers.
- Calculate nearest distances and spatial aggregations for enviromental exposure.
- Scale indicators to a common interpretation range.
- Detect and correct coordinate outliers using a robust MAD-based approach.
The package is especially useful when your raw survey data contains binary food availability columns, comma-separated produce color fields, vendor operating days or hours, latitude and longitude, vendor type, population denominators, and land-area denominators.
โ๏ธ Installation
From PyPI:
pip install nfei
Importing the package
import nfei
๐งฑ NFEI package architecture
1. Availability Module
Captures temporal access to food vendors
- Daily availability (weighted by time of day)
- Weekly availability (days open)
Reflects real-world accessibility patterns where:
- Morning to evening has higher weight than night
- Full-day and full-week operations imply maximum availability
2. Diversity Module
Captures nutritional quality of the food environment
Includes:
- Vendor Healthy Food Diversity Score (MDD-W based)
- Environment-level diversity (spatial aggregation)
- Unhealthy food exposure
Key idea:
Food diversity is a proxy for nutrient adequacy and malnutrition risk.
3. Color Diversity Module
Captures bioactive nutrient diversity using ProColor
- Maps fruits and vegetables into 6 color groups
- Counts presence across vendors or environments
This complements traditional food group diversity by capturing micronutrient richness
4. Density Module
Captures market structure and saturation
- Vendors per population
- Vendors per kmยฒ
Used to assess:
- Over-concentration vs under-service
- Accessibility at population level
5. Spatial Module
Captures environmental exposure
- Distance calculations
- Buffer-based aggregation (e.g., 50m radius)
This is critical because:
Consumers interact with food environments, not just individual vendors
6. Scaling Module
Handles normalization and comparability
- Aligns indicators to common scale (0โ10)
- Supports inversion (e.g., unhealthy food)
7. Validation Module
Ensures data quality and robustness
- Outlier detection
- Spatial consistency checks
N-FEI specific indicator construction logic
An N-FEI style indicator construction workflow usually involves these steps:
- Start with raw vendor, food availability, sanitation, and spatial data.
- Validate coordinate and required input columns.
- Compute individual food environment indicators.
- Use spatial aggregation where indicators require environmental exposure around vendors.
- Scale indicators to a common range.
- Invert negative indicators where higher raw values represent poorer food environments.
- Aggregate selected normalized indicators into a composite score.
- Compute final NFEI score
Step 1: Compute raw indicators
Examples:
mldsoverall_colorperc_vendor_availvendor_type_per_popvendor_type_per_sqkmunhealthy_food_count
Step 2: Add spatial exposure indicators when needed
Examples:
- food diversity within 50 metres
- produce color diversity within 50 metres
- sanitation or water access within 500 metres
Step 3: Normalize indicators to a common scale
Use create_linear_scale to align indicators to a common 0โ10 interpretation.
Step 4: Invert negative indicators
Unhealthy food exposure should usually be inverted before aggregation.
Step 5: Aggregate selected normalized indicators
The published N-FEI uses a simple unweighted aggregation of normalized indicators. In practice, users should only aggregate indicators that are available and appropriate for their dataset.
Example:
indicator_cols = [
"mlds_scaled",
"mlds_scaled_50m",
"overall_color_scaled",
"overall_color_scaled_50m",
"unhealthy_food_inverted",
"vendor_availability_scaled",
"vendor_per_pop_scaled",
"vendor_per_sqkm_scaled",
"access_to_sanitatn"
]
df["nfei_score"] = df[indicator_cols].mean(axis=1)
Complete example notebook
A fully reproducible simulated end-to-end workflow is provided in the end-to-end online documentation
The notebook demonstrates with the use of a simulated data:
- computing MLDS
- computing produce color diversity
- computing daily and weekly availability
- computing unhealthy food count
- computing vendor density
- computing spatial proximity aggregation
- scaling indicators
- assembling a simple N-FEI-style composite score
The example is intentionally simulated so users can run it without access to restricted or project-specific survey data.
Important notes and data assumptions
- This package provides indicator-building functions, not a single one-size-fits-all N-FEI button.
- Column names are never assumed. Users must map their own dataset columns.
- Binary variables are coded as 0/1
- Multi-response fields are comma-separated strings or already coverted to binary columns
- Spatial coordinates are in decimal degrees
- Missing values are handled explicitly where relevant.
- Spatial functions assume latitude and longitude are in decimal degrees unless otherwise specified.
- The final composite index should be assembled using indicators that are valid for the userโs specific study design.
Repository structure
Suggested project structure:
nutrition-food-environment-index/
โโโ docs/
โ โโโ api/
โ โโโ availability.md
โ โโโ color.md
โ โโโ density.md
โ โโโ diversity.md
โ โโโ scaling.md
โ โโโ spatial.md
โ โโโ validation.md
โ โโโ examples/
โ โโโ nfei_end_to_end_example.ipynb
โ โโโ getting-started.md
โ โโโ methodology.md
โ โโโ index.md
โโโ src/
โ โโโ nfei/
โ โโโ availability.py
โ โโโ color.py
โ โโโ density.py
โ โโโ diversity.py
โ โโโ scaling.py
โ โโโ spatial.py
โ โโโ validation.py
โ โโโ __init__.py
โโโ tests/
โ โโโ test_availability.py
โ โโโ test_color.py
โ โโโ test_density.py
โ โโโ test_diversity.py
โ โโโ test_public.py
โ โโโ test_scaling.py
โ โโโ test_spatial.py
โ โโโ test_validation.py
โโโ README.md
โโโ CITATION.cff
โโโ LICENSE
โโโ mkdocs.yml
โโโ pyproject.toml
Citation
If you use this package or the N-FEI methodology, please cite:
Akingbemisilu, T. H., Jordan, I., Asiimwe, R., Bodjrenou, S., Nabuuma, D., Odongo, N., Onyango, K. O., Teferi, E., Tokeshi, C., Lundy, M., & Termote, C. (2025). The Nutrition-Sensitive Food Environment Index: A Comprehensive Approach to Assessing Food Environments in Association with Health Risks for Policy Decision Making. Journal of Sustainability, 1(1). https://doi.org/10.55845/jos-2025-1116
Contributing
Contributions are welcome. Please ensure that new functionality:
- follows the transparent, modular design of the package
- includes tests
- avoids hidden assumptions about user column names
- documents expected input format and output interpretation
- remains aligned with food environment measurement logic
License
MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nfei-0.1.0.tar.gz.
File metadata
- Download URL: nfei-0.1.0.tar.gz
- Upload date:
- Size: 36.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c05064b647a49867635f25ccae0c6e74f5788ebd1a8f3e8c9f4a7c3c79194afa
|
|
| MD5 |
8078054e50507889745d5664605eab9e
|
|
| BLAKE2b-256 |
46586c8e1042d6976be7519be4dbf22633a286ed0e8fc8203033ff23d19fdd08
|
Provenance
The following attestation bundles were made for nfei-0.1.0.tar.gz:
Publisher:
publish.yml on tosmartak/nutrition-food-environment-index
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nfei-0.1.0.tar.gz -
Subject digest:
c05064b647a49867635f25ccae0c6e74f5788ebd1a8f3e8c9f4a7c3c79194afa - Sigstore transparency entry: 1439658689
- Sigstore integration time:
-
Permalink:
tosmartak/nutrition-food-environment-index@1687e7665f2d18d3764090f7756184fba87e9b57 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/tosmartak
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@1687e7665f2d18d3764090f7756184fba87e9b57 -
Trigger Event:
push
-
Statement type:
File details
Details for the file nfei-0.1.0-py3-none-any.whl.
File metadata
- Download URL: nfei-0.1.0-py3-none-any.whl
- Upload date:
- Size: 30.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2f0dc7989d059e16dbd405b8e0f2744680bc231e1c24c20aa056118b5f11b24c
|
|
| MD5 |
731a0d5dbecad133fcd1353b3d3c74ab
|
|
| BLAKE2b-256 |
331ae54646be92a440589393922ba940f86c658dd5ff8291b0139ed0f5664fbe
|
Provenance
The following attestation bundles were made for nfei-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on tosmartak/nutrition-food-environment-index
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nfei-0.1.0-py3-none-any.whl -
Subject digest:
2f0dc7989d059e16dbd405b8e0f2744680bc231e1c24c20aa056118b5f11b24c - Sigstore transparency entry: 1439658700
- Sigstore integration time:
-
Permalink:
tosmartak/nutrition-food-environment-index@1687e7665f2d18d3764090f7756184fba87e9b57 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/tosmartak
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@1687e7665f2d18d3764090f7756184fba87e9b57 -
Trigger Event:
push
-
Statement type: