Browse Source

dealing with improperly set rows in convertToNRDD.py

Andrej 1 year ago
parent
commit
3c277a73dc
1 changed files with 16 additions and 1 deletions
  1. 16 1
      slicerScripts/convertToNRRD.py

+ 16 - 1
slicerScripts/convertToNRRD.py

@@ -65,6 +65,9 @@ def main(configFile):
       print('No rows returned')
       return
    for r in rows:
+      #check row sanity
+      
+
       print("Loading {}/{}".format(config.getPatientId(r,xconfig),config.getVisitId(r,xconfig)))
       rPath=fb.formatPathURL(xconfig['project'],config.getOutputDir(r,xconfig))
       rPath+='/'+config.getNodeName(r,xconfig,'CT')+'.nrrd'
@@ -80,10 +83,13 @@ def main(configFile):
 
          print('Forced recalculation')
 
-            
+      code=config.getCode(r,xconfig)
       print('{} available:{}'.format(config.getNodeName(r,xconfig,'CT'),fb.entryExists(rPath)))
       #loadPatient into slicer
       patient=loadPatient(ofb,r,xconfig)
+      if not patient:
+         print(f'{code} failed to load from Orthanc')
+         continue
       #convert to nodes
       addCT(r,patient,xconfig)
       addFrames(r,patient,xconfig)
@@ -134,11 +140,15 @@ def loadPatient(ofb,r,xconfig):
    pd=parseDicom.parseDicom()
 
    masterPath=downloadAndUnzip(ofb,r,"nmMaster",xconfig)
+   if not masterPath:
+      return None
    pd.readMasterDirectory(masterPath,False)
    print('Time [{} .. {}]'.format(pd.frame_start,pd.frame_stop))
    clearUnzipDir(r,xconfig)
 
    nmPath=downloadAndUnzip(ofb,r,"nmCorrData",xconfig)
+   if not nmPath:
+      return None
    frame_data, frame_time, frame_duration, frame_origin, \
        frame_pixel_size, frame_orientation=\
        pd.readNMDirectory(nmPath,False)
@@ -146,6 +156,8 @@ def loadPatient(ofb,r,xconfig):
    clearUnzipDir(r,xconfig)
 
    ctPath=downloadAndUnzip(ofb,r,"ct",xconfig)
+   if not ctPath:
+      return None
    ct_data,ct_origin,ct_pixel_size, \
       ct_orientation=pd.readCTDirectory(ctPath,False)
    print('CT pixel {}'.format(ct_pixel_size))
@@ -185,6 +197,9 @@ def downloadAndUnzip(ofb,r,code,xconfig):
       os.makedirs(tempDir)
 
    orthancId=r[code+'OrthancId']
+   if not orthancId:
+      return None
+
    fileCode='{}_{}'.format(config.getCode(r,xconfig),code)
    zipFile=os.path.join(tempDir,fileCode+'.zip')
    ofb.getZip('series',orthancId,zipFile)