
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "auto_examples/input_output/plot_read_rtplan.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_auto_examples_input_output_plot_read_rtplan.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_auto_examples_input_output_plot_read_rtplan.py:


======================================
Read RTPLAN DICOM and list information
======================================

Given an RTPLAN DICOM file, list basic info for the beams in it.

.. GENERATED FROM PYTHON SOURCE LINES 9-35




.. rst-class:: sphx-glr-script-out

 .. code-block:: none


      Beam name    Number   Gantry   SSD (cm)  
       Field 1           1      0.0     89.8






|

.. code-block:: Python


    # authors : Darcy Mason
    #           Guillaume Lemaitre <g.lemaitre58@gmail.com>
    # license : MIT

    import pydicom
    from pydicom.data import get_testdata_file

    print(__doc__)


    def list_beams(ds: pydicom.Dataset) -> str:
        """Summarizes the RTPLAN beam information in the dataset."""
        lines = [f"{'Beam name':^13s} {'Number':^8s} {'Gantry':^8s} {'SSD (cm)':^11s}"]
        for beam in ds.BeamSequence:
            cp0 = beam.ControlPointSequence[0]
            ssd = float(cp0.SourceToSurfaceDistance / 10)
            lines.append(
                f"{beam.BeamName:^13s} {beam.BeamNumber:8d} {cp0.GantryAngle:8.1f} {ssd:8.1f}"
            )
        return "\n".join(lines)


    path = get_testdata_file("rtplan.dcm")
    ds = pydicom.dcmread(path)
    print(list_beams(ds))


.. rst-class:: sphx-glr-timing

   **Total running time of the script:** (0 minutes 0.004 seconds)


.. _sphx_glr_download_auto_examples_input_output_plot_read_rtplan.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: plot_read_rtplan.ipynb <plot_read_rtplan.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: plot_read_rtplan.py <plot_read_rtplan.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: plot_read_rtplan.zip <plot_read_rtplan.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
