本文整理汇总了Python中pydicom.filebase.DicomBytesIO类的典型用法代码示例。如果您正苦于以下问题:Python DicomBytesIO类的具体用法?Python DicomBytesIO怎么用?Python DicomBytesIO使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DicomBytesIO类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_deferred_data_element_deprecated
def test_deferred_data_element_deprecated():
"""Test the deprecation warning is working"""
fp = DicomBytesIO()
fp.is_little_endian = True
fp.is_implicit_VR = True
with pytest.deprecated_call():
elem = DeferredDataElement(0x00000000, 'UL', fp, 0, 0, 4)
示例2: test_read_be_tag
def test_read_be_tag(self):
"""Test DicomIO.read_be_tag indirectly"""
# Tags are 2 + 2 = 4 bytes
bytestream = b'\x01\x02\x03\x04\x05\x06'
fp = DicomBytesIO(bytestream)
fp.is_little_endian = False
assert Tag(fp.read_be_tag()) == 0x01020304
示例3: test_charset_patient_names
def test_charset_patient_names(self, filename, patient_name):
"""Test patient names are correctly decoded and encoded."""
# check that patient names are correctly read
file_path = get_charset_files(filename + '.dcm')[0]
ds = dcmread(file_path)
ds.decode()
assert patient_name == ds.PatientName
# check that patient names are correctly written back
fp = DicomBytesIO()
fp.is_implicit_VR = False
fp.is_little_endian = True
ds.save_as(fp, write_like_original=False)
fp.seek(0)
ds = dcmread(fp)
assert patient_name == ds.PatientName
# check that patient names are correctly written back
# without original byte string (PersonName3 only)
if hasattr(ds.PatientName, 'original_string'):
ds.PatientName.original_string = None
fp = DicomBytesIO()
fp.is_implicit_VR = False
fp.is_little_endian = True
ds.save_as(fp, write_like_original=False)
fp.seek(0)
ds = dcmread(fp)
assert patient_name == ds.PatientName
示例4: test_zero_length
def test_zero_length(self):
"""Test reading BOT with zero length"""
bytestream = b'\xFE\xFF\x00\xE0' \
b'\x00\x00\x00\x00'
fp = DicomBytesIO(bytestream)
fp.is_little_endian = True
assert [0] == get_frame_offsets(fp)
示例5: test_encapsulate_single_fragment_per_frame_bot
def test_encapsulate_single_fragment_per_frame_bot(self):
"""Test encapsulating single fragment per frame with BOT values."""
ds = dcmread(JP2K_10FRAME_NOBOT)
frames = decode_data_sequence(ds.PixelData)
assert len(frames) == 10
data = encapsulate(frames, fragments_per_frame=1, has_bot=True)
test_frames = decode_data_sequence(data)
for a, b in zip(test_frames, frames):
assert a == b
fp = DicomBytesIO(data)
fp.is_little_endian = True
offsets = get_frame_offsets(fp)
assert offsets == [
0x0000, # 0
0x0eee, # 3822
0x1df6, # 7670
0x2cf8, # 11512
0x3bfc, # 15356
0x4ade, # 19166
0x59a2, # 22946
0x6834, # 26676
0x76e2, # 30434
0x8594 # 34196
]
示例6: test_single_frame
def test_single_frame(self):
"""Test reading single-frame BOT item"""
bytestream = b'\xFE\xFF\x00\xE0' \
b'\x04\x00\x00\x00' \
b'\x00\x00\x00\x00'
fp = DicomBytesIO(bytestream)
fp.is_little_endian = True
assert [0] == get_frame_offsets(fp)
示例7: encode
def encode(ds, is_implicit_VR, is_little_endian):
f = DicomBytesIO()
f.is_implicit_VR = is_implicit_VR
f.is_little_endian = is_little_endian
write_dataset(f, ds)
rawstr = f.parent.getvalue()
f.close()
return rawstr
示例8: test_single_fragment_no_delimiter
def test_single_fragment_no_delimiter(self):
"""Test single fragment is returned OK"""
bytestream = b'\xFE\xFF\x00\xE0' \
b'\x04\x00\x00\x00' \
b'\x01\x00\x00\x00'
fp = DicomBytesIO(bytestream)
fp.is_little_endian = True
assert read_item(fp) == b'\x01\x00\x00\x00'
示例9: encode_element
def encode_element(el, is_implicit_VR, is_little_endian):
f = DicomBytesIO()
f.is_implicit_VR = is_implicit_VR
f.is_little_endian = is_little_endian
write_data_element(f, el)
rawstr = f.parent.getvalue()
f.close()
return rawstr
示例10: test_read_exact_length_raises
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)
示例11: test_read_le_ul
def test_read_le_ul(self):
"""Test DicomIO.read_leUL indirectly"""
# UL are 4 bytes fixed
bytestream = b'\x00\x00\x00\x00\xFF\xFF\x00\x00\xFE\xFF\xFF\xFF'
fp = DicomBytesIO(bytestream)
fp.is_little_endian = True
assert fp.read_leUL() == 0
assert fp.read_leUL() == 0xFFFF
assert fp.read_leUL() == 0xFFFFFFFE
示例12: test_read_be_us
def test_read_be_us(self):
"""Test DicomIO.read_beUS indirectly"""
# US are 2 bytes fixed
bytestream = b'\x00\x00\x00\xFF\xFF\xFE'
fp = DicomBytesIO(bytestream)
fp.is_little_endian = True
assert fp.read_beUS() == 0
assert fp.read_beUS() == 255
assert fp.read_beUS() == 0xFFFE
示例13: test_not_little_endian
def test_not_little_endian(self):
"""Test reading big endian raises exception"""
bytestream = b'\xFE\xFF\x00\xE0' \
b'\x00\x00\x00\x00'
fp = DicomBytesIO(bytestream)
fp.is_little_endian = False
with pytest.raises(ValueError,
match="'fp.is_little_endian' must be True"):
get_frame_offsets(fp)
示例14: test_multi_frame
def test_multi_frame(self):
"""Test reading multi-frame BOT item"""
bytestream = b'\xFE\xFF\x00\xE0' \
b'\x10\x00\x00\x00' \
b'\x00\x00\x00\x00' \
b'\x66\x13\x00\x00' \
b'\xF4\x25\x00\x00' \
b'\xFE\x37\x00\x00'
fp = DicomBytesIO(bytestream)
fp.is_little_endian = True
assert [0, 4966, 9716, 14334] == get_frame_offsets(fp)
示例15: test_item_undefined_length
def test_item_undefined_length(self):
"""Test exception raised if item length undefined."""
bytestream = b'\xFE\xFF\x00\xE0' \
b'\xFF\xFF\xFF\xFF' \
b'\x00\x00\x00\x01'
fp = DicomBytesIO(bytestream)
fp.is_little_endian = True
with pytest.raises(ValueError,
match="Encapsulated data fragment had Undefined "
"Length at data position 0x4"):
read_item(fp)