.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/metadata_processing/plot_add_dict_entries.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_metadata_processing_plot_add_dict_entries.py: ===================================================== Add dictionary items in the standard DICOM dictionary ===================================================== This examples illustrates how to add dictionary items to the 'standard' DICOM dictionary dynamically. .. warning:: Note that this is not a recommended solution in general but it is useful as a demonstration or for in-house programs only, or to get around elements missing from pydicom's DICOM dictionaries. .. GENERATED FROM PYTHON SOURCE LINES 16-51 .. rst-class:: sphx-glr-script-out .. code-block:: none (1001, 1001) Private tag data UL: 42 (1001, 1002) Private tag data OB: '12345' (1001, 1003) Private tag data UI: 1.2.3.4.5 | .. code-block:: Python # authors : Darcy Mason # Guillaume Lemaitre # license : MIT from pydicom.datadict import DicomDictionary, keyword_dict from pydicom.dataset import Dataset print(__doc__) # Define items as (VR, VM, description, is_retired flag, keyword) # Leave is_retired flag blank. new_dict_items = { 0x10011001: ('UL', '1', "Test One", '', 'TestOne'), 0x10011002: ('OB', '1', "Test Two", '', 'TestTwo'), 0x10011003: ('UI', '1', "Test Three", '', 'TestThree'), } # Update the dictionary itself DicomDictionary.update(new_dict_items) # Update the reverse mapping from name to tag new_names_dict = dict([(val[4], tag) for tag, val in new_dict_items.items()]) keyword_dict.update(new_names_dict) # Test that it is working ds = Dataset() # or could get one from dcmread, etc ds.TestOne = 42 ds.TestTwo = '12345' ds.TestThree = '1.2.3.4.5' print(ds.top()) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.001 seconds) .. _sphx_glr_download_auto_examples_metadata_processing_plot_add_dict_entries.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_add_dict_entries.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_add_dict_entries.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_