|
@@ -46,6 +46,12 @@ def getCOWAxis(seg,val,axis):
|
|
|
s1=i
|
|
|
break
|
|
|
s1+=1
|
|
|
+ try:
|
|
|
+ sm=numpy.average(x,weights=s)
|
|
|
+ except ZeroDivisionError:
|
|
|
+ print('getCOWaxis - Zero division error')
|
|
|
+ raise
|
|
|
+
|
|
|
return [s0,numpy.average(x,weights=s),s1]
|
|
|
|
|
|
def getGeometry(seg,val):
|
|
@@ -160,10 +166,18 @@ def main(parameterFile):
|
|
|
imageResampledField={"CT":"ctResampled","PET":"petResampled","patientmask":"ROImask"}
|
|
|
|
|
|
rows=ds['rows']
|
|
|
+ #rows=[r for r in rows if r[participantField]=='8701/08']
|
|
|
#rows=[ds['rows'][0]]
|
|
|
|
|
|
for r in rows:
|
|
|
- print(r)
|
|
|
+ missingCodes=[r[f]==None for f in ['patientCode','visitCode']]
|
|
|
+ if any(missingCodes):
|
|
|
+ print('[{}/{}] - Skipping, missing codes'.\
|
|
|
+ format(r[participantField],r['SequenceNum']))
|
|
|
+ continue
|
|
|
+
|
|
|
+
|
|
|
+ #print(r)
|
|
|
iTypes=['CT','PET','Segm']
|
|
|
needToCalculate=False
|
|
|
for t in ['CT','PET']:
|
|
@@ -172,7 +186,8 @@ def main(parameterFile):
|
|
|
verFilter={'variable':'version','value':pars['version'],'oper':'eq'}
|
|
|
typeFilter={'variable':'type','value':t,'oper':'eq'}
|
|
|
|
|
|
- ds2=db.selectRows(project,reportSchema,reportQuery,[idFilter,visitFilter,verFilter,typeFilter])
|
|
|
+ ds2=db.selectRows(project,reportSchema,reportQuery,\
|
|
|
+ [idFilter,visitFilter,verFilter,typeFilter])
|
|
|
|
|
|
if len(ds2['rows'])==0:
|
|
|
#skip if row is present
|
|
@@ -181,15 +196,33 @@ def main(parameterFile):
|
|
|
break
|
|
|
|
|
|
if not needToCalculate:
|
|
|
+ print('[{}/{}] - done'.format(r[participantField],r['SequenceNum']))
|
|
|
+ continue
|
|
|
+
|
|
|
+ ds1=db.selectRows(project,pars['segmentationSchema'],pars['segmentationQuery'],\
|
|
|
+ [idFilter,visitFilter,verFilter])
|
|
|
+
|
|
|
+ #check if CT, PET and Segm images are set
|
|
|
+ imagesAvailable=[r[imageResampledField[t]] for t in ['CT','PET']]
|
|
|
+ imagesAvailable=[f!=None for f in imagesAvailable]
|
|
|
+ try:
|
|
|
+ imagesAvailable.append(ds1['rows'][0]['segmentation']!=None)
|
|
|
+ except IndexError:
|
|
|
+ imagesAvailable.append(False)
|
|
|
+
|
|
|
+ if not all(imagesAvailable):
|
|
|
+ print('[{}/{}] Skipping - not all images available :{}'.\
|
|
|
+ format(r[participantField],r['SequenceNum'],imagesAvailable))
|
|
|
continue
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
imgs={}
|
|
|
for t in iTypes:
|
|
|
|
|
|
try:
|
|
|
imagePath=r['_labkeyurl_'+imageResampledField[t]]
|
|
|
except KeyError:
|
|
|
- ds1=db.selectRows(project,pars['segmentationSchema'],pars['segmentationQuery'],\
|
|
|
- [idFilter,visitFilter,verFilter])
|
|
|
imagePath=ds1['rows'][0]['_labkeyurl_segmentation']
|
|
|
|
|
|
localPath=os.path.join(tempBase,'image'+t+'.nii.gz')
|
|
@@ -198,12 +231,24 @@ def main(parameterFile):
|
|
|
fb.readFileToFile(imagePath,localPath)
|
|
|
img=nibabel.load(localPath)
|
|
|
imgs[t]=img.get_fdata()
|
|
|
+
|
|
|
print('Loading completed')
|
|
|
+
|
|
|
for t in ['CT','PET']:
|
|
|
for val in [3,4,5]:
|
|
|
- outfile=plot(imgs,t,val,tempBase)
|
|
|
- remoteDir=fb.buildPathURL(project,[pars['imageDir'],r['patientCode'],r['visitCode']])
|
|
|
- imageFile=r['patientCode']+'-'+r['visitCode']+'_'+t+'_{}'.format(val)+'_'+pars['version']+'.png'
|
|
|
+
|
|
|
+
|
|
|
+ try:
|
|
|
+ outfile=plot(imgs,t,val,tempBase)
|
|
|
+ except ZeroDivisionError:
|
|
|
+ print('[{}/{}] - Skipping. Failed to plot for organ [{}]'.\
|
|
|
+ format(r[participantField],r['SequenceNum'],val))
|
|
|
+ continue
|
|
|
+
|
|
|
+ remoteDir=fb.buildPathURL(project,
|
|
|
+ [pars['imageDir'],r['patientCode'],r['visitCode']])
|
|
|
+ imageFile=r['patientCode']+'-'+r['visitCode']+'_'+t+'_{}'.\
|
|
|
+ format(val)+'_'+pars['version']+'.png'
|
|
|
remoteFile='/'.join([remoteDir,imageFile])
|
|
|
fb.writeFileToFile(outfile,remoteFile)
|
|
|
print('Uploaded {}'.format(remoteFile))
|