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


Python dataset.Dataset类代码示例

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


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

示例1: create_metadata

 def create_metadata():
     metadata = Dataset()
     metadata.MediaStorageSOPClassUID = '1.2.840.10008.5.1.4.1.1.7'
     metadata.MediaStorageSOPInstanceUID = '1.2.3'
     metadata.TransferSyntaxUID = '1.2.840.10008.1.2'
     metadata.ImplementationClassUID = '1.3.6.1.4.1.5962.2'
     return metadata
开发者ID:mrbean-bremen,项目名称:dcm-spec-tools,代码行数:7,代码来源:test_dicom_file_validator.py

示例2: testAddEntry

 def testAddEntry(self):
     """dicom_dictionary: Can add and use a single dictionary entry"""
     add_dict_entry(0x10011001, "UL", "TestOne", "Test One")
     add_dict_entry(0x10011002, "DS", "TestTwo", "Test Two", VM='3')
     ds = Dataset()
     ds.TestOne = 'test'
     ds.TestTwo = ['1', '2', '3']
开发者ID:jrkerns,项目名称:pydicom,代码行数:7,代码来源:test_dictionary.py

示例3: testSetNewDataElementByName

 def testSetNewDataElementByName(self):
     """Dataset: set new data_element by name............................"""
     ds = Dataset()
     ds.TreatmentMachineName = "unit #1"
     data_element = ds[0x300A, 0x00B2]
     self.assertEqual(data_element.value, "unit #1", "Unable to set data_element by name")
     self.assertEqual(data_element.VR, "SH", "data_element not the expected VR")
开发者ID:DimitriPapadopoulos,项目名称:pydicom,代码行数:7,代码来源:test_dataset.py

示例4: _build_message_classes

def _build_message_classes(message_name):
    """
    Create a new subclass instance of DIMSEMessage for the given DIMSE
    `message_name`.
    
    Parameters
    ----------
    message_name : str
        The name/type of message class to construct, one of the following:
        * C-ECHO-RQ
        * C-ECHO-RSP
        * C-STORE-RQ
        * C-STORE-RSP
        * C-FIND-RQ
        * C-FIND-RSP
        * C-GET-RQ
        * C-GET-RSP
        * C-MOVE-RQ
        * C-MOVE-RSP
        * C-CANCEL-RQ
        * N-EVENT-REPORT-RQ
        * N-EVENT-REPORT-RSP
        * N-GET-RQ
        * N-GET-RSP
        * N-SET-RQ
        * N-SET-RSP
        * N-ACTION-RQ
        * N-ACTION-RSP
        * N-CREATE-RQ
        * N-CREATE-RSP
        * N-DELETE-RQ
        * N-DELETE-RSP
    """
    def __init__(self):
        DIMSEMessage.__init__(self)

    # Create new subclass of DIMSE Message using the supplied name
    #   but replace hyphens with underscores
    cls = type(message_name.replace('-', '_'), 
                (DIMSEMessage,), 
                {"__init__": __init__})

    # Create a new Dataset object for the command_set attributes
    d = Dataset()
    for elem_tag in command_set_elem[message_name]:
        tag = Tag(elem_tag)
        vr = dcm_dict[elem_tag][0]

        # If the required command set elements are expanded this will need
        #   to be checked to ensure it functions OK
        try:
            d.add_new(tag, vr, None)
        except:
            d.add_new(tag, vr, '')

    cls.command_set = d

    globals()[cls.__name__] = cls
    
    return cls
开发者ID:scaramallion,项目名称:pynetdicom,代码行数:60,代码来源:DIMSEmessages.py

示例5: test_conversion_rq

 def test_conversion_rq(self):
     """ Check conversion to a -RQ PDU produces the correct output """
     primitive = C_MOVE_ServiceParameters()
     primitive.MessageID = 7
     primitive.AffectedSOPClassUID = '1.2.840.10008.5.1.4.1.1.2'
     primitive.Priority = 0x02
     primitive.MoveDestination = validate_ae_title("MOVE_SCP")
     
     refIdentifier = Dataset()
     refIdentifier.PatientID = '*'
     refIdentifier.QueryRetrieveLevel = "PATIENT"
     
     primitive.Identifier = BytesIO(encode(refIdentifier, True, True))
     
     dimse_msg = C_MOVE_RQ()
     dimse_msg.primitive_to_message(primitive)
     
     pdvs = dimse_msg.Encode(1, 16382)
     
     # Command Set
     ref = b'\x03\x00\x00\x00\x00\x04\x00\x00\x00\x62\x00\x00\x00\x00\x00\x02' \
           b'\x00\x1a\x00\x00\x00\x31\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30\x30' \
           b'\x30\x38\x2e\x35\x2e\x31\x2e\x34\x2e\x31\x2e\x31\x2e\x32\x00\x00' \
           b'\x00\x00\x01\x02\x00\x00\x00\x21\x00\x00\x00\x10\x01\x02\x00\x00' \
           b'\x00\x07\x00\x00\x00\x00\x06\x10\x00\x00\x00\x4d\x4f\x56\x45\x5f' \
           b'\x53\x43\x50\x20\x20\x20\x20\x20\x20\x20\x20\x00\x00\x00\x07\x02' \
           b'\x00\x00\x00\x02\x00\x00\x00\x00\x08\x02\x00\x00\x00\x01\x00'
     self.assertEqual(pdvs[0].presentation_data_value_list[0][1], ref)
     
     # Dataset
     ref = b'\x02\x08\x00\x52\x00\x08\x00\x00\x00\x50\x41\x54\x49\x45\x4e\x54' \
           b'\x20\x10\x00\x20\x00\x02\x00\x00\x00\x2a\x20'
     self.assertEqual(pdvs[1].presentation_data_value_list[0][1], ref)
开发者ID:scaramallion,项目名称:pynetdicom,代码行数:33,代码来源:test_dimse_c.py

示例6: create_dicom

    def create_dicom(self):
        """ Creates a DICOM RT-Dose object from self.

        This function can be used to convert a TRiP98 Dose file to DICOM format.

        :returns: a DICOM RT-Dose object.
        """

        if not _dicom_loaded:
            raise ModuleNotLoadedError("DICOM")
        if not self.header_set:
            raise InputError("Header not loaded")

        ds = self.create_dicom_base()
        ds.Modality = 'RTDOSE'
        ds.SamplesPerPixel = 1
        ds.BitsAllocated = self.num_bytes * 8
        ds.BitsStored = self.num_bytes * 8
        ds.AccessionNumber = ''
        ds.SeriesDescription = 'RT Dose'
        ds.DoseUnits = 'GY'
        ds.DoseType = 'PHYSICAL'
        ds.DoseGridScaling = self.target_dose / 10**5
        ds.DoseSummationType = 'PLAN'
        ds.SliceThickness = ''
        ds.InstanceCreationDate = '19010101'
        ds.InstanceCreationTime = '000000'
        ds.NumberOfFrames = len(self.cube)
        ds.PixelRepresentation = 0
        ds.StudyID = '1'
        ds.SeriesNumber = '14'  # SeriesNumber tag 0x0020,0x0011 (type IS - Integer String)
        ds.GridFrameOffsetVector = [x * self.slice_distance for x in range(self.dimz)]
        ds.InstanceNumber = ''
        ds.PositionReferenceIndicator = "RF"
        ds.TissueHeterogeneityCorrection = ['IMAGE', 'ROI_OVERRIDE']
        ds.ImagePositionPatient = ["%.3f" % (self.xoffset * self.pixel_size), "%.3f" % (self.yoffset * self.pixel_size),
                                   "%.3f" % (self.slice_pos[0])]
        ds.SOPClassUID = '1.2.840.10008.5.1.4.1.1.481.2'
        ds.SOPInstanceUID = '1.2.246.352.71.7.320687012.47206.20090603085223'

        # Study Instance UID tag 0x0020,0x000D (type UI - Unique Identifier)
        # self._dicom_study_instance_uid may be either set in __init__ when creating new object
        #   or set when import a DICOM file
        #   Study Instance UID for structures is the same as Study Instance UID for CTs
        ds.StudyInstanceUID = self._dicom_study_instance_uid

        # Series Instance UID tag 0x0020,0x000E (type UI - Unique Identifier)
        # self._dose_dicom_series_instance_uid may be either set in __init__ when creating new object
        #   Series Instance UID might be different than Series Instance UID for CTs
        ds.SeriesInstanceUID = self._dose_dicom_series_instance_uid

        # Bind to rtplan
        rt_set = Dataset()
        rt_set.RefdSOPClassUID = '1.2.840.10008.5.1.4.1.1.481.5'
        rt_set.RefdSOPInstanceUID = '1.2.3'
        ds.ReferencedRTPlanSequence = Sequence([rt_set])
        pixel_array = np.zeros((len(self.cube), ds.Rows, ds.Columns), dtype=self.pydata_type)
        pixel_array[:][:][:] = self.cube[:][:][:]
        ds.PixelData = pixel_array.tostring()
        return ds
开发者ID:pytrip,项目名称:pytrip,代码行数:60,代码来源:dos.py

示例7: test_conversion_rsp

 def test_conversion_rsp(self):
     """ Check conversion to a -RSP PDU produces the correct output """
     primitive = C_FIND_ServiceParameters()
     primitive.MessageIDBeingRespondedTo = 5
     primitive.AffectedSOPClassUID = '1.2.840.10008.5.1.4.1.1.2'
     primitive.Status = 0xFF00
     
     refIdentifier = Dataset()
     refIdentifier.QueryRetrieveLevel = "PATIENT"
     refIdentifier.RetrieveAETitle = validate_ae_title("FINDSCP")
     refIdentifier.PatientName = "ANON^A^B^C^D"
     
     primitive.Identifier = BytesIO(encode(refIdentifier, True, True))
     
     dimse_msg = C_FIND_RSP()
     dimse_msg.primitive_to_message(primitive)
     
     pdvs = dimse_msg.Encode(1, 16382)
     
     # Command Set
     ref = b'\x03\x00\x00\x00\x00\x04\x00\x00\x00\x4a\x00\x00\x00\x00\x00\x02' \
           b'\x00\x1a\x00\x00\x00\x31\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30\x30' \
           b'\x30\x38\x2e\x35\x2e\x31\x2e\x34\x2e\x31\x2e\x31\x2e\x32\x00\x00' \
           b'\x00\x00\x01\x02\x00\x00\x00\x20\x80\x00\x00\x20\x01\x02\x00\x00' \
           b'\x00\x05\x00\x00\x00\x00\x08\x02\x00\x00\x00\x01\x00\x00\x00\x00' \
           b'\x09\x02\x00\x00\x00\x00\xff'
     self.assertEqual(pdvs[0].presentation_data_value_list[0][1], ref)
     
     ref = b'\x02\x08\x00\x52\x00\x08\x00\x00\x00\x50\x41\x54\x49\x45\x4e\x54' \
           b'\x20\x08\x00\x54\x00\x10\x00\x00\x00\x46\x49\x4e\x44\x53\x43\x50' \
           b'\x20\x20\x20\x20\x20\x20\x20\x20\x20\x10\x00\x10\x00\x0c\x00\x00' \
           b'\x00\x41\x4e\x4f\x4e\x5e\x41\x5e\x42\x5e\x43\x5e\x44'
     self.assertEqual(pdvs[1].presentation_data_value_list[0][1], ref)
开发者ID:scaramallion,项目名称:pynetdicom,代码行数:33,代码来源:test_dimse_c.py

示例8: test_assignment

 def test_assignment(self):
     """ Check assignment works correctly """
     primitive = C_MOVE_ServiceParameters()
     
     primitive.MessageID = 11
     self.assertEqual(primitive.MessageID, 11)
     
     primitive.MessageIDBeingRespondedTo = 13
     self.assertEqual(primitive.MessageIDBeingRespondedTo, 13)
     
     primitive.AffectedSOPClassUID = '1.2.4.10'
     self.assertEqual(primitive.AffectedSOPClassUID, '1.2.4.10')
     
     primitive.Priority = 0x02
     self.assertEqual(primitive.Priority, 0x02)
     
     primitive.MoveDestination = 'UNITTEST_SCP'
     self.assertEqual(primitive.MoveDestination, b'UNITTEST_SCP    ')
     
     refDataset = Dataset()
     refDataset.PatientID = 1234567
     
     primitive.Identifier = BytesIO(encode(refDataset, True, True))
     #self.assertEqual(primitive.DataSet, refDataset)
     
     primitive.Status = 0x0000
     self.assertEqual(primitive.Status, 0x0000)
     
     primitive.Status = 0xC123
     self.assertEqual(primitive.Status, 0xC123)
开发者ID:scaramallion,项目名称:pynetdicom,代码行数:30,代码来源:test_dimse_c.py

示例9: testEqualitySequence

    def testEqualitySequence(self):
        """Dataset: equality returns correct value when dataset has sequences"""
        # Test even sequences
        d = Dataset()
        d.SOPInstanceUID = "1.2.3.4"
        d.BeamSequence = []
        beam_seq = Dataset()
        beam_seq.PatientName = "ANON"
        d.BeamSequence.append(beam_seq)
        self.assertTrue(d == d)

        e = Dataset()
        e.SOPInstanceUID = "1.2.3.4"
        e.BeamSequence = []
        beam_seq = Dataset()
        beam_seq.PatientName = "ANON"
        e.BeamSequence.append(beam_seq)
        self.assertTrue(d == e)

        e.BeamSequence[0].PatientName = "ANONY"
        self.assertFalse(d == e)

        # Test uneven sequences
        e.BeamSequence[0].PatientName = "ANON"
        self.assertTrue(d == e)

        e.BeamSequence.append(beam_seq)
        self.assertFalse(d == e)

        d.BeamSequence.append(beam_seq)
        self.assertTrue(d == e)
        d.BeamSequence.append(beam_seq)
        self.assertFalse(d == e)
开发者ID:DimitriPapadopoulos,项目名称:pydicom,代码行数:33,代码来源:test_dataset.py

示例10: test_reshape_pixel_array_not_implemented

 def test_reshape_pixel_array_not_implemented(self):
     """Test Dataset._reshape_pixel_array raises exception"""
     ds = Dataset()
     ds.SamplesPerPixel = 2
     ds.BitsAllocated = 16
     with pytest.raises(NotImplementedError):
         ds._reshape_pixel_array(None)
开发者ID:moloney,项目名称:pydicom,代码行数:7,代码来源:test_dataset.py

示例11: test_top

 def test_top(self):
     """Test Dataset.top returns only top level str"""
     ds = Dataset()
     ds.PatientName = 'CITIZEN^Jan'
     ds.BeamSequence = [Dataset()]
     ds.BeamSequence[0].PatientID = 'JAN^Citizen'
     assert "Patient's Name" in ds.top()
     assert "Patient ID" not in ds.top()
开发者ID:moloney,项目名称:pydicom,代码行数:8,代码来源:test_dataset.py

示例12: test_get_pixel_array_already_have

 def test_get_pixel_array_already_have(self):
     """Test Dataset._get_pixel_array when we already have the array"""
     # Test that _pixel_array is returned unchanged unless required
     ds = Dataset()
     ds.PixelData = b'\x00'
     ds._pixel_id = id(ds.PixelData)
     ds._pixel_array = 'Test Value'
     assert ds._get_pixel_array() == 'Test Value'
开发者ID:moloney,项目名称:pydicom,代码行数:8,代码来源:test_dataset.py

示例13: testSetNonDicom

 def testSetNonDicom(self):
     """Dataset: can set class instance property (non-dicom)............."""
     ds = Dataset()
     ds.SomeVariableName = 42
     has_it = hasattr(ds, "SomeVariableName")
     self.assertTrue(has_it, "Variable did not get created")
     if has_it:
         self.assertEqual(ds.SomeVariableName, 42, "There, but wrong value")
开发者ID:DimitriPapadopoulos,项目名称:pydicom,代码行数:8,代码来源:test_dataset.py

示例14: on_c_store

def on_c_store(dataset):
    """
    Function replacing ApplicationEntity.on_store(). Called when a dataset is 
    received following a C-STORE. Write the received dataset to file 
    
    Parameters
    ----------
    dataset - pydicom.Dataset
        The DICOM dataset sent via the C-STORE
            
    Returns
    -------
    status : pynetdicom.SOPclass.Status or int
        A valid return status code, see PS3.4 Annex B.2.3 or the 
        StorageServiceClass implementation for the available statuses
    """
    mode_prefix = 'UN'
    mode_prefixes = {'CT Image Storage' : 'CT',
                     'Enhanced CT Image Storage' : 'CTE',
                     'MR Image Storage' : 'MR',
                     'Enhanced MR Image Storage' : 'MRE',
                     'Positron Emission Tomography Image Storage' : 'PT',
                     'Enhanced PET Image Storage' : 'PTE',
                     'RT Image Storage' : 'RI',
                     'RT Dose Storage' : 'RD',
                     'RT Plan Storage' : 'RP',
                     'RT Structure Set Storage' : 'RS',
                     'Computed Radiography Image Storage' : 'CR',
                     'Ultrasound Image Storage' : 'US',
                     'Enhanced Ultrasound Image Storage' : 'USE',
                     'X-Ray Angiographic Image Storage' : 'XA',
                     'Enhanced XA Image Storage' : 'XAE',
                     'Nuclear Medicine Image Storage' : 'NM',
                     'Secondary Capture Image Storage' : 'SC'}

    try:
        mode_prefix = mode_prefixes[dataset.SOPClassUID.__str__()]
    except:
        pass

    filename = '%s.%s' %(mode_prefix, dataset.SOPInstanceUID)
    logger.info('Storing DICOM file: %s' %filename)
    
    if os.path.exists(filename):
        logger.warning('DICOM file already exists, overwriting')
    
    meta = Dataset()
    meta.MediaStorageSOPClassUID = dataset.SOPClassUID
    meta.MediaStorageSOPInstanceUID = dataset.SOPInstanceUID
    meta.ImplementationClassUID = pynetdicom_uid_prefix
    
    ds = FileDataset(filename, {}, file_meta=meta, preamble=b"\0" * 128)
    ds.update(dataset)
    ds.is_little_endian = True
    ds.is_implicit_VR = True
    ds.save_as(filename)
        
    return 0x0000 # Success
开发者ID:scaramallion,项目名称:pynetdicom,代码行数:58,代码来源:getscu.py

示例15: test_inequality

    def test_inequality(self):
        """Test inequality operator"""
        d = Dataset()
        d.SOPInstanceUID = '1.2.3.4'
        self.assertFalse(d != d)

        e = Dataset()
        e.SOPInstanceUID = '1.2.3.5'
        self.assertTrue(d != e)
开发者ID:moloney,项目名称:pydicom,代码行数:9,代码来源:test_dataset.py


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