Slicer often crashes when running with python-script in loading

The ideal would be to put the data someplace like a public google drive folder or pull them from IDC and then provide a python script that downloads the data and then runs the simplest script that replicates the crash you are seeing. This way it would be possible to see if the issue is with the data, the script, the docker configuration or something else.

For example, here’s the task I did yesterday to make nifti files and screen grabs for all the files in the CBM-CRC collection on IDC. This pulls down more data than we’d want for trying to replicate the crash, but it should give you an idea how to make a reproducible example.

First I got the list of URLs:

bq query -n 50000 --format=csv --use_legacy_sql=false \
  'SELECT gcs_url FROM `bigquery-public-data.idc_current.dicom_all` WHERE collection_id = "cmb_crc" LIMIT 50000' \
    > cbm_crc-urls.csv

Then I downloaded them all to a local directory:

mkdir cbm_crc
cat cbm_crc-urls.csv| tail -n +2 | gsutil -m cp -I cbm_crc

In Slicer, I imported that directory into a new dicom database and then ran this script:

from DICOMLib import DICOMUtils

niiDir = "/opt/data/idc/cbm_crc-nii"

db = slicer.dicomDatabase
for patient in db.patients():
    for study in db.studiesForPatient(patient):
        accessionNumber = db.fieldForStudy("AccessionNumber", study)
        if accessionNumber == "":
            accessionNumber = study
        for series in db.seriesForStudy(study):
            slicer.mrmlScene.Clear()
            loadedNodeIDs = DICOMUtils.loadSeriesByUID([series])
            if len(loadedNodeIDs) != 1:
                print(f"Skipping {series} because it generated {len(loadedNodeIDs)} nodes")
                continue
            seriesDescription = db.fieldForSeries("SeriesDescription", series)
            seriesDescription = seriesDescription.replace(" ", "_").replace("/","-")
            seriesNumber = int(db.fieldForSeries("SeriesNumber", series))
            niiPath = f"{niiDir}/{accessionNumber}_{seriesNumber}_{seriesDescription}.nii.gz"
            pngPath = f"{niiDir}/{accessionNumber}_{seriesNumber}_{seriesDescription}.png"
            slicer.util.delayDisplay(niiPath, 100)
            print(niiPath)
            slicer.util.saveNode(slicer.util.getNode(loadedNodeIDs[0]), niiPath)
            slicer.util.mainWindow().centralWidget().grab().toImage().save(pngPath)

The whole process took a few hours but no crashes.

2 Likes