Преглед изворни кода

Adding automated segmentation script

Andrej пре 3 година
родитељ
комит
1bdf95612e
1 измењених фајлова са 47 додато и 7 уклоњено
  1. 47 7
      pythonScripts/runSegmentation.py

+ 47 - 7
pythonScripts/runSegmentation.py

@@ -86,11 +86,18 @@ def runDeepMedic(setup,pars):
     print(args) 
     print(subprocess.run(args,check=True,stdout=subprocess.PIPE).stdout)
 
+def runDeepMedicDocker(setup,pars):
+    args=[]
+    args.extend(['docker-compose','-f',pars['deepmedic']['segmentationdmYAML'],'up'])
+    print(args) 
+    print(subprocess.run(args,check=True,stdout=subprocess.PIPE).stdout)
+
+
 def getSegmentationFile(pars):
     #this is how deep medic stores files
     return getSegmImagePath(\
             os.path.join(pars['tempBase'],'output','predictions','currentSession','predictions',\
-            pars['images']['images']['segmentations']['tempFile'])
+            pars['images']['segmentations']['tempFile'])
             )
 
 def runSegmentation(fb,row,pars,setup):
@@ -98,28 +105,30 @@ def runSegmentation(fb,row,pars,setup):
      
     #download to temp file (could be a fixed name)
     project=pars['project']
-    images=pars['images']['images']
+    images=pars['images']
     participantField=pars['participantField']
     baseDir=fb.formatPathURL(project,pars['imageDir']+'/'+\
         getPatientLabel(row,participantField)+'/'+\
         getVisitLabel(row))
     
     #download 
+    fullFile={key:os.path.join(pars['tempBase'],images[key]['tempFile']) for key in images}
     for im in images:
-        tmpFile=images[im]['tempFile']
         if 'queryField' in images[im]:
-            fb.readFileToFile(baseDir+'/'+row[images[im]['queryField']],tmpFile)
+            fb.readFileToFile(baseDir+'/'+row[images[im]['queryField']],fullFile[im])
    
     #normalize 
-    normalizeCT(images['CT']['tempFile'],images['patientmask']['tempFile'])
+
+    normalizeCT(fullFile['CT'],fullFile['patientmask'])
 
     #update templates to know which files to process
 
 
     #run deep medic
-    #runDeepMedic(setup,pars)
+    runDeepMedicDocker(setup,pars)
     
-    #segFile=os.path.join(pars['tempBase'],images['segmentations']['tempFile'])
+    #processed file is
+    segFile=getSegmentationFile(pars)
     #SimpleITK.WriteImage(outImg,segFile)
     return segFile
 
@@ -127,6 +136,37 @@ def runSegmentation(fb,row,pars,setup):
 def main(parameterFile):
     
     fhome=os.path.expanduser('~')
+
+
+    with open(os.path.join(fhome,".labkey","setup.json")) as f:
+        setup=json.load(f)
+
+    sys.path.insert(0,setup["paths"]["labkeyInterface"])
+    import labkeyInterface
+    import labkeyDatabaseBrowser
+    import labkeyFileBrowser
+
+    sys.path.append(setup['paths']['parseConfig'])
+    import parseConfig
+
+    with open(parameterFile) as f:
+        pars=json.load(f)
+    
+    pars=parseConfig.convert(pars)
+    pars=parseConfig.convertValues(pars)
+    print(pars)
+    #images=pars['images']
+    #ctFile=os.path.join(pars['tempBase'],images['CT']['tempFile'])
+    #maskFile=os.path.join(pars['tempBase'],images['patientmask']['tempFile'])
+    #normalizeCT(ctFile,maskFile)
+
+
+    
+
+def doSegmentation(parameterFile):
+    fhome=os.path.expanduser('~')
+
+
     with open(os.path.join(fhome,".labkey","setup.json")) as f:
         setup=json.load(f)