# How to read the value of certain attribute (tag) in DICOM Metadata" from "Python Interactor"

**URL:** <https://discourse.slicer.org/t/how-to-read-the-value-of-certain-attribute-tag-in-dicom-metadata-from-python-interactor/7184>\
**Category:** Support\
**Created:** [June 16, 2019, 9:16am UTC](https://discourse.slicer.org/t/how-to-read-the-value-of-certain-attribute-tag-in-dicom-metadata-from-python-interactor/7184 "2019-06-16T09:16:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![shahrokh](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/shahrokh/32/1499_2.png) [@shahrokh](https://discourse.slicer.org/u/shahrokh)\
**Post date:** [June 16, 2019, 9:16am UTC](https://discourse.slicer.org/t/how-to-read-the-value-of-certain-attribute-tag-in-dicom-metadata-from-python-interactor/7184/1 "2019-06-16T09:16:18Z")

</div>

Hi Dears 3DSlicer developers

After loading dicom files using DICOM module, how can I access the value of certain attribute (tag) in “DICOM Metadata” from Python Interactor?

For example, I want to access the value of IsocenterPosition with the tag number (300a,012c) from Python Interactor. How can I do that?

Please guide me,  
Thanks a lot.  
Shahrokh.

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [June 16, 2019, 7:52pm UTC](https://discourse.slicer.org/t/how-to-read-the-value-of-certain-attribute-tag-in-dicom-metadata-from-python-interactor/7184/2 "2019-06-16T19:52:19Z")

</div>

Hi -

Here are some examples - let us know if this doesn’t cover your use case.

[https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#DICOM\_2](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#DICOM_2)

---

<div class="post-metadata">

**Author:** ![shahrokh](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/shahrokh/32/1499_2.png) [@shahrokh](https://discourse.slicer.org/u/shahrokh)\
**Post date:** [June 17, 2019, 9:20am UTC](https://discourse.slicer.org/t/how-to-read-the-value-of-certain-attribute-tag-in-dicom-metadata-from-python-interactor/7184/3 "2019-06-17T09:20:52Z")

</div>

Hi Steve

Thanks a lot for sending to me the link to ScriptRepository.

I can access to tags such as (0020,0010) to (300a,000c), but unfortunately I can not read tags that are located in **item** , such as (300a,012c), highlighted in the following figure.

The following figure is screenshot of DICOM File Browser and the tag that I want to access its value (300a,012c).

 ![Screenshot%20from%202019-06-17%2011-58-27](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/a/f/af7e3228f4a789c677a3aa305dcba7569485423b.png)

I enter the following commands:  
\>\>\> patientList=db.patients()  
\>\>\> studyList=db.studiesForPatient(patientList[0])  
\>\>\> seriesList=db.seriesForStudy(studyList[0])  
\>\>\> fileList=db.filesForSeries(seriesList[0])  
\>\>\> print(db.fileValue(fileList[0],‘300a,000c’))  
PATIENT  
\>\>\> print(db.fileValue(fileList[0],‘300a,012c’))

```
>>>

```

As you see, the last command dose not give any output.  
Please guide me to access tags that are loacted in **Items**.  
Thanks a lot.  
Shahrokh.

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [June 17, 2019, 12:50pm UTC](https://discourse.slicer.org/t/how-to-read-the-value-of-certain-attribute-tag-in-dicom-metadata-from-python-interactor/7184/4 "2019-06-17T12:50:26Z")

</div>

Hi Shahrokh -

Ah, sorry - you are right, the database doesn’t cache nested tags, only top level ones.

I added a new section to the script repository showing how to access nested tags using pydicom.

[https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#How\_to\_access\_DICOM\_tags\_nested\_in\_a\_sequence](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#How_to_access_DICOM_tags_nested_in_a_sequence)

-Steve

---

<div class="post-metadata">

**Author:** ![shahrokh](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/shahrokh/32/1499_2.png) [@shahrokh](https://discourse.slicer.org/u/shahrokh)\
**Post date:** [June 17, 2019, 1:41pm UTC](https://discourse.slicer.org/t/how-to-read-the-value-of-certain-attribute-tag-in-dicom-metadata-from-python-interactor/7184/5 "2019-06-17T13:41:36Z")

</div>

Hi Dear Steve  
Thank you very much for the link you provided. I study it now.  
But I accidentally solved my problem according to the description given on the site of [Pydicom User Guide — pydicom 1.0a documentation](https://pydicom.github.io/pydicom/0.9/pydicom_user_guide.html).

In JupyterLab, I enter the following commands:

```
[1]: import pydicom
[2]: ds = dicom.read_file("112325-00000000.dcm")
[3]: ds
...
(300a, 00b0) Beam Sequence 2 item(s) ---- 
   (300a, 00b2) Treatment Machine Name SH: 'Compact'
   ...
   (300a, 0111) Control Point Sequence 2 item(s) ---- 
      (300a, 0112) Control Point Index IS: "0"
      ...
      (300a, 012c) Isocenter Position DS: ['111.908', '-52.0623', '-1212.2']
      ...
   ...
...
[4]: ds[0x300a,0xb0][0][0x300a,0x111][0][0x300a,0x12c].value
['111.908', '-52.0623', '-1212.2']

```

But this method is difficult. 🤔

Best regards.  
Shahrokh

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [June 18, 2019, 3:59pm UTC](https://discourse.slicer.org/t/how-to-read-the-value-of-certain-attribute-tag-in-dicom-metadata-from-python-interactor/7184/6 "2019-06-18T15:59:36Z")

</div>

Yes, getting data out of nested dicom sequences is kind of awkward. The example I linked is abit easier to read, since it uses the dicom dictionary name instead of the hex tag. `ds.CTExposureSequence[0].ExposureModulationType`
