Skip to content

Fix metadata inheritance for multi-echo data (fixes #1044)#1254

Open
anushkagupta200615-jpg wants to merge 1 commit into
bids-standard:mainfrom
anushkagupta200615-jpg:fix-issue-1044
Open

Fix metadata inheritance for multi-echo data (fixes #1044)#1254
anushkagupta200615-jpg wants to merge 1 commit into
bids-standard:mainfrom
anushkagupta200615-jpg:fix-issue-1044

Conversation

@anushkagupta200615-jpg

Copy link
Copy Markdown

Description

Fixes #1044

This PR addresses an issue where inherited metadata could incorrectly override immediate metadata for multi-echo data (or other sidecars at the same directory level) when they share the same base entities.

The Issue

According to BIDS inheritance principles, when multiple JSON sidecars apply to a given data file, the sidecar that shares the most matching entities should take precedence (e.g. _echo-2_bold.json should override _bold.json).
Previously, BIDSLayout was appending matching JSON sidecars at the same directory level in an arbitrary order before generating the reverse inheritance stack. This resulted in less specific generic sidecars sometimes erroneously overriding the more specific sidecars.

The Fix

Added a deterministic sort to src/bids/layout/index.py for all JSON payloads and ancestors found at any given directory level. By sorting the payloads by the number of matching entities in descending order, we guarantee that the more generic files are processed first and the more specific files (with more entities) are processed last during the reverse stack update.

This ensures that the sidecar with the most entities correctly takes precedence.


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inherited metadata overrides immediate metadata for multi-echo data with same-named single-echo

1 participant