Python Script - Export DICOM Tag issue

Hi all. I have a python script to automate making a bunch of masked data based on a PET and RTStruct file. As there are quite a few segments per study, and I have hundreds of studies, I want to automate this as much as possible. The mask bit works great, but the next stage is exporting the data as a DICOM dataset.

When I do this manually, I would drag the masked data into the parent folder in the Data scene, and right click Export DICOM. I would select an appropriate folder and leave everything else as default, and this works create but as I can only do one at a time, it is slow and prone to human error.

My script is all set up to create the relevant folders etc. and save the nodes, but with the DICOMExportScalarVolume command, it needs the tags. I was hoping to just copy these from the initial PET data, but I’m struggling to find a way to do this. Any direction would be greatly appreciated.

Thank you

If you look at the source code there’s a comment with an example of copying tags from a study:

Thank you Steve. I saw that bit of the code commented out and labelled TODO and assumed it was just a bit that wasn’t working yet. I don’t really understand what it is doing at the moment, but I’ll spend some time with it and see if I can digest it.

That’s good that you can investigate and report back what you find. The tags argument should allow you to populate the headers with the needed values to make valid (or at least usable) dicom files. Creating valid files for various modalities is tricky, and you may need to check them with a tool like dciodvfy and make further tweaks, perhaps with pydicom, to make them work for your intended use.