# How to use python programming to open and save data in batches?

**URL:** <https://discourse.slicer.org/t/how-to-use-python-programming-to-open-and-save-data-in-batches/26604>\
**Category:** Support\
**Created:** [December 6, 2022, 3:11pm UTC](https://discourse.slicer.org/t/how-to-use-python-programming-to-open-and-save-data-in-batches/26604 "2022-12-06T15:11:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lyh-ecnu](https://avatars.discourse-cdn.com/v4/letter/l/51bf81/32.png) [@lyh-ecnu](https://discourse.slicer.org/u/lyh-ecnu)\
**Post date:** [December 6, 2022, 3:11pm UTC](https://discourse.slicer.org/t/how-to-use-python-programming-to-open-and-save-data-in-batches/26604/1 "2022-12-06T15:11:47Z")

</div>

I tried to write a program to open the folder and read several cases inside，but after I run it, only the data of the first case can be successfully loaded, and the following cases will report errors。My code and error message are as follows：  
My code:

```python
dicomDataDir = r"D:/test" #my folder
loadedNodeIDs = [] # this list will contain the list of all loaded node IDs
from DICOMLib import DICOMUtils
with DICOMUtils.TemporaryDICOMDatabase() as db:
  DICOMUtils.importDicom(dicomDataDir, db)
  patientUIDs = db.patients()
  for patientUID in patientUIDs:
    loadedNodeIDs.extend(DICOMUtils.loadPatientByUID(patientUID))

```

error message :

```auto
Loading with imageIOName: GDCM
Could not read scalar volume using GDCM approach. Error is: FileNotFoundError
Loading with imageIOName: DCMTK
Could not read scalar volume using DCMTK approach. Error is: FileNotFoundError
Failed to read a multivolume: Volume frame 0 is invalid - Reference image in series does not contain geometry information. Please use caution.
Traceback (most recent call last):
  File "C:/Users/18729/AppData/Local/NA-MIC/Slicer 5.0.3/bin/../lib/Slicer-5.0/qt-scripted-modules/MultiVolumeImporterPlugin.py", line 639, in load
    raise OSError(f"Volume frame {frameNumber} is invalid - {svLoadables[0].warning}")
OSError: Volume frame 0 is invalid - Reference image in series does not contain geometry information. Please use caution.

```

The problem seems to be that the program doesn’t read the file.But the first file can be opened normally.anyone can help me?thanks!

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [December 6, 2022, 4:29pm UTC](https://discourse.slicer.org/t/how-to-use-python-programming-to-open-and-save-data-in-batches/26604/3 "2022-12-06T16:29:44Z")

</div>

Can you load data sets using the DICOM module GUI?

---

<div class="post-metadata">

**Author:** ![lyh-ecnu](https://avatars.discourse-cdn.com/v4/letter/l/51bf81/32.png) [@lyh-ecnu](https://discourse.slicer.org/u/lyh-ecnu)\
**Post date:** [December 7, 2022, 2:02am UTC](https://discourse.slicer.org/t/how-to-use-python-programming-to-open-and-save-data-in-batches/26604/4 "2022-12-07T02:02:57Z")

</div>

yes,individual files open fine, but not with this code

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [December 7, 2022, 12:27pm UTC](https://discourse.slicer.org/t/how-to-use-python-programming-to-open-and-save-data-in-batches/26604/5 "2022-12-07T12:27:09Z")

</div>

Did you use the DICOM module or just the “Add data” window? “Add data” should not be used because it does not do any geometry checks.

Can you share the data set? (upload somewhere and post the download link here; make sure it does not contain patient information)

---

<div class="post-metadata">

**Author:** ![lyh-ecnu](https://avatars.discourse-cdn.com/v4/letter/l/51bf81/32.png) [@lyh-ecnu](https://discourse.slicer.org/u/lyh-ecnu)\
**Post date:** [December 9, 2022, 6:54am UTC](https://discourse.slicer.org/t/how-to-use-python-programming-to-open-and-save-data-in-batches/26604/6 "2022-12-09T06:54:49Z")

</div>

thanks,butl dont know what impact will geometry checks have.l use dicom library upload three data(By the way, lt’s upload speed is too slow, is there any good anonymized upload solution?)，I put them in the same folder when I use，and run my code trying to open them.The download link is as follows：  
[https://www.dicomlibrary.com?requestType=WADO&studyUID=1.3.6.1.4.1.44316.6.102.1.202212091317352.4411468198218093536139&manage=c06965fa4641dc8493e7fe635047d58f&token=94c7c87523e6750c370bee8837c8fbc0](https://www.dicomlibrary.com?requestType=WADO&studyUID=1.3.6.1.4.1.44316.6.102.1.202212091317352.4411468198218093536139&manage=c06965fa4641dc8493e7fe635047d58f&token=94c7c87523e6750c370bee8837c8fbc0)  
[https://www.dicomlibrary.com?requestType=WADO&studyUID=1.3.6.1.4.1.44316.6.102.1.20221209135222936.37252472383452532849&manage=cf12dfb851db42146c9a02f90a7811de&token=9345b0eeef371789711f503695e8094f](https://www.dicomlibrary.com?requestType=WADO&studyUID=1.3.6.1.4.1.44316.6.102.1.20221209135222936.37252472383452532849&manage=cf12dfb851db42146c9a02f90a7811de&token=9345b0eeef371789711f503695e8094f)  
[https://www.dicomlibrary.com?requestType=WADO&studyUID=1.3.6.1.4.1.44316.6.102.1.20221209141950624.15861645053471484630&manage=2d6e48d4dea24f252a01ec479a02176a&token=2f409b7a6fbf1a7243dd33ff5bb26ad9](https://www.dicomlibrary.com?requestType=WADO&studyUID=1.3.6.1.4.1.44316.6.102.1.20221209141950624.15861645053471484630&manage=2d6e48d4dea24f252a01ec479a02176a&token=2f409b7a6fbf1a7243dd33ff5bb26ad9)
