Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENH] filter dicoms earlier to avoid nibabel crash with XA ill-formed mutli-planar localizer dicoms #806

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions heudiconv/dicoms.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,6 @@
Parse DICOM attributes. Returns None if not valid.
"""
mw = dw.wrapper_from_file(fl, force=True, stop_before_pixels=True)
# clean series signature
for sig in ("iop", "ICE_Dims", "SequenceName"):
try:
del mw.series_signature[sig]
except KeyError:
pass
# Workaround for protocol name in private siemens csa header
if not getattr(mw.dcm_data, "ProtocolName", "").strip():
mw.dcm_data.ProtocolName = (
Expand All @@ -189,9 +183,6 @@
except AttributeError as e:
lgr.warning('Ignoring %s since not quite a "normal" DICOM: %s', fl, e)
return None
if dcmfilter is not None and dcmfilter(mw.dcm_data):
lgr.warning("Ignoring %s because of DICOM filter", fl)
return None
if mw.dcm_data[0x0008, 0x0016].repval in (
"Raw Data Storage",
"GrayscaleSoftcopyPresentationStateStorage",
Expand All @@ -203,6 +194,15 @@
except AttributeError:
lgr.info("File {} is missing any StudyInstanceUID".format(fl))
file_studyUID = None
if dcmfilter is not None and dcmfilter(mw.dcm_data):
lgr.warning("Ignoring %s because of DICOM filter", fl)
return None

Check warning on line 199 in heudiconv/dicoms.py

View check run for this annotation

Codecov / codecov/patch

heudiconv/dicoms.py#L198-L199

Added lines #L198 - L199 were not covered by tests
# clean series signature
for sig in ("iop", "ICE_Dims", "SequenceName"):
try:
del mw.series_signature[sig]
except KeyError:
pass
return mw, series_id, file_studyUID


Expand Down
13 changes: 10 additions & 3 deletions heudiconv/heuristics/reproin.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@

def filter_dicom(dcmdata: dcm.dataset.Dataset) -> bool:
"""Return True if a DICOM dataset should be filtered out, else False"""
return True if dcmdata.StudyInstanceUID in dicoms2skip else False
return True if dcmdata.get("StudyInstanceUID") in dicoms2skip else False


def filter_files(_fn: str) -> bool:
Expand Down Expand Up @@ -406,7 +406,11 @@
# XXX: skip derived sequences, we don't store them to avoid polluting
# the directory, unless it is the motion corrected ones
# (will get _rec-moco suffix)
if skip_derived and curr_seqinfo.is_derived and not curr_seqinfo.is_motion_corrected:
if (
skip_derived
and curr_seqinfo.is_derived
and not curr_seqinfo.is_motion_corrected
):
skipped.append(curr_seqinfo.series_id)
lgr.debug("Ignoring derived data %s", curr_seqinfo.series_id)
continue
Expand Down Expand Up @@ -552,7 +556,10 @@
# XXX if we have a known earlier study, we need to always
# increase the run counter for phasediff because magnitudes
# were not acquired
if get_study_hash([curr_seqinfo]) == "9d148e2a05f782273f6343507733309d":
if (

Check warning on line 559 in heudiconv/heuristics/reproin.py

View check run for this annotation

Codecov / codecov/patch

heudiconv/heuristics/reproin.py#L559

Added line #L559 was not covered by tests
get_study_hash([curr_seqinfo])
== "9d148e2a05f782273f6343507733309d"
):
current_run += 1
else:
raise RuntimeError(
Expand Down
Loading