當前位置: 首頁>>代碼示例>>Python>>正文


Python Dataset.add_new方法代碼示例

本文整理匯總了Python中dicom.dataset.Dataset.add_new方法的典型用法代碼示例。如果您正苦於以下問題:Python Dataset.add_new方法的具體用法?Python Dataset.add_new怎麽用?Python Dataset.add_new使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在dicom.dataset.Dataset的用法示例。


在下文中一共展示了Dataset.add_new方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: testValidAssignment

# 需要導入模塊: from dicom.dataset import Dataset [as 別名]
# 或者: from dicom.dataset.Dataset import add_new [as 別名]
    def testValidAssignment(self):
        """Sequence: ensure ability to assign a Dataset to a Sequence item"""
        ds = Dataset()
        ds.add_new((1,1), 'IS', 1)

        # Create a single element Sequence first
        seq = Sequence([Dataset(),])
        seq[0] = ds

        self.assertEqual(seq[0], ds, "Dataset modified during assignment")
開發者ID:psy2013GitHub,項目名稱:Atom,代碼行數:12,代碼來源:test_sequence.py

示例2: write_file

# 需要導入模塊: from dicom.dataset import Dataset [as 別名]
# 或者: from dicom.dataset.Dataset import add_new [as 別名]
def write_file(filename, dataset, WriteLikeOriginal=True):
    """Store a Dataset to the filename specified.
    
    Set dataset.preamble if you want something other than 128 0-bytes.
    If the dataset was read from an existing dicom file, then its preamble
    was stored at read time. It is up to you to ensure the preamble is still
    correct for its purposes.
    If there is no Transfer Syntax tag in the dataset,
       Set dataset.is_implicit_VR, and .is_little_endian
       to determine the transfer syntax used to write the file.
    WriteLikeOriginal -- True if want to preserve the following for each sequence 
        within this dataset:
        - preamble -- if no preamble in read file, than not used here
        - dataset.hasFileMeta -- if writer did not do file meta information,
            then don't write here either
        - seq.is_undefined_length -- if original had delimiters, write them now too,
            instead of the more sensible length characters
        - <dataset>.is_undefined_length_sequence_item -- for datasets that belong to a 
            sequence, write the undefined length delimiters if that is 
            what the original had
        Set WriteLikeOriginal = False to produce a "nicer" DICOM file for other readers,
            where all lengths are explicit.
    """

    # Decide whether to write DICOM preamble. Should always do so unless trying to mimic the original file read in
    preamble = getattr(dataset, "preamble", None)
    if not preamble and not WriteLikeOriginal:
        preamble = "\0" * 128

    file_meta = dataset.file_meta
    if file_meta is None:
        file_meta = Dataset()
    if "TransferSyntaxUID" not in file_meta:
        if dataset.is_little_endian and dataset.is_implicit_VR:
            file_meta.add_new((2, 0x10), "UI", ImplicitVRLittleEndian)
        elif dataset.is_little_endian and not dataset.is_implicit_VR:
            file_meta.add_new((2, 0x10), "UI", ExplicitVRLittleEndian)
        elif dataset.is_big_endian and not dataset.is_implicit_VR:
            file_meta.add_new((2, 0x10), "UI", ExplicitVRBigEndian)
        else:
            raise NotImplementedError, "pydicom has not been verified for Big Endian with Implicit VR"

    fp = DicomFile(filename, "wb")
    try:
        if preamble:
            fp.write(preamble)  # blank 128 byte preamble
            _write_file_meta_info(fp, file_meta)

        # Set file VR, endian. MUST BE AFTER writing META INFO (which changes to Explict LittleEndian)
        fp.is_implicit_VR = dataset.is_implicit_VR
        fp.is_little_endian = dataset.is_little_endian

        write_dataset(fp, dataset)
    finally:
        fp.close()
開發者ID:rharnish,項目名稱:pydicom,代碼行數:57,代碼來源:filewriter.py

示例3: dummy_dataset

# 需要導入模塊: from dicom.dataset import Dataset [as 別名]
# 或者: from dicom.dataset.Dataset import add_new [as 別名]
 def dummy_dataset(self):
     # This dataset is used by many of the tests
     ds = Dataset()
     ds.add_new((0x300a, 0x00b2), "SH", "unit001")  # TreatmentMachineName
     return ds
開發者ID:IMAGE-ET,項目名稱:pydicom,代碼行數:7,代碼來源:test_dataset.py

示例4: test_anonymize_dicom

# 需要導入模塊: from dicom.dataset import Dataset [as 別名]
# 或者: from dicom.dataset.Dataset import add_new [as 別名]
def test_anonymize_dicom():
    anon_tags = [\
                 Tag(0x0008, 0x0014), # Instance Creator UID 
                 Tag(0x0008, 0x0018), # SOP Instance UID 
                 Tag(0x0008, 0x0050), # Accession Number 
                 Tag(0x0008, 0x0080), # Institution Name 
                 Tag(0x0008, 0x0081), # Institution Address
                 Tag(0x0008, 0x0090), # Referring Physician's Name
                 Tag(0x0008, 0x0092), # Referring Physician's Address 
                 Tag(0x0008, 0x0094), # Referring Physician's Telephone Numbers 
                 Tag(0x0008, 0x1010), # Station Name 
                 Tag(0x0008, 0x1030), # Study Description 
                 Tag(0x0008, 0x103E), # Series Description 
                 Tag(0x0008, 0x1040), # Institutional Department Name 
                 Tag(0x0008, 0x1048), # Physician(s) of Record 
                 Tag(0x0008, 0x1050), # Performing Physicians' Name 
                 Tag(0x0008, 0x1060), # Name of Physician(s) Reading Study 
                 Tag(0x0008, 0x1070), # Operators' Name 
                 Tag(0x0008, 0x1080), # Admitting Diagnoses Description 
                 Tag(0x0008, 0x1155), # Referenced SOP Instance UID 
                 Tag(0x0008, 0x2111), # Derivation Description 
                 Tag(0x0010, 0x0010), # Patient's Name 
                 Tag(0x0010, 0x0020), # Patient ID 
                 Tag(0x0010, 0x0030), # Patient's Birth Date 
                 Tag(0x0010, 0x0032), # Patient's Birth Time 
                 Tag(0x0010, 0x0040), # Patient's Sex 
                 Tag(0x0010, 0x1000), # Other Patient Ids 
                 Tag(0x0010, 0x1001), # Other Patient Names 
                 Tag(0x0010, 0x1010), # Patient's Age 
                 Tag(0x0010, 0x1020), # Patient's Size 
                 Tag(0x0010, 0x1030), # Patient's Weight 
                 Tag(0x0010, 0x1090), # Medical Record Locator 
                 Tag(0x0010, 0x2160), # Ethnic Group 
                 Tag(0x0010, 0x2180), # Occupation 
                 Tag(0x0010, 0x21B0), # Additional Patient's History 
                 Tag(0x0010, 0x4000), # Patient Comments 
                 Tag(0x0018, 0x1000), # Device Serial Number 
                 Tag(0x0018, 0x1030), # Protocol Name 
                 Tag(0x0020, 0x000D), # Study Instance UID 
                 Tag(0x0020, 0x000E), # Series Instance UID 
                 Tag(0x0020, 0x0010), # Study ID 
                 Tag(0x0020, 0x0052), # Frame of Reference UID 
                 Tag(0x0020, 0x0200), # Synchronization Frame of Reference UID 
                 Tag(0x0020, 0x4000), # Image Comments 
                 Tag(0x0040, 0x0275), # Request Attributes Sequence 
                 Tag(0x0040, 0xA124), # UID 
                 Tag(0x0040, 0xA730), # Content Sequence 
                 Tag(0x0088, 0x0140), # Storage Media File-set UID 
                 Tag(0x3006, 0x0024), # Referenced Frame of Reference UID 
                 Tag(0x3006, 0x00C2)] # Related Frame of Reference UID 

    ds = Dataset()
    if hasattr(ds, 'AddNew'): 
        ds.AddNew(Tag(0x0008, 0x0018), 'dicom.UID.UID', 'TestAnonymization')
        ds.AddNew(Tag(0x0008, 0x0080), 'str', 'TestAnonymization')
        ds.AddNew(Tag(0x0008, 0x0081), 'str', 'TestAnonymization')
        ds.AddNew(Tag(0x0008, 0x1010), 'str', 'TestAnonymization')
        ds.AddNew(Tag(0x0008, 0x1030), 'str', 'TestAnonymization')
        ds.AddNew(Tag(0x0008, 0x103e), 'str', 'TestAnonymization')
        ds.AddNew(Tag(0x0010, 0x0010), 'dicom.valuerep.PersonName', 'TestAnonymization')
        ds.AddNew(Tag(0x0010, 0x0020), 'str', 'TestAnonymization')
        ds.AddNew(Tag(0x0010, 0x0040), 'str', 'TestAnonymization')
        ds.AddNew(Tag(0x0010, 0x1010), 'str', 'TestAnonymization')
        ds.AddNew(Tag(0x0018, 0x1000), 'str', 'TestAnonymization')
        ds.AddNew(Tag(0x0018, 0x1030), 'str', 'TestAnonymization')
        ds.AddNew(Tag(0x0020, 0x000d), 'dicom.UID.UID', 'TestAnonymization')
        ds.AddNew(Tag(0x0020, 0x000e), 'dicom.UID.UID', 'TestAnonymization')
        ds.AddNew(Tag(0x0020, 0x0052), 'dicom.UID.UID', 'TestAnonymization')
        ds.AddNew(Tag(0x0020, 0x4000), 'str', 'TestAnonymization')
    else:
        ds.add_new(Tag(0x0008, 0x0018), 'dicom.UID.UID', 'TestAnonymization')
        ds.add_new(Tag(0x0008, 0x0080), 'str', 'TestAnonymization')
        ds.add_new(Tag(0x0008, 0x0081), 'str', 'TestAnonymization')
        ds.add_new(Tag(0x0008, 0x1010), 'str', 'TestAnonymization')
        ds.add_new(Tag(0x0008, 0x1030), 'str', 'TestAnonymization')
        ds.add_new(Tag(0x0008, 0x103e), 'str', 'TestAnonymization')
        ds.add_new(Tag(0x0010, 0x0010), 'dicom.valuerep.PersonName', 'TestAnonymization')
        ds.add_new(Tag(0x0010, 0x0020), 'str', 'TestAnonymization')
        ds.add_new(Tag(0x0010, 0x0040), 'str', 'TestAnonymization')
        ds.add_new(Tag(0x0010, 0x1010), 'str', 'TestAnonymization')
        ds.add_new(Tag(0x0018, 0x1000), 'str', 'TestAnonymization')
        ds.add_new(Tag(0x0018, 0x1030), 'str', 'TestAnonymization')
        ds.add_new(Tag(0x0020, 0x000d), 'dicom.UID.UID', 'TestAnonymization')
        ds.add_new(Tag(0x0020, 0x000e), 'dicom.UID.UID', 'TestAnonymization')
        ds.add_new(Tag(0x0020, 0x0052), 'dicom.UID.UID', 'TestAnonymization')
        ds.add_new(Tag(0x0020, 0x4000), 'str', 'TestAnonymization')        

    anonymize_dicom(ds)

    keys = ds.keys()
    for t in anon_tags:
        if t in keys:
            assert ds[t].value == 'Anonymized' or ds[t].value == '', \
                'Dicom not anonymized'
開發者ID:151706061,項目名稱:ChestImagingPlatform,代碼行數:96,代碼來源:test_anonymize_dicom.py

示例5: __init__

# 需要導入模塊: from dicom.dataset import Dataset [as 別名]
# 或者: from dicom.dataset.Dataset import add_new [as 別名]
class DIMSEMessage:

    def __init__(self):
        self.CommandSet = None
        self.EncodedDataSet = None
        self.DataSet = None
        self.encoded_command_set = ''
        self.ID = id

        self.ts = ImplicitVRLittleEndian  # imposed by standard.
        if self.__class__ != DIMSEMessage:
            self.CommandSet = Dataset()
            for ii in self.CommandFields:
                self.CommandSet.add_new(ii[1], ii[2], '')

    def Encode(self, id, maxpdulength):
        """Returns the encoded message as a series of P-DATA service
        parameter objects"""
        self.ID = id
        pdatas = []
        encoded_command_set = dsutils.encode(
            self.CommandSet, self.ts.is_implicit_VR, self.ts.is_little_endian)

        # fragment command set
        pdvs = fragment(maxpdulength, encoded_command_set)
        assert ''.join(pdvs) == encoded_command_set
        for ii in pdvs[:-1]:
            # send only one pdv per pdata primitive
            pdata = P_DATA_ServiceParameters()
            # not last command fragment
            pdata.PresentationDataValueList = [[self.ID, pack('b', 1) + ii]]
            pdatas.append(pdata)
        # last command fragment
        pdata = P_DATA_ServiceParameters()
        # last command fragment
        pdata.PresentationDataValueList = [[self.ID, pack('b', 3) + pdvs[-1]]]
        pdatas.append(pdata)

        # fragment data set
        #if self.__dict__.has_key('DataSet') and self.DataSet:
        if 'DataSet' in self.__dict__ and self.DataSet is not None:
            pdvs = fragment(maxpdulength, self.DataSet)
            assert ''.join(pdvs) == self.DataSet
            for ii in pdvs[:-1]:
                pdata = P_DATA_ServiceParameters()
                # not last data fragment
                pdata.PresentationDataValueList = [
                    [self.ID, pack('b', 0) + ii]]
                pdatas.append(pdata)
            pdata = P_DATA_ServiceParameters()
            # last data fragment
            pdata.PresentationDataValueList = [
                [self.ID, pack('b', 2) + pdvs[-1]]]
            pdatas.append(pdata)

        return pdatas

    def Decode(self, pdata):
        """Constructs itself receiving a series of P-DATA primitives.
        Returns True when complete, False otherwise."""
        if pdata.__class__ != P_DATA_ServiceParameters:
            # not a pdata
            return False
        if pdata is None:
            return False
        ii = pdata
        for vv in ii.PresentationDataValueList:
            # must be able to read P-DATA with several PDVs
            self.ID = vv[0]
            if unpack('b', vv[1][0])[0] in (1, 3):
                logger.debug("  command fragment %s", self.ID)
                self.encoded_command_set += vv[1][1:]
                if unpack('b', vv[1][0])[0] == 3:
                    logger.debug("  last command fragment %s", self.ID)
                    self.CommandSet = dsutils.decode(
                        self.encoded_command_set, self.ts.is_implicit_VR,
                        self.ts.is_little_endian)
                    self.__class__ = MessageType[
                        self.CommandSet[(0x0000, 0x0100)].value]
                    if self.CommandSet[(0x0000, 0x0800)].value == 0x0101:
                        # response: no dataset
                        return True
            elif unpack('b', vv[1][0])[0] in (0, 2):
                if self.DataSet is None:
                    self.DataSet = ''
                self.DataSet += vv[1][1:]
                logger.debug("  data fragment %s", self.ID)
                if unpack('b', vv[1][0])[0] == 2:
                    logger.debug("  last data fragment %s", self.ID)
                    return True
            else:
                raise "Error"

        return False

    def SetLength(self):
        # compute length
        l = 0
        for ii in self.CommandSet.values()[1:]:
            l += len(dsutils.encode_element(ii,
#.........這裏部分代碼省略.........
開發者ID:suever,項目名稱:pynetdicom,代碼行數:103,代碼來源:DIMSEmessages.py

示例6: test_find_private_section_real

# 需要導入模塊: from dicom.dataset import Dataset [as 別名]
# 或者: from dicom.dataset.Dataset import add_new [as 別名]
def test_find_private_section_real():
    # Find section containing named private creator information
    # On real data first
    assert_equal(find_private_section(DATA, 0x29, 'SIEMENS CSA HEADER'),
                 0x1000)
    assert_equal(find_private_section(DATA, 0x29, 'SIEMENS MEDCOM HEADER2'),
                 0x1100)
    assert_equal(find_private_section(DATA_PHILIPS, 0x29, 'SIEMENS CSA HEADER'),
                 None)
    # Make fake datasets
    try:
        from dicom.dataset import Dataset
    except ImportError:
        from pydicom.dataset import Dataset
    ds = Dataset({})
    ds.add_new((0x11, 0x10), 'LO', b'some section')
    assert_equal(find_private_section(ds, 0x11, 'some section'), 0x1000)
    ds.add_new((0x11, 0x11), 'LO', b'anther section')
    ds.add_new((0x11, 0x12), 'LO', b'third section')
    assert_equal(find_private_section(ds, 0x11, 'third section'), 0x1200)
    # Wrong 'OB' is acceptable for VM (should be 'LO')
    ds.add_new((0x11, 0x12), 'OB', b'third section')
    assert_equal(find_private_section(ds, 0x11, 'third section'), 0x1200)
    # Anything else not acceptable
    ds.add_new((0x11, 0x12), 'PN', b'third section')
    assert_equal(find_private_section(ds, 0x11, 'third section'), None)
    # The input (DICOM value) can be a string insteal of bytes
    ds.add_new((0x11, 0x12), 'LO', 'third section')
    assert_equal(find_private_section(ds, 0x11, 'third section'), 0x1200)
    # Search can be bytes as well as string
    ds.add_new((0x11, 0x12), 'LO', b'third section')
    assert_equal(find_private_section(ds, 0x11, b'third section'), 0x1200)
    # Search with string or bytes must be exact
    assert_equal(find_private_section(ds, 0x11, b'third sectio'), None)
    assert_equal(find_private_section(ds, 0x11, 'hird sectio'), None)
    # The search can be a regexp
    assert_equal(find_private_section(ds,
                                      0x11,
                                      re.compile(r'third\Wsectio[nN]')),
                 0x1200)
    # No match -> None
    assert_equal(find_private_section(ds,
                                      0x11,
                                      re.compile(r'not third\Wsectio[nN]')),
                 None)
    # If there are gaps in the sequence before the one we want, that is OK
    ds.add_new((0x11, 0x13), 'LO', b'near section')
    assert_equal(find_private_section(ds, 0x11, 'near section'), 0x1300)
    ds.add_new((0x11, 0x15), 'LO', b'far section')
    assert_equal(find_private_section(ds, 0x11, 'far section'), 0x1500)
開發者ID:lpetit,項目名稱:nibabel,代碼行數:52,代碼來源:test_utils.py


注:本文中的dicom.dataset.Dataset.add_new方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。