How to use the pydicom.sequence.Sequence 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_rawread.py View on Github external
)
        # "\x08\x00\x32\x10\x08\x00\x00\x00\xfe\xff\x00\xe0\x00\x00\x00\x00"
        # from issue 27, procedure code sequence (0008,1032)
        # hexstr += "\x08\x00\x3e\x10\x0c\x00\x00\x00\x52\x20
        # \x41\x44\x44\x20\x56\x49\x45\x57\x53\x20"
        # data element following

        fp = BytesIO(hex2bytes(hexstr))
        gen = data_element_generator(fp,
                                     is_implicit_VR=True,
                                     is_little_endian=True)
        raw_seq = next(gen)
        seq = convert_value("SQ", raw_seq)

        got_type = "got type {0}".format(str(type(seq)))
        self.assertTrue(isinstance(seq, Sequence),
                        "Did not get Sequence, %s" % got_type)
        expected = "Expected Sequence with single (empty) item"
        got = "got {0:d} item(s)".format(len(seq))
        self.assertTrue(len(seq) == 1, "%s, %s" % (expected, got))
        msg = "Expected the sequence item (dataset) to be empty"
        self.assertTrue(len(seq[0]) == 0,msg)
        elem2 = next(gen)
        self.assertEqual(elem2.tag,
                         0x0008103e,
                         "Expected a data element after empty sequence item")
github pydicom / pydicom / tests / test_sequence.py View on Github external
def testDefaultInitialization(self):
        """Sequence: Ensure a valid Sequence is created"""
        empty = Sequence()
        self.assertTrue(len(empty) == 0, "Non-empty Sequence created")
github pydicom / pydicom / tests / test_sequence.py View on Github external
def testInvalidAssignment(self):
        """Sequence: validate exception for invalid assignment"""
        seq = Sequence([Dataset(), ])
        # Attempt to assign an integer to the first element
        self.assertRaises(TypeError, seq.__setitem__, 0, 1)
github pymedphys / pymedphys / notebooks / dcmplan / generate_rp.py View on Github external
wedge.AccessoryCode = ""  # Optional TODO: check if needed
        wedge.WedgeAngle = 60
        wedge.WedgeFactor = ""  # Required but can leave empty
        # Degrees relative to Beam Limiting Device TODO: (always 0 for EDW?)
        wedge.WedgeOrientation = 0
        wedge_sequence.append(wedge)

    beam.NumberOfCompensators = "0"  # ASSUME NO COMPENSATORS
    beam.NumberOfBoli = "0"  # ASSUME NO BOLI

    # ASSUME NO BLOCKS (TODO: check if used for electrons)
    beam.NumberOfBlocks = "0"

    # ----- Applicator Sequence (electrons & SRS) TODO: Handle cones -----
    if HAS_APPLICATOR:
        applicator_sequence = Sequence()
        beam.ApplicatorSequence = applicator_sequence

        # Applicator Sequence: Applicator
        applicator = Dataset()
        applicator.ApplicatorID = ""  # TODO: check cone ID
        applicator.AccessoryCode = ""  # Optional TODO: check if needed
        applicator.ApplicatorType = "ELECTRON_SQUARE"  # many others possible
        applicator.ApplicatorGeometrySequence = [Dataset()]
        # RECTANGLE and CIRCULAR also possible
        applicator.ApplicatorGeometrySequence[0].ApplicatorApertureShape = "SYM_SQUARE"
        # Required for SQUARE and CIRCLE = length of side or diameter
        applicator.ApplicatorGeometrySequence[0].ApplicatorOpening = 10
        # Required if RECTANGLE
        applicator.ApplicatorGeometrySequence[0].ApplicatorOpeningX
        # Required if RECTANGLE
        applicator.ApplicatorGeometrySequence[0].ApplicatorOpeningY
github pydicom / pydicom / pydicom / filereader.py View on Github external
is_undefined_length = False
    if bytelength != 0:  # SQ of length 0 possible (PS 3.5-2008 7.5.1a (p.40)
        if bytelength == 0xffffffff:
            is_undefined_length = True
            bytelength = None
        fp_tell = fp.tell  # for speed in loop
        fpStart = fp_tell()
        while (not bytelength) or (fp_tell() - fpStart < bytelength):
            file_tell = fp.tell()
            dataset = read_sequence_item(fp, is_implicit_VR, is_little_endian,
                                         encoding, offset)
            if dataset is None:  # None is returned if hit Sequence Delimiter
                break
            dataset.file_tell = file_tell + offset
            seq.append(dataset)
    seq = Sequence(seq)
    seq.is_undefined_length = is_undefined_length
    return seq
github pydicom / pydicom / pydicom / contrib / pydicom_series.py View on Github external
def __init__(self, suid, showProgress):
        # Init dataset list and the callback
        self._datasets = Sequence()
        self._showProgress = showProgress

        # Init props
        self._suid = suid
        self._info = None
        self._shape = None
        self._sampling = None
github pymedphys / pymedphys / packages / pymedphys_pinnacle / src / pymedphys_pinnacle / exporttool / rtstruct.py View on Github external
def read_points(ds, plan):

    plan.roi_count = 0

    for point in plan.points:

        plan.roi_count = plan.roi_count + 1

        refpoint = plan.convert_point(point)

        roi_contour = Dataset()
        roi_contour.ReferencedROINumber = str(plan.roi_count)
        roi_contour.ROIDisplayColor = colors[point["Color"]]
        roi_contour.ContourSequence = Sequence()
        contour = Dataset()
        contour.ContourData = refpoint
        contour.ContourGeometricType = 'POINT'
        contour.NumberOfContourPoints = 1
        contour.ContourImageSequence = Sequence()

        contour_image = Dataset()

        closestvalue = abs(float(plan.primary_image.image_info[0]['TablePosition']) - float(refpoint[-1]))
        for s in plan.primary_image.image_info:
            if abs(float(s['TablePosition']) - (-float(refpoint[-1]/10))) <= closestvalue:
                closestvalue = abs(float(s['TablePosition']) - (-float(refpoint[-1]/10)))
                contour_image.ReferencedSOPClassUID = '1.2.840.10008.5.1.4.1.1.2'
                contour_image.ReferencedSOPInstanceUID = s['InstanceUID']

        contour.ContourImageSequence.append(contour_image)
github pymedphys / pymedphys / notebooks / dcmplan / generate_rp.py View on Github external
applicator.ApplicatorGeometrySequence[0].ApplicatorOpening = 10
        # Required if RECTANGLE
        applicator.ApplicatorGeometrySequence[0].ApplicatorOpeningX
        # Required if RECTANGLE
        applicator.ApplicatorGeometrySequence[0].ApplicatorOpeningY
        # Optional TODO: decide whether to set cone desc
        applicator.ApplicatorDescription = ""
        applicator_sequence.append(applicator)

    # ASSUME NO ACCESSORIES? TODO: check if this includes cutouts

    beam.FinalCumulativeMetersetWeight = "1"
    beam.NumberOfControlPoints = "2"

    # ----- Control Point Sequence -----
    cp_sequence = Sequence()
    beam.ControlPointSequence = cp_sequence

    # Control Point Sequence: Control Point 0
    cp0 = Dataset()
    cp0.ControlPointIndex = "0"
    cp0.CumulativeMetersetWeight = "0"
    cp0.NominalBeamEnergy = "6"  # TODO: User supplied
    cp0.DoseRateSet = "600"  # TODO: User supplied

    # Wedge Position Sequence
    if HAS_WEDGE:
        wedge_position_sequence = Sequence()
        cp0.WedgePositionSequence = wedge_position_sequence

        # Wedge Position Sequence: Wedge
        wedge_position = Dataset()