Browse Source

Resolving merging mismatches

Andrej 1 year ago
parent
commit
aca8e9e402
1 changed files with 40 additions and 2 deletions
  1. 40 2
      pythonScripts/segmentation.py

+ 40 - 2
pythonScripts/segmentation.py

@@ -134,7 +134,8 @@ def updateSegmentation(db,setup,r,pixels):
       db.modifyRows(mode,setup['project'],'study','Segmentation',[entry])
    print('Done')
     
-def getSegmentationFileName(db,r,setup):
+def getSegmentationFileName(r,setup):
+   db,fb=getData.connectDB(setup['network'])
    if setup['segmentationMode']=='TXT':
       return '{}_Segmentation.txt'.format(config.getCode(r,setup))
    if setup['segmentationMode']=='NRRD':
@@ -143,8 +144,34 @@ def getSegmentationFileName(db,r,setup):
       qFilter.append({'variable':'User','value':setup['targetUser'],'oper':'eq'})
       rows=getData.getSegmentation(db,setup,qFilter)
       r=rows[0]
-      return '/'.join(['Segmentations',r['latestFile']])
+      return r['latestFile']
+
+def getURL(fb,r,setup,name):
+   remoteDir=fb.buildPathURL(setup['project'],config.getPathList(r,setup))
+   return '/'.join([remoteDir,'Segmentations',name])
  
+def copyFromServer(fb,r,setup,names):
+   try:
+      forceReload=setup['forceReload']
+   except KeyError:
+      forceReload=False
+
+   getData.getLocalDir(r,setup,createIfMissing=True)
+   remoteDir=fb.buildPathURL(setup['project'],config.getPathList(r,setup))
+   for n in names:
+      localPath=getData.getLocalPath(r,setup,n)
+      if os.path.isfile(localPath) and not forceReload:
+         continue
+      remotePath='/'.join([remoteDir,'Segmentations',n])
+      fb.readFileToFile(remotePath,localPath)
+
+def copyToServer(fb,r,setup,names):
+   remoteDir=fb.buildPathURL(setup['project'],config.getPathList(r,setup))
+   for n in names:
+      localPath=getLocalPath(r,setup,n)
+      remotePath='/'.join([remoteDir,'Segmentations',n])
+      fb.writeFileToFile(localPath,remotePath)
+
 
 def writeSegmentation(db,fb,r,setup):
 
@@ -261,3 +288,14 @@ def plotSegmentation(db,fb,r,setup,vmax=1000):
    fPath=getData.getLocalPath(r,setup,name)
    fig.savefig(fPath)
    getData.copyToServer(fb,r,setup,[name])
+
+
+def getNRRDImage(r,setup,names=None):
+   if names:
+      localFile=getData.getLocalPath(r,setup,names['segmentation'][0])
+   else:
+      localFile=getData.getLocalPath(r,setup,getSegmentationFileName(r,setup))
+   segImg=SimpleITK.ReadImage(localFile) 
+   seg=SimpleITK.GetArrayFromImage(segImg)
+   return seg
+