本文整理汇总了Python中pydicom.dataset.Dataset.walk方法的典型用法代码示例。如果您正苦于以下问题:Python Dataset.walk方法的具体用法?Python Dataset.walk怎么用?Python Dataset.walk使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pydicom.dataset.Dataset
的用法示例。
在下文中一共展示了Dataset.walk方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_walk
# 需要导入模块: from pydicom.dataset import Dataset [as 别名]
# 或者: from pydicom.dataset.Dataset import walk [as 别名]
def test_walk(self):
"""Test Dataset.walk iterates through sequences"""
def test_callback(dataset, elem):
if elem.keyword is 'PatientID':
dataset.PatientID = 'FIXED'
ds = Dataset()
ds.PatientName = 'CITIZEN^Jan'
ds.BeamSequence = [Dataset(), Dataset()]
ds.BeamSequence[0].PatientID = 'JAN^Citizen^Snr'
ds.BeamSequence[0].PatientName = 'Some^Name'
ds.BeamSequence[1].PatientID = 'JAN^Citizen^Jr'
ds.BeamSequence[1].PatientName = 'Other^Name'
ds.walk(test_callback, recursive=True)
assert ds.PatientName == 'CITIZEN^Jan'
assert ds.BeamSequence[0].PatientID == 'FIXED'
assert ds.BeamSequence[0].PatientName == 'Some^Name'
assert ds.BeamSequence[1].PatientID == 'FIXED'
assert ds.BeamSequence[1].PatientName == 'Other^Name'
示例2: testTagExceptionWalk
# 需要导入模块: from pydicom.dataset import Dataset [as 别名]
# 或者: from pydicom.dataset.Dataset import walk [as 别名]
def testTagExceptionWalk(self):
# When recursing through dataset, a tag number should appear in
# error messages
ds = Dataset()
ds.PatientID = "123456" # Valid value
ds.SmallestImagePixelValue = 0 # Invalid value
if compat.in_PyPy:
expected_msg = "Invalid tag (0028, 0106): 'int' has no length"
else:
expected_msg = "Invalid tag (0028, 0106): object of type 'int' " "has no len()"
callback = lambda dataset, data_element: str(data_element)
func = lambda: ds.walk(callback)
self.failUnlessExceptionArgs(expected_msg, TypeError, func)