# wpgp/poprf architecture

> Architecture diagram of the GitHub repository wpgp/poprf, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/wpgp/poprf
- Repository: https://github.com/wpgp/poprf

## Overview

popRF is an R package for producing fine-resolution population rasters by using random forests to inform dasymetric redistribution of census counts. The documented workflow is to provide census counts, covariates, a mastergrid, watermask, and pixel-area data to popRF, then use its raster and model outputs; the demo downloads WorldPop covariates for a country. Source excerpts were unavailable, so internal links are limited to relationships stated in the README rather than inferred from filenames.

Main entry points: [`R/popRF.R`](https://github.com/wpgp/poprf/blob/main/R/popRF.R) (Model run), [`R/popRFdemo.R`](https://github.com/wpgp/poprf/blob/main/R/popRFdemo.R) (Country demo), [`R/create_covariates_list.R`](https://github.com/wpgp/poprf/blob/main/R/create_covariates_list.R) (Geospatial covariates), [`R/popfit.R`](https://github.com/wpgp/poprf/blob/main/R/popfit.R) (Random forest)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["User entry points"]
  node_poprf["Model run<br/>[popRF.R]"]
  node_demo["Country demo<br/>[popRFdemo.R]"]
end

subgraph group_model["Population modelling"]
  node_census["Census counts"]
  node_covariates["Geospatial covariates"]
  node_mastergrid["Mastergrid"]
  node_watermask["Watermask"]
  node_pixelarea["Pixel area"]
  node_randomforest["Random forest<br/>[popfit.R]"]
  node_redistribution["Population redistribution"]
end

subgraph group_outputs["Results"]
  node_populationraster["Population raster<br/>[popRF.R]"]
  node_modeloutput["Model result<br/>[popRF.R]"]
end

node_user(("Package user"))
node_worldpop["WorldPop data"]

node_user -->|"runs with inputs"| node_poprf
node_user -->|"starts demo"| node_demo
node_poprf -->|"accepts counts"| node_census
node_poprf -->|"accepts covariates"| node_covariates
node_poprf -->|"accepts template"| node_mastergrid
node_poprf -->|"accepts mask"| node_watermask
node_poprf -->|"accepts area data"| node_pixelarea
node_poprf -->|"uses random forests"| node_randomforest
node_poprf -->|"performs redistribution"| node_redistribution
node_demo -->|"downloads covariates"| node_worldpop
node_poprf -->|"produces raster"| node_populationraster
node_poprf -->|"returns model result"| node_modeloutput

click node_poprf "https://github.com/wpgp/poprf/blob/main/R/popRF.R"
click node_demo "https://github.com/wpgp/poprf/blob/main/R/popRFdemo.R"
click node_covariates "https://github.com/wpgp/poprf/blob/main/R/create_covariates_list.R"
click node_randomforest "https://github.com/wpgp/poprf/blob/main/R/popfit.R"
click node_redistribution "https://github.com/wpgp/poprf/blob/main/R/apply_constrained.R"
click node_populationraster "https://github.com/wpgp/poprf/blob/main/R/popRF.R"
click node_modeloutput "https://github.com/wpgp/poprf/blob/main/R/popRF.R"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_poprf,node_demo,node_user toneBlue
class node_census,node_covariates,node_mastergrid,node_watermask,node_pixelarea,node_randomforest,node_redistribution toneAmber
class node_populationraster,node_modeloutput toneMint
class node_worldpop toneIndigo
```

## Components

### User entry points

- [Model run](https://github.com/wpgp/poprf/blob/main/R/popRF.R): `R/popRF.R`
- [Country demo](https://github.com/wpgp/poprf/blob/main/R/popRFdemo.R): `R/popRFdemo.R`

### Population modelling

- **Census counts**
- [Geospatial covariates](https://github.com/wpgp/poprf/blob/main/R/create_covariates_list.R): `R/create_covariates_list.R`
- **Mastergrid**
- **Watermask**
- **Pixel area**
- [Random forest](https://github.com/wpgp/poprf/blob/main/R/popfit.R): `R/popfit.R`
- [Population redistribution](https://github.com/wpgp/poprf/blob/main/R/apply_constrained.R): `R/apply_constrained.R`

### Results

- [Population raster](https://github.com/wpgp/poprf/blob/main/R/popRF.R): `R/popRF.R`
- [Model result](https://github.com/wpgp/poprf/blob/main/R/popRF.R): `R/popRF.R`

### Other components

- **Package user**
- **WorldPop data**

## Connections

- Package user → Model run: runs with inputs (evidence: `README.md`)
- Package user → Country demo: starts demo (evidence: `README.md`)
- Model run → Census counts: accepts counts (evidence: `README.md`)
- Model run → Geospatial covariates: accepts covariates (evidence: `README.md`)
- Model run → Mastergrid: accepts template (evidence: `README.md`)
- Model run → Watermask: accepts mask (evidence: `README.md`)
- Model run → Pixel area: accepts area data (evidence: `README.md`)
- Model run → Random forest: uses random forests (evidence: `README.md`)
- Model run → Population redistribution: performs redistribution (evidence: `README.md`)
- Country demo → WorldPop data: downloads covariates (evidence: `README.md`)
- Model run → Population raster: produces raster (evidence: `README.md`)
- Model run → Model result: returns model result (evidence: `README.md`)
