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


Python data.get_testdata_files函数代码示例

本文整理汇总了Python中pydicom.data.get_testdata_files函数的典型用法代码示例。如果您正苦于以下问题:Python get_testdata_files函数的具体用法?Python get_testdata_files怎么用?Python get_testdata_files使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: test_invalid_sop_no_file_meta

 def test_invalid_sop_no_file_meta(self):
     """Test exception raised if invalid sop class but no file_meta"""
     ds = read_file(get_testdata_files('CT_small.dcm')[0])
     with pytest.raises(AttributeError,
                        match="'DicomDir' object has no attribute "
                              "'DirectoryRecordSequence'"):
         DicomDir("some_name", ds, b'\x00' * 128, None, True, True)
开发者ID:jrkerns,项目名称:pydicom,代码行数:7,代码来源:test_dicomdir.py

示例2: testJPEGlossless_odd_data_size

 def testJPEGlossless_odd_data_size(self):
     """Test decoding JPEG with pillow handler succeeds."""
     test_file = get_testdata_files('SC_rgb_small_odd_jpeg.dcm')[0]
     ds = dcmread(test_file)
     pixel_data = ds.pixel_array
     assert pixel_data.nbytes == 27
     assert pixel_data.shape == (3, 3, 3)
开发者ID:darcymason,项目名称:pydicom,代码行数:7,代码来源:test_pillow_pixel_data.py

示例3: test_invalid_sop_file_meta

 def test_invalid_sop_file_meta(self):
     """Test exception raised if SOP Class is not Media Storage Directory"""
     ds = read_file(get_testdata_files('CT_small.dcm')[0])
     with pytest.raises(InvalidDicomError,
                        match="SOP Class is not Media Storage "
                              "Directory \(DICOMDIR\)"):
         DicomDir("some_name", ds, b'\x00' * 128, ds.file_meta, True, True)
开发者ID:jrkerns,项目名称:pydicom,代码行数:7,代码来源:test_dicomdir.py

示例4: test_get_dataset

    def test_get_dataset(self):
        """Test the different functions to get lists of data files."""

        # Test base locations
        charbase = os.path.join(DATA_ROOT, 'charset_files')
        self.assertTrue(os.path.exists(charbase))

        testbase = os.path.join(DATA_ROOT, 'test_files')
        self.assertTrue(os.path.exists(testbase))

        # Test file get
        chardata = get_charset_files()
        self.assertTrue(len(chardata) > 15)

        # Test that top level file is included
        bases = [basename(x) for x in chardata]

        # Test that subdirectory files included
        testdata = get_testdata_files()
        bases = [basename(x) for x in testdata]
        self.assertTrue('2693' in bases)
        self.assertTrue(len(testdata) > 70)

        # The files should be from their respective bases
        [self.assertTrue(testbase in x) for x in testdata]
        [self.assertTrue(charbase in x) for x in chardata]
开发者ID:darcymason,项目名称:pydicom,代码行数:26,代码来源:test_data_manager.py

示例5: test_code_file

 def test_code_file(self, capsys):
     """Test utils.codify.code_file"""
     filename = get_testdata_files("rtplan.dcm")[0]
     args = ["--save-as", r"c:\temp\testout.dcm", filename]
     codify_main(100, args)
     out, err = capsys.readouterr()
     assert r"c:\temp\testout.dcm" in out
开发者ID:darcymason,项目名称:pydicom,代码行数:7,代码来源:test_util.py

示例6: test_invalid_character_set_enforce_valid

 def test_invalid_character_set_enforce_valid(self):
     """charset: raise on invalid encoding"""
     config.enforce_valid_values = True
     ds = dcmread(get_testdata_files("CT_small.dcm")[0])
     ds.read_encoding = None
     ds.SpecificCharacterSet = 'Unsupported'
     with pytest.raises(LookupError, match='unknown encoding: Unsupported'):
         ds.decode()
开发者ID:scaramallion,项目名称:pydicom,代码行数:8,代码来源:test_charset.py

示例7: test_trait_names

 def test_trait_names(self):
     """Test Dataset.trait_names contains element keywords"""
     test_file = get_testdata_files('CT_small.dcm')[0]
     ds = dcmread(test_file, force=True)
     names = ds.trait_names()
     assert 'PatientName' in names
     assert 'save_as' in names
     assert 'PixelData' in names
开发者ID:moloney,项目名称:pydicom,代码行数:8,代码来源:test_dataset.py

示例8: test_get_dataset_pattern

    def test_get_dataset_pattern(self):
        """Test that pattern is working properly."""

        pattern = 'CT_small'
        filename = get_testdata_files(pattern)
        self.assertTrue(filename[0].endswith('CT_small.dcm'))

        pattern = 'chrX1'
        filename = get_charset_files(pattern)
        self.assertTrue(filename[0].endswith('chrX1.dcm'))
开发者ID:darcymason,项目名称:pydicom,代码行数:10,代码来源:test_data_manager.py

示例9: test_invalid_character_set

 def test_invalid_character_set(self):
     """charset: replace invalid encoding with default encoding"""
     ds = dcmread(get_testdata_files("CT_small.dcm")[0])
     ds.read_encoding = None
     ds.SpecificCharacterSet = 'Unsupported'
     with pytest.warns(UserWarning,
                       match=u"Unknown encoding 'Unsupported' "
                             u"- using default encoding instead"):
         ds.decode()
         assert u'CompressedSamples^CT1' == ds.PatientName
开发者ID:scaramallion,项目名称:pydicom,代码行数:10,代码来源:test_charset.py

示例10: test_set_convert_private_elem_from_raw

    def test_set_convert_private_elem_from_raw(self):
        """Test Dataset.__setitem__ with a raw private element"""
        test_file = get_testdata_files('CT_small.dcm')[0]
        ds = dcmread(test_file, force=True)
        # 'tag VR length value value_tell is_implicit_VR is_little_endian'
        elem = RawDataElement((0x0043, 0x1029), 'OB', 2, b'\x00\x01', 0,
                              True, True)
        ds.__setitem__((0x0043, 0x1029), elem)

        assert ds[(0x0043, 0x1029)].value == b'\x00\x01'
        assert type(ds[(0x0043, 0x1029)]) == DataElement
开发者ID:moloney,项目名称:pydicom,代码行数:11,代码来源:test_dataset.py

示例11: test_get_item

    def test_get_item(self):
        """Test Dataset.get_item"""
        ds = Dataset()
        ds.CommandGroupLength = 120  # 0000,0000
        ds.SOPInstanceUID = '1.2.3.4'  # 0008,0018

        # Test non-deferred read
        assert ds.get_item(0x00000000) == ds[0x00000000]
        assert ds.get_item(0x00000000).value == 120
        assert ds.get_item(0x00080018) == ds[0x00080018]
        assert ds.get_item(0x00080018).value == '1.2.3.4'

        # Test deferred read
        test_file = get_testdata_files('MR_small.dcm')[0]
        ds = dcmread(test_file, force=True, defer_size='0.8 kB')
        ds_ref = dcmread(test_file, force=True)
        # get_item will follow the deferred read branch
        assert ds.get_item((0x7fe00010)).value == ds_ref.PixelData
开发者ID:moloney,项目名称:pydicom,代码行数:18,代码来源:test_dataset.py

示例12: import

from pydicom.data import get_testdata_files
from pydicom.dataset import Dataset
from pydicom.pixel_data_handlers.util import (
    dtype_corrected_for_endianness,
    reshape_pixel_array,
    convert_color_space,
    pixel_dtype,
    get_expected_length
)
from pydicom.uid import (ExplicitVRLittleEndian,
                         UncompressedPixelTransferSyntaxes)


# 8 bit, 3 samples/pixel, 1 and 2 frame datasets
# RGB colorspace, uncompressed
RGB_8_3_1F = get_testdata_files("SC_rgb.dcm")[0]
RGB_8_3_2F = get_testdata_files("SC_rgb_2frame.dcm")[0]


# Tests with Numpy unavailable
@pytest.mark.skipif(HAVE_NP, reason='Numpy is available')
class TestNoNumpy(object):
    """Tests for the util functions without numpy."""
    def test_pixel_dtype_raises(self):
        """Test that pixel_dtype raises exception without numpy."""
        with pytest.raises(ImportError,
                           match="Numpy is required to determine the dtype"):
            pixel_dtype(None)

    def test_reshape_pixel_array_raises(self):
        """Test that reshape_pixel_array raises exception without numpy."""
开发者ID:darcymason,项目名称:pydicom,代码行数:31,代码来源:test_handler_util.py

示例13: get_testdata_files

# Copyright 2008-2018 pydicom authors. See LICENSE file for details.
"""Tests for misc.py"""

import os

import pytest

from pydicom.data import get_testdata_files
from pydicom.misc import is_dicom, size_in_bytes

test_file = get_testdata_files('CT_small.dcm')[0]
no_meta_file = get_testdata_files('ExplVR_LitEndNoMeta.dcm')[0]


class TestMisc(object):
    def test_is_dicom(self):
        """Test the is_dicom function."""
        invalid_file = test_file.replace('CT_', 'CT')  # invalid file
        notdicom_file = os.path.abspath(__file__)  # use own file

        # valid file returns True
        assert is_dicom(test_file)

        # return false for real file but not dicom
        assert not is_dicom(notdicom_file)

        # test invalid path
        with pytest.raises(IOError):
            is_dicom(invalid_file)

        # Test no meta prefix/preamble fails
开发者ID:darcymason,项目名称:pydicom,代码行数:31,代码来源:test_misc.py

示例14: print

This examples illustrates how to find the differences between two DICOM files.

"""

# authors : Guillaume Lemaitre <[email protected]>
# license : MIT

import difflib

import pydicom
from pydicom.data import get_testdata_files

print(__doc__)

filename_mr = get_testdata_files('MR_small.dcm')[0]
filename_ct = get_testdata_files('CT_small.dcm')[0]

datasets = tuple([pydicom.dcmread(filename, force=True)
                  for filename in (filename_mr, filename_ct)])

# difflib compare functions require a list of lines, each terminated with
# newline character massage the string representation of each dicom dataset
# into this form:
rep = []
for dataset in datasets:
    lines = str(dataset).split("\n")
    lines = [line + "\n" for line in lines]  # add the newline to end
    rep.append(lines)

开发者ID:darcymason,项目名称:pydicom,代码行数:28,代码来源:plot_dicom_difference.py

示例15: import

if not in_py2:
    from pydicom.valuerep import PersonName3 as PersonNameUnicode

    PersonName = PersonNameUnicode
else:
    from pydicom.valuerep import (
        PersonName,
        PersonNameUnicode
    )

try:
    import cPickle as pickle
except ImportError:
    import pickle

badvr_name = get_testdata_files("badVR.dcm")[0]
default_encoding = 'iso8859'


@pytest.mark.skipif(platform.python_implementation() == 'PyPy',
                    reason="PyPy has trouble with this pickle")
class TestTM(object):
    """Unit tests for pickling TM"""

    def test_pickling(self):
        # Check that a pickled TM is read back properly
        x = pydicom.valuerep.TM("212223")
        x.original_string = 'hello'
        assert 'hello' == x.original_string
        assert time(21, 22, 23) == x
        data1_string = pickle.dumps(x)
开发者ID:darcymason,项目名称:pydicom,代码行数:31,代码来源:test_valuerep.py


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