sparktk.dicom.ops.extract_keywords module
# vim: set encoding=utf-8
# Copyright (c) 2016 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
def extract_keywords(self, keywords):
"""
Extracts value for each keyword from column holding xml string and adds column for each keyword to assign value
For missing keyword, the value is None
Ex: keywords -> ["PatientID"]
Parameters
----------
:param keywords: (str or list(str)) List of keywords from metadata xml string
Examples
--------
>>> dicom_path = "../datasets/dicom_uncompressed"
>>> dicom = tc.dicom.import_dcm(dicom_path)
>>> dicom.metadata.count()
3
>>> dicom.metadata.inspect(truncate=30)
[#] id metadata
=======================================
[0] 0
AAE=
1.2.840.10008.5.1.4.1.1.4
1.3.6.1.4.1.14519.5.2.1.7308.2101.234736319276602547946349519685
...
#Extract values for given keywords and add as new columns in metadata frame
>>> dicom.extract_keywords(["SOPInstanceUID", "Manufacturer", "StudyDate"])
>>> dicom.metadata.count()
3
>>> dicom.metadata.column_names
[u'id', u'metadata', u'SOPInstanceUID', u'Manufacturer', u'StudyDate']
>>> dicom.metadata.inspect(truncate=20)
[#] id metadata SOPInstanceUID Manufacturer StudyDate
============================================================================
[0] 0
Functions
def extract_keywords(
self, keywords)
Extracts value for each keyword from column holding xml string and adds column for each keyword to assign value For missing keyword, the value is None
Ex: keywords -> ["PatientID"]
Parameters:
keywords | (str or list(str)): | List of keywords from metadata xml string |
Examples:
>>> dicom_path = "../datasets/dicom_uncompressed"
>>> dicom = tc.dicom.import_dcm(dicom_path)
>>> dicom.metadata.count()
3
>>> dicom.metadata.inspect(truncate=30)
[#] id metadata
=======================================
[0] 0 <?xml version="1.0" encodin...
[1] 1 <?xml version="1.0" encodin...
[2] 2 <?xml version="1.0" encodin...
#Part of xml string looks as below
<?xml version="1.0" encoding="UTF-8"?>
<NativeDicomModel xml:space="preserve">
<DicomAttribute keyword="FileMetaInformationVersion" tag="00020001" vr="OB"><InlineBinary>AAE=</InlineBinary></DicomAttribute>
<DicomAttribute keyword="MediaStorageSOPClassUID" tag="00020002" vr="UI"><Value number="1">1.2.840.10008.5.1.4.1.1.4</Value></DicomAttribute>
<DicomAttribute keyword="MediaStorageSOPInstanceUID" tag="00020003" vr="UI"><Value number="1">1.3.6.1.4.1.14519.5.2.1.7308.2101.234736319276602547946349519685</Value></DicomAttribute>
...
#Extract values for given keywords and add as new columns in metadata frame
>>> dicom.extract_keywords(["SOPInstanceUID", "Manufacturer", "StudyDate"])
>>> dicom.metadata.count()
3
>>> dicom.metadata.column_names
[u'id', u'metadata', u'SOPInstanceUID', u'Manufacturer', u'StudyDate']
>>> dicom.metadata.inspect(truncate=20)
[#] id metadata SOPInstanceUID Manufacturer StudyDate
============================================================================
[0] 0 <?xml version="1.... 1.3.6.1.4.1.14519... SIEMENS 20030315
[1] 1 <?xml version="1.... 1.3.6.1.4.1.14519... SIEMENS 20030315
[2] 2 <?xml version="1.... 1.3.6.1.4.1.14519... SIEMENS 20030315
def extract_keywords(self, keywords):
"""
Extracts value for each keyword from column holding xml string and adds column for each keyword to assign value
For missing keyword, the value is None
Ex: keywords -> ["PatientID"]
Parameters
----------
:param keywords: (str or list(str)) List of keywords from metadata xml string
Examples
--------
>>> dicom_path = "../datasets/dicom_uncompressed"
>>> dicom = tc.dicom.import_dcm(dicom_path)
>>> dicom.metadata.count()
3
>>> dicom.metadata.inspect(truncate=30)
[#] id metadata
=======================================
[0] 0
AAE=
1.2.840.10008.5.1.4.1.1.4
1.3.6.1.4.1.14519.5.2.1.7308.2101.234736319276602547946349519685
...
#Extract values for given keywords and add as new columns in metadata frame
>>> dicom.extract_keywords(["SOPInstanceUID", "Manufacturer", "StudyDate"])
>>> dicom.metadata.count()
3
>>> dicom.metadata.column_names
[u'id', u'metadata', u'SOPInstanceUID', u'Manufacturer', u'StudyDate']
>>> dicom.metadata.inspect(truncate=20)
[#] id metadata SOPInstanceUID Manufacturer StudyDate
============================================================================
[0] 0