dcmmeta2tsv¶
Give a tab separated metadata value line per dicom file.
Module Attributes
keys are names from |
Functions
|
safely look into |
|
extract parameters from siemens CSA :param csa: content of siemens private tag (0x0029, 0x1010) :return: nibabel's csareader dictionary or None if cannot read |
|
read in tsv file like with header name,tag,desc. |
|
|
|
Read dicom header and isolate tags |
|
move our text files has tags like "0051,1017" to pydicom indexe like (0x51,0x1017) |
Classes
Class to cache |
|
|
Container to imitate |
- class dcmmeta2tsv.DicomTagReader[source]¶
Class to cache
read_known_tags()
output- read_dicom_tags(dcm_path)[source]¶
return values of dicom header priority fields ordered as defined in
taglist.txt
:param dcm_path: path to dciom :return: dict[taglist.txt tagname, tag value]>>> dtr = DicomTagReader() >>> hdr = dtr.read_dicom_tags('example_dicoms/RewardedAnti_good.dcm') >>> list(hdr.values()) [1, 'p2', '154833.265000', '20220913', ...
>>> list(hdr.values())[-1] 'example_dicoms/RewardedAnti_good.dcm'
- Parameters:
dcm_path (PathLike)
- Return type:
dict[str, str]
- class dcmmeta2tsv.NULLVAL[source]¶
Container to imitate
pydicom.dcmread
. object that hasobj.value
for when a dicom tag does not exist. Using “null” to match AFNI’s dicom_hinfo missing text
- dcmmeta2tsv.csa_fetch(csa_tr, itemname)[source]¶
safely look into
csa_tr
dicom dictionary. Expect nested structure like'tags'->itemname->'items'->[0]
.In future, might want to check itemname and pull out more than the first array item.
>>> csa_fetch({'notags':'badinput'}, 'PhaseEncodingDirectionPositive') 'null' >>> csa_fetch({'tags':{'ImaPATModeText': {'items': [1]}}}, 'ImaPATModeText') 1
- Parameters:
csa_tr (dict)
itemname (str)
- Return type:
str
- dcmmeta2tsv.read_csa(csa)[source]¶
extract parameters from siemens CSA :param csa: content of siemens private tag (0x0029, 0x1010) :return: nibabel’s csareader dictionary or None if cannot read
>>> read_csa(None) is None True
- Return type:
dict | None
- dcmmeta2tsv.read_known_tags(tagfile='taglist.txt')[source]¶
read in tsv file like with header name,tag,desc. skip comments and header
- Parameters:
tagfile – text tsv file to get name,tag(hex pair),desc from
- Returns:
file parsed into a list of dictonaires
- Return type:
list[Tag]
- dcmmeta2tsv.read_shims(csa_s)[source]¶
- Param:
csa_s
0x0029,0x1020
CSA Series Header Info:: csa_s = dcmmeta2tsv.read_csa(dcm.get(())- Returns:
list of shim values in order of CHM matlab code
- Parameters:
csa_s (dict | None)
- Return type:
list
- CHM maltab code concats
sAdjData.uiAdjShimMode sGRADSPEC.asGPAData[0].lOffset{X,Y,Z} sGRADSPEC.alShimCurrent[0:4] sTXSPEC.asNucleusInfo[0].lFrequency
>>> csa_s = pydicom.dcmread('example_dicoms/RewardedAnti_good.dcm').get((0x0029, 0x1020)) >>> ",".join(read_shims(read_csa(csa_s))) '1174,-2475,4575,531,-20,59,54,-8,123160323,4' >>> read_shims(None) ['null', ...'null']
- dcmmeta2tsv.read_tags(dcm_path, tags)[source]¶
Read dicom header and isolate tags
- Parameters:
dcm_path (PathLike) – dicom file with headers to extract
tags (list[Tag]) – ordered dictionary with ‘tag’ key as hex pair, see
tagpair_to_hex()
- Returns:
dict[tag,value] values in same order as
tags
- Return type:
dict[str, str]
>>> tr = {'name': 'TR', 'tag': (0x0018,0x0080), 'loc': 'header'} >>> ipat = {'name': 'iPAT', 'tag': 'ImaPATModeText', 'loc': 'csa'} >>> list(read_tags('example_dicoms/RewardedAnti_good.dcm', [ipat, tr]).values()) ['p2', '1300.0', 'example_dicoms/RewardedAnti_good.dcm']
>>> list(read_tags('example_dicoms/DNE.dcm', [ipat,tr]).values()) ['null', 'null', 'example_dicoms/DNE.dcm']