• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python data.get_testdata_files函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: get_testdata_files

This example shows how to read DICOM directory.

"""

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

from os.path import dirname, join
from pprint import pprint

import pydicom
from pydicom.data import get_testdata_files
from pydicom.filereader import read_dicomdir

# fetch the path to the test data
filepath = get_testdata_files('DICOMDIR')[0]
print('Path to the DICOM directory: {}'.format(filepath))
# load the data
dicom_dir = read_dicomdir(filepath)
base_dir = dirname(filepath)

# go through the patient record and print information
for patient_record in dicom_dir.patient_records:
    if (hasattr(patient_record, 'PatientID') and
            hasattr(patient_record, 'PatientName')):
        print("Patient: {}: {}".format(patient_record.PatientID,
                                       patient_record.PatientName))
    studies = patient_record.children
    # got through each serie
    for study in studies:
        print(" " * 4 + "Study {}: {}: {}".format(study.StudyID,
开发者ID:darcymason,项目名称:pydicom,代码行数:31,代码来源:plot_read_dicom_directory.py


示例17: get_testdata_files

from platform import python_implementation
from tempfile import TemporaryFile

import numpy as np

from pydicom import dcmread
from pydicom.dataset import Dataset
from pydicom.data import get_testdata_files
from pydicom.encaps import decode_data_sequence
from pydicom.pixel_data_handlers.numpy_handler import get_pixeldata
from pydicom.uid import ExplicitVRLittleEndian, generate_uid


# 1/1, 1 sample/pixel, 1 frame
EXPL_1_1_1F = get_testdata_files("liver_1frame.dcm")[0]
# 1/1, 1 sample/pixel, 3 frame
EXPL_1_1_3F = get_testdata_files("liver.dcm")[0]
# 8/8, 1 sample/pixel, 1 frame
EXPL_8_1_1F = get_testdata_files("OBXXXX1A.dcm")[0]
# 8/8, 1 sample/pixel, 2 frame
EXPL_8_1_2F = get_testdata_files("OBXXXX1A_2frame.dcm")[0]
# 8/8, 3 sample/pixel, 1 frame
EXPL_8_3_1F = get_testdata_files("SC_rgb.dcm")[0]
# 8/8, 3 sample/pixel, 2 frame
EXPL_8_3_2F = get_testdata_files("SC_rgb_2frame.dcm")[0]
# 16/16, 1 sample/pixel, 1 frame
EXPL_16_1_1F = get_testdata_files("MR_small.dcm")[0]
# 16/12, 1 sample/pixel, 10 frame
EXPL_16_1_10F = get_testdata_files("emri_small.dcm")[0]
# 16/16, 3 sample/pixel, 1 frame
开发者ID:darcymason,项目名称:pydicom,代码行数:30,代码来源:bench_handler_numpy.py


示例18: get_testdata_files

# Copyright 2008-2017 pydicom authors. See LICENSE file for details.
"""Test for dicomdir.py"""

import pytest

from pydicom.data import get_testdata_files
from pydicom.dicomdir import DicomDir
from pydicom.errors import InvalidDicomError
from pydicom import read_file


TEST_FILE = get_testdata_files('DICOMDIR')[0]


class TestDicomDir(object):
    """Test dicomdir.DicomDir class"""
    def test_read_file(self):
        """Test creation of DicomDir instance using filereader.read_file"""
        ds = read_file(TEST_FILE)
        assert isinstance(ds, DicomDir)

    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)

    def test_invalid_sop_no_file_meta(self):
        """Test exception raised if invalid sop class but no file_meta"""
开发者ID:jrkerns,项目名称:pydicom,代码行数:31,代码来源:test_dicomdir.py


示例19: setUp

 def setUp(self):
     self.original_handlers = pydicom.config.image_handlers
     pydicom.config.image_handlers = [numpy_handler]
     self.odd_size_image = dcmread(
         get_testdata_files('SC_rgb_small_odd.dcm')[0])
     self.emri_small = dcmread(emri_name)
开发者ID:kayarre,项目名称:pydicom,代码行数:6,代码来源:test_numpy_pixel_data.py


示例20: setUp

 def setUp(self):
     self.test_file = get_testdata_files('CT_small.dcm')[0]
开发者ID:moloney,项目名称:pydicom,代码行数:2,代码来源:test_dataset.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python dataelem.DataElement类代码示例发布时间:2022-05-25
下一篇:
Python logger.debug函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap