Skip to main content

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)

Python License CI Docs Status Research

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:

  1. Vendor Healthy Food Diversity Score, using food groups aligned with the Minimum Dietary Diversity for Women framework.
  2. Vendor Environment Healthy Food Diversity Score, capturing what is available around vendors, not only at a single vendor.
  3. Vendor ProColor Diversity Score, Fruit and vegetable color diversity reflecting ProColor-style produce diversity.
  4. Vendor Environment ProColor Diversity Score, capturing the broader produce-color environment around vendors.
  5. Access to Water and Sanitation, especially relevant for informal and mobile food vendors.
  6. Vendor availability, measured through daily and weekly operating patterns.
  7. Vendor density per population, capturing vendor availability relative to population size.
  8. Vendor density per square kilometre, capturing geographic distribution.
  9. 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:

  1. Start with raw vendor, food availability, sanitation, and spatial data.
  2. Validate coordinate and required input columns.
  3. Compute individual food environment indicators.
  4. Use spatial aggregation where indicators require environmental exposure around vendors.
  5. Scale indicators to a common range.
  6. Invert negative indicators where higher raw values represent poorer food environments.
  7. Aggregate selected normalized indicators into a composite score.
  8. Compute final NFEI score

Step 1: Compute raw indicators

Examples:

  • mlds
  • overall_color
  • perc_vendor_avail
  • vendor_type_per_pop
  • vendor_type_per_sqkm
  • unhealthy_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

  1. This package provides indicator-building functions, not a single one-size-fits-all N-FEI button.
  2. Column names are never assumed. Users must map their own dataset columns.
  3. Binary variables are coded as 0/1
  4. Multi-response fields are comma-separated strings or already coverted to binary columns
  5. Spatial coordinates are in decimal degrees
  6. Missing values are handled explicitly where relevant.
  7. Spatial functions assume latitude and longitude are in decimal degrees unless otherwise specified.
  8. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nfei-0.1.0.tar.gz (36.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nfei-0.1.0-py3-none-any.whl (30.8 kB view details)

Uploaded Python 3

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

Hashes for nfei-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c05064b647a49867635f25ccae0c6e74f5788ebd1a8f3e8c9f4a7c3c79194afa
MD5 8078054e50507889745d5664605eab9e
BLAKE2b-256 46586c8e1042d6976be7519be4dbf22633a286ed0e8fc8203033ff23d19fdd08

See more details on using hashes here.

Provenance

The following attestation bundles were made for nfei-0.1.0.tar.gz:

Publisher: publish.yml on tosmartak/nutrition-food-environment-index

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for nfei-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2f0dc7989d059e16dbd405b8e0f2744680bc231e1c24c20aa056118b5f11b24c
MD5 731a0d5dbecad133fcd1353b3d3c74ab
BLAKE2b-256 331ae54646be92a440589393922ba940f86c658dd5ff8291b0139ed0f5664fbe

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page