Spaces:
Running
Running
Download app.py from lauransotomayor/hyperFVC: direct link, hf CLI and curl.
- Browser
- Download file 43.6 kB
-
https://huggingface.co/spaces/lauransotomayor/hyperFVC/resolve/main/app.py
- Command line
-
hf download hf://spaces/lauransotomayor/hyperFVC/app.py
-
curl -L -o app.py https://huggingface.co/spaces/lauransotomayor/hyperFVC/resolve/main/app.py
43.6 kB
| import marimo | |
| __generated_with = "0.25.2" | |
| app = marimo.App( | |
| width="full", | |
| app_title="hyperFVC | Paper methods and results", | |
| css_file="viewer.css", | |
| ) | |
| async def _(): | |
| from pathlib import Path | |
| import marimo as mo | |
| from paper import FIGURES, TABLES, image_or_note, load_paper | |
| from paper_sections import DISCUSSION, METHODS, RESULTS | |
| from reuse import MODULES, checkpoint_families, load_reuse, module_ids, source_bytes | |
| from reuse_guides import example_code, figure_modules, visual_example | |
| root = Path(__file__).resolve().parent | |
| paper = await load_paper(root) | |
| reuse = await load_reuse(root) | |
| return ( | |
| DISCUSSION, FIGURES, METHODS, MODULES, RESULTS, TABLES, checkpoint_families, | |
| example_code, figure_modules, image_or_note, mo, module_ids, paper, reuse, | |
| root, source_bytes, visual_example, | |
| ) | |
| def _(mo): | |
| section = mo.ui.radio( | |
| { | |
| "🏠 Overview": "Overview", | |
| "🧪 Methods": "Methods", | |
| "📊 Results": "Results", | |
| "💬 Discussion": "Discussion", | |
| "🔁 Reproduce": "Reproduce", | |
| }, | |
| value="🏠 Overview", | |
| ) | |
| return (section,) | |
| def _(mo): | |
| # Persistent tab bar: content is rendered below so its selection survives reruns. | |
| view_tabs = mo.ui.tabs({"📄 Paper": "", "🧩 Reuse code & checkpoints": ""}) | |
| return (view_tabs,) | |
| def _(DISCUSSION, METHODS, RESULTS, mo, section): | |
| _topics = ( | |
| METHODS if section.value == "Methods" | |
| else RESULTS if section.value == "Results" | |
| else DISCUSSION if section.value == "Discussion" | |
| else {} | |
| ) | |
| topic_picker = mo.ui.radio(list(_topics), value=next(iter(_topics), None)) | |
| return (topic_picker,) | |
| def _(FIGURES, MODULES, TABLES, mo, paper, reuse): | |
| _sha = paper["manifest"]["tex_sha256"] | |
| mo.Html(f""" | |
| <header class="fvc-topbar"> | |
| <div> | |
| <p class="fvc-eyebrow">Semi-arid UAS hyperspectral · manuscript explorer</p> | |
| <h1>hyperFVC</h1> | |
| <p>Methods, experiments and results of the paper, read from the captured TeX.</p> | |
| </div> | |
| <div class="fvc-chips"> | |
| <span class="fvc-chip">{len(TABLES)} tables</span> | |
| <span class="fvc-chip">{len(FIGURES)} figures</span> | |
| <span class="fvc-chip">{len(MODULES)} reusable modules</span> | |
| <span class="fvc-chip">{len(reuse["checkpoints"])} checkpoint locations</span> | |
| <span class="fvc-chip" title="{_sha}">TeX {_sha[:12]}…</span> | |
| <span class="fvc-chip"><a href="https://github.com/LNSOTOM/fvc_function" | |
| target="_blank" rel="noopener">Workflow code ↗</a></span> | |
| </div> | |
| </header> | |
| """) | |
| return | |
| def _(mo, section, topic_picker): | |
| _nav = [ | |
| mo.Html('<div class="fvc-brand">🌿 hyperFVC</div>'), | |
| mo.Html('<p class="fvc-side-title">Section</p>'), | |
| section, | |
| ] | |
| if section.value in ("Methods", "Results", "Discussion"): | |
| _nav += [mo.Html(f'<p class="fvc-side-title">{section.value} topics</p>'), topic_picker] | |
| _nav += [ | |
| mo.Html(""" | |
| <p class="fvc-side-title">Classes</p> | |
| <div class="fvc-legend"> | |
| <div><i style="background:#e346ee"></i><span><b>PV</b> photosynthetic vegetation</span></div> | |
| <div><i style="background:#6332ea"></i><span><b>NPV</b> non-photosynthetic vegetation</span></div> | |
| <div><i style="background:#dae22f"></i><span><b>BE</b> bare earth</span></div> | |
| </div> | |
| <p class="fvc-side-title">Reading tips</p> | |
| <p class="fvc-note">New here? Start at <b>Overview → Methods → Results → | |
| Discussion</b> in order; <b>Discussion</b> is where the paper explains what | |
| the Results numbers actually mean and where the evidence stops. Use the | |
| <b>Paper</b> tab for text, tables and figures, and <b>Reuse code</b> for | |
| notebook-style module guides. Nothing is trained or recomputed by this | |
| viewer.</p> | |
| <p class="fvc-side-title">Live analysis</p> | |
| <p class="fvc-note">For interactive ENVI tiles, spectra, indices and ONNX | |
| inference run <code>marimo run analysis.py</code> | |
| (or <code>marimo edit analysis.py</code> to add your own cells).</p> | |
| """), | |
| ] | |
| mo.sidebar(_nav) | |
| return | |
| async def _( | |
| DISCUSSION, FIGURES, METHODS, MODULES, RESULTS, TABLES, figure_modules, | |
| image_or_note, mo, paper, root, section, topic_picker, | |
| ): | |
| _blocks = [] | |
| if section.value == "Overview": | |
| def _chart(bars, wide=False): | |
| _cols = "".join( | |
| f'<div class="fvc-bar-col">' | |
| f'<span class="fvc-bar-val">{_v:.3f}</span>' | |
| f'<div class="fvc-bar" style="height:{round(_v * 100)}%;background:{_c}"></div>' | |
| f'<span class="fvc-bar-label">{_l}</span>' | |
| f'</div>' | |
| for _l, _v, _c in bars | |
| ) | |
| _cls = "fvc-chart wide" if wide else "fvc-chart" | |
| return f'<div class="{_cls}">{_cols}</div>' | |
| _grey, _ltblue, _medblue, _purple, _navy, _green = ( | |
| "#c9ccd1", "#9fc4ec", "#4f82c9", "#7d4fd9", "#1f3b6e", "#2f8f5b", | |
| ) | |
| _model_legend = """ | |
| <div class="fvc-chart-legend"> | |
| <span><i style="background:#c9ccd1"></i>PCA-3 + U-Net</span> | |
| <span><i style="background:#9fc4ec"></i>PCA-10 + U-Net</span> | |
| <span><i style="background:#4f82c9"></i>Full-band U-Net (M1)</span> | |
| <span><i style="background:#7d4fd9"></i>SS3FCN</span> | |
| <span><i style="background:#1f3b6e"></i>Random Forest</span> | |
| <span><i style="background:#2f8f5b"></i>CNN M5 (proposed)</span> | |
| </div> | |
| """ | |
| _blocks = [ | |
| mo.Html(f""" | |
| <div class="fvc-metrics"> | |
| <div><span>Sections</span><strong>{len(METHODS)} methods · {len(RESULTS)} results · {len(DISCUSSION)} discussion</strong></div> | |
| <div><span>Manuscript tables</span><strong>{len(TABLES)}</strong></div> | |
| <div><span>Manuscript figures</span><strong>{len(FIGURES)}</strong></div> | |
| <div><span>Classes</span><strong>BE · NPV · PV</strong></div> | |
| </div> | |
| """), | |
| mo.md(""" | |
| ## Start with the study | |
| **Methods** explains the study site, inputs, FVC labels, model versions, | |
| training and evaluation protocols. **Results** presents the paper's | |
| ablation, baseline, spatial, external-site, spectral and edge-deployment | |
| evidence. **Discussion** explains what those results mean, where they | |
| disagree with a simple "bigger model wins" story, and where the evidence | |
| stops (limitations, future work, conclusions). | |
| The visual explorer distinguishes internal held-out tests from external | |
| zero-shot evaluation and preserves the averaging unit of each table. | |
| """), | |
| mo.md(""" | |
| ## Why this study | |
| Fractional vegetation cover — bare earth (**BE**), non-photosynthetic | |
| vegetation (**NPV**: dry/senescent material, litter, woody debris) and | |
| photosynthetic vegetation (**PV**) — is an ecologically meaningful | |
| descriptor of dryland condition, but **NPV is the hardest component to | |
| separate**: its spectral and spatial signature overlaps shadow, exposed | |
| substrate and mixed vegetation–soil pixels. This study benchmarks a | |
| spectral-channel-adapted CNN against five baselines, characterises *why* | |
| NPV stays ambiguous post-inference, and tests edge-GPU deployment — | |
| see **Methods → Study context and objectives** for the full framing. | |
| """), | |
| mo.hstack([ | |
| mo.vstack([ | |
| mo.md("#### Study sites, Calperum Station, South Australia"), | |
| await image_or_note( | |
| mo, root, root / "paper" / paper["manifest"]["figures"]["study_area"]["path"], | |
| "Site locations at Calperum Station and the UAS platforms used.", "100%", | |
| ), | |
| ]), | |
| mo.vstack([ | |
| mo.md("#### Training site (medium density) vs. zero-shot site (low density)"), | |
| await image_or_note( | |
| mo, root, root / "paper" / paper["manifest"]["figures"]["study_sites"]["path"], | |
| "Multi-sensor imagery contrast between the medium (training) and low (inference) vegetation sites.", "100%", | |
| ), | |
| ]), | |
| ], widths="equal", gap=1), | |
| mo.md(""" | |
| | Site | Role | Vegetation | Area | | |
| |---|---|---|---| | |
| | **SASMDD0001** (medium) | Training / internal evaluation | Regenerating multi-stemmed mallee *Eucalyptus* spp. over sparse *Triodia* hummock grassland | ≈15 ha | | |
| | **SASMDD0013** (low) | Zero-shot external evaluation only | Low open *Eucalyptus largiflorens* woodland, sparse chenopod shrubs | ≈2.8 ha | | |
| SASMDD0013 never contributes training data — it is used exclusively for | |
| frozen, zero-shot cross-site testing. | |
| """), | |
| mo.Html(""" | |
| <div class="fvc-diagram"> | |
| <p class="fvc-diagram-title">From spectra to vegetation maps</p> | |
| <p class="fvc-diagram-sub">How data, models and evaluation design fit | |
| together — numbers below are this manuscript's, not a different | |
| study's; see Discussion → Limitations, future work & conclusions | |
| for the full table and caveats.</p> | |
| <div class="fvc-diagram-row"> | |
| <div class="fvc-dcard teal"> | |
| <div class="fvc-dcard-head"> | |
| <span class="fvc-dbadge teal">1</span> | |
| <div><strong>Data & task</strong> | |
| <span>Classify BE / NPV / PV at Calperum Station, SA</span></div> | |
| </div> | |
| <div class="fvc-dcard-body"><ul> | |
| <li>MicaSense: native 5 cm + a 10 cm matched-resolution control</li> | |
| <li>Specim FX10+FX17 fused: 10 cm, 296 combined bands (VNIR–SWIR)</li> | |
| <li>15 annotated tiles; 1 cm manual masks, majority-vote downsampled</li> | |
| </ul></div> | |
| </div> | |
| <div class="fvc-dcard orange"> | |
| <div class="fvc-dcard-head"> | |
| <span class="fvc-dbadge orange">2</span> | |
| <div><strong>Models compared</strong> | |
| <span>Common U-Net backbone + 5 external baselines</span></div> | |
| </div> | |
| <div class="fvc-dcard-body"><ul> | |
| <li>M1 plain U-Net → M5 spectral adapter + cross-channel attention + NPV-weighted loss</li> | |
| <li>Baselines (296-band benchmark): Random Forest, PCA-3, PCA-10, SS3FCN</li> | |
| <li>Same architecture family throughout the M1–M5 ablation</li> | |
| </ul></div> | |
| </div> | |
| <div class="fvc-dcard blue"> | |
| <div class="fvc-dcard-head"> | |
| <span class="fvc-dbadge blue">3</span> | |
| <div><strong>Evaluation design</strong> | |
| <span>Same labels, folds and metrics for every model</span></div> | |
| </div> | |
| <div class="fvc-dcard-body"><ul> | |
| <li>3-fold spatial block CV (8 train / 3 val / 4 test tiles), within-site</li> | |
| <li>5-tile zero-shot cross-site transfer (SASMDD0013, frozen checkpoints)</li> | |
| <li>BE/NPV/PV F1, macro F1, mIoU, 50-pass MC-dropout uncertainty</li> | |
| </ul></div> | |
| </div> | |
| </div> | |
| <div class="fvc-dcard purple"> | |
| <div class="fvc-dcard-head"> | |
| <span class="fvc-dbadge purple">4</span> | |
| <div><strong>Results — four questions, four answers</strong> | |
| <span>Each links to a Discussion topic for the full caveats</span></div> | |
| </div> | |
| <div class="fvc-dresults"> | |
| <div class="fvc-dq"> | |
| <p class="fvc-dq-label">A · NPV-weighting</p> | |
| <h4>Does it help?</h4> | |
| <p class="fvc-dstat">NPV F1 0.496</p> | |
| <p>M5 vs plain U-Net M1, +0.148 — the single largest driver of | |
| NPV gain in the ablation.</p> | |
| </div> | |
| <div class="fvc-dq"> | |
| <p class="fvc-dq-label">B · Baselines</p> | |
| <h4>Does M5 beat them all?</h4> | |
| <p class="fvc-dstat">NPV F1 0.461</p> | |
| <p>M5 vs Random Forest (0.688 mean F1) and SS3FCN (0.685) — M5's | |
| edge is specifically NPV, not every class.</p> | |
| </div> | |
| <div class="fvc-dq"> | |
| <p class="fvc-dq-label">C · Resolution</p> | |
| <h4>Does fine detail matter?</h4> | |
| <p class="fvc-dstat">+0.094 mIoU</p> | |
| <p>Matched at 10 cm, MICA still beats FX10–FX17 by this | |
| margin — resolution helps, but doesn't explain everything.</p> | |
| </div> | |
| <div class="fvc-dq"> | |
| <p class="fvc-dq-label">D · Cross-site transfer</p> | |
| <h4>Does it hold at a new site?</h4> | |
| <p class="fvc-dstat">NPV F1 ≤ 0.120</p> | |
| <p>Zero-shot at SASMDD0013, every model tested — BE/PV | |
| transferred better than NPV.</p> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="fvc-dtakeaways"> | |
| <div><strong>1 · Weighting, not architecture</strong> | |
| NPV-weighted loss drove the FVC-mapping gain; spectral adaptation | |
| and attention were supporting components.</div> | |
| <div><strong>2 · Compression costs NPV</strong> | |
| PCA underperformed the full 296-band input despite keeping | |
| >99% of spectral variance.</div> | |
| <div><strong>3 · Resolution helps, unevenly</strong> | |
| Fine detail improved metrics, but not identically across | |
| sensors or patch scales.</div> | |
| <div><strong>4 · Within-site ≠ cross-site</strong> | |
| Strong source-site numbers did not guarantee NPV transfer to | |
| a new site.</div> | |
| </div> | |
| </div> | |
| """), | |
| mo.Html(f""" | |
| <div class="fvc-diagram"> | |
| <p class="fvc-diagram-title">Model & resolution comparison, MICA within-site</p> | |
| <p class="fvc-diagram-sub">Recreated in code from the author's own conference | |
| poster ("Mapping Vegetation Functional States", companion to this manuscript — | |
| see Reproduce → Poster). This is a MICA-native-resolution benchmark, a | |
| different cut of the same study to the FX10–FX17 296-band tables above; | |
| numbers are transcribed from the poster graphic, not re-parsed from the | |
| captured TeX, so treat exact decimals as approximate.</p> | |
| <div class="fvc-diagram-row"> | |
| <div class="fvc-dcard teal"> | |
| <div class="fvc-dcard-head"> | |
| <span class="fvc-dbadge teal">1</span> | |
| <div><strong>Spatial resolution matters</strong> | |
| <span>CNN benefits from fine spatial detail (5 cm)</span></div> | |
| </div> | |
| <div class="fvc-dcard-body"> | |
| <p class="fvc-chart-title">Macro F1 by resolution</p> | |
| {_chart([ | |
| ("RF 5cm", 0.822, _navy), ("M5 5cm", 0.886, _green), | |
| ("RF 10cm", 0.773, _navy), ("M5 10cm", 0.772, _green), | |
| ])} | |
| <p class="fvc-chart-title">NPV F1 by resolution</p> | |
| {_chart([ | |
| ("RF 5cm", 0.600, _navy), ("M5 5cm", 0.725, _green), | |
| ("RF 10cm", 0.528, _navy), ("M5 10cm", 0.539, _green), | |
| ])} | |
| </div> | |
| </div> | |
| <div class="fvc-dcard orange"> | |
| <div class="fvc-dcard-head"> | |
| <span class="fvc-dbadge orange">2</span> | |
| <div><strong>Spectral dimensionality</strong> | |
| <span>PCA reduction removes useful information</span></div> | |
| </div> | |
| <div class="fvc-dcard-body"> | |
| <p class="fvc-chart-title">NPV F1 (hyperspectral, within-site)</p> | |
| {_chart([ | |
| ("PCA-3", 0.320, _grey), ("PCA-10", 0.367, _ltblue), | |
| ("Full-band (M1)", 0.461, _medblue), | |
| ])} | |
| </div> | |
| </div> | |
| <div class="fvc-dcard blue"> | |
| <div class="fvc-dcard-head"> | |
| <span class="fvc-dbadge blue">3</span> | |
| <div><strong>NPV weighting</strong> | |
| <span>Same architecture — helps the difficult NPV class</span></div> | |
| </div> | |
| <div class="fvc-dcard-body"> | |
| <p class="fvc-chart-title">NPV F1 (within-site, 5 cm)</p> | |
| {_chart([("M4, no weighting", 0.661, _grey), ("M5, NPV-weighted", 0.725, _green)])} | |
| </div> | |
| </div> | |
| </div> | |
| <div class="fvc-dcard purple"> | |
| <div class="fvc-dcard-head"> | |
| <span class="fvc-dbadge purple">4</span> | |
| <div><strong>Model comparison (5 cm, within-site)</strong> | |
| <span>CNN M5 outperforms traditional and other baselines</span></div> | |
| </div> | |
| <div class="fvc-dcard-body"> | |
| {_model_legend} | |
| <div class="fvc-chart-row"> | |
| <div> | |
| <p class="fvc-chart-title">Macro F1</p> | |
| {_chart([ | |
| ("PCA-3", 0.603, _grey), ("PCA-10", 0.641, _ltblue), | |
| ("M1", 0.669, _medblue), ("SS3FCN", 0.688, _purple), | |
| ("RF", 0.822, _navy), ("M5", 0.886, _green), | |
| ], wide=True)} | |
| </div> | |
| <div> | |
| <p class="fvc-chart-title">mIoU</p> | |
| {_chart([ | |
| ("PCA-3", 0.520, _grey), ("PCA-10", 0.550, _ltblue), | |
| ("M1", 0.571, _medblue), ("SS3FCN", 0.579, _purple), | |
| ("RF", 0.700, _navy), ("M5", 0.750, _green), | |
| ], wide=True)} | |
| </div> | |
| <div> | |
| <p class="fvc-chart-title">NPV F1</p> | |
| {_chart([ | |
| ("PCA-3", 0.320, _grey), ("PCA-10", 0.367, _ltblue), | |
| ("M1", 0.461, _medblue), ("SS3FCN", 0.452, _purple), | |
| ("RF", 0.600, _navy), ("M5", 0.725, _green), | |
| ], wide=True)} | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="fvc-dcard" style="border-color:rgba(127,127,127,0.22)"> | |
| <div class="fvc-dcard-head"> | |
| <span class="fvc-dbadge" style="background:#9a8a3a">5</span> | |
| <div><strong>Cross-site generalisation</strong> | |
| <span>Useful overall at 5 cm, but NPV remains challenging</span></div> | |
| </div> | |
| <div class="fvc-dcard-body"> | |
| <p class="fvc-chart-title">External site (5 tiles, MICA)</p> | |
| <div class="fvc-chart-row"> | |
| {_chart([ | |
| ("Macro F1 5cm", 0.648, _green), ("Macro F1 10cm", 0.609, _navy), | |
| ])} | |
| {_chart([ | |
| ("mIoU 5cm", 0.602, _green), ("mIoU 10cm", 0.519, _navy), | |
| ])} | |
| {_chart([ | |
| ("NPV F1 5cm", 0.415, _green), ("NPV F1 10cm", 0.347, _navy), | |
| ])} | |
| </div> | |
| </div> | |
| </div> | |
| <div class="fvc-dtakeaways"> | |
| <div><strong>1 · Fine spatial detail matters</strong> | |
| At 5 cm, CNN M5 improves overall and NPV classification vs | |
| Random Forest; at 10 cm the two are similar.</div> | |
| <div><strong>2 · Spectral dimensionality matters</strong> | |
| PCA-reduced inputs lower NPV performance even at high explained | |
| variance; full spectral information works better.</div> | |
| <div><strong>3 · NPV weighting helps</strong> | |
| Weighting the NPV class within the same CNN improves detection | |
| of this difficult, under-represented class.</div> | |
| <div><strong>4 · CNNs reduce feature engineering</strong> | |
| CNNs learn spectral–spatial patterns directly; traditional ML | |
| needs manual features and is more sensitive to shadow.</div> | |
| </div> | |
| </div> | |
| """), | |
| mo.callout(mo.md( | |
| "**Source of truth:** the captured `elsarticle-template-harv.tex`. " | |
| "The accompanying PDF has an older modification time and has not been " | |
| "verified to match the TeX; consult the TeX for exact wording and citations. " | |
| "This is a manuscript snapshot, not a live publication." | |
| ), kind="warn"), | |
| mo.md( | |
| "### How to read the results\n" | |
| "- **BE**, **NPV**, **PV** are the three segmentation classes.\n" | |
| "- F1 and mIoU summarise segmentation; uncertainty is not error probability.\n" | |
| "- Spectral importance is model sensitivity, not a measured plant trait.\n" | |
| "- Deployment agreement is parity against PyTorch, not ground-truth accuracy.\n" | |
| "- The five external tiles are not established as representative of the site." | |
| ), | |
| ] | |
| elif section.value == "Reproduce": | |
| _manifest = paper["manifest"] | |
| _blocks = [ | |
| mo.md(f""" | |
| ## Manuscript snapshot and workflow | |
| - Captured TeX: `paper/elsarticle-template-harv.tex` | |
| (source modified **{_manifest['tex_modified_utc']}**). | |
| - Captured PDF: `paper/elsarticle-template-harv.pdf` | |
| (source modified **{_manifest['pdf_modified_utc']}**). | |
| - The PDF is older and may not reflect the TeX. They were **not** | |
| regenerated or checked for equivalence. | |
| - `paper/manifest.json` records SHA-256 hashes for the TeX, PDF and | |
| every figure. The displayed tables are parsed from the captured TeX. | |
| The source snapshot under `workflow/` retains the three original | |
| pipeline phases and scripts. See `README.md` for environment and | |
| external data mapping; raw imagery, masks and checkpoints are not | |
| bundled. Training and inference have not been rerun for this viewer. | |
| The former broad notebook/CSV explorer is preserved as | |
| `archive_app.py`; its historical outputs are **not** paper results. | |
| """), | |
| mo.md(f"**TeX SHA-256:** `{_manifest['tex_sha256']}` \n" | |
| f"**PDF SHA-256:** `{_manifest['pdf_sha256']}`"), | |
| mo.callout(mo.md(""" | |
| **Companion poster** | |
| `paper/1400_Wednesday_Centurion1_lauraSotomayor.pptx` is the conference | |
| talk for "Mapping Vegetation Functional States" — the same study's | |
| MICA-native-resolution benchmark, summarised as `paper/diagram_1.png` | |
| (results panels, recreated on the Overview tab) and `paper/diagram_2.png` | |
| ("From spectra to vegetation maps", recreated as the Overview's first | |
| diagram). It is a different cut of the data to the FX10–FX17 296-band | |
| tables captured from the manuscript TeX elsewhere in this viewer — not | |
| parsed/hash-verified the way the TeX tables are, so treat its numbers as | |
| the author's own reporting rather than this viewer's verified source of | |
| truth. The full A0 poster lives at the repository root as | |
| `README_POSTER.md` / `vegetation_functional_states_A0_portrait.pdf`. | |
| """), kind="neutral"), | |
| mo.md(""" | |
| ## Reproduction walkthrough | |
| From the full `workflow/` tree, in the **modelling** environment | |
| (`environment.yml`), not this viewer's small environment: | |
| ```bash | |
| mamba env create -f environment.yml | |
| mamba activate fvc_function | |
| python utils/fvc_paths.py --check # confirm data roots resolve before anything else | |
| ``` | |
| `configs/paths.yaml` holds every machine-specific location; override a | |
| root per run with `FVC_DATA_ROOT=/mnt/disk/calperumResearch bash scripts/<script>.sh` | |
| instead of editing files. | |
| """), | |
| mo.mermaid(""" | |
| flowchart LR | |
| UAS["UAS orthomosaics<br/>(RGB · MICA · FX10/FX17)"] --> P1 | |
| P1["phase_1_image_processing/<br/>reprojection · aligned grid · tiling · band stacking"] --> P3 | |
| P1 --> P2["phase_2_reference_data/<br/>LabelMe to BE/NPV/PV masks · majority-vote downsampling"] | |
| P2 --> P3["phase_3_models/<br/>U-Net M1-M5 training · block CV · streaming inference"] | |
| P3 --> PH["post_inference/<br/>spectral characterisation · uncertainty · senescence"] | |
| P3 --> EDGE["jetsonOrinAGX/<br/>ONNX export to TensorRT · edge benchmark"] | |
| P3 --> VIEWER["deliverables/fvc_results/<br/>this portable marimo viewer (read-only snapshot)"] | |
| """), | |
| mo.md(""" | |
| **Repository layout** (relative to `workflow/`, the tracked snapshot of | |
| the original `fvc_function` repo root): | |
| ```text | |
| fvc_function/ | |
| ├── configs/paths.yaml # data, model-weight and output locations | |
| ├── utils/fvc_paths.py # path resolver used by Python and shell | |
| ├── scripts/ # phase driver scripts (+ lib/fvc_env.sh) | |
| │ └── lib/fvc_env.sh | |
| ├── phase_1_image_processing/ # step_1 reprojection … step_5 band stacking | |
| ├── phase_2_reference_data/ # step_1 BE class … step_5 label downsampling | |
| ├── phase_3_models/ | |
| │ ├── unet_site_models/ # architecture, training, inference, post_inference/ | |
| │ ├── unet_generic_model/ | |
| │ └── performance_metrics/ | |
| ├── jetsonOrinAGX/ # ONNX → TensorRT edge benchmarks | |
| ├── docs/ # METHODS.md, REPRODUCTION.md, ENVIRONMENT.md | |
| └── environment.yml, requirements.txt | |
| ``` | |
| Every reusable module shown in **Reuse code & checkpoints** links back | |
| into this same tree (its `path` is relative to `workflow/`); the | |
| phase table below is the recommended run order. | |
| """), | |
| mo.ui.table([ | |
| {"Phase": "1 — Image processing", "Does": "Reprojection, aligned grid build, orthomosaic clipping, band stacking", | |
| "Entry point": "scripts/build_site1_alignment_grids.sh + regenerate_*/refresh_* drivers"}, | |
| {"Phase": "2 — Reference data", "Does": "LabelMe → shapefile, BE class from MSAVI/NDVI, majority-vote downsampling", | |
| "Entry point": "scripts/downsample_site1_labels_low_offset.sh; remaining step_* scripts run individually"}, | |
| {"Phase": "3a — Patch export", "Does": "Export non-overlapping patch pairs per sensor profile", | |
| "Entry point": "scripts/prepare_site1_patch_training.sh, prepare_fx10_76_training.sh, …"}, | |
| {"Phase": "3b — Training", "Does": "Train M1–M5 per sensor profile with block cross-validation", | |
| "Entry point": "scripts/run_sensor_profiles_in_order.sh (canonical sweep, 2084 lines)"}, | |
| {"Phase": "3c — Inference", "Does": "Single-tile or streaming whole-orthomosaic prediction", | |
| "Entry point": "scripts/run_inference_tile.sh; inference_FVCmapping*.py directly for streaming"}, | |
| {"Phase": "3d — Post-hoc analysis", "Does": "Spectral characterisation, uncertainty, senescence profiles", | |
| "Entry point": "scripts/run_senescence_profiles_in_order.sh; post_inference/*.py directly"}, | |
| {"Phase": "3e — Edge export", "Does": "ONNX export then TensorRT build/benchmark on Jetson", | |
| "Entry point": "export_*_onnx_docker.sh → jetsonOrinAGX/scripts/build_and_benchmark_trt.py"}, | |
| ], selection=None, page_size=10), | |
| mo.callout(mo.md(""" | |
| **Known gaps in the tracked workflow** (so you don't debug a phantom bug): | |
| - `export_checkpoint_to_onnx.py`, called by both ONNX export scripts, is | |
| **absent** from the working tree and git history — both export drivers | |
| fail past their directory checks until it is restored or rewritten. | |
| - `phase_1_image_processing/step_*` and `phase_2_reference_data/step_*` | |
| scripts still carry **hardcoded paths** (highest: `2_6_spectrum.py`, | |
| 186 occurrences); only the `scripts/` drivers and `config_param.py` | |
| resolve through `configs/paths.yaml` today. | |
| - QGIS steps (`phase_1_image_processing/step_2_orthomosaic_to_tiling/a_qgis/`) | |
| run from the QGIS Python console, outside `requirements.txt`. | |
| See `workflow/docs/REPRODUCTION.md` for the complete script-by-script map. | |
| """), kind="warn"), | |
| ] | |
| else: | |
| _sections = ( | |
| METHODS if section.value == "Methods" | |
| else RESULTS if section.value == "Results" | |
| else DISCUSSION | |
| ) | |
| _selected = _sections[topic_picker.value] | |
| _tabs = {"📝 Summary": mo.md(_selected["text"])} | |
| _tables = [ | |
| mo.vstack([ | |
| mo.md(f"#### {_caption}\nManuscript table label: `{TABLES[_key][0]}`"), | |
| mo.ui.table(paper["tables"][_key], selection=None, page_size=20), | |
| ]) | |
| for _key, _caption in _selected.get("tables", []) | |
| ] | |
| _figures = [] | |
| for _key, _caption in _selected.get("figures", []): | |
| _reuse_ids = figure_modules(_key) | |
| _figure_block = [ | |
| mo.md(f"#### {_caption}\n" | |
| f"Manuscript figure label: `{FIGURES[_key][1]}`."), | |
| await image_or_note( | |
| mo, root, root / "paper" / paper["manifest"]["figures"][_key]["path"], | |
| _caption, "100%", | |
| ), | |
| ] | |
| if _reuse_ids: | |
| _names = ", ".join(f"**{MODULES[_mid]['name']}**" for _mid in _reuse_ids) | |
| _figure_block.append(mo.md( | |
| f"🧩 Produced by: {_names} — open **Reuse code & checkpoints** " | |
| "above and pick this module for the notebook-style guide." | |
| )) | |
| _figures.append(mo.vstack(_figure_block)) | |
| if _tables: | |
| _tabs[f"📋 Tables ({len(_tables)})"] = mo.vstack(_tables, gap=2) | |
| if _figures: | |
| _tabs[f"🖼️ Figures ({len(_figures)})"] = mo.vstack(_figures, gap=2) | |
| if ( | |
| section.value == "Discussion" | |
| and topic_picker.value == "Limitations, future work & conclusions" | |
| ): | |
| _tabs["🧪 Pilot inference (not in manuscript)"] = mo.vstack([ | |
| mo.callout(mo.md( | |
| "Real inference runs for this viewer on 2026-11-18, using the actual " | |
| "fine-tuned checkpoints via the existing `inference_FVCmapping.py` " | |
| "module, on the two held-out test tiles (8, 15) from each driver's own " | |
| "split. **Two different NPV F1 numbers are reported per sensor because " | |
| "they come from two different evaluation methods** — neither is wrong, " | |
| "they measure slightly different things." | |
| ), kind="info"), | |
| mo.md("#### MICA, 5 cm, 304 px (`site13_mica05_s304_finetune`)"), | |
| await image_or_note( | |
| mo, root, root / "paper" / "pilot_finetune_tiles8_15.png", | |
| "Pilot few-shot fine-tuning: reference vs. prediction on held-out " | |
| "target-site test tiles 8 and 15 (MICA 5 cm). False-colour composite " | |
| "is NIR-842 nm/Red-668 nm/Blue-475 nm, the same convention used " | |
| "elsewhere in this viewer's Methods figures.", "100%", | |
| ), | |
| mo.md(""" | |
| | Source | NPV F1 | Macro F1 | Method | | |
| |---|---|---|---| | |
| | Training pipeline's own test-set report (`best_model_metrics_block_1.txt`) | **0.546** | 0.740 (mIoU) | Per-patch metrics computed by the training/eval harness | | |
| | Independent re-run for this viewer (pooled confusion matrix) | **0.484** | 0.796 | Re-ran `inference_FVCmapping.py` standalone on the stitched 608×608 tiles, then pooled BE/NPV/PV counts across both tiles | | |
| """), | |
| mo.md("#### FX10–FX17, 296-band, 152 px (`site13_m5_s152_finetune`)"), | |
| await image_or_note( | |
| mo, root, root / "paper" / "pilot_finetune_hsi_tiles8_15.png", | |
| "Pilot few-shot fine-tuning: reference vs. prediction on held-out " | |
| "target-site test tiles 8 and 15 (FX10–FX17, 296-band, 152 px).", "100%", | |
| ), | |
| mo.md(""" | |
| | Source | NPV F1 | Macro F1 | Method | | |
| |---|---|---|---| | |
| | Training pipeline's own test-set report (`best_model_metrics_block_1.txt`) | **0.202** | 0.611 (mIoU) | Per-patch metrics computed by the training/eval harness | | |
| | Independent re-run for this viewer (pooled confusion matrix) | **0.175** | 0.673 | Re-ran `inference_FVCmapping.py` standalone on the stitched 304×304 tiles, then pooled BE/NPV/PV counts across both tiles | | |
| Both sensor configurations land far above the manuscript's ≤0.120 | |
| zero-shot ceiling, but MICA 5 cm improved far more (0.48–0.55) than | |
| FX10–FX17 152 px (0.18–0.20). The within-sensor gap between the two | |
| reported numbers reflects different evaluation units (non-overlapping | |
| training-time patches vs. this viewer's independently stitched, | |
| overlap-reconciled tiles), not a disagreement about whether fine-tuning | |
| helped. MICA 10 cm at 152 px (not re-run here) reached NPV F1 0.30–0.46 | |
| per the training pipeline's own report, in between the two above. | |
| **None of this is in the reviewed manuscript.** | |
| """), | |
| ]) | |
| _blocks.append(mo.ui.tabs(_tabs)) | |
| paper_view = mo.vstack(_blocks) | |
| return (paper_view,) | |
| def _(MODULES, mo, module_ids, section, topic_picker): | |
| reuse_ids = module_ids(section.value, topic_picker.value) | |
| module_names = {MODULES[key]["name"]: key for key in reuse_ids} | |
| # Square tab bar instead of a dropdown: every module name is one click away. | |
| module_picker = mo.ui.tabs(dict.fromkeys(module_names, ""), value=MODULES[reuse_ids[0]]["name"]) | |
| return module_names, module_picker, reuse_ids | |
| def _(module_names, module_picker): | |
| # .value must be read in a different cell from the one that created the element. | |
| module_key = module_names[module_picker.value] | |
| return (module_key,) | |
| def _(checkpoint_families, mo, reuse, reuse_ids): | |
| _families = checkpoint_families(reuse_ids) | |
| _options = { | |
| f"{entry['family']} | {entry['location']}": index | |
| for index, entry in enumerate(reuse["checkpoints"]) | |
| if entry["family"] in _families | |
| } | |
| checkpoint_picker = mo.ui.dropdown( | |
| _options, value=next(iter(_options), None), label="Related checkpoint location" | |
| ) | |
| return (checkpoint_picker,) | |
| async def _( | |
| MODULES, checkpoint_picker, example_code, image_or_note, mo, module_key, paper, | |
| reuse, root, source_bytes, visual_example, | |
| ): | |
| import json | |
| _module = MODULES[module_key] | |
| _record = reuse["modules"][module_key] | |
| _content = await source_bytes(root, reuse, module_key) | |
| _language, _code, _usage_note = await example_code(root, module_key) | |
| _example = visual_example(reuse, paper, module_key) | |
| _panels = [ | |
| mo.md(f"### Notebook guide: {_module['name']}\n{_module['purpose']}"), | |
| mo.hstack([ | |
| mo.callout(mo.md(f"**INPUTS**\n\n{_module['inputs']}")), | |
| mo.callout(mo.md(f"**MODULE**\n\n{_module['name']}")), | |
| mo.callout(mo.md(f"**OUTPUTS**\n\n{_module['outputs']}")), | |
| ], wrap=True), | |
| mo.md( | |
| "#### Cell 1 · Configure the step\n" | |
| f"Use `workflow/{_module['path']}` from the complete workflow tree. " | |
| "Set the input/output locations and select compatible sensor settings. " | |
| "Any `/path/to/...` values below are placeholders, not available datasets." | |
| ), | |
| mo.md(f"#### Cell 2 · Example code (not executed)\n" | |
| f"{_usage_note}\n\n```{_language}\n{_code}\n```"), | |
| mo.md(f"#### Cell 3 · Understand the output\n{_module['outputs']}\n\n" | |
| "Examples below are reference illustrations, not outputs generated by this code cell."), | |
| ] | |
| if "caution" in _module: | |
| _panels.insert(2, mo.callout(mo.md(_module["caution"]), kind="warn")) | |
| if _example: | |
| _panels.extend([ | |
| mo.md(_example["caption"]), | |
| await image_or_note(mo, root, root / _example["path"], _example["caption"], "100%"), | |
| ]) | |
| else: | |
| _panels.append(mo.md( | |
| "This is a configuration/helper step: it has no image output. " | |
| "Follow the input → module → output diagram above." | |
| )) | |
| _panels.extend([ | |
| mo.download( | |
| data=_content, filename=_module["path"].split("/")[-1], | |
| label="Download module source", | |
| ), | |
| mo.accordion({ | |
| "Source preview and public symbols": mo.vstack([ | |
| mo.md( | |
| "**Public symbols:** " | |
| + (", ".join(f"`{s['name']}` (line {s['line']})" | |
| for s in _record["symbols"]) or "Not a Python API module.") | |
| ), | |
| mo.plain_text(_content.decode("utf-8")), | |
| ]), | |
| }), | |
| ]) | |
| _panels.append(mo.callout(mo.md( | |
| "Run from the full `workflow/` tree using the modelling environment, not this " | |
| "small viewer environment. A single downloaded module may depend on neighbouring " | |
| "files. Current source defaults are not automatically the paper's exact run configuration." | |
| ), kind="info")) | |
| if checkpoint_picker.value is not None: | |
| _checkpoint = reuse["checkpoints"][checkpoint_picker.value] | |
| _panels.extend([ | |
| mo.md( | |
| f"#### Cell 4 · Reuse saved weights: {_checkpoint['family']}\n" | |
| f"**Location:** `{_checkpoint['location']}`\n\n" | |
| f"**Captured:** {reuse['captured_at']} · **Origin:** {_checkpoint['origin']}\n\n" | |
| "**Status:** files existed at capture; availability is not rechecked " | |
| "by this portable viewer. No binaries are copied, loaded, or validated. " | |
| "Inventory does not establish which checkpoint produced a paper table." | |
| ), | |
| mo.ui.table([ | |
| {"File": item["name"], "Size (MiB)": round(item["bytes"] / 2**20, 2), | |
| "Modified (UTC)": item["modified_utc"]} | |
| for item in _checkpoint["files"] | |
| ], selection=None, page_size=5), | |
| mo.download( | |
| data=json.dumps(_checkpoint, indent=2).encode("utf-8"), | |
| filename="checkpoint_inventory.json", label="Download checkpoint inventory (not weights)", | |
| ), | |
| ]) | |
| if _checkpoint["selection_manifest"]: | |
| _panels.append(mo.accordion({ | |
| "Original best-model selection file (paths may need relocation)": | |
| mo.plain_text(_checkpoint["selection_manifest"]), | |
| })) | |
| if _checkpoint["provenance"]: | |
| _panels.append(mo.accordion({ | |
| "RF training provenance from experiment.json": | |
| mo.plain_text(json.dumps(_checkpoint["provenance"], indent=2)), | |
| })) | |
| if _checkpoint["family"] == "Random Forest": | |
| _panels.append(mo.md(""" | |
| **Reuse saved RF models:** point `--model-dir` in | |
| `future_work/random_forest_baseline/Scripts/evaluate_random_forest_zero_shot.py` | |
| to a trusted directory containing the fold `.joblib` files. | |
| Supply paired `--image` / `--mask` rasters and a new `--output-dir`. | |
| Match the sensor, band order, reflectance scaling and training environment. | |
| Windows locations must be mounted or copied before use from Linux. | |
| Models exceed GitHub's 100 MB/file limit; they remain external assets. | |
| """)) | |
| _panels.append(mo.md( | |
| f"Inventory scope: {reuse['scope']} " | |
| f"Local RF: **{reuse['local_rf_status']}**. " | |
| f"Windows drive: **{reuse['windows_status']}**." | |
| )) | |
| guide_view = mo.vstack(_panels) | |
| return (guide_view,) | |
| def _( | |
| checkpoint_picker, guide_view, mo, module_picker, paper_view, section, | |
| topic_picker, view_tabs, | |
| ): | |
| _crumb = " › ".join(str(part) for part in (section.value, topic_picker.value) if part) | |
| if view_tabs.value.endswith("Paper"): | |
| _body = paper_view | |
| else: | |
| _body = mo.vstack([ | |
| mo.md("Choose a module to follow a notebook-style guide: inputs → configuration " | |
| "→ example code → expected outputs. No code or models run automatically. " | |
| f"Modules are filtered to **{_crumb}**."), | |
| mo.hstack([ | |
| module_picker, | |
| checkpoint_picker if checkpoint_picker.value is not None else mo.md( | |
| "_No matching checkpoint location; data preparation does not need a model._" | |
| ), | |
| ], justify="start", wrap=True), | |
| guide_view, | |
| ]) | |
| mo.vstack([mo.Html(f'<p class="fvc-crumb">{_crumb}</p>'), view_tabs, _body]) | |
| return | |
| if __name__ == "__main__": | |
| app.run() | |