/ concept-collection / seqlab
Sign in
concept-collection / seqlab
seqlab / src / examples / index.ts
65 lines · 2.0 KBCodeBlameHistory
78d04f1seqlab: write and view pulseq MRI sequences in the browserJeremy Magland 1// Example registry. Sources come from two places:
2// - curated hand-written scripts (fid/epi/gre) with friendlier comments
3// - auto-adapted pulseq demoSeq scripts under ./pulseq/*.m, generated by
4// scripts/gen-examples.mjs (only demos that actually run on numbl)
5// Metadata (name/category/description) is looked up in CATALOG; run-time
6// labels come from generated-timings.ts. An id without a CATALOG entry is
7// skipped, so stale generated files can't leak in unlabeled.
8import { CATALOG, type Category } from './catalog.ts'
9import { TIMINGS } from './generated-timings.ts'
10import fidSource from './fid.m?raw'
11import epiSource from './epi.m?raw'
12import greSource from './gre.m?raw'
14export interface Example {
15 id: string
16 name: string
17 category: Category
18 description: string
19 source: string
20 /** Rough in-browser run time, e.g. "~2 s". */
21 approx: string
22 /** True for the hand-written curated scripts. */
23 curated: boolean
26const curated: Record<string, string> = {
27 fid: fidSource,
28 epi: epiSource,
29 gre: greSource,
32const generatedModules = import.meta.glob('./pulseq/*.m', {
33 query: '?raw',
34 import: 'default',
35 eager: true,
36}) as Record<string, string>
38const generated: Record<string, string> = {}
39for (const [path, source] of Object.entries(generatedModules)) {
40 const id = path.replace(/^\.\/pulseq\//, '').replace(/\.m$/, '')
41 if (!(id in curated)) generated[id] = source
44function build(id: string, source: string, curatedFlag: boolean): Example | null {
45 const meta = CATALOG[id]
46 if (!meta) return null
47 return {
48 id,
49 name: meta.name,
50 category: meta.category,
51 description: meta.description,
52 source,
53 approx: TIMINGS[id] ?? '',
54 curated: curatedFlag,
55 }
58export const EXAMPLES: Example[] = [
59 ...Object.entries(curated).map(([id, src]) => build(id, src, true)),
60 ...Object.entries(generated).map(([id, src]) => build(id, src, false)),
61].filter((e): e is Example => e !== null)
63export function findExample(id: string): Example | undefined {
64 return EXAMPLES.find((e) => e.id === id)
moveopenescclose