How to use the pymedphys._imports.pydicom.dataset.Dataset function in pymedphys

To help you get started, we’ve selected a few pymedphys 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 pymedphys / pymedphys / pymedphys / labs / pinnacle / rtstruct.py View on Github external
if len(points) == 3:
                    points[0] = round(points[0], 5)
                    points[1] = round(points[1], 5)
                    points[2] = round(points[2], 5)

                points = points + curr_points
            if "Beginning of ROI" in line:  # Start of ROI
                plan.roi_count = (
                    plan.roi_count + 1
                )  # increment ROI_num because I've found a new ROI
                roi_contour = pydicom.dataset.Dataset()
                roi_contour.ReferencedROINumber = str(plan.roi_count)
                ds.ROIContourSequence.append(roi_contour)
                structure_set_roi = pydicom.dataset.Dataset()
                ds.StructureSetROISequence.append(roi_contour)
                rt_roi_observations = pydicom.dataset.Dataset()
                ds.RTROIObservationsSequence.append(rt_roi_observations)
                ds.StructureSetROISequence[
                    plan.roi_count - 1
                ].ROINumber = plan.roi_count
                ROIName = line[22:]  # gets a string of ROI name
                ROIName = ROIName.replace("\n", "")
                ds.StructureSetROISequence[plan.roi_count - 1].ROIName = ROIName
                ds.StructureSetROISequence[
                    plan.roi_count - 1
                ].ROIGenerationAlgorithm = "SEMIAUTOMATIC"
                ds.StructureSetROISequence[
                    plan.roi_count - 1
                ].ReferencedFrameOfReferenceUID = plan.primary_image.image_info[0][
                    "FrameUID"
                ]
                ds.ROIContourSequence[
github pymedphys / pymedphys / pymedphys / labs / pinnacle / 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 = pydicom.dataset.Dataset()
        roi_contour.ReferencedROINumber = str(plan.roi_count)
        roi_contour.ROIDisplayColor = colors[point["Color"]]
        roi_contour.ContourSequence = pydicom.sequence.Sequence()
        contour = pydicom.dataset.Dataset()
        contour.ContourData = refpoint
        contour.ContourGeometricType = "POINT"
        contour.NumberOfContourPoints = 1
        contour.ContourImageSequence = pydicom.sequence.Sequence()

        contour_image = pydicom.dataset.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
            ):
github pymedphys / pymedphys / pymedphys / labs / pinnacle / 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 = pydicom.dataset.Dataset()
        roi_contour.ReferencedROINumber = str(plan.roi_count)
        roi_contour.ROIDisplayColor = colors[point["Color"]]
        roi_contour.ContourSequence = pydicom.sequence.Sequence()
        contour = pydicom.dataset.Dataset()
        contour.ContourData = refpoint
        contour.ContourGeometricType = "POINT"
        contour.NumberOfContourPoints = 1
        contour.ContourImageSequence = pydicom.sequence.Sequence()

        contour_image = pydicom.dataset.Dataset()

        closestvalue = abs(
            float(plan.primary_image.image_info[0]["TablePosition"])
            - float(refpoint[-1])
        )
        for s in plan.primary_image.image_info:
github pymedphys / pymedphys / pymedphys / labs / pinnacle / rtstruct.py View on Github external
-float(curr_points[0]) * 10,
                        -float(curr_points[1]) * 10,
                        float(curr_points[2]) * 10,
                    ]

                if len(points) == 3:
                    points[0] = round(points[0], 5)
                    points[1] = round(points[1], 5)
                    points[2] = round(points[2], 5)

                points = points + curr_points
            if "Beginning of ROI" in line:  # Start of ROI
                plan.roi_count = (
                    plan.roi_count + 1
                )  # increment ROI_num because I've found a new ROI
                roi_contour = pydicom.dataset.Dataset()
                roi_contour.ReferencedROINumber = str(plan.roi_count)
                ds.ROIContourSequence.append(roi_contour)
                structure_set_roi = pydicom.dataset.Dataset()
                ds.StructureSetROISequence.append(roi_contour)
                rt_roi_observations = pydicom.dataset.Dataset()
                ds.RTROIObservationsSequence.append(rt_roi_observations)
                ds.StructureSetROISequence[
                    plan.roi_count - 1
                ].ROINumber = plan.roi_count
                ROIName = line[22:]  # gets a string of ROI name
                ROIName = ROIName.replace("\n", "")
                ds.StructureSetROISequence[plan.roi_count - 1].ROIName = ROIName
                ds.StructureSetROISequence[
                    plan.roi_count - 1
                ].ROIGenerationAlgorithm = "SEMIAUTOMATIC"
                ds.StructureSetROISequence[
github pymedphys / pymedphys / pymedphys / labs / pinnacle / rtplan.py View on Github external
"RTPLAN export functionality is currently not validated and not stable. Use with caution."
    )

    patient_info = plan.pinnacle.patient_info
    plan_info = plan.plan_info
    trial_info = plan.trial_info
    image_info = plan.primary_image.image_info[0]
    machine_info = plan.machine_info

    patient_position = plan.patient_position

    # Get the UID for the Plan
    planInstanceUID = plan.plan_inst_uid

    # Populate required values for file meta information
    file_meta = pydicom.dataset.Dataset()
    file_meta.MediaStorageSOPClassUID = RTPlanSOPClassUID
    file_meta.TransferSyntaxUID = GTransferSyntaxUID
    file_meta.MediaStorageSOPInstanceUID = planInstanceUID
    file_meta.ImplementationClassUID = GImplementationClassUID

    # Create the pydicom.dataset.FileDataset instance (initially no data elements, but
    # file_meta supplied)
    RPfilename = "RP." + file_meta.MediaStorageSOPInstanceUID + ".dcm"
    ds = pydicom.dataset.FileDataset(
        RPfilename, {}, file_meta=file_meta, preamble=b"\x00" * 128
    )

    ds.SpecificCharacterSet = "ISO_IR 100"
    ds.InstanceCreationDate = time.strftime("%Y%m%d")
    ds.InstanceCreationTime = time.strftime("%H%M%S")
github pymedphys / pymedphys / pymedphys / labs / pinnacle / rtstruct.py View on Github external
ds.ROIContourSequence.append(roi_contour)

        structure_set_roi = pydicom.dataset.Dataset()
        structure_set_roi.ROINumber = plan.roi_count
        structure_set_roi.ROIName = point["Name"]
        plan.logger.info("Exporting point: " + point["Name"])

        # Not sure what this is for, just basing off template, should look into further
        structure_set_roi.ROIGenerationAlgorithm = "SEMIAUTOMATIC"
        structure_set_roi.ReferencedFrameOfReferenceUID = plan.primary_image.image_info[
            0
        ]["FrameUID"]

        ds.StructureSetROISequence.append(structure_set_roi)

        rt_roi_observations = pydicom.dataset.Dataset()
        rt_roi_observations.ObservationNumber = plan.roi_count
        rt_roi_observations.ReferencedROINumber = plan.roi_count
        rt_roi_observations.RTROIInterpretedType = "MARKER"
        rt_roi_observations.ROIInterpreter = ""
        ds.RTROIObservationsSequence.append(rt_roi_observations)

    # Not applying any shifts of points at the moment. Needed for Pinnacle pre v9.0
    # for enteredpoints in ds.ROIContourSequence:
    #     #logger.debug("In loop applying shifts: isocenter:" + str(data["isocenter"]) )
    #     enteredpoints.ContourSequence[0].ContourData[0] = str(float(enteredpoints.ContourSequence[0].ContourData[0]) - data["xshift"])
    #     enteredpoints.ContourSequence[0].ContourData[1] = str(float(enteredpoints.ContourSequence[0].ContourData[1]) - data["yshift"])
    #     #enteredpoints.ContourSequence[0].ContourData[2] = str(float(enteredpoints.ContourSequence[0].ContourData[2]) - float(data["isocenter"][2]))
    #     #logger.debug("bottom of loop applying shifts isocenter:" + str(data["isocenter"]))

    return ds
github pymedphys / pymedphys / pymedphys / labs / pinnacle / rtdose.py View on Github external
ds.Columns = int(trial_info["DoseGrid .Dimension .X"])
    ds.PixelSpacing = [
        trial_info["DoseGrid .VoxelSize .X"] * 10,
        trial_info["DoseGrid .VoxelSize .Y"] * 10,
    ]
    ds.BitsAllocated = 16  # ????
    ds.BitsStored = 16  # ???
    ds.HighBit = 15  # ???
    ds.PixelRepresentation = 0
    ds.DoseUnits = "GY"  # 'RELATIVE'#'GY'
    ds.DoseType = "PHYSICAL"
    ds.DoseSummationType = "PLAN"

    # TODO: need to look at what is required from this block
    ds.ReferencedRTPlanSequence = pydicom.sequence.Sequence()
    ReferencedRTPlan1 = pydicom.dataset.Dataset()
    ds.ReferencedRTPlanSequence.append(ReferencedRTPlan1)
    ds.ReferencedRTPlanSequence[0].ReferencedSOPClassUID = RTPlanSOPClassUID
    ds.ReferencedRTPlanSequence[0].ReferencedSOPInstanceUID = planInstanceUID
    ds.ReferencedRTPlanSequence[
        0
    ].ReferencedFractionGroupSequence = pydicom.sequence.Sequence()
    ReferencedFractionGroup1 = pydicom.dataset.Dataset()
    ds.ReferencedRTPlanSequence[0].ReferencedFractionGroupSequence.append(
        ReferencedFractionGroup1
    )
    ds.ReferencedRTPlanSequence[0].ReferencedFractionGroupSequence[
        0
    ].ReferencedBeamSequence = pydicom.sequence.Sequence()
    ReferencedBeam1 = pydicom.dataset.Dataset()
    ds.ReferencedRTPlanSequence[0].ReferencedFractionGroupSequence[
        0
github pymedphys / pymedphys / pymedphys / labs / pinnacle / rtplan.py View on Github external
].BeamLimitingDeviceAngle = colangle
                    ds.BeamSequence[beam_count - 1].ControlPointSequence[
                        j
                    ].SourceToSurfaceDistance = (beam["SSD"] * 10)
                    ds.BeamSequence[beam_count - 1].ControlPointSequence[
                        j
                    ].ReferencedDoseReferenceSequence[
                        0
                    ].CumulativeDoseReferenceCoefficient = "0"
                    ds.BeamSequence[beam_count - 1].ControlPointSequence[
                        j
                    ].ReferencedDoseReferenceSequence[
                        0
                    ].ReferencedDoseReferenceNumber = "1"
                    if numwedges > 0:
                        WedgePosition1 = pydicom.dataset.Dataset()
                        ds.BeamSequence[beam_count - 1].ControlPointSequence[
                            j
                        ].WedgePositionSequence = pydicom.sequence.Sequence()
                        ds.BeamSequence[beam_count - 1].ControlPointSequence[
                            j
                        ].WedgePositionSequence.append(WedgePosition1)
                        ds.BeamSequence[beam_count - 1].ControlPointSequence[
                            j
                        ].WedgePositionSequence[0].WedgePosition = "IN"
                        ds.BeamSequence[beam_count - 1].ControlPointSequence[
                            j
                        ].WedgePositionSequence[0].ReferencedWedgeNumber = "1"
                    ds.BeamSequence[beam_count - 1].ControlPointSequence[
                        j
                    ].BeamLimitingDevicePositionSequence.append(
                        pydicom.dataset.Dataset()
github pymedphys / pymedphys / pymedphys / labs / pinnacle / rtstruct.py View on Github external
ds.ReferencedFrameOfReferenceSequence[0].RTReferencedStudySequence[
        0
    ].RTReferencedSeriesSequence.append(RTReferencedSeries)
    ds.ReferencedFrameOfReferenceSequence[0].RTReferencedStudySequence[
        0
    ].RTReferencedSeriesSequence[0].SeriesInstanceUID = plan.primary_image.image_info[
        0
    ][
        "SeriesUID"
    ]
    ds.ReferencedFrameOfReferenceSequence[0].RTReferencedStudySequence[
        0
    ].RTReferencedSeriesSequence[0].ContourImageSequence = pydicom.sequence.Sequence()

    for info in plan.primary_image.image_info:
        contour_image = pydicom.dataset.Dataset()
        contour_image.ReferencedSOPClassUID = "1.2.840.10008.5.1.4.1.1.2"
        contour_image.ReferencedSOPInstanceUID = info["InstanceUID"]
        ds.ReferencedFrameOfReferenceSequence[0].RTReferencedStudySequence[
            0
        ].RTReferencedSeriesSequence[0].ContourImageSequence.append(contour_image)

    ds.ROIContourSequence = pydicom.sequence.Sequence()
    ds.StructureSetROISequence = pydicom.sequence.Sequence()
    ds.RTROIObservationsSequence = pydicom.sequence.Sequence()

    # Determine ISO Center
    find_iso_center(plan)

    ds = read_points(ds, plan)
    ds = read_roi(ds, plan)
github pymedphys / pymedphys / pymedphys / labs / pinnacle / rtstruct.py View on Github external
def convert_struct(plan, export_path):

    # Check that the plan has a primary image, as we can't create a meaningful RTSTRUCT without it:
    if not plan.primary_image:
        plan.logger.error(
            "No primary image found for plan. Unable to generate RTSTRUCT."
        )
        return

    patient_info = plan.pinnacle.patient_info

    struct_sop_instuid = plan.struct_inst_uid

    # Populate required values for file meta information
    file_meta = pydicom.dataset.Dataset()
    file_meta.MediaStorageSOPClassUID = RTStructSOPClassUID
    file_meta.TransferSyntaxUID = GTransferSyntaxUID
    file_meta.MediaStorageSOPInstanceUID = struct_sop_instuid
    file_meta.ImplementationClassUID = GImplementationClassUID

    struct_filename = "RS." + struct_sop_instuid + ".dcm"

    ds = pydicom.dataset.FileDataset(
        struct_filename, {}, file_meta=file_meta, preamble=b"\x00" * 128
    )
    ds = pydicom.dataset.FileDataset(
        struct_filename, {}, file_meta=file_meta, preamble=b"\x00" * 128
    )

    struct_series_instuid = pydicom.uid.generate_uid()
    ds.ReferencedStudySequence = pydicom.sequence.Sequence()