Skip to content

Commit 3ccf8a3

Browse files
committed
enh: use private CSA tags if possible
1 parent 53f1d67 commit 3ccf8a3

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

heudiconv/dicoms.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,20 +75,9 @@ def group_dicoms_into_seqinfos(files, file_filter, dcmfilter, grouping):
7575

7676
# Workaround for protocol name in private siemens csa header
7777
try:
78-
ProtocolName = mw.dcm_data.ProtocolName
78+
mw.dcm_data.ProtocolName
7979
except AttributeError:
80-
mw.dcm_data.ProtocolName = ''
81-
82-
# try parsing Siemens csa header
83-
try:
84-
if mw.is_csa and mw.dcm_data.ProtocolName == '':
85-
csastr = csareader.get_csa_header(mw.dcm_data, 'series')['tags']['MrPhoenixProtocol']['items'][0]
86-
#Make sure dcmstack finds beginning of header.
87-
csastr = csastr.replace("### ASCCONV BEGIN", "### ASCCONV BEGIN ### ") #Remove when dmcstack is updated
88-
parsedhdr = ds.extract.parse_phoenix_prot('MrPhoenixProtocol', csastr)
89-
mw.dcm_data.ProtocolName = parsedhdr['tProtocolName'].replace(" ", "")
90-
except:
91-
lgr.info("File {} is missing ProtocolName".format(filename))
80+
mw.dcm_data.ProtocolName = parse_private_csa_header(mw.dcm_data, 'ProtocolName', 'tProtocolName') if mw.is_csa else ''
9281

9382
try:
9483
series_id = (int(mw.dcm_data.SeriesNumber),
@@ -500,3 +489,20 @@ def embed_metadata_from_dicoms(bids, item_dicoms, outname, outname_bids,
500489
except Exception as exc:
501490
lgr.error("Embedding failed: %s", str(exc))
502491
os.chdir(cwd)
492+
493+
def parse_private_csa_header(dcm_data, public_attr, private_attr, default=None):
494+
"""Doc"""
495+
# tProtocolName
496+
# TODO: provide mapping to private_attr from public_attr
497+
from nibabel.nicom import csareader
498+
import dcmstack.extract as dsextract
499+
try:
500+
# TODO: test with attr besides ProtocolName
501+
csastr = csareader.get_csa_header(dcm_data, 'series')['tags']['MrPhoenixProtocol']['items'][0]
502+
csastr = csastr.replace("### ASCCONV BEGIN", "### ASCCONV BEGIN ### ")
503+
parsedhdr = dsextract.parse_phoenix_prot('MrPhoenixProtocol', csastr)
504+
val = parsedhdr[private_attr].replace(' ', '')
505+
except Exception as e:
506+
lgr.info("Failed to parse CSA header: %s", str(e))
507+
val = default if default else ''
508+
return val

0 commit comments

Comments
 (0)