|
@@ -116,7 +116,7 @@ def guessPixelPosition4(sx=-1,sy=-1,sz=-1):
|
|
|
return [{'regionId':x,'x':pts[x][0],'y':pts[x][1],'z':pts[x][2],'sliceId':sliceCode[x]} for x in pts]
|
|
|
|
|
|
def updateSegmentation(db,setup,r,pixels):
|
|
|
- copyFields=['PatientId','visitName']
|
|
|
+ copyFields=['PatientId','visitCode']
|
|
|
for x in pixels:
|
|
|
for c in copyFields:
|
|
|
x[c]=r[c]
|
|
@@ -134,16 +134,16 @@ def updateSegmentation(db,setup,r,pixels):
|
|
|
db.modifyRows(mode,setup['project'],'study','Segmentation',[entry])
|
|
|
print('Done')
|
|
|
|
|
|
-def getSegmentationFileName(r,setup):
|
|
|
+def getSegmentationFileName(db,r,setup):
|
|
|
if setup['segmentationMode']=='TXT':
|
|
|
return '{}_Segmentation.txt'.format(config.getCode(r,setup))
|
|
|
if setup['segmentationMode']=='NRRD':
|
|
|
- copyFields=['PatientId','visitName']
|
|
|
+ copyFields=['PatientId','visitCode']
|
|
|
qFilter=[{'variable':x,'value':r[x],'oper':'eq'} for x in copyFields]
|
|
|
qFilter.append({'variable':'User','value':setup['targetUser'],'oper':'eq'})
|
|
|
rows=getData.getSegmentation(db,setup,qFilter)
|
|
|
r=rows[0]
|
|
|
- return r['latestFile']
|
|
|
+ return '/'.join(['Segmentations',r['latestFile']])
|
|
|
|
|
|
|
|
|
def writeSegmentation(db,fb,r,setup):
|
|
@@ -152,9 +152,9 @@ def writeSegmentation(db,fb,r,setup):
|
|
|
print('Failed to load segmentation')
|
|
|
return
|
|
|
|
|
|
- fileName=getSegmentationFileName(r,setup)
|
|
|
+ fileName=getSegmentationFileName(db,r,setup)
|
|
|
idFilter={'variable':'PatientId','value':config.getPatientId(r,setup),'oper':'eq'}
|
|
|
- visitFilter={'variable':'visitName','value':config.getVisitId(r,setup),'oper':'eq'}
|
|
|
+ visitFilter={'variable':'visitCode','value':config.getVisitId(r,setup),'oper':'eq'}
|
|
|
rows=getData.getSegmentation(db,setup,[idFilter,visitFilter])
|
|
|
v=numpy.zeros((len(rows),3))
|
|
|
for qr in rows:
|
|
@@ -171,32 +171,29 @@ def getNC(r,xsetup):
|
|
|
if xsetup['segmentationMode']=='TXT':
|
|
|
getNCTxt(r,xsetup)
|
|
|
if xsetup['segmentationMode']=='NRRD':
|
|
|
- return 500
|
|
|
-
|
|
|
-def loadSegmentation(db,fb,r,xsetup):
|
|
|
- if xsetup['segmentationMode']=='TXT':
|
|
|
- return loadSegmentationTxt(db,fb,r,xsetup)
|
|
|
- if xsetup['segmentationMode']=='NRRD':
|
|
|
- return loadSegmentationNrrd(db,fb,r,xsetup)
|
|
|
-
|
|
|
+ return xsetup['NC']
|
|
|
|
|
|
def getNCTxt(r,xsetup):
|
|
|
- sName=getSegmentationFileName(r,xsetup)
|
|
|
+ sName=getSegmentationFileName(db=None,r=r,setup=xsetup)
|
|
|
fName=getData.getLocalPath(r,xsetup,sName)
|
|
|
x=numpy.loadtxt(fName)
|
|
|
nc=x.shape[0]
|
|
|
return nc
|
|
|
|
|
|
def loadSegmentation(db,fb,r,setup):
|
|
|
- sName=getSegmentationFileName(r,setup)
|
|
|
+
|
|
|
+ sName=getSegmentationFileName(db,r,setup)
|
|
|
+ print(f'Looking for {sName}')
|
|
|
fName=getData.getLocalPath(r,setup,sName)
|
|
|
+ print(f'Local {fName}')
|
|
|
if not os.path.isfile(fName):
|
|
|
- qName=sName
|
|
|
- if setup['segmentationMode']=='NRRD':
|
|
|
- qName='/'.join(['Segmentations',sName])
|
|
|
- fURL=getData.getURL(fb,r,setup,qName)
|
|
|
+ fURL=getData.getURL(fb,r,setup,sName)
|
|
|
if fb.entryExists(fURL):
|
|
|
- getData.copyFromServer(fb,r,setup,[qName])
|
|
|
+ getData.copyFromServer(fb,r,setup,[sName])
|
|
|
+ if os.path.isfile(fName):
|
|
|
+ print(f'Copied {fURL} to {fName}')
|
|
|
+ else:
|
|
|
+ print(f'Failed to load {fName} from {fURL}')
|
|
|
else:
|
|
|
#this creates local and global file
|
|
|
writeSegmentation(db,fb,r,setup)
|
|
@@ -206,13 +203,15 @@ def loadSegmentation(db,fb,r,setup):
|
|
|
|
|
|
|
|
|
def plotSegmentation(db,fb,r,setup,vmax=1000):
|
|
|
- copyFields=['PatientId','visitName']
|
|
|
+ copyFields=['PatientId','visitCode']
|
|
|
qFilter=[{'variable':x,'value':r[x],'oper':'eq'} for x in copyFields]
|
|
|
nim=getData.getPatientNIM(fb,r,setup)
|
|
|
rows=getData.getSegmentation(db,setup,qFilter)
|
|
|
|
|
|
if len(rows)==0:
|
|
|
- print('Not found for id={}/{}'.format(pId,visitName))
|
|
|
+ pId=r['PatientId']
|
|
|
+ visitCode=r['visitCode']
|
|
|
+ print(f'Not found for id={pId}/{visitCode}')
|
|
|
return
|
|
|
|
|
|
fp={}
|