Visualise Data#

Open In Colab

PyDicer’s visualise module will produce cross-sections of data objects and store them in .png format within the data object directory. This is particularly useful for fast inspection of the data to ensure that nothing has gone wrong during conversion.

The visualise module can be run at any time after conversion. If you are using advanced features of PyDicer, such as auto-segmentation inference and object generation, you can run the visualise module following the generation of the new data objects to produce the cross-section .png files.

[1]:
try:
    from pydicer import PyDicer
except ImportError:
    !pip install pydicer
    from pydicer import PyDicer

from pathlib import Path

from pydicer.utils import fetch_converted_test_data

Setup PyDicer#

HNSCC data prepared for this example are downloaded and stored into a testdata_hnscc directory. We will use this for our PyDicer working directory. We also initialise our PyDicer object.

[2]:
working_directory = fetch_converted_test_data("./testdata_hnscc", dataset="HNSCC")

pydicer = PyDicer(working_directory)
Working directory %s aready exists, won't download test data.

Visualise Data#

We simply call the visualise function of the visualise module to produce the cross-sections.

Inspect some of the data object directories in testdata_hnscc/data and look for the .png cross-sections. The {hashed_uid} in files named vis_{hashed_uid}.png refers to a UID hash linking to the image being visualised. Visualisations are produced for: - Images - RT Structure Sets - RT Dose Grids

[3]:
pydicer.visualise.visualise()
 17%|█▋        | 5/30 [00:25<02:00,  4.81s/objects, visualise]/home/runner/.cache/pypoetry/virtualenvs/pydicer-pNPN9n62-py3.9/lib/python3.9/site-packages/pydicom/valuerep.py:443: UserWarning: Invalid value for VR DA: 'NaT'.
  warnings.warn(msg)
 37%|███▋      | 11/30 [01:05<02:06,  6.68s/objects, visualise]/home/runner/.cache/pypoetry/virtualenvs/pydicer-pNPN9n62-py3.9/lib/python3.9/site-packages/pydicom/valuerep.py:443: UserWarning: Invalid value for VR DA: 'NaT'.
  warnings.warn(msg)
 87%|████████▋ | 26/30 [02:05<00:09,  2.44s/objects, visualise]/home/runner/.cache/pypoetry/virtualenvs/pydicer-pNPN9n62-py3.9/lib/python3.9/site-packages/pydicom/valuerep.py:443: UserWarning: Invalid value for VR DA: 'NaT'.
  warnings.warn(msg)
 90%|█████████ | 27/30 [02:05<00:05,  1.81s/objects, visualise]/home/runner/.cache/pypoetry/virtualenvs/pydicer-pNPN9n62-py3.9/lib/python3.9/site-packages/pydicom/valuerep.py:443: UserWarning: Invalid value for VR DA: 'NaT'.
  warnings.warn(msg)
 93%|█████████▎| 28/30 [02:05<00:02,  1.35s/objects, visualise]/home/runner/.cache/pypoetry/virtualenvs/pydicer-pNPN9n62-py3.9/lib/python3.9/site-packages/pydicom/valuerep.py:443: UserWarning: Invalid value for VR DA: 'NaT'.
  warnings.warn(msg)
 97%|█████████▋| 29/30 [02:06<00:01,  1.02s/objects, visualise]/home/runner/.cache/pypoetry/virtualenvs/pydicer-pNPN9n62-py3.9/lib/python3.9/site-packages/pydicom/valuerep.py:443: UserWarning: Invalid value for VR DA: 'NaT'.
  warnings.warn(msg)
100%|██████████| 30/30 [02:06<00:00,  4.22s/objects, visualise]

Run for a single patient#

You can run the visualisation for only a single patient (or list of specific patients) by providing the patient argument.

[4]:
pydicer.visualise.visualise(patient="HNSCC-01-0199")
 83%|████████▎ | 5/6 [00:39<00:07,  7.32s/objects, visualise]/home/runner/.cache/pypoetry/virtualenvs/pydicer-pNPN9n62-py3.9/lib/python3.9/site-packages/pydicom/valuerep.py:443: UserWarning: Invalid value for VR DA: 'NaT'.
  warnings.warn(msg)
100%|██████████| 6/6 [00:39<00:00,  6.61s/objects, visualise]

Avoid Re-generating Visualisation#

If you’ve added more data to your dataset, and want to avoid re-generating visualisations, set the force argument to False.

[5]:
pydicer.visualise.visualise(force=False)
100%|██████████| 30/30 [00:00<00:00, 390.94objects/s, visualise]
[ ]: