Archive 4 checkpoints (1-4)
Browse files- .gitattributes +2 -0
- paper-releases/pbisc-diffusion/updates/20261002T085943Z-deck-restructure-contrast-metrics-zeroshot-len/diffusion/dataset/server_1/model8/presentations/2026-09-30--paper-summary--r00/PBISC-Diffusion_paper_summary_20260930.pdf +3 -0
- paper-releases/pbisc-diffusion/updates/20261002T085943Z-deck-restructure-contrast-metrics-zeroshot-len/diffusion/dataset/server_1/model8/presentations/2026-09-30--paper-summary--r00/PBISC-Diffusion_paper_summary_20260930.pptx +3 -0
- paper-releases/pbisc-diffusion/updates/20261002T085943Z-deck-restructure-contrast-metrics-zeroshot-len/diffusion/dataset/server_1/model8/presentations/2026-09-30--paper-summary--r00/README.md +103 -0
- paper-releases/pbisc-diffusion/updates/20261002T085943Z-deck-restructure-contrast-metrics-zeroshot-len/diffusion/dataset/server_1/model8/presentations/2026-09-30--paper-summary--r00/generate_deck.py +361 -0
.gitattributes
CHANGED
|
@@ -78,3 +78,5 @@ paper-releases/pbisc-diffusion/updates/20261002T022002Z-deck-time-to-apply-scsem
|
|
| 78 |
paper-releases/pbisc-diffusion/updates/20261002T022002Z-deck-time-to-apply-scsemi-reps/diffusion/dataset/server_1/model8/plans/paired_finetune_intradataset_20260927/scsemi/work/immicro/fewshot_n5/draw0/scsemi_project/processed_bulkdata.h5ad filter=lfs diff=lfs merge=lfs -text
|
| 79 |
paper-releases/pbisc-diffusion/updates/20261002T022002Z-deck-time-to-apply-scsemi-reps/diffusion/dataset/server_1/model8/plans/paired_finetune_intradataset_20260927/scsemi/work/ji2025_chili/fewshot_n5/draw0/scsemi_project/processed_bulkdata.h5ad filter=lfs diff=lfs merge=lfs -text
|
| 80 |
paper-releases/pbisc-diffusion/updates/20261002T022002Z-deck-time-to-apply-scsemi-reps/diffusion/dataset/server_1/model8/plans/paired_finetune_intradataset_20260927/scsemi/work/ye2026_sepsis/fewshot_n5/draw0/scsemi_project/processed_bulkdata.h5ad filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
| 78 |
paper-releases/pbisc-diffusion/updates/20261002T022002Z-deck-time-to-apply-scsemi-reps/diffusion/dataset/server_1/model8/plans/paired_finetune_intradataset_20260927/scsemi/work/immicro/fewshot_n5/draw0/scsemi_project/processed_bulkdata.h5ad filter=lfs diff=lfs merge=lfs -text
|
| 79 |
paper-releases/pbisc-diffusion/updates/20261002T022002Z-deck-time-to-apply-scsemi-reps/diffusion/dataset/server_1/model8/plans/paired_finetune_intradataset_20260927/scsemi/work/ji2025_chili/fewshot_n5/draw0/scsemi_project/processed_bulkdata.h5ad filter=lfs diff=lfs merge=lfs -text
|
| 80 |
paper-releases/pbisc-diffusion/updates/20261002T022002Z-deck-time-to-apply-scsemi-reps/diffusion/dataset/server_1/model8/plans/paired_finetune_intradataset_20260927/scsemi/work/ye2026_sepsis/fewshot_n5/draw0/scsemi_project/processed_bulkdata.h5ad filter=lfs diff=lfs merge=lfs -text
|
| 81 |
+
paper-releases/pbisc-diffusion/updates/20261002T085943Z-deck-restructure-contrast-metrics-zeroshot-len/diffusion/dataset/server_1/model8/presentations/2026-09-30--paper-summary--r00/PBISC-Diffusion_paper_summary_20260930.pdf filter=lfs diff=lfs merge=lfs -text
|
| 82 |
+
paper-releases/pbisc-diffusion/updates/20261002T085943Z-deck-restructure-contrast-metrics-zeroshot-len/diffusion/dataset/server_1/model8/presentations/2026-09-30--paper-summary--r00/PBISC-Diffusion_paper_summary_20260930.pptx filter=lfs diff=lfs merge=lfs -text
|
paper-releases/pbisc-diffusion/updates/20261002T085943Z-deck-restructure-contrast-metrics-zeroshot-len/diffusion/dataset/server_1/model8/presentations/2026-09-30--paper-summary--r00/PBISC-Diffusion_paper_summary_20260930.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e392eb0e282a657d15588cdf3e3bc5395f97e5fe334d733628178a468d712908
|
| 3 |
+
size 6270469
|
paper-releases/pbisc-diffusion/updates/20261002T085943Z-deck-restructure-contrast-metrics-zeroshot-len/diffusion/dataset/server_1/model8/presentations/2026-09-30--paper-summary--r00/PBISC-Diffusion_paper_summary_20260930.pptx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f2191c33ebbb5e08e3be4f93805dcc1c3ee1c4cfd62446b4eda729316694f5d7
|
| 3 |
+
size 7091989
|
paper-releases/pbisc-diffusion/updates/20261002T085943Z-deck-restructure-contrast-metrics-zeroshot-len/diffusion/dataset/server_1/model8/presentations/2026-09-30--paper-summary--r00/README.md
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# PBISC-Diffusion paper summary deck (2026-09-30, r00; restructured 2026-10-02)
|
| 2 |
+
|
| 3 |
+
35-slide English summary of the PBISC-Diffusion (Model 8) paper experiments: title, outline and 10 sections
|
| 4 |
+
(33 content slides). There is no Backup section: every slide sits in the section it supports. Short keyword lines
|
| 5 |
+
only; the figures carry the results. Every slide that uses a published method, metric or baseline has a one-line
|
| 6 |
+
"References:" footer; full citations are in the speaker notes. Section 10 is planned work.
|
| 7 |
+
|
| 8 |
+
- `PBISC-Diffusion_paper_summary_20260930.pptx`: the deck
|
| 9 |
+
- `PBISC-Diffusion_paper_summary_20260930.pdf`: LibreOffice PDF of the deck
|
| 10 |
+
- `data/slides_spec.json`: slide order, titles, keywords, footnotes, references, speaker-note text
|
| 11 |
+
- `generate_deck.py`: builds the pptx from `data/slides_spec.json` only (python-pptx)
|
| 12 |
+
- `figures/`: exactly the figures the slides show (PNG + PDF), made by `tools/sec*.py`. Intermediate panels go to a
|
| 13 |
+
temporary folder; superseded figures are deleted, not kept (2026-10-02, user request; every deleted file was
|
| 14 |
+
checked to be in the paper archive by sha256 first).
|
| 15 |
+
- `data/sec*.csv` and `data/*_slide_text.json`: every plotted or quoted number with its source path
|
| 16 |
+
- `render/`: PDF and 70-dpi slide JPGs for checking
|
| 17 |
+
|
| 18 |
+
## Slide order
|
| 19 |
+
|
| 20 |
+
| section | slides |
|
| 21 |
+
|---|---|
|
| 22 |
+
| 1 Model overview | bulk in, cells out; denoiser |
|
| 23 |
+
| 2 Backbone | SDD → PBISC-Diffusion; bulk conditioning |
|
| 24 |
+
| 3 Architecture ablation | width & context (loss, benchmark); gene panel |
|
| 25 |
+
| 4 Metrics + SLE benchmark | **how we score generated cells** (metric table with references); SLE benchmark; per cell type; bulk broadcast baseline |
|
| 26 |
+
| 5 Real bulk vs pseudobulk | input shift; same shift in three cohorts; cells off-manifold; disease direction flips |
|
| 27 |
+
| 6 Paired fine-tuning | method; evaluation design |
|
| 28 |
+
| 7 LoRA ablations | full vs LoRA vs cond.-encoder-only; LoRA rank r = 4 / 16 / 64; K diversification |
|
| 29 |
+
| 8 Pairs needed | composition / coverage / steps; donor and disease signal |
|
| 30 |
+
| 9 Paired validation | cohorts; 5 donors: cells, realism beyond P/C, P/C at k = 3 / 5 / 10, scSemiProfiler copies its representative, disease signal, CAT curves, time to apply; 5-fold CV and its realism metrics |
|
| 31 |
+
| 10 Paired-subset cohorts | planned |
|
| 32 |
+
|
| 33 |
+
## Rebuild
|
| 34 |
+
|
| 35 |
+
Everything is CPU only; no GPU or checkpoint is touched.
|
| 36 |
+
|
| 37 |
+
```bash
|
| 38 |
+
# prerequisites (plan folder plans/paired_finetune_intradataset_20260927/, CPU):
|
| 39 |
+
# scsemi/tools/representative_dependence.py -> scsemi/analysis/representative_dependence_20261002/
|
| 40 |
+
# tools/contrast_extra.py (+ tools/contrast_extra_tables.py) -> scores_contrast/ (Spearman, ceiling, limma, CAT, RBO)
|
| 41 |
+
# tools/build_tpm_zeroshot.py + tools/score_tpm_zeroshot.sh -> scores/<ds>/zeroshot_tpm_20261002/pooled/
|
| 42 |
+
# (the length-corrected zero-shot arm needs one GPU sampling step: tools/sample_lockwait.sh, coordinator only)
|
| 43 |
+
cd /home/sj_server_1/PBISC/immun-pbmc-fm/model_8_sparse_data_diffusion/presentations/2026-09-30--paper-summary--r00
|
| 44 |
+
# shared helpers, not run directly: style.py, sec03_common.py, scsemi_results.py, fold_sizes.py
|
| 45 |
+
for f in sec01_overview sec02_backbone sec03_width_loss sec03_width_bench sec03_panel \
|
| 46 |
+
sec04_metrics_overview sec04_sle_benchmark sec05_condition_space sec05_cells_offmanifold \
|
| 47 |
+
sec05_behcet_direction sec05_shift_cohorts sec06_finetune_method sec07_ft_modes \
|
| 48 |
+
sec07_k_aug sec07_rank_sweep sec08_pairs_needed sec09_paired_validation sec09_extra_metrics \
|
| 49 |
+
sec09_time_to_apply sec09_scsemi_representative sec09_cat_curves sec10_paired_subset_cohorts; do
|
| 50 |
+
python3 "tools/$f.py" || break
|
| 51 |
+
done
|
| 52 |
+
python3 tools/sync_sec09_text.py # copy every generated slide text (sec09_index / text_source) into the spec
|
| 53 |
+
python3 generate_deck.py # -> PBISC-Diffusion_paper_summary_20260930.pptx
|
| 54 |
+
soffice --headless --convert-to pdf --outdir render PBISC-Diffusion_paper_summary_20260930.pptx
|
| 55 |
+
pdftoppm -jpeg -r 70 render/PBISC-Diffusion_paper_summary_20260930.pdf render/slide
|
| 56 |
+
cp render/PBISC-Diffusion_paper_summary_20260930.pdf .
|
| 57 |
+
```
|
| 58 |
+
|
| 59 |
+
`generate_deck.py` stops with an error if a figure is missing, a title does not fit on one line, a footnote needs
|
| 60 |
+
more than 2 lines (1 line when the slide has references), the reference line needs more than 1 line, or any text
|
| 61 |
+
contains Korean or placeholder words. `tools/restructure_20261002.py` is the one-off script that produced the current
|
| 62 |
+
slide order and the references (it refuses to run twice).
|
| 63 |
+
|
| 64 |
+
## Notes
|
| 65 |
+
|
| 66 |
+
- **No "all" label (2026-10-02).** The 5-fold arm trains each fold model on the other four folds minus 7–8
|
| 67 |
+
inner-validation donors; its test fold is never trained on (RUN.json `test_rows_never_loaded_for_training`). Figures
|
| 68 |
+
label it "5-fold CV (other 4 folds)" and learning-curve ticks show the training-pair count per fold (78–79 ImMicro,
|
| 69 |
+
58–59 sepsis), read by `tools/fold_sizes.py`.
|
| 70 |
+
- **Learning curve x = 0 uses no pairs (2026-10-02).** It shows the zero-shot model fed the real bulk as measured
|
| 71 |
+
and after exon-length correction (counts / Ensembl union-exon kb, then the same fixed-depth arithmetic;
|
| 72 |
+
`plans/.../tools/build_tpm_zeroshot.py`, scored in `scores/<ds>/zeroshot_tpm_20261002/pooled`). The old x = 0
|
| 73 |
+
calibration point, whose alpha used every training pair of the fold, is gone; calibration appears only fitted on the
|
| 74 |
+
same n pairs as the LoRA point (squares; `cal_budget_20261001`).
|
| 75 |
+
- **Disease metrics (2026-10-02).** Next to Pearson logFC r and the Welch top-50 DEG overlap: Spearman r, the
|
| 76 |
+
split-half ceiling (observed vs observed, Spearman–Brown), limma-voom top-50 DEG, each arm's chance overlap, and
|
| 77 |
+
CAT curves with the k / 2G chance line (`plans/.../scores_contrast/`, tools/contrast_extra.py; every Pearson r and
|
| 78 |
+
Welch count reproduced exactly). Repeated samples of one patient (Imperial, Giroux, Ji) count as separate samples in
|
| 79 |
+
both DE tests, as in the scorer (footnote).
|
| 80 |
+
- Section 9 text is generated: `tools/sec09_paired_validation.py`, `sec09_extra_metrics.py`, `sec07_rank_sweep.py`,
|
| 81 |
+
`sec09_time_to_apply.py`, `sec09_scsemi_representative.py`, `sec09_cat_curves.py` write slide text JSON; sync copies
|
| 82 |
+
it. Hand-written: the keywords of the two "Pairs needed" slides (section 8) and of every slide in sections 1–7 and 10.
|
| 83 |
+
- Giroux's disease metrics exclude 196 sex-linked genes (severity is confounded with sex), from
|
| 84 |
+
`plans/.../scores_nosex/`. The calibration comparator is "Zero-shot + calibration" (user decision 2026-10-01).
|
| 85 |
+
- Story rule (user decision 2026-09-30): no PBISC-VAE and no reference calibration (refcal). The exon-length-corrected
|
| 86 |
+
input is used only as the no-pair x = 0 point of the learning curve (user decision 2026-10-02).
|
| 87 |
+
`tools/sec04_immicro.py` (refcal vs scSemiProfiler on ImMicro) is kept but is not part of the deck or the rebuild.
|
| 88 |
+
- scSemiProfiler 5-fold and equal-budget results are picked up automatically when they appear (`tools/scsemi_results.py`;
|
| 89 |
+
arm `scsemi__raw` in `scores/<cohort>/scsemi_cv_20261002/pooled*/`, `scsemi_n{5,10,20,40}__raw` in
|
| 90 |
+
`scores/<cohort>/scsemi_budget_20261002/pooled*/`; same donors and reference cells as the main pooled call only).
|
| 91 |
+
Then rerun sections 8 and 9, sync, recheck the section 8 keywords and rebuild.
|
| 92 |
+
- Earlier versions: `_archive/2026-09-30_before_no_vae_refcal/`, `_archive/2026-10-01_before_extra_metrics/`,
|
| 93 |
+
`_archive/2026-10-02_before_time_to_apply/`, `_archive/2026-10-02_before_restructure/` (pptx, PDF, spec; their
|
| 94 |
+
figures are in the paper archive). `DRAFT_1150_*`: the copy shown at the 2026-09-30 12:00 meeting.
|
| 95 |
+
|
| 96 |
+
## Sources
|
| 97 |
+
|
| 98 |
+
Final model: `runs/f01_6k_1x_seed20260627` (epoch 16, EMA). Scores and receipts come from
|
| 99 |
+
`plans/utility_studies_final6k_20260925/`, `plans/paired_finetune_intradataset_20260927/`,
|
| 100 |
+
`plans/immicro_scsemi_comparison_20260927/`, `plans/floor01_campaign_20260923/`,
|
| 101 |
+
`analysis/scsemi_benchmark_diffusion_20260913/` and the run folders named in each `data/sec*.csv`. Reference PDFs:
|
| 102 |
+
`/home/sj_server_1/PBISC/paper-release-20260928/reference-papers/` (INDEX.md). Manuscript:
|
| 103 |
+
`/home/sj_server_1/PBISC/paper-release-20260928/manuscript/`.
|
paper-releases/pbisc-diffusion/updates/20261002T085943Z-deck-restructure-contrast-metrics-zeroshot-len/diffusion/dataset/server_1/model8/presentations/2026-09-30--paper-summary--r00/generate_deck.py
ADDED
|
@@ -0,0 +1,361 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Build the PBISC-Diffusion paper-summary deck.
|
| 3 |
+
|
| 4 |
+
Reads data/slides_spec.json only and writes
|
| 5 |
+
PBISC-Diffusion_paper_summary_20260930.pptx next to this script.
|
| 6 |
+
Rerunnable; CPU only.
|
| 7 |
+
|
| 8 |
+
Design rules (user request: plain, clean, no decoration):
|
| 9 |
+
16:9 13.333 x 7.5 in, white background, Arial only.
|
| 10 |
+
Text #1A1A1A, footnotes / labels #6E6E6E. Colour only inside figures.
|
| 11 |
+
Title 26 pt bold at (0.45, 0.30); section label 11 pt grey, top right.
|
| 12 |
+
Figures fill x 0.45-12.9, y 1.05-6.75, aspect kept, never cropped.
|
| 13 |
+
Keywords 16 pt, max 3 lines of content, beside or below the figure.
|
| 14 |
+
Footnote 9 pt grey from y 7.0, at most 2 lines; slide number bottom right.
|
| 15 |
+
With 'refs' (short citations) the footer is one footnote line plus one 'References:' line;
|
| 16 |
+
'refs_full' (full citations with DOI) goes to the speaker notes.
|
| 17 |
+
|
| 18 |
+
The script measures text with the Arial TrueType metrics and fails loudly
|
| 19 |
+
if a title, keyword block or footnote would not fit.
|
| 20 |
+
"""
|
| 21 |
+
from __future__ import annotations
|
| 22 |
+
|
| 23 |
+
import json
|
| 24 |
+
import re
|
| 25 |
+
import sys
|
| 26 |
+
from pathlib import Path
|
| 27 |
+
|
| 28 |
+
from PIL import Image, ImageFont
|
| 29 |
+
from pptx import Presentation
|
| 30 |
+
from pptx.dml.color import RGBColor
|
| 31 |
+
from pptx.enum.text import MSO_ANCHOR, PP_ALIGN
|
| 32 |
+
from pptx.util import Emu, Inches, Pt
|
| 33 |
+
|
| 34 |
+
DECK = Path(__file__).resolve().parent
|
| 35 |
+
SPEC = DECK / "data" / "slides_spec.json"
|
| 36 |
+
|
| 37 |
+
# ---------------------------------------------------------------- geometry
|
| 38 |
+
SLIDE_W, SLIDE_H = 13.333, 7.5
|
| 39 |
+
X0, X1 = 0.45, 12.9 # content left / right
|
| 40 |
+
Y0, YFIG1 = 1.05, 6.75 # figure top / bottom limit
|
| 41 |
+
KW_BOTTOM = 6.85 # keywords below a figure must end here
|
| 42 |
+
FOOT_Y = 7.0 # footnote top
|
| 43 |
+
FOOT_W = 11.6 # leaves room for the slide number
|
| 44 |
+
GAP_BELOW = 0.20 # figure -> keywords (below)
|
| 45 |
+
GAP_RIGHT = 0.35 # figure -> keyword column (right)
|
| 46 |
+
MIN_COL = 2.9 # narrowest keyword column
|
| 47 |
+
FIG_GAP = 0.25 # between two figures
|
| 48 |
+
|
| 49 |
+
INK = RGBColor(0x1A, 0x1A, 0x1A)
|
| 50 |
+
GREY = RGBColor(0x6E, 0x6E, 0x6E)
|
| 51 |
+
WHITE = RGBColor(0xFF, 0xFF, 0xFF)
|
| 52 |
+
FONT = "Arial"
|
| 53 |
+
|
| 54 |
+
TITLE_PT, LABEL_PT, KW_PT, FOOT_PT, NUM_PT = 26, 11, 16, 9, 9
|
| 55 |
+
AGENDA_PT, COVER_PT, COVER_SUB_PT = 18, 36, 18
|
| 56 |
+
LINE = 1.2 # line height / font size used for layout
|
| 57 |
+
KW_PARA_GAP_PT = 6
|
| 58 |
+
|
| 59 |
+
_FONT_FILES = {
|
| 60 |
+
False: "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf",
|
| 61 |
+
True: "/usr/share/fonts/truetype/msttcorefonts/arialbd.ttf",
|
| 62 |
+
}
|
| 63 |
+
_font_cache: dict = {}
|
| 64 |
+
|
| 65 |
+
HANGUL = re.compile("[ᄀ-ᇿ-가-힣]")
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def text_w_in(text: str, pt: float, bold: bool = False) -> float:
|
| 69 |
+
"""Rendered width of one line in inches (Arial metrics)."""
|
| 70 |
+
key = bold
|
| 71 |
+
if key not in _font_cache:
|
| 72 |
+
_font_cache[key] = ImageFont.truetype(_FONT_FILES[bold], 1000)
|
| 73 |
+
return _font_cache[key].getlength(text) * pt / 1000.0 / 72.0
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def wrap(text: str, pt: float, width_in: float, bold: bool = False) -> list[str]:
|
| 77 |
+
words, lines, cur = text.split(" "), [], ""
|
| 78 |
+
for w in words:
|
| 79 |
+
trial = w if not cur else cur + " " + w
|
| 80 |
+
if text_w_in(trial, pt, bold) <= width_in:
|
| 81 |
+
cur = trial
|
| 82 |
+
else:
|
| 83 |
+
if cur:
|
| 84 |
+
lines.append(cur)
|
| 85 |
+
cur = w
|
| 86 |
+
if cur:
|
| 87 |
+
lines.append(cur)
|
| 88 |
+
return lines
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
def line_h(pt: float) -> float:
|
| 92 |
+
return pt * LINE / 72.0
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
def kw_block_h(keywords: list[str], width_in: float) -> float:
|
| 96 |
+
n_lines = sum(len(wrap(k, KW_PT, width_in)) for k in keywords)
|
| 97 |
+
return n_lines * line_h(KW_PT) + (len(keywords) - 1) * KW_PARA_GAP_PT / 72.0
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
# ---------------------------------------------------------------- helpers
|
| 101 |
+
def check_text(s: str, where: str) -> None:
|
| 102 |
+
if HANGUL.search(s):
|
| 103 |
+
sys.exit(f"Korean text in {where}: {s!r}")
|
| 104 |
+
for bad in ("TODO", "TBD", "lorem", "xxxx", "PLACEHOLDER"):
|
| 105 |
+
if bad.lower() in s.lower():
|
| 106 |
+
sys.exit(f"placeholder text {bad!r} in {where}: {s!r}")
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
def white_bg(slide) -> None:
|
| 110 |
+
fill = slide.background.fill
|
| 111 |
+
fill.solid()
|
| 112 |
+
fill.fore_color.rgb = WHITE
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
def add_text(slide, x, y, w, h, paras, pt, color=INK, bold=False,
|
| 116 |
+
align=PP_ALIGN.LEFT, anchor=MSO_ANCHOR.TOP, wrap_text=True,
|
| 117 |
+
space_before_pt=0):
|
| 118 |
+
"""paras: list of strings, one paragraph each."""
|
| 119 |
+
tb = slide.shapes.add_textbox(Inches(x), Inches(y), Inches(w), Inches(h))
|
| 120 |
+
tf = tb.text_frame
|
| 121 |
+
tf.word_wrap = wrap_text
|
| 122 |
+
tf.auto_size = None
|
| 123 |
+
tf.margin_left = tf.margin_right = tf.margin_top = tf.margin_bottom = Emu(0)
|
| 124 |
+
tf.vertical_anchor = anchor
|
| 125 |
+
for i, text in enumerate(paras):
|
| 126 |
+
p = tf.paragraphs[0] if i == 0 else tf.add_paragraph()
|
| 127 |
+
p.alignment = align
|
| 128 |
+
p.line_spacing = 1.0
|
| 129 |
+
if i > 0 and space_before_pt:
|
| 130 |
+
p.space_before = Pt(space_before_pt)
|
| 131 |
+
r = p.add_run()
|
| 132 |
+
r.text = text
|
| 133 |
+
f = r.font
|
| 134 |
+
f.name = FONT
|
| 135 |
+
f.size = Pt(pt)
|
| 136 |
+
f.bold = bold
|
| 137 |
+
f.color.rgb = color
|
| 138 |
+
return tb
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
def add_title(slide, title: str, label: str | None) -> None:
|
| 142 |
+
label_w = text_w_in(label, LABEL_PT) if label else 0.0
|
| 143 |
+
room = (X1 - X0) - (label_w + 0.3 if label else 0.0)
|
| 144 |
+
tw = text_w_in(title, TITLE_PT, bold=True)
|
| 145 |
+
if tw > room:
|
| 146 |
+
sys.exit(f"title too long ({tw:.2f} > {room:.2f} in): {title!r}")
|
| 147 |
+
# title box stops short of the section label so the two never overlap
|
| 148 |
+
add_text(slide, X0, 0.30, min(12.4, room), 0.5, [title], TITLE_PT,
|
| 149 |
+
bold=True, wrap_text=False)
|
| 150 |
+
if label:
|
| 151 |
+
# baseline of the label aligned with the title baseline
|
| 152 |
+
asc = 0.905
|
| 153 |
+
y = 0.30 + asc * TITLE_PT / 72.0 - asc * LABEL_PT / 72.0
|
| 154 |
+
add_text(slide, X1 - label_w - 0.05, y, label_w + 0.05, 0.25, [label],
|
| 155 |
+
LABEL_PT,
|
| 156 |
+
color=GREY, align=PP_ALIGN.RIGHT, wrap_text=False)
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
def refs_line(refs: list[str] | None) -> str | None:
|
| 160 |
+
return ("References: " + "; ".join(refs)) if refs else None
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
def add_footer(slide, footnote: str | None, number: int, refs: list[str] | None = None) -> None:
|
| 164 |
+
ref = refs_line(refs)
|
| 165 |
+
if ref:
|
| 166 |
+
# one footnote line + one reference line (2026-10-02: every slide cites the papers behind its method or metric)
|
| 167 |
+
if footnote and len(wrap(footnote, FOOT_PT, FOOT_W)) > 1:
|
| 168 |
+
sys.exit(f"footnote must fit one line when the slide has references: {footnote!r}")
|
| 169 |
+
if len(wrap(ref, FOOT_PT, FOOT_W)) > 1:
|
| 170 |
+
sys.exit(f"reference line needs more than one line: {ref!r}")
|
| 171 |
+
check_text(ref, "references")
|
| 172 |
+
y = FOOT_Y
|
| 173 |
+
if footnote:
|
| 174 |
+
add_text(slide, X0, y, FOOT_W, line_h(FOOT_PT) + 0.02, [footnote], FOOT_PT, color=GREY)
|
| 175 |
+
y += line_h(FOOT_PT) + 0.02
|
| 176 |
+
add_text(slide, X0, y, FOOT_W, line_h(FOOT_PT) + 0.02, [ref], FOOT_PT, color=GREY)
|
| 177 |
+
elif footnote:
|
| 178 |
+
lines = wrap(footnote, FOOT_PT, FOOT_W)
|
| 179 |
+
if len(lines) > 2:
|
| 180 |
+
sys.exit(f"footnote needs {len(lines)} lines (max 2): {footnote!r}")
|
| 181 |
+
add_text(slide, X0, FOOT_Y, FOOT_W, 2 * line_h(FOOT_PT) + 0.02,
|
| 182 |
+
[footnote], FOOT_PT, color=GREY)
|
| 183 |
+
add_text(slide, X1 - 0.6, FOOT_Y, 0.6, line_h(NUM_PT), [str(number)],
|
| 184 |
+
NUM_PT, color=GREY, align=PP_ALIGN.RIGHT, wrap_text=False)
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
def add_notes(slide, s: dict) -> None:
|
| 188 |
+
parts = []
|
| 189 |
+
if s.get("say"):
|
| 190 |
+
parts.append(s["say"])
|
| 191 |
+
full = s.get("footnote_full")
|
| 192 |
+
if full and full != s.get("footnote"):
|
| 193 |
+
parts.append("Full footnote: " + full)
|
| 194 |
+
if s.get("refs_full"):
|
| 195 |
+
parts.append("References: " + " | ".join(s["refs_full"]))
|
| 196 |
+
if s.get("sources"):
|
| 197 |
+
parts.append("Sources: " + s["sources"])
|
| 198 |
+
if parts:
|
| 199 |
+
slide.notes_slide.notes_text_frame.text = "\n\n".join(parts)
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
# ---------------------------------------------------------------- layout
|
| 203 |
+
def aspect(path: Path) -> float:
|
| 204 |
+
with Image.open(path) as im:
|
| 205 |
+
w, h = im.size
|
| 206 |
+
return w / h
|
| 207 |
+
|
| 208 |
+
|
| 209 |
+
def fit(total_aspect: float, extra_w: float, wmax: float, hmax: float):
|
| 210 |
+
"""Largest (w, h) with w = h * total_aspect + extra_w inside the box."""
|
| 211 |
+
h = min(hmax, (wmax - extra_w) / total_aspect)
|
| 212 |
+
return h * total_aspect + extra_w, h
|
| 213 |
+
|
| 214 |
+
|
| 215 |
+
def plan(aspects: list[float], keywords: list[str], layout: str):
|
| 216 |
+
"""Return dict with figure height/width and keyword placement."""
|
| 217 |
+
n = len(aspects)
|
| 218 |
+
tot = sum(aspects)
|
| 219 |
+
extra = FIG_GAP * (n - 1)
|
| 220 |
+
full_w, full_h = X1 - X0, YFIG1 - Y0
|
| 221 |
+
options = []
|
| 222 |
+
if not keywords:
|
| 223 |
+
w, h = fit(tot, extra, full_w, full_h)
|
| 224 |
+
return {"mode": "none", "w": w, "h": h}
|
| 225 |
+
# keywords below
|
| 226 |
+
kh = kw_block_h(keywords, full_w)
|
| 227 |
+
hmax = min(full_h, KW_BOTTOM - GAP_BELOW - kh - Y0)
|
| 228 |
+
w, h = fit(tot, extra, full_w, hmax)
|
| 229 |
+
kh = kw_block_h(keywords, full_w) # keywords sit at the text margin X0
|
| 230 |
+
if Y0 + h + GAP_BELOW + kh <= KW_BOTTOM + 1e-6:
|
| 231 |
+
options.append({"mode": "below", "w": w, "h": h, "area": w * h,
|
| 232 |
+
"kw_w": full_w, "kw_h": kh})
|
| 233 |
+
# keywords right
|
| 234 |
+
w, h = fit(tot, extra, full_w - GAP_RIGHT - MIN_COL, full_h)
|
| 235 |
+
col = X1 - (X0 + w) - GAP_RIGHT
|
| 236 |
+
kh = kw_block_h(keywords, col)
|
| 237 |
+
if kh <= full_h:
|
| 238 |
+
options.append({"mode": "right", "w": w, "h": h, "area": w * h,
|
| 239 |
+
"kw_w": col, "kw_h": kh})
|
| 240 |
+
if not options:
|
| 241 |
+
sys.exit(f"no layout fits keywords {keywords!r}")
|
| 242 |
+
best = max(options, key=lambda o: o["area"])
|
| 243 |
+
if layout == "figure_keywords":
|
| 244 |
+
right = [o for o in options if o["mode"] == "right"]
|
| 245 |
+
if right and right[0]["area"] * 1.15 >= best["area"]:
|
| 246 |
+
best = right[0]
|
| 247 |
+
return best
|
| 248 |
+
|
| 249 |
+
|
| 250 |
+
def build_content(prs, s: dict, number: int) -> None:
|
| 251 |
+
slide = prs.slides.add_slide(prs.slide_layouts[6])
|
| 252 |
+
white_bg(slide)
|
| 253 |
+
for fld in ("title", "footnote", "section_label"):
|
| 254 |
+
if s.get(fld):
|
| 255 |
+
check_text(s[fld], f"slide {number} {fld}")
|
| 256 |
+
kws = s.get("keywords", [])
|
| 257 |
+
if len(kws) > 3:
|
| 258 |
+
sys.exit(f"slide {number}: more than 3 keywords")
|
| 259 |
+
for k in kws:
|
| 260 |
+
check_text(k, f"slide {number} keyword")
|
| 261 |
+
add_title(slide, s["title"], s.get("section_label"))
|
| 262 |
+
|
| 263 |
+
paths = [DECK / f for f in s["figures"]]
|
| 264 |
+
for p in paths:
|
| 265 |
+
if not p.is_file():
|
| 266 |
+
sys.exit(f"slide {number}: missing figure {p}")
|
| 267 |
+
asp = [aspect(p) for p in paths]
|
| 268 |
+
L = plan(asp, kws, s.get("layout", "full"))
|
| 269 |
+
w, h = L["w"], L["h"]
|
| 270 |
+
if L["mode"] == "below":
|
| 271 |
+
fx = X0 + ((X1 - X0) - w) / 2.0 # centred; keywords at the text margin
|
| 272 |
+
else:
|
| 273 |
+
fx = X0
|
| 274 |
+
fy = Y0
|
| 275 |
+
x = fx
|
| 276 |
+
for p, a in zip(paths, asp):
|
| 277 |
+
pw = h * a
|
| 278 |
+
slide.shapes.add_picture(str(p), Inches(x), Inches(fy),
|
| 279 |
+
Inches(pw), Inches(h))
|
| 280 |
+
x += pw + FIG_GAP
|
| 281 |
+
assert fy + h <= YFIG1 + 1e-6 and fx + w <= X1 + 1e-6, s["title"]
|
| 282 |
+
|
| 283 |
+
if L["mode"] == "below":
|
| 284 |
+
add_text(slide, X0, fy + h + GAP_BELOW, L["kw_w"], L["kw_h"] + 0.05,
|
| 285 |
+
kws, KW_PT, space_before_pt=KW_PARA_GAP_PT)
|
| 286 |
+
elif L["mode"] == "right":
|
| 287 |
+
kx = fx + w + GAP_RIGHT
|
| 288 |
+
add_text(slide, kx, fy + 0.15, L["kw_w"], L["kw_h"] + 0.05, kws,
|
| 289 |
+
KW_PT, space_before_pt=KW_PARA_GAP_PT)
|
| 290 |
+
add_footer(slide, s.get("footnote"), number, s.get("refs"))
|
| 291 |
+
add_notes(slide, s)
|
| 292 |
+
print(f"{number:>2} {L['mode']:<5} fig {w:5.2f}x{h:4.2f} in {s['title']}")
|
| 293 |
+
|
| 294 |
+
|
| 295 |
+
def build_title(prs, s: dict) -> None:
|
| 296 |
+
slide = prs.slides.add_slide(prs.slide_layouts[6])
|
| 297 |
+
white_bg(slide)
|
| 298 |
+
check_text(s["title"] + s.get("subtitle", ""), "title slide")
|
| 299 |
+
if text_w_in(s["title"], COVER_PT, bold=True) > X1 - X0:
|
| 300 |
+
sys.exit("cover title too long")
|
| 301 |
+
add_text(slide, X0, 2.95, X1 - X0, 0.7, [s["title"]], COVER_PT, bold=True,
|
| 302 |
+
wrap_text=False)
|
| 303 |
+
if s.get("subtitle"):
|
| 304 |
+
add_text(slide, X0, 3.8, X1 - X0, 0.4, [s["subtitle"]], COVER_SUB_PT,
|
| 305 |
+
color=GREY, wrap_text=False)
|
| 306 |
+
|
| 307 |
+
|
| 308 |
+
def build_agenda(prs, s: dict, number: int) -> None:
|
| 309 |
+
slide = prs.slides.add_slide(prs.slide_layouts[6])
|
| 310 |
+
white_bg(slide)
|
| 311 |
+
add_title(slide, s["title"], None)
|
| 312 |
+
items = s["items"]
|
| 313 |
+
if len(items) != 10:
|
| 314 |
+
sys.exit("agenda must list 10 sections")
|
| 315 |
+
step = 0.52
|
| 316 |
+
for i, item in enumerate(items):
|
| 317 |
+
check_text(item, "agenda")
|
| 318 |
+
y = 1.3 + i * step
|
| 319 |
+
add_text(slide, X0, y, 0.45, 0.35, [str(i + 1)], AGENDA_PT, color=GREY,
|
| 320 |
+
align=PP_ALIGN.RIGHT, wrap_text=False)
|
| 321 |
+
add_text(slide, X0 + 0.65, y, 10.5, 0.35, [item], AGENDA_PT,
|
| 322 |
+
wrap_text=False)
|
| 323 |
+
add_footer(slide, None, number)
|
| 324 |
+
|
| 325 |
+
|
| 326 |
+
def build_divider(prs, s: dict, number: int) -> None:
|
| 327 |
+
slide = prs.slides.add_slide(prs.slide_layouts[6])
|
| 328 |
+
white_bg(slide)
|
| 329 |
+
check_text(s["title"], "divider")
|
| 330 |
+
add_text(slide, X0, 2.95, X1 - X0, 0.7, [s["title"]], COVER_PT, bold=True,
|
| 331 |
+
wrap_text=False)
|
| 332 |
+
add_footer(slide, None, number)
|
| 333 |
+
|
| 334 |
+
|
| 335 |
+
def main() -> None:
|
| 336 |
+
spec = json.loads(SPEC.read_text())
|
| 337 |
+
out = DECK / spec["deck"]["output_pptx"]
|
| 338 |
+
prs = Presentation()
|
| 339 |
+
prs.slide_width = Inches(SLIDE_W)
|
| 340 |
+
prs.slide_height = Inches(SLIDE_H)
|
| 341 |
+
for i, s in enumerate(spec["slides"], start=1):
|
| 342 |
+
kind = s["kind"]
|
| 343 |
+
if kind == "title":
|
| 344 |
+
build_title(prs, s)
|
| 345 |
+
print(f"{i:>2} title {s['title']}")
|
| 346 |
+
elif kind == "agenda":
|
| 347 |
+
build_agenda(prs, s, i)
|
| 348 |
+
print(f"{i:>2} agenda {s['title']}")
|
| 349 |
+
elif kind == "divider":
|
| 350 |
+
build_divider(prs, s, i)
|
| 351 |
+
print(f"{i:>2} divider {s['title']}")
|
| 352 |
+
elif kind == "content":
|
| 353 |
+
build_content(prs, s, i)
|
| 354 |
+
else:
|
| 355 |
+
sys.exit(f"unknown slide kind {kind!r}")
|
| 356 |
+
prs.save(out)
|
| 357 |
+
print(f"wrote {out} ({len(spec['slides'])} slides)")
|
| 358 |
+
|
| 359 |
+
|
| 360 |
+
if __name__ == "__main__":
|
| 361 |
+
main()
|