Skip to content

Commit 348e9c9

Browse files
committed
feat: Add associations.events.sidecar
1 parent 0a37254 commit 348e9c9

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/schema/associations.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,26 @@ import type { BIDSFile } from '../types/filetree.ts'
55
import type { BIDSContext } from './context.ts'
66
import { loadTSV } from '../files/tsv.ts'
77
import { parseBvalBvec } from '../files/dwi.ts'
8-
import { walkBack } from '../files/inheritance.ts'
8+
import { readSidecars, walkBack } from '../files/inheritance.ts'
99
import { evalCheck } from './applyRules.ts'
1010
import { expressionFunctions } from './expressionLanguage.ts'
1111

1212
import { readText } from '../files/access.ts'
1313

14+
interface WithSidecar {
15+
sidecar: Record<string, unknown>
16+
}
17+
1418
function defaultAssociation(file: BIDSFile, _options: any): Promise<{ path: string }> {
1519
return Promise.resolve({ path: file.path })
1620
}
1721

22+
async function constructSidecar(file: BIDSFile): Promise<Record<string, unknown>> {
23+
const sidecars = await readSidecars(file)
24+
// Note ordering here gives precedence to the more specific sidecar
25+
return sidecars.values().reduce((acc, json) => ({ ...json, ...acc }), {})
26+
}
27+
1828
/**
1929
* This object describes lookup functions for files associated to data files in a bids dataset.
2030
* For any given data file we iterate over the associations defined schema.meta.associations.
@@ -24,14 +34,15 @@ function defaultAssociation(file: BIDSFile, _options: any): Promise<{ path: stri
2434
* Many associations only consist of a path; this object is for more complex associations.
2535
*/
2636
const associationLookup = {
27-
events: async (file: BIDSFile, options: { maxRows: number }): Promise<Events> => {
37+
events: async (file: BIDSFile, options: { maxRows: number }): Promise<Events & WithSidecar> => {
2838
const columns = await loadTSV(file, options.maxRows)
2939
.catch((e) => {
3040
return new Map()
3141
})
3242
return {
3343
path: file.path,
3444
onset: columns.get('onset') || [],
45+
sidecar: await constructSidecar(file),
3546
}
3647
},
3748
aslcontext: async (

0 commit comments

Comments
 (0)