Fix metadata inheritance for multi-echo data (fixes #1044)#1254
Open
anushkagupta200615-jpg wants to merge 1 commit into
Open
Fix metadata inheritance for multi-echo data (fixes #1044)#1254anushkagupta200615-jpg wants to merge 1 commit into
anushkagupta200615-jpg wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.jsonshould override_bold.json).Previously,
BIDSLayoutwas 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.pyfor 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.