Skip to content

Commit 612d57f

Browse files
committed
Docs+tools: automate model onboarding (setup_model.ps1) + tabs for setup, smaller fonts, collapsible details
1 parent bc172b1 commit 612d57f

3 files changed

Lines changed: 106 additions & 30 deletions

File tree

docs/introduction/introduction_case_studies.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ As the World Bank's primary power sector planning tool, EPM has been applied in
66

77
## Coverage
88

9-
<div style="display:inline-block; margin:0.1rem 0 0.7rem 0; padding:4px 11px; border:1px solid #d8b24a; border-radius:8px; background:#fcf6e6; font-size:0.66rem; font-style:italic; color:#7a5d1e;">
9+
<div style="display:inline-block; margin:0.1rem 0 0.7rem 0; padding:3px 10px; border:1px solid #d8b24a; border-radius:8px; background:#fcf6e6; font-size:0.58rem; font-style:italic; color:#7a5d1e;">
1010
→ Explore the data &amp; results interactively in
1111
<a href="https://epm-data-explorer.vercel.app" target="_blank" rel="noopener" style="font-style:normal; font-weight:600; color:#1E6DB8;">EPM&nbsp;View</a>
1212
&nbsp;·&nbsp;<span style="color:#a98a4a;">access required — ask the team</span>

docs/run/run_data_sync.md

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Publishing & Syncing Data (DVC)
22

3+
<style>.md-typeset { font-size: 0.8rem; }</style>
4+
35
EPM **code** is public, but the **data** (input CSVs, results) is kept in a **private
46
store** — not in this public repository. The repo only keeps tiny **pointer files**
57
(`*.dvc`); the real data lives in the store and is fetched on demand.
@@ -27,23 +29,24 @@ and is moved with `dvc push` / `dvc pull`. So git stays light, and the data stay
2729

2830
You work in **your clone of the EPM repo** — the same folder you run EPM from.
2931

30-
**A. If you already run EPM on this machine** (Python env ready) — just add the data tools:
32+
=== "Already running EPM here"
3133

32-
```bash
33-
# in your EPM Python environment (the one you use to run EPM)
34-
pip install -r requirements.txt
35-
```
36-
This installs **DVC**, `s3fs`, and (on Windows) `pip-system-certs`.
34+
Your Python environment is ready — just add the data tools:
35+
```bash
36+
pip install -r requirements.txt
37+
```
38+
Installs **DVC**, `s3fs`, and (on Windows) `pip-system-certs`.
3739

38-
**B. If it's a fresh machine** — set EPM up first, then the line above:
40+
=== "Fresh machine"
3941

40-
```bash
41-
git clone https://github.com/ESMAP-World-Bank-Group/EPM.git
42-
cd EPM
43-
git checkout <your-branch> # e.g. blacksea_2026
44-
conda activate <your-epm-env> # your EPM Python environment
45-
pip install -r requirements.txt
46-
```
42+
Set EPM up first, then install:
43+
```bash
44+
git clone https://github.com/ESMAP-World-Bank-Group/EPM.git
45+
cd EPM
46+
git checkout <your-branch> # e.g. blacksea_2026
47+
conda activate <your-epm-env> # your EPM Python environment
48+
pip install -r requirements.txt
49+
```
4750

4851
**Then (both cases) add your store keys — once:**
4952

@@ -78,25 +81,32 @@ That's it — the store URL/endpoint is already in the repo (`.dvc/config`).
7881
This moves a model's data **out of git** into the store. Do it **once**, by whoever sets the
7982
model up; afterwards everyone just uses *setup + publish/sync*.
8083

84+
**One command** (from the repo root) — it asks for confirmation, then makes the change locally:
85+
8186
```bash
82-
# 1. Initialise DVC for the repo (once per repo)
83-
dvc init
87+
powershell -File tools/setup_model.ps1 data_<model> # e.g. data_sapp
88+
```
8489

85-
# 2. Point DVC at the store
86-
dvc remote add -d store s3://<bucket>/dvcstore
87-
dvc remote modify store endpointurl <endpoint>
90+
Then **review** (`git status`) and **publish** (double-click `Publish.bat`). Finally, to make
91+
**EPM View** show this model, add its branch name to `R2_BRANCHES` in `src/utils/epmFetch.js`
92+
of the `epm-data-explorer` repo.
8893

89-
# 3. In .gitignore: remove the line that force-tracks your data folder,
90-
# and add an exception for its pointer:
91-
# !epm/input/data_<model>.dvc
94+
??? info "What `setup_model.ps1` does under the hood (the manual steps)"
95+
The script automates exactly these — your files **stay on disk**, and it commits/pushes
96+
nothing (you review, then publish):
9297

93-
# 4. Stop tracking the data in git (files stay on your disk), then hand it to DVC
94-
git rm -r --cached epm/input/data_<model>
95-
dvc add epm/input/data_<model> # creates the .dvc pointer
96-
```
97-
98-
Then **publish** (step 4). Finally, to make **EPM View** read this model from the store, add
99-
its branch name to `R2_BRANCHES` in `src/utils/epmFetch.js` of the `epm-data-explorer` repo.
98+
```bash
99+
# 1. Initialise DVC for the repo (once per repo)
100+
dvc init
101+
# 2. Point DVC at the store (once — already set in this repo's .dvc/config)
102+
dvc remote add -d store s3://<bucket>/dvcstore
103+
dvc remote modify store endpointurl <endpoint>
104+
# 3. .gitignore: drop the whitelist of the data folder, keep its pointer tracked
105+
# !epm/input/data_<model>.dvc
106+
# 4. Stop tracking the data in git (files stay), then hand the folder to DVC
107+
git rm -r --cached epm/input/data_<model>
108+
dvc add epm/input/data_<model> # creates the .dvc pointer
109+
```
100110

101111
---
102112

@@ -163,5 +173,6 @@ run the model with up-to-date data.
163173
|------|------|
164174
| `publish.ps1` | engine behind `Publish.bat` |
165175
| `sync.ps1` / `sync.sh` | get code + data (Windows / server) |
176+
| `setup_model.ps1` | onboard a new model's data to the store (one-time, step 3) |
166177
| `upload_to_r2.py`, `upload_output_view_to_r2.py` | upload the readable copies |
167178
| `.env.example` | keys template (copy to `.env`, git-ignored) |

tools/setup_model.ps1

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# setup_model.ps1 — onboard a model's data to the private store (one-time, per model).
2+
#
3+
# Usage: powershell -File tools/setup_model.ps1 data_<model>
4+
# Example: powershell -File tools/setup_model.ps1 data_sapp
5+
#
6+
# Moves a data folder OUT of git into DVC (the store). Files stay on your disk.
7+
# This script only makes LOCAL changes — review them, then publish with Publish.bat.
8+
9+
param([Parameter(Mandatory = $true)][string]$DataFolder)
10+
11+
$ErrorActionPreference = "Stop"
12+
$TOOLS = $PSScriptRoot
13+
$REPO = Split-Path $TOOLS -Parent
14+
Set-Location $REPO
15+
16+
$path = "epm/input/$DataFolder"
17+
if (-not (Test-Path $path)) { Write-Error "Not found: $path"; exit 1 }
18+
19+
$branch = (git rev-parse --abbrev-ref HEAD).Trim()
20+
Write-Host ""
21+
Write-Host "Repo : $REPO" -ForegroundColor DarkGray
22+
Write-Host "Branch : $branch" -ForegroundColor DarkGray
23+
Write-Host "Folder : $path" -ForegroundColor DarkGray
24+
Write-Host ""
25+
Write-Host "This moves '$path' OUT of git into DVC/the store." -ForegroundColor Yellow
26+
Write-Host "Files STAY on your disk; on your next push the data leaves the public repo." -ForegroundColor Yellow
27+
if ((Read-Host "Continue? (y/N)") -ne "y") { Write-Host "Aborted."; exit 0 }
28+
29+
# 1. DVC init (once per repo)
30+
if (-not (Test-Path ".dvc")) {
31+
Write-Host "[1/4] dvc init"
32+
dvc init | Out-Null
33+
Write-Host " /!\ remote not configured. Run once, then re-run this script:" -ForegroundColor DarkYellow
34+
Write-Host " dvc remote add -d store s3://<bucket>/dvcstore" -ForegroundColor DarkYellow
35+
Write-Host " dvc remote modify store endpointurl <endpoint>" -ForegroundColor DarkYellow
36+
} else {
37+
Write-Host "[1/4] dvc already initialised"
38+
}
39+
40+
# 2. .gitignore: drop the whitelist of the folder, keep only its .dvc pointer tracked
41+
Write-Host "[2/4] update .gitignore"
42+
$gi = ".gitignore"
43+
$esc = [regex]::Escape("epm/input/$DataFolder")
44+
$lines = Get-Content $gi | Where-Object { $_ -notmatch "^\!$esc(/|$)" } # remove !epm/input/<folder>/ and /**
45+
$ptr = "!epm/input/$DataFolder.dvc"
46+
if ($lines -notcontains $ptr) {
47+
# make sure the data folder is ignored at all (covers the 'epm/input/*' pattern repos)
48+
if (-not (Select-String -Path $gi -SimpleMatch "epm/input/*" -Quiet)) { $lines += "epm/input/$DataFolder/" }
49+
$lines += $ptr
50+
}
51+
Set-Content $gi $lines
52+
53+
# 3+4. stop tracking in git (files stay on disk), then hand the folder to DVC
54+
Write-Host "[3/4] git rm --cached (untrack, files stay on disk)"
55+
git rm -r --cached $path | Out-Null
56+
Write-Host "[4/4] dvc add (create the pointer)"
57+
dvc add $path
58+
59+
Write-Host ""
60+
Write-Host "DONE (local changes only)." -ForegroundColor Green
61+
Write-Host "Next:" -ForegroundColor Green
62+
Write-Host " 1. review : git status"
63+
Write-Host " 2. publish : double-click Publish.bat"
64+
Write-Host " 3. EPM View : add '$branch' to R2_BRANCHES in"
65+
Write-Host " epm-data-explorer/src/utils/epmFetch.js"

0 commit comments

Comments
 (0)