eduaguilera / eduaguilera/whep

build_food_supply: wire method='faostat_fbs' from the FBS per-capita elements (already in the pin)

Open
#413 4 comments 0 reactions 1 assignee Claimed by @lbm364dl View on GitHub
area:cbs area:data-io mechanical priority:medium
Dominant language
R
Stars
1
Forks
5
Avg merge
1d 11h
Merged PRs (30d)
183

Description

## What

`build_food_supply(method = "faostat_fbs")` currently requires the caller to
inject `data$fbs_supply` by hand. The wiring note in `R/food_supply.R` says the
FAOSTAT per-capita elements are unavailable because `.extract_fao()` drops them
at extraction.

They are dropped from the *extraction*, but they are present in the **pin**.
Verified by reading `faostat-fbs-new` directly (2010 slice):

| Element | Item carrying it |
|---|---|
| `Protein supply quantity (g/capita/day)` | 2901 Grand Total (and per commodity) |
| `Food supply (kcal/capita/day)` | 2901 Grand Total |
| `Food supply quantity (kg/capita/yr)` | leaf commodities only |
| `Total Population - Both sexes` | 2501 Population |

So no new data acquisition is needed — only a reader that keeps these elements.

## Why it matters

This is the nourishment axis's external validation dataset. Without it the
axis has no independent benchmark, which is exactly how #360 came to compare
WHEP against hand-transcribed FAOSTAT figures that turned out to be wrong.

Having it wired would have caught #361 immediately: the same comparison shows
WHEP's food quantity is fine (median ratio 1.015) while derived protein is
inflated 1.209x.

## Suggested action

Add a reader for the per-capita FBS elements, keyed by `year` and `area_code`,
returning `protein_g_cap_day`, `energy_kcal_cap_day` and `population`, so
`method = "faostat_fbs"` resolves from the pins rather than from an injected
list.

Two details worth encoding, both learned the hard way in
`inst/scripts/diagnose_food_supply.R`:

- Aggregate items (code >= 2900, plus 2501 Population) must be excluded when
summing leaf commodities, or the total double counts. Summed leaf protein
matches the reported Grand Total to a median relative difference of 2e-4.
- `Food supply quantity (kg/capita/yr)` is not reported on item 2901, so a
national food quantity has to be summed over leaves; protein and energy are
reported on 2901 directly.

---
Found while diagnosing #360. Depends on the same `cb_elements` allow-list as
the companion Losses/Residuals issue.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.