From abe23f7011784a99f3711dc1e534f12d1df8ca30 Mon Sep 17 00:00:00 2001 From: Marcel Zwiers Date: Fri, 27 Sep 2024 13:50:59 +0200 Subject: [PATCH] Fix dcm2niix "BidsGuess" entity checks --- bidscoin/bids.py | 6 +++++- bidscoin/plugins/dcm2niix2bids.py | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/bidscoin/bids.py b/bidscoin/bids.py index 22a32ca6..7e7e27d0 100644 --- a/bidscoin/bids.py +++ b/bidscoin/bids.py @@ -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 @@ -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 = '' diff --git a/bidscoin/plugins/dcm2niix2bids.py b/bidscoin/plugins/dcm2niix2bids.py index 4c1e1da4..a9551b7c 100644 --- a/bidscoin/plugins/dcm2niix2bids.py +++ b/bidscoin/plugins/dcm2niix2bids.py @@ -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