当前位置: 首页>>代码示例>>Python>>正文


Python DataElement.value方法代码示例

本文整理汇总了Python中pydicom.dataelem.DataElement.value方法的典型用法代码示例。如果您正苦于以下问题:Python DataElement.value方法的具体用法?Python DataElement.value怎么用?Python DataElement.value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pydicom.dataelem.DataElement的用法示例。


在下文中一共展示了DataElement.value方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_write_UR_explicit_little

# 需要导入模块: from pydicom.dataelem import DataElement [as 别名]
# 或者: from pydicom.dataelem.DataElement import value [as 别名]
    def test_write_UR_explicit_little(self):
        """Test writing elements with VR of UR works correctly.

        Elements with a VR of 'UR' use the newer explicit VR
        encoded (see PS3.5 Section 7.1.2).
        """
        # Even length URL
        elem = DataElement(0x00080120, 'UR', 'ftp://bits')
        encoded_elem = self.encode_element(elem, False, True)
        # Tag pair (0008, 2001): 08 00 20 01
        # VR (UR): \x55\x52
        # Reserved: \x00\x00
        # Length (4): \x0a\x00\x00\x00
        # Value: \x66\x74\x70\x3a\x2f\x2f\x62\x69\x74\x73
        ref_bytes = b'\x08\x00\x20\x01\x55\x52\x00\x00\x0a\x00\x00\x00' \
                    b'\x66\x74\x70\x3a\x2f\x2f\x62\x69\x74\x73'
        self.assertEqual(encoded_elem, ref_bytes)

        # Odd length URL has trailing \x20 (SPACE) padding
        elem.value = 'ftp://bit'
        encoded_elem = self.encode_element(elem, False, True)
        ref_bytes = b'\x08\x00\x20\x01\x55\x52\x00\x00\x0a\x00\x00\x00' \
                    b'\x66\x74\x70\x3a\x2f\x2f\x62\x69\x74\x20'
        self.assertEqual(encoded_elem, ref_bytes)

        # Empty value
        elem.value = ''
        encoded_elem = self.encode_element(elem, False, True)
        ref_bytes = b'\x08\x00\x20\x01\x55\x52\x00\x00\x00\x00\x00\x00'
        self.assertEqual(encoded_elem, ref_bytes)
开发者ID:bastula,项目名称:pydicom,代码行数:32,代码来源:test_filewriter.py

示例2: test_write_UC_implicit_little

# 需要导入模块: from pydicom.dataelem import DataElement [as 别名]
# 或者: from pydicom.dataelem.DataElement import value [as 别名]
    def test_write_UC_implicit_little(self):
        """Test writing elements with VR of UC works correctly."""
        # VM 1, even data
        elem = DataElement(0x00189908, 'UC', 'Test')
        encoded_elem = self.encode_element(elem)
        # Tag pair (0018, 9908): 08 00 20 01
        # Length (4): 04 00 00 00
        # Value: \x54\x65\x73\x74
        ref_bytes = b'\x18\x00\x08\x99\x04\x00\x00\x00\x54\x65\x73\x74'
        self.assertEqual(encoded_elem, ref_bytes)

        # VM 1, odd data - padded to even length
        elem.value = 'Test.'
        encoded_elem = self.encode_element(elem)
        ref_bytes = b'\x18\x00\x08\x99\x06\x00\x00\x00\x54\x65\x73\x74\x2e\x20'
        self.assertEqual(encoded_elem, ref_bytes)

        # VM 3, even data
        elem.value = ['Aa', 'B', 'C']
        encoded_elem = self.encode_element(elem)
        ref_bytes = b'\x18\x00\x08\x99\x06\x00\x00\x00\x41\x61\x5c\x42\x5c\x43'
        self.assertEqual(encoded_elem, ref_bytes)

        # VM 3, odd data - padded to even length
        elem.value = ['A', 'B', 'C']
        encoded_elem = self.encode_element(elem)
        ref_bytes = b'\x18\x00\x08\x99\x06\x00\x00\x00\x41\x5c\x42\x5c\x43\x20'
        self.assertEqual(encoded_elem, ref_bytes)

        # Empty data
        elem.value = ''
        encoded_elem = self.encode_element(elem)
        ref_bytes = b'\x18\x00\x08\x99\x00\x00\x00\x00'
        self.assertEqual(encoded_elem, ref_bytes)
开发者ID:bastula,项目名称:pydicom,代码行数:36,代码来源:test_filewriter.py

示例3: test_write_UR_implicit_little

# 需要导入模块: from pydicom.dataelem import DataElement [as 别名]
# 或者: from pydicom.dataelem.DataElement import value [as 别名]
    def test_write_UR_implicit_little(self):
        """Test writing elements with VR of UR works correctly."""
        # Even length URL
        elem = DataElement(0x00080120, 'UR',
                           'http://github.com/darcymason/pydicom')
        encoded_elem = self.encode_element(elem)
        # Tag pair (0008, 2001): 08 00 20 01
        # Length (36): 24 00 00 00
        # Value: 68 to 6d
        ref_bytes = b'\x08\x00\x20\x01\x24\x00\x00\x00\x68\x74' \
                    b'\x74\x70\x3a\x2f\x2f\x67\x69\x74\x68\x75' \
                    b'\x62\x2e\x63\x6f\x6d\x2f\x64\x61\x72\x63' \
                    b'\x79\x6d\x61\x73\x6f\x6e\x2f\x70\x79\x64' \
                    b'\x69\x63\x6f\x6d'
        self.assertEqual(encoded_elem, ref_bytes)

        # Odd length URL has trailing \x20 (SPACE) padding
        elem.value = '../test/test.py'
        encoded_elem = self.encode_element(elem)
        # Tag pair (0008, 2001): 08 00 20 01
        # Length (16): 10 00 00 00
        # Value: 2e to 20
        ref_bytes = b'\x08\x00\x20\x01\x10\x00\x00\x00\x2e\x2e' \
                    b'\x2f\x74\x65\x73\x74\x2f\x74\x65\x73\x74' \
                    b'\x2e\x70\x79\x20'
        self.assertEqual(encoded_elem, ref_bytes)

        # Empty value
        elem.value = ''
        encoded_elem = self.encode_element(elem)
        self.assertEqual(encoded_elem, b'\x08\x00\x20\x01\x00\x00\x00\x00')
开发者ID:bastula,项目名称:pydicom,代码行数:33,代码来源:test_filewriter.py

示例4: testEqualityStandardElement

# 需要导入模块: from pydicom.dataelem import DataElement [as 别名]
# 或者: from pydicom.dataelem.DataElement import value [as 别名]
    def testEqualityStandardElement(self):
        """DataElement: equality returns correct value for simple elements"""
        dd = DataElement(0x00100010, 'PN', 'ANON')
        self.assertTrue(dd == dd)
        ee = DataElement(0x00100010, 'PN', 'ANON')
        self.assertTrue(dd == ee)

        # Check value
        ee.value = 'ANAN'
        self.assertFalse(dd == ee)

        # Check tag
        ee = DataElement(0x00100011, 'PN', 'ANON')
        self.assertFalse(dd == ee)

        # Check VR
        ee = DataElement(0x00100010, 'SH', 'ANON')
        self.assertFalse(dd == ee)

        dd = DataElement(0x00080018, 'UI', '1.2.3.4')
        ee = DataElement(0x00080018, 'UI', '1.2.3.4')
        self.assertTrue(dd == ee)

        ee = DataElement(0x00080018, 'PN', '1.2.3.4')
        self.assertFalse(dd == ee)
开发者ID:bastula,项目名称:pydicom,代码行数:27,代码来源:test_dataelem.py

示例5: test_write_UC_explicit_little

# 需要导入模块: from pydicom.dataelem import DataElement [as 别名]
# 或者: from pydicom.dataelem.DataElement import value [as 别名]
    def test_write_UC_explicit_little(self):
        """Test writing elements with VR of UC works correctly.

        Elements with a VR of 'UC' use the newer explicit VR
        encoding (see PS3.5 Section 7.1.2).
        """
        # VM 1, even data
        elem = DataElement(0x00189908, 'UC', 'Test')
        encoded_elem = self.encode_element(elem, False, True)
        # Tag pair (0018, 9908): 08 00 20 01
        # VR (UC): \x55\x43
        # Reserved: \x00\x00
        # Length (4): \x04\x00\x00\x00
        # Value: \x54\x65\x73\x74
        ref_bytes = b'\x18\x00\x08\x99\x55\x43\x00\x00\x04\x00\x00\x00' \
                    b'\x54\x65\x73\x74'
        self.assertEqual(encoded_elem, ref_bytes)

        # VM 1, odd data - padded to even length
        elem.value = 'Test.'
        encoded_elem = self.encode_element(elem, False, True)
        ref_bytes = b'\x18\x00\x08\x99\x55\x43\x00\x00\x06\x00\x00\x00' \
                    b'\x54\x65\x73\x74\x2e\x20'
        self.assertEqual(encoded_elem, ref_bytes)

        # VM 3, even data
        elem.value = ['Aa', 'B', 'C']
        encoded_elem = self.encode_element(elem, False, True)
        ref_bytes = b'\x18\x00\x08\x99\x55\x43\x00\x00\x06\x00\x00\x00' \
                    b'\x41\x61\x5c\x42\x5c\x43'
        self.assertEqual(encoded_elem, ref_bytes)

        # VM 3, odd data - padded to even length
        elem.value = ['A', 'B', 'C']
        encoded_elem = self.encode_element(elem, False, True)
        ref_bytes = b'\x18\x00\x08\x99\x55\x43\x00\x00\x06\x00\x00\x00' \
                    b'\x41\x5c\x42\x5c\x43\x20'
        self.assertEqual(encoded_elem, ref_bytes)

        # Empty data
        elem.value = ''
        encoded_elem = self.encode_element(elem, False, True)
        ref_bytes = b'\x18\x00\x08\x99\x55\x43\x00\x00\x00\x00\x00\x00'
        self.assertEqual(encoded_elem, ref_bytes)
开发者ID:bastula,项目名称:pydicom,代码行数:46,代码来源:test_filewriter.py

示例6: test_inequality_sequence

# 需要导入模块: from pydicom.dataelem import DataElement [as 别名]
# 或者: from pydicom.dataelem.DataElement import value [as 别名]
    def test_inequality_sequence(self):
        """Test DataElement.__ne__ for sequence element"""
        dd = DataElement(0x300A00B0, 'SQ', [])
        assert not dd != dd
        ee = DataElement(0x300A00B0, 'SQ', [])
        assert not dd != ee
        ee = DataElement(0x300A00B0, 'SQ', [Dataset()])
        assert dd != ee

        # Check value
        dd.value = [Dataset()]
        dd[0].PatientName = 'ANON'
        ee[0].PatientName = 'ANON'
        assert not dd != ee
        ee[0].PatientName = 'ANONA'
        assert dd != ee
开发者ID:jrkerns,项目名称:pydicom,代码行数:18,代码来源:test_dataelem.py

示例7: testEqualityPrivateElement

# 需要导入模块: from pydicom.dataelem import DataElement [as 别名]
# 或者: from pydicom.dataelem.DataElement import value [as 别名]
    def testEqualityPrivateElement(self):
        """DataElement: equality returns correct value for private elements"""
        dd = DataElement(0x01110001, 'PN', 'ANON')
        self.assertTrue(dd == dd)
        ee = DataElement(0x01110001, 'PN', 'ANON')
        self.assertTrue(dd == ee)

        # Check value
        ee.value = 'ANAN'
        self.assertFalse(dd == ee)

        # Check tag
        ee = DataElement(0x01110002, 'PN', 'ANON')
        self.assertFalse(dd == ee)

        # Check VR
        ee = DataElement(0x01110001, 'SH', 'ANON')
        self.assertFalse(dd == ee)
开发者ID:bastula,项目名称:pydicom,代码行数:20,代码来源:test_dataelem.py

示例8: test_write_OL_implicit_little

# 需要导入模块: from pydicom.dataelem import DataElement [as 别名]
# 或者: from pydicom.dataelem.DataElement import value [as 别名]
    def test_write_OL_implicit_little(self):
        """Test writing elements with VR of OL works correctly."""
        # TrackPointIndexList
        bytestring = b'\x00\x01\x02\x03\x04\x05\x06\x07' \
                     b'\x01\x01\x02\x03'
        elem = DataElement(0x00660129, 'OL', bytestring)
        encoded_elem = self.encode_element(elem)
        # Tag pair (0066, 0129): 66 00 29 01
        # Length (12): 0c 00 00 00
        #             | Tag          |   Length      |    Value ->
        ref_bytes = b'\x66\x00\x29\x01\x0c\x00\x00\x00' + bytestring
        self.assertEqual(encoded_elem, ref_bytes)

        # Empty data
        elem.value = b''
        encoded_elem = self.encode_element(elem)
        ref_bytes = b'\x66\x00\x29\x01\x00\x00\x00\x00'
        self.assertEqual(encoded_elem, ref_bytes)
开发者ID:bastula,项目名称:pydicom,代码行数:20,代码来源:test_filewriter.py

示例9: test_write_OD_implicit_little

# 需要导入模块: from pydicom.dataelem import DataElement [as 别名]
# 或者: from pydicom.dataelem.DataElement import value [as 别名]
    def test_write_OD_implicit_little(self):
        """Test writing elements with VR of OD works correctly."""
        # VolumetricCurvePoints
        bytestring = b'\x00\x01\x02\x03\x04\x05\x06\x07' \
                     b'\x01\x01\x02\x03\x04\x05\x06\x07'
        elem = DataElement(0x0070150d, 'OD', bytestring)
        encoded_elem = self.encode_element(elem)
        # Tag pair (0070, 150d): 70 00 0d 15
        # Length (16): 10 00 00 00
        #             | Tag          |   Length      |    Value ->
        ref_bytes = b'\x70\x00\x0d\x15\x10\x00\x00\x00' + bytestring
        self.assertEqual(encoded_elem, ref_bytes)

        # Empty data
        elem.value = b''
        encoded_elem = self.encode_element(elem)
        ref_bytes = b'\x70\x00\x0d\x15\x00\x00\x00\x00'
        self.assertEqual(encoded_elem, ref_bytes)
开发者ID:bastula,项目名称:pydicom,代码行数:20,代码来源:test_filewriter.py

示例10: __setattr__

# 需要导入模块: from pydicom.dataelem import DataElement [as 别名]
# 或者: from pydicom.dataelem.DataElement import value [as 别名]
    def __setattr__(self, name, value):
        """Intercept any attempts to set a value for an instance attribute.

        If name is a dicom descriptive string (cleaned with CleanName),
        then set the corresponding tag and data_element.
        Else, set an instance (python) attribute as any other class would do.

        """
        tag = tag_for_name(name)
        if tag is not None:  # successfully mapped name to a tag
            if tag not in self:  # don't have this tag yet->create the data_element instance
                VR = dictionaryVR(tag)
                data_element = DataElement(tag, VR, value)
            else:  # already have this data_element, just changing its value
                data_element = self[tag]
                data_element.value = value
            # Now have data_element - store it in this dict
            self[tag] = data_element
        else:  # name not in dicom dictionary - setting a non-dicom instance attribute
            # XXX note if user mis-spells a dicom data_element - no error!!!
            self.__dict__[name] = value
开发者ID:BulatSuleymanov,项目名称:pydicom,代码行数:23,代码来源:dataset.py

示例11: testEqualitySequenceElement

# 需要导入模块: from pydicom.dataelem import DataElement [as 别名]
# 或者: from pydicom.dataelem.DataElement import value [as 别名]
    def testEqualitySequenceElement(self):
        """DataElement: equality returns correct value for sequence elements"""
        dd = DataElement(0x300A00B0, 'SQ', [])
        self.assertTrue(dd == dd)
        ee = DataElement(0x300A00B0, 'SQ', [])
        self.assertTrue(dd == ee)

        # Check value
        e = Dataset()
        e.PatientName = 'ANON'
        ee.value = [e]
        self.assertFalse(dd == ee)

        # Check tag
        ee = DataElement(0x01110002, 'SQ', [])
        self.assertFalse(dd == ee)

        # Check VR
        ee = DataElement(0x300A00B0, 'SH', [])
        self.assertFalse(dd == ee)

        # Check with dataset
        dd = DataElement(0x300A00B0, 'SQ', [Dataset()])
        dd.value[0].PatientName = 'ANON'
        ee = DataElement(0x300A00B0, 'SQ', [Dataset()])
        ee.value[0].PatientName = 'ANON'
        self.assertTrue(dd == ee)

        # Check uneven sequences
        dd.value.append(Dataset())
        dd.value[1].PatientName = 'ANON'
        self.assertFalse(dd == ee)

        ee.value.append(Dataset())
        ee.value[1].PatientName = 'ANON'
        self.assertTrue(dd == ee)
        ee.value.append(Dataset())
        ee.value[2].PatientName = 'ANON'
        self.assertFalse(dd == ee)
开发者ID:bastula,项目名称:pydicom,代码行数:41,代码来源:test_dataelem.py

示例12: __setattr__

# 需要导入模块: from pydicom.dataelem import DataElement [as 别名]
# 或者: from pydicom.dataelem.DataElement import value [as 别名]
    def __setattr__(self, name, value):
        """Intercept any attempts to set a value for an instance attribute.

        If name is a DICOM keyword, set the corresponding tag and DataElement.
        Else, set an instance (python) attribute as any other class would do.

        Parameters
        ----------
        name : str
            The element keyword for the DataElement you wish to add/change. If
            `name` is not a DICOM element keyword then this will be the
            name of the attribute to be added/changed.
        value
            The value for the attribute to be added/changed.
        """
        tag = tag_for_keyword(name)
        if tag is not None:  # successfully mapped name to a tag
            if tag not in self:
                # don't have this tag yet->create the data_element instance
                VR = dictionary_VR(tag)
                data_element = DataElement(tag, VR, value)
            else:
                # already have this data_element, just changing its value
                data_element = self[tag]
                data_element.value = value
            # Now have data_element - store it in this dict
            self[tag] = data_element
        elif repeater_has_keyword(name):
            # Check if `name` is repeaters element
            raise ValueError('{} is a DICOM repeating group '
                             'element and must be added using '
                             'the add() or add_new() methods.'
                             .format(name))
        else:
            # name not in dicom dictionary - setting a non-dicom instance
            # attribute
            # XXX note if user mis-spells a dicom data_element - no error!!!
            super(Dataset, self).__setattr__(name, value)
开发者ID:jrkerns,项目名称:pydicom,代码行数:40,代码来源:dataset.py

示例13: test_write_OL_explicit_little

# 需要导入模块: from pydicom.dataelem import DataElement [as 别名]
# 或者: from pydicom.dataelem.DataElement import value [as 别名]
    def test_write_OL_explicit_little(self):
        """Test writing elements with VR of OL works correctly.

        Elements with a VR of 'OL' use the newer explicit VR
        encoding (see PS3.5 Section 7.1.2).
        """
        # TrackPointIndexList
        bytestring = b'\x00\x01\x02\x03\x04\x05\x06\x07' \
                     b'\x01\x01\x02\x03'
        elem = DataElement(0x00660129, 'OL', bytestring)
        encoded_elem = self.encode_element(elem, False, True)
        # Tag pair (0066, 0129): 66 00 29 01
        # VR (OL): \x4f\x4c
        # Reserved: \x00\x00
        # Length (12): 0c 00 00 00
        #             | Tag          | VR    | Rsrvd |   Length      |    Value ->
        ref_bytes = b'\x66\x00\x29\x01\x4f\x4c\x00\x00\x0c\x00\x00\x00' + bytestring
        self.assertEqual(encoded_elem, ref_bytes)

        # Empty data
        elem.value = b''
        encoded_elem = self.encode_element(elem, False, True)
        ref_bytes = b'\x66\x00\x29\x01\x4f\x4c\x00\x00\x00\x00\x00\x00'
        self.assertEqual(encoded_elem, ref_bytes)
开发者ID:bastula,项目名称:pydicom,代码行数:26,代码来源:test_filewriter.py

示例14: test_write_OD_explicit_little

# 需要导入模块: from pydicom.dataelem import DataElement [as 别名]
# 或者: from pydicom.dataelem.DataElement import value [as 别名]
    def test_write_OD_explicit_little(self):
        """Test writing elements with VR of OD works correctly.

        Elements with a VR of 'OD' use the newer explicit VR
        encoding (see PS3.5 Section 7.1.2).
        """
        # VolumetricCurvePoints
        bytestring = b'\x00\x01\x02\x03\x04\x05\x06\x07' \
                     b'\x01\x01\x02\x03\x04\x05\x06\x07'
        elem = DataElement(0x0070150d, 'OD', bytestring)
        encoded_elem = self.encode_element(elem, False, True)
        # Tag pair (0070, 150d): 70 00 0d 15
        # VR (OD): \x4f\x44
        # Reserved: \x00\x00
        # Length (16): \x10\x00\x00\x00
        #             | Tag          | VR    | Rsrvd |   Length      |    Value ->
        ref_bytes = b'\x70\x00\x0d\x15\x4f\x44\x00\x00\x10\x00\x00\x00' + bytestring
        self.assertEqual(encoded_elem, ref_bytes)

        # Empty data
        elem.value = b''
        encoded_elem = self.encode_element(elem, False, True)
        ref_bytes = b'\x70\x00\x0d\x15\x4f\x44\x00\x00\x00\x00\x00\x00'
        self.assertEqual(encoded_elem, ref_bytes)
开发者ID:bastula,项目名称:pydicom,代码行数:26,代码来源:test_filewriter.py


注:本文中的pydicom.dataelem.DataElement.value方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。