本文整理汇总了Python中pydicom.filebase.DicomBytesIO.read方法的典型用法代码示例。如果您正苦于以下问题:Python DicomBytesIO.read方法的具体用法?Python DicomBytesIO.read怎么用?Python DicomBytesIO.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pydicom.filebase.DicomBytesIO
的用法示例。
在下文中一共展示了DicomBytesIO.read方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_read_exact_length_raises
# 需要导入模块: from pydicom.filebase import DicomBytesIO [as 别名]
# 或者: from pydicom.filebase.DicomBytesIO import read [as 别名]
def test_read_exact_length_raises(self):
"""Test DicomIO.read exact length raises if short"""
fp = DicomBytesIO(b'\x00\x01\x03')
fp.is_little_endian = True
with pytest.raises(EOFError,
match="Unexpected end of file. Read 3 bytes of 4 "
"expected starting at position 0x0"):
fp.read(length=4, need_exact_length=True)
示例2: test_read_exact_length
# 需要导入模块: from pydicom.filebase import DicomBytesIO [as 别名]
# 或者: from pydicom.filebase.DicomBytesIO import read [as 别名]
def test_read_exact_length(self):
"""Test DicomIO.read exact length"""
fp = DicomBytesIO(b'\x00\x01\x03\x04')
fp.is_little_endian = True
bytestream = fp.read(length=4, need_exact_length=True)
assert bytestream == b'\x00\x01\x03\x04'
示例3: test_read
# 需要导入模块: from pydicom.filebase import DicomBytesIO [as 别名]
# 或者: from pydicom.filebase.DicomBytesIO import read [as 别名]
def test_read(self):
"""Test DicomIO.read entire length"""
fp = DicomBytesIO(b'\x00\x01\x03')
fp.is_little_endian = True
bytestream = fp.read(length=None, need_exact_length=False)
assert bytestream == b'\x00\x01\x03'
示例4: test_read_length
# 需要导入模块: from pydicom.filebase import DicomBytesIO [as 别名]
# 或者: from pydicom.filebase.DicomBytesIO import read [as 别名]
def test_read_length(self):
"""Test DicomIO.read specific length"""
fp = DicomBytesIO(b'\x00\x01\x03')
fp.is_little_endian = True
bytestream = fp.read(length=2, need_exact_length=False)
assert bytestream == b'\x00\x01'
示例5: TestWriteFileMetaInfo
# 需要导入模块: from pydicom.filebase import DicomBytesIO [as 别名]
# 或者: from pydicom.filebase.DicomBytesIO import read [as 别名]
class TestWriteFileMetaInfo(unittest.TestCase):
"""Unit tests for _write_file_meta_info."""
def setUp(self):
"""Create an empty file-like for use in testing."""
self.fp = DicomBytesIO()
def test_bad_elements(self):
"""Test that non-group 2 elements aren't written to the file meta."""
meta = Dataset()
meta.PatientID = '12345678'
meta.MediaStorageSOPClassUID = '1.1'
meta.MediaStorageSOPInstanceUID = '1.2'
meta.TransferSyntaxUID = '1.3'
meta.ImplementationClassUID = '1.4'
self.assertRaises(ValueError, _write_file_meta_info, self.fp, meta)
def test_missing_elements(self):
"""Test that missing required elements raises ValueError."""
meta = Dataset()
self.assertRaises(ValueError, _write_file_meta_info, self.fp, meta)
meta.MediaStorageSOPClassUID = '1.1'
self.assertRaises(ValueError, _write_file_meta_info, self.fp, meta)
meta.MediaStorageSOPInstanceUID = '1.2'
self.assertRaises(ValueError, _write_file_meta_info, self.fp, meta)
meta.TransferSyntaxUID = '1.3'
self.assertRaises(ValueError, _write_file_meta_info, self.fp, meta)
meta.ImplementationClassUID = '1.4'
_write_file_meta_info(self.fp, meta)
def test_prefix(self):
"""Test that the 'DICM' prefix is present."""
meta = Dataset()
meta.MediaStorageSOPClassUID = '1.1'
meta.MediaStorageSOPInstanceUID = '1.2'
meta.TransferSyntaxUID = '1.3'
meta.ImplementationClassUID = '1.4'
_write_file_meta_info(self.fp, meta)
self.fp.seek(0)
prefix = self.fp.read(4)
self.assertEqual(prefix, b'DICM')
def test_group_length(self):
"""Test that the value for FileMetaInformationGroupLength is OK."""
meta = Dataset()
meta.MediaStorageSOPClassUID = '1.1'
meta.MediaStorageSOPInstanceUID = '1.2'
meta.TransferSyntaxUID = '1.3'
meta.ImplementationClassUID = '1.4'
_write_file_meta_info(self.fp, meta)
# 78 in total, - 4 for prefix, - 12 for group length = 62
self.fp.seek(12)
self.assertEqual(self.fp.read(4), b'\x3E\x00\x00\x00')
def test_group_length_updated(self):
"""Test that FileMetaInformationGroupLength gets updated if present."""
meta = Dataset()
meta.FileMetaInformationGroupLength = 100 # Actual length
meta.MediaStorageSOPClassUID = '1.1'
meta.MediaStorageSOPInstanceUID = '1.2'
meta.TransferSyntaxUID = '1.3'
meta.ImplementationClassUID = '1.4'
_write_file_meta_info(self.fp, meta)
self.fp.seek(12)
self.assertEqual(self.fp.read(4), b'\x3E\x00\x00\x00')
# Check original file meta is unchanged/updated
self.assertEqual(meta.FileMetaInformationGroupLength, 62)
self.assertEqual(meta.FileMetaInformationVersion, b'\x00\x01')
self.assertEqual(meta.MediaStorageSOPClassUID, '1.1')
self.assertEqual(meta.MediaStorageSOPInstanceUID, '1.2')
self.assertEqual(meta.TransferSyntaxUID, '1.3')
self.assertEqual(meta.ImplementationClassUID, '1.4')
def test_version(self):
"""Test that the value for FileMetaInformationVersion is OK."""
meta = Dataset()
meta.MediaStorageSOPClassUID = '1.1'
meta.MediaStorageSOPInstanceUID = '1.2'
meta.TransferSyntaxUID = '1.3'
meta.ImplementationClassUID = '1.4'
_write_file_meta_info(self.fp, meta)
self.fp.seek(16 + 12)
self.assertEqual(self.fp.read(2), b'\x00\x01')
def test_filelike_position(self):
"""Test that the file-like's ending position is OK."""
# 4 bytes prefix
# 8 + 4 bytes FileMetaInformationGroupLength
# 12 + 2 bytes FileMetaInformationVersion
# 8 + 4 bytes MediaStorageSOPClassUID
# 8 + 4 bytes MediaStorageSOPInstanceUID
# 8 + 4 bytes TransferSyntaxUID
# 8 + 4 bytes ImplementationClassUID
# 78 bytes total
meta = Dataset()
meta.MediaStorageSOPClassUID = '1.1'
meta.MediaStorageSOPInstanceUID = '1.2'
#.........这里部分代码省略.........