def update_wad(filename, mode, axorder, sporder, **kwargs): #sphereac = 999, ctimespac = '120000', bgac = 999, bgactime = '120000', spremac = 999, spremactime = '120000', bgremac = 999, bgremactime = '120000',scantime='120000' output = {} #Float values fmt = '%H%M%S' #assumed format for all times output['Sphere activity'] = kwargs['sphereac'] output['Calibration time sphere'] = kwargs['ctimespac'] output['Background activity'] = kwargs['bgac'] output['Background act time'] = kwargs['bgactime'] output['Sphere rem act'] = kwargs['spremac'] output['Sphere rem act time'] = kwargs['spremactime'] output['Bg rem act'] = kwargs['bgremac'] output['Bg rem act time'] = kwargs['bgremactime'] ''' With all the activities known we can simply calculate the activity concentration of the spheres @ scantime and the activity concentration of the background @ scantime ''' th = niqlib.thf18 # convert all 'string' times to datetime format so we can calculate something scantime = datetime.strptime(kwargs['scantime'],fmt) ctimespac = datetime.strptime(kwargs['ctimespac'],fmt) bgactime = datetime.strptime(kwargs['bgactime'],fmt) spremactime = datetime.strptime(kwargs['spremactime'],fmt) bgremactime = datetime.strptime(kwargs['bgremactime'],fmt) actspsctime = niqlib.decay(float(kwargs['sphereac']),float((scantime - ctimespac).seconds/60.),th) - niqlib.decay(float(kwargs['spremac']),float((scantime - spremactime).seconds/60.),th) actbgsctime = niqlib.decay(float(kwargs['bgac']),float((scantime - bgactime).seconds/60.),th) - niqlib.decay(float(kwargs['bgremac']),float((scantime - bgremactime).seconds/60.),th) output['Act Spheres (scantime)'] = actspsctime output['Act BG (scantime)'] = actbgsctime output['Scantime'] = scantime.time() print axorder print "1 - loading data" iqphantom = simple_nema_phantom(data=filename,mode=mode,order=axorder,orientation=sporder) print "z_slice bollen: ",iqphantom.z zslicefig = plt.figure() ax1 = zslicefig.add_subplot(111) plt.xtitle = "Z slice" plt.ytitle = "Counts in slice" #plt.plot(iqphantom.z_slice()) #plt.show() # images output['EARL z_slice'] = iqphantom.z output['EARL zprofile'] = zslicefig print "2 - registering data" print "COR and angle before registration:", iqphantom.cor, iqphantom.angle #regpars = iqphantom.register_phantom() #print "registration pars:", regpars[0], regpars[1] # output['regpars'] = regpars print "COR and angle after registration:", iqphantom.cor, iqphantom.angle output['cor'] = iqphantom.cor output['angle'] = iqphantom.angle print "3 - show result: " print "zslice", iqphantom.z output['EARL halfslice'] = iqphantom.plot_dataspheres(iqphantom.z) print "4 - sphere statistics: " results = iqphantom.get_stats() for key in results.keys(): print "Sphere: ", key tmpresult = results[key] for subkey in tmpresult.keys(): print '\t', subkey, tmpresult[subkey] bgresults = iqphantom.get_bg_stats() for key in bgresults.keys(): print "BG Sphere: ", key tmpresult = bgresults[key] for subkey in tmpresult.keys(): print '\t', subkey, tmpresult[subkey] bgaverage = np.average([bgresults[key]['avg'] for key in bgresults.keys()]) print bgaverage meancontrastlist = {} maxcontrastlist = {} for key in results.keys(): meancontrastlist[key] = (results[key]['avg'] - bgaverage)/bgaverage maxcontrastlist[key] = (results[key]['max'] - bgaverage)/bgaverage output['maxcontrast'] = maxcontrastlist output['meancontrast'] = meancontrastlist print "5 - contrasts: " for key in meancontrastlist.keys(): print "mean:", key, meancontrastlist[key] print "max:", key, maxcontrastlist[key] print "6 - rc list: " inputcontrast = (actspsctime - actbgsctime)/ actbgsctime meanrclist = {} maxrclist = {} for key in results.keys(): meanrclist[key] = meancontrastlist[key]/inputcontrast maxrclist[key] = maxcontrastlist[key]/inputcontrast for key in meanrclist.keys(): print "mean: ",key, meanrclist[key] print "max: ", key, maxrclist[key] output['maxrc'] = maxrclist output['meanrc'] = meanrclist output['RC-1'] = meanrclist[1] output['RC-2'] = meanrclist[2] output['RC-3'] = meanrclist[3] output['RC-4'] = meanrclist[4] output['RC-5'] = meanrclist[5] output['RC-6'] = meanrclist[6] output['EARL rc mean curve'] = plot_rclist(meanrclist,'za') output['EARL rc max curve'] = plot_rclist(maxrclist,'za') output['status'] = 'processed' print "Writing results to wadserver" return output
def update_wad(filename, mode, axorder, sporder, **kwargs): output = {} #Float results volume = kwargs['volume'] output['volume'] = volume output['length'] = kwargs['dimensions'][0] output['radius'] = kwargs['dimensions'][1] output['activity'] = kwargs['bgac'] output['caltime'] = kwargs['bgactime'] output['remaindoer'] = kwargs['bgremac'] output['remtime'] = kwargs['bgremactime'] output['deltat0'] = 999999 output['deltatr'] = 999999 output['scanto'] = 999999 output['maxsuv'] =999999 output['avgsuv'] =999999 output['minsuv'] =999999 th = niqlib.thf18 fmt = '%H%M%S' #assumed format for all times # convert all 'string' times to datetime format so we can calculate something scantime = datetime.strptime(kwargs['scantime'],fmt) ctimespac = datetime.strptime(kwargs['ctimespac'],fmt) bgactime = datetime.strptime(kwargs['bgactime'],fmt) spremactime = datetime.strptime(kwargs['spremactime'],fmt) bgremactime = datetime.strptime(kwargs['bgremactime'],fmt) actbgsctime = niqlib.decay(float(kwargs['bgac']),float((scantime - bgactime).seconds/60.),th) - niqlib.decay(float(kwargs['bgremac']),float((scantime - bgremactime).seconds/60.),th) output['Act BG (scantime)'] = actbgsctime output['Scantime'] = scantime.time() print "Writing results to wadserver" print "1 - loading data" phantom = uniform_phantom(data=filename, order=axorder,phantomdim=kwargs['dimensions'],phantomvolume=kwargs['volume'],dose=kwargs['bgac'],dosecaltime=kwargs['bgactime'],remdose=kwargs['bgremac'],remdosecaltime=kwargs['bgremactime']) print phantom.z output['z_slice'] = phantom.z zslicefig = plt.figure() ax1 = zslicefig.add_subplot(111) plt.xtitle = "Z slice" plt.ytitle = "Counts in slice" plt.plot(phantom.z_slice()) #plt.show() output['EARL zprofile'] = zslicefig print "2 - info from header" """We need to calculate the activity concentration in Bq/ml from the volume of the phantom and the administered activity. """ # suv = c(t) / (A(t) / bodyweight) # # In the case of suv phantom: # suv = c(t) / (A(t) / 9.293), where A in MBq and c in kBq/cc # # dicom[7053,1000] converts to SUV # For Philips specific: # There are 2 ways to calculate the suv # 1 - multiply pixel value with tag 7053,1000 and make sure the correct weight was used (or correct) # 2 - multiply pix. val. with tag 7053, 1009 (rescale slope) which converts to bq/cc and correct for decay suv = lambda x:1000*x*float(phantom.suvfactor)/phantom.currconc #option 2 print "3 - show result: " sid = phantom.z output['EARL histogram']=phantom.plot_img_hist(sid, bins=256,showfig=False) for k in [sid - 6, sid - 4, sid, sid + 4, sid + 6]: tmpfig, tmpunif,tmpstd = phantom.slice_uniformity(k,showfig=False) print "uniformity: ", k, tmpunif, tmpstd, actbgsctime, suv(tmpunif) output['SUV slice %s'%str(k - sid)] = suv(tmpunif) output['COV slice %s'%str(k - sid)] = tmpstd/tmpunif output['EARL halfslice'] = phantom.plot_dataspheres(sid) #phantom.visualize_slices(sid) print "4 - sphere statistics: " bgresults = phantom.get_bg_stats() meansuvlist = [] maxsuvlist = [] for key in bgresults.keys(): print "BG Sphere: ", key tmpresult = bgresults[key] meansuvlist.append([key,tmpresult['avg'],tmpresult['avg']/phantom.currconc]) maxsuvlist.append([key,tmpresult['max'],tmpresult['max']/phantom.currconc]) for subkey in tmpresult.keys(): print '\t', subkey, tmpresult[subkey] print "SUVmean: ",meansuvlist print "SUVmax: ",maxsuvlist fig = plt.figure() ax1 = fig.add_subplot(111) ax1.plot(zip(*meansuvlist)[2]) #plt.show() fig = plt.figure() ax1 = fig.add_subplot(111) ax1.plot(zip(*maxsuvlist)[2]) output['EARL suvcurve'] = fig #plt.show() output['procstat'] = 'processed' output['status'] = 'processed' return output