Skip to content

Commit

Permalink
Fix dcm2niix "BidsGuess" entity checks
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelzwiers committed Sep 27, 2024
1 parent 63c93bf commit abe23f7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 5 additions & 1 deletion bidscoin/bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -1338,7 +1338,7 @@ def get_matching_run(self, datasource: DataSource, runtime=False) -> Tuple[RunIt

# Stop searching the bidsmap if we have a match
if match:
LOGGER.bcdebug(f"Found bidsmap match: {runitem} -> {runitem}")
LOGGER.bcdebug(f"Found bidsmap match: {runitem}")
runitem = RunItem('', datatype, copy.deepcopy(rundata), datasource, self.options, self.plugins)

# SeriesDescriptions (and ProtocolName?) may get a suffix like '_SBRef' from the vendor, try to strip it off
Expand Down Expand Up @@ -1749,6 +1749,10 @@ def get_dicomfield(tagname: str, dicomfile: Path) -> Union[str, int]:

global _DICOMDICT_CACHE, _DICOMFILE_CACHE

# Skip the RunItem properties
if tagname in ():
return ''

if not dicomfile.is_file():
LOGGER.warning(f"{dicomfile} not found")
value = ''
Expand Down
4 changes: 3 additions & 1 deletion bidscoin/plugins/dcm2niix2bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,12 +509,14 @@ def bidscoiner_plugin(session: Path, bidsmap: BidsMap, bidsses: Path) -> Union[N

# Check if the target output aligns with dcm2niix's "BidsGuess" datatype and filename entities
typeguess, targetguess = metadata.get('BidsGuess') or ['', ''] # BidsGuess: [datatype, filename]
LOGGER.bcdebug(f"BidsGuess: [{typeguess}, {targetguess}]")
if typeguess and run.datatype != typeguess:
LOGGER.warning(f"The datatype of {run} does not match with the datatype suggested by dcm2niix: {typeguess}")
elif targetguess and run.bids['suffix'] != bids.get_bidsvalue(targetguess, 'suffix'):
LOGGER.warning(f"The suffix of {run} does not match with the suffix suggested by dcm2niix: {targetguess}")
for entity in ('part', 'inv', 'echo', 'dir'):
if targetguess and run.bids.get(entity) and run.bids[entity] != bids.get_bidsvalue(targetguess, entity):
targetvalue = bids.get_bidsvalue(target, entity)
if targetvalue and targetguess and targetvalue != bids.get_bidsvalue(targetguess, entity):
LOGGER.warning(f"The '{entity}' value in {run} does not match with the '{entity}' value suggested by dcm2niix: {targetguess}")

# Write the scans_table to disk
Expand Down

0 comments on commit abe23f7

Please sign in to comment.