How to use the pydicom.tag.Tag function in pydicom

To help you get started, we’ve selected a few pydicom examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pydicom / pydicom / tests / test_tag.py View on Github external
def test_tag_double_int(self):
        """Test creating a Tag from a two ints."""
        self.assertEqual(Tag(0x0000, 0x0000), BaseTag(0x00000000))
        self.assertEqual(Tag(2, 0), BaseTag(0x00020000))
        self.assertTrue(Tag(2, 0).elem == 0x0000)
        self.assertEqual(Tag(0x99, 0xFE), BaseTag(0x009900FE))
        self.assertEqual(Tag(15, 14), BaseTag(0x000F000E))
        self.assertEqual(Tag(0x1000, 0x2000), BaseTag(0x10002000))

        # Must be 32-bit
        self.assertRaises(OverflowError, Tag, 65536, 0)
        self.assertRaises(OverflowError, Tag, 0, 65536)
        # Must be positive
        self.assertRaises(ValueError, Tag, -1, 0)
        self.assertRaises(ValueError, Tag, 0, -1)
        self.assertRaises(ValueError, Tag, -65535, -1)
github pydicom / pydicom / pydicom / dataset.py View on Github external
if enforce_standard:
        if 'FileMetaInformationVersion' not in file_meta:
            file_meta.FileMetaInformationVersion = b'\x00\x01'

        if 'ImplementationClassUID' not in file_meta:
            file_meta.ImplementationClassUID = PYDICOM_IMPLEMENTATION_UID

        if 'ImplementationVersionName' not in file_meta:
            file_meta.ImplementationVersionName = (
                'PYDICOM ' + ".".join(str(x) for x in __version_info__))

        # Check that required File Meta Information elements are present
        missing = []
        for element in [0x0002, 0x0003, 0x0010]:
            if Tag(0x0002, element) not in file_meta:
                missing.append(Tag(0x0002, element))
        if missing:
            msg = ("Missing required File Meta Information elements from "
                   "'file_meta':\n")
            for tag in missing:
                msg += '\t{0} {1}\n'.format(tag, keyword_for_tag(tag))
            raise ValueError(msg[:-1])  # Remove final newline
github pydicom / pydicom / pydicom / dataset.py View on Github external
>>> 'SliceLocation' in ds
        True

        Parameters
        ----------
        name : str or int or 2-tuple
            The element keyword or tag to search for.

        Returns
        -------
        bool
            ``True`` if the corresponding element is in the :class:`Dataset`,
            ``False`` otherwise.
        """
        try:
            tag = Tag(name)
        except (ValueError, OverflowError):
            return False
        # Test against None as (0000,0000) is a possible tag
        if tag is not None:
            return tag in self._dict
        return name in self._dict  # will no doubt raise an exception
github pydicom / pydicom / pydicom / datadict.py View on Github external
Raises
    ------
    KeyError
        If the tag is not present in the DICOM data dictionary.

    See Also
    --------
    get_private_entry
        Return an entry from the private dictionary.
    """
    # Note: tried the lookup with 'if tag in DicomDictionary'
    # and with DicomDictionary.get, instead of try/except
    # Try/except was fastest using timeit if tag is valid (usual case)
    # My test had 5.2 usec vs 8.2 for 'contains' test, vs 5.32 for dict.get
    if not isinstance(tag, BaseTag):
        tag = Tag(tag)
    try:
        return DicomDictionary[tag]
    except KeyError:
        if not tag.is_private:
            mask_x = mask_match(tag)
            if mask_x:
                return RepeatersDictionary[mask_x]
        raise KeyError("Tag {0} not found in DICOM dictionary".format(tag))
github acil-bwh / ChestImagingPlatform / cip_python / utils / anonymize_dicom.py View on Github external
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 
    
    keys = ds.keys()

    for t in anon_tags:
        if t in keys:
            if type(ds[t].value) == str or \
                type(ds[t].value) == dicom.valuerep.PersonName or \
                type(ds[t].value) == dicom.UID.UID:
                ds[t].value = 'Anonymized'
github acil-bwh / ChestImagingPlatform / cip_python / utils / anonymize_dicom.py View on Github external
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 
github acil-bwh / ChestImagingPlatform / cip_python / utils / anonymize_dicom.py View on Github external
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 
    
    keys = ds.keys()
github acil-bwh / ChestImagingPlatform / cip_python / utils / anonymize_dicom.py View on Github external
----------
    For a description of the tags that are anonymized, see:
    ftp://medical.nema.org/medical/dicom/final/sup55_ft.pdf
    """
    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 
github pydicom / pydicom / pydicom / dataset.py View on Github external
element_offset : int
            The lower 16 bits (e.g. 2 hex numbers) of the element tag.

        Returns
        -------
            The tag ID defined by the private block location and the
            given element offset.

        Raises
        ------
        ValueError
            If `element_offset` is too large.
        """
        if element_offset > 0xff:
            raise ValueError('Element offset must be less than 256')
        return Tag(self.group, self.block_start + element_offset)
github pydicom / pydicom / pydicom / dataset.py View on Github external
self._private_blocks[key] = block
            return block

        key = (group, private_creator)
        if key in self._private_blocks:
            return self._private_blocks[key]

        if not private_creator:
            raise ValueError('Private creator must have a value')

        if group % 2 == 0:
            raise ValueError(
                'Tag must be private if private creator is given')

        for element in range(0x10, 0x100):
            private_creator_tag = Tag(group, element)
            if private_creator_tag not in self._dict:
                if create:
                    self.add_new(private_creator_tag, 'LO', private_creator)
                    return new_block()
                else:
                    break
            if self._dict[private_creator_tag].value == private_creator:
                return new_block()

        raise KeyError(
            "Private creator '{}' not found".format(private_creator))