Skip to content

Commit 65df3b3

Browse files
committed
feat: Add associations.events.sidecar
1 parent ebbcdd4 commit 65df3b3

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,14 +5,24 @@ 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

12+
interface WithSidecar {
13+
sidecar: Record<string, unknown>
14+
}
15+
1216
function defaultAssociation(file: BIDSFile, _options: any): Promise<{ path: string }> {
1317
return Promise.resolve({ path: file.path })
1418
}
1519

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

0 commit comments

Comments
 (0)