How to use the pydicom.uid 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 radiasoft / sirepo / sirepo / template / rs4pi.py View on Github external
ds.InstanceCreationTime = now.strftime('%H%M%S.%f')
    ds.SOPClassUID = _DICOM_CLASS[dicom_class]
    ds.SOPInstanceUID = sop_uid
    ds.StudyDate = ''
    ds.StudyTime = ''
    ds.AccessionNumber = ''
    ds.Modality = modality
    ds.Manufacturer = _RADIASOFT_ID
    ds.ReferringPhysiciansName = ''
    ds.ManufacturersModelName = _RADIASOFT_ID
    ds.PatientsName = _RADIASOFT_ID
    ds.PatientID = _RADIASOFT_ID
    ds.PatientsBirthDate = ''
    ds.PatientsSex = ''
    ds.StudyInstanceUID = study_uid
    ds.SeriesInstanceUID = dicom.uid.generate_uid()
    ds.StudyID = ''
    ds.SeriesNumber = ''
    return ds
github ryanneph / PyMedImage / pymedimage / rttypes.py View on Github external
def toDicom(self, dname, fprefix=''):
        import pydicom  # pydicom
        SeriesInstanceUID   = pydicom.uid.generate_uid()
        StudyInstanceUID    = pydicom.uid.generate_uid()
        FrameOfReferenceUID = pydicom.uid.generate_uid()
        min_val = np.min(self.data)
        for i in range(self.frameofreference.size[2]):
            ds = dcmio.make_dicom_boilerplate(SeriesInstanceUID, StudyInstanceUID, FrameOfReferenceUID)
            ds.SliceThickness = self.frameofreference.spacing[2]
            ds.PixelSpacing = list(self.frameofreference.spacing[:2])
            ds.SliceLocation = self.frameofreference.start[2] + i*self.frameofreference.spacing[2]
            ds.ImagePositionPatient = [*self.frameofreference.start[:2], ds.SliceLocation]
            ds.Columns = self.frameofreference.size[0]
            ds.Rows = self.frameofreference.size[1]
            ds.AcquisitionNumber = i+1
            ds.Modality = self.modality if self.modality is not None else ''
            ds.DerivationDescription = self.feature_label if self.feature_label is not None else ''
            ds.PixelData = ((self.data[i, :, :]-min_val).flatten().astype(np.uint16)).tostring()
            ds.RescaleSlope = 1.0
github pymedphys / pymedphys / notebooks / dcmplan / generate_rp.py View on Github external
def generate_rtplan_skeleton():

    ds = Dataset()

    # ----- File meta -----
    file_meta = generate_rtplan_file_meta()
    ds.file_meta = file_meta

    # ----- Patient Module -----
    ds.PatientName = "PyMedPhys"  # Required - can be empty - could fill in?
    ds.PatientID = "PMP"  # Required - can be empty - could fill in?
    ds.PatientSex = "O"  # Required - can be empty
    ds.PatientBirthDate = ""  # Required - can be empty TODO: check if RS happy

    ds.StudyInstanceUID = pydicom.uid.generate_uid()
    ds.StudyDate = ""  # Required - can be empty
    ds.StudyTime = ""  # Required - can be empty'
    ds.ReferringPhysicianName = ""  # Required - can be empty'
    ds.StudyID = ""  # Required - can be empty'
    ds.AccessionNumber = ""  # Required - can be empty'

    # ----- RT Series Module -----
    ds.Modality = "RTPLAN"
    ds.SeriesInstanceUID = pydicom.uid.generate_uid()
    ds.SeriesNumber = ""  # Required - can be empty'
    ds.OperatorsName = ""  # Required - can be empty'

    # ----- Frame of Reference Module -----
    ds.FrameOfReferenceUID = pydicom.uid.generate_uid()
    ds.PositionReferenceIndicator = ""  # Required - can be empty'
github pydicom / pydicom / pydicom / contrib / dicom_dao.py View on Github external
This code is lifted from PyDicom.

    """
    TransferSyntax = dcm.file_meta.TransferSyntaxUID
    if TransferSyntax == pydicom.uid.ExplicitVRLittleEndian:
        dcm.is_implicit_vr = False

        # This line not in PyDicom
        dcm.is_little_endian = True

    elif TransferSyntax == pydicom.uid.ImplicitVRLittleEndian:
        dcm.is_implicit_vr = True
        dcm.is_little_endian = True

    elif TransferSyntax == pydicom.uid.ExplicitVRBigEndian:
        dcm.is_implicit_vr = False
        dcm.is_little_endian = False

    elif TransferSyntax == pydicom.uid.DeflatedExplicitVRLittleEndian:

        # Deleted lines above as it relates
        dcm.is_implicit_vr = False

        # to reading compressed file data.
        dcm.is_little_endian = True

    else:
        # Any other syntax should be Explicit VR Little Endian,
        #   e.g. all Encapsulated (JPEG etc) are ExplVR-LE by
        #   Standard PS 3.5-2008 A.4 (p63)
        dcm.is_implicit_vr = False
github pydicom / pydicom / pydicom / pixel_data_handlers / rle_handler.py View on Github external
except ImportError:
    HAVE_RLE = False

from pydicom.encaps import decode_data_sequence, defragment_data
from pydicom.pixel_data_handlers.util import pixel_dtype
import pydicom.uid


HANDLER_NAME = 'RLE Lossless'

DEPENDENCIES = {
    'numpy': ('http://www.numpy.org/', 'NumPy'),
}

SUPPORTED_TRANSFER_SYNTAXES = [
    pydicom.uid.RLELossless
]


def is_available():
    """Return ``True`` if the handler has its dependencies met."""
    return HAVE_RLE


def supports_transfer_syntax(transfer_syntax):
    """Return ``True`` if the handler supports the `transfer_syntax`.

    Parameters
    ----------
    transfer_syntax : uid.UID
        The Transfer Syntax UID of the *Pixel Data* that is to be used with
        the handler.
github cutright / DVH-Analytics / dvha / tools / utilities.py View on Github external
def validate_transfer_syntax_uid(data_set):
    meta = pydicom.Dataset()
    meta.ImplementationClassUID = pydicom.uid.generate_uid()
    meta.TransferSyntaxUID = ImplicitVRLittleEndian
    new_data_set = pydicom.FileDataset(filename_or_obj=None, dataset=data_set, is_little_endian=True,
                                       file_meta=meta)
    new_data_set.is_little_endian = True
    new_data_set.is_implicit_VR = True

    return new_data_set
github pydicom / pydicom / pydicom / pixel_data_handlers / jpeg_ls_handler.py View on Github external
HAVE_JPEGLS = False

import pydicom.encaps
from pydicom.pixel_data_handlers.util import dtype_corrected_for_endianness
import pydicom.uid


HANDLER_NAME = 'JPEG-LS'

DEPENDENCIES = {
    'numpy': ('http://www.numpy.org/', 'NumPy'),
    'jpeg_ls': ('https://github.com/Who8MyLunch/CharPyLS', 'CharPyLS'),
}

SUPPORTED_TRANSFER_SYNTAXES = [
    pydicom.uid.JPEGLSLossless,
    pydicom.uid.JPEGLSLossy,
]


def is_available():
    """Return True if the handler has its dependencies met."""
    return HAVE_NP and HAVE_JPEGLS


def needs_to_convert_to_RGB(dicom_dataset):
    return False


def should_change_PhotometricInterpretation_to_RGB(dicom_dataset):
    should_change = dicom_dataset.SamplesPerPixel == 3
    return False
github pydicom / pydicom / pydicom / filereader.py View on Github external
# Test the VR to see if it's valid, and if so then assume explicit VR
        from pydicom.values import converters
        if not in_py2:
            VR = VR.decode(default_encoding)
        if VR in converters.keys():
            is_implicit_VR = False
            # Big endian encoding can only be explicit VR
            #   Big endian 0x0004 decoded as little endian will be 1024
            #   Big endian 0x0100 decoded as little endian will be 1
            # Therefore works for big endian tag groups up to 0x00FF after
            #   which it will fail, in which case we leave it as little endian
            #   and hope for the best (big endian is retired anyway)
            if group >= 1024:
                is_little_endian = False
    elif transfer_syntax == pydicom.uid.ImplicitVRLittleEndian:
        pass
    elif transfer_syntax == pydicom.uid.ExplicitVRLittleEndian:
        is_implicit_VR = False
    elif transfer_syntax == pydicom.uid.ExplicitVRBigEndian:
        is_implicit_VR = False
        is_little_endian = False
    elif transfer_syntax == pydicom.uid.DeflatedExplicitVRLittleEndian:
        # See PS3.6-2008 A.5 (p 71)
        # when written, the entire dataset following
        #     the file metadata was prepared the normal way,
        #     then "deflate" compression applied.
        #  All that is needed here is to decompress and then
        #     use as normal in a file-like object
        zipped = fileobj.read()
        # -MAX_WBITS part is from comp.lang.python answer:
        # groups.google.com/group/comp.lang.python/msg/e95b3b38a71e6799
github pydicom / pydicom / pydicom / pixel_data_handlers / gdcm_handler.py View on Github external
import pydicom.uid
from pydicom import compat
from pydicom.pixel_data_handlers.util import get_expected_length, pixel_dtype


HANDLER_NAME = 'GDCM'

DEPENDENCIES = {
    'numpy': ('http://www.numpy.org/', 'NumPy'),
    'gdcm': ('http://gdcm.sourceforge.net/wiki/index.php/Main_Page', 'GDCM'),
}

SUPPORTED_TRANSFER_SYNTAXES = [
    pydicom.uid.JPEGBaseline,
    pydicom.uid.JPEGExtended,
    pydicom.uid.JPEGLosslessP14,
    pydicom.uid.JPEGLossless,
    pydicom.uid.JPEGLSLossless,
    pydicom.uid.JPEGLSLossy,
    pydicom.uid.JPEG2000Lossless,
    pydicom.uid.JPEG2000,
]

should_convert_these_syntaxes_to_RGB = [
    pydicom.uid.JPEGBaseline, ]


def is_available():
    """Return ``True`` if the handler has its dependencies met."""
    return HAVE_NP and HAVE_GDCM
github pymedphys / pymedphys / packages / pymedphys_pinnacle / src / pymedphys_pinnacle / export / pinnacle_plan.py View on Github external
def is_prefix_valid(self, prefix):
        """Check if a UID prefix is valid.

        Parameters
        ----------
            prefix :  str
                The UID prefix to check.

        Returns:
            True if valid, False otherwise.
        """

        if re.match(pydicom.uid.RE_VALID_UID_PREFIX, prefix):
            return True

        return False