def run_casedir(sett, casedir, v): for sopid, d in v.items(): if isinstance(d, dict): gpumcd_factor = False try: tpsdosespecpt = d['dose_im'].get_value( d['plan'].BeamDoseSpecificationPoint) assert (d['plan'].BeamDose * 0.9 < tpsdosespecpt < d['plan'].BeamDose * 1.1) except: print( "TPS dose it outside of expected planned dose per fraction in beamdosespecificationpoint. Your TPS probably exported the PLAN dose instead of FRACTION dose, GPUMCD dose will be multiplied with the number of fractions." ) gpumcd_factor = True d['dose_im'].saveas( path.join(casedir, "xdr", sopid, "dose_tps.xdr")) ctcpy = v['ct_im'] ctcpy.crop_as(d['dose_im']) ctcpy.saveas(path.join(casedir, "xdr", sopid, "ct_on_dosegrid.xdr")) ct_obj = gpumcd.CT(sett, ctcpy) try: p = gpumcd.Rtplan(sett, d['plan']) except: print("Invalid plan found:", d['plan'].filename, "Skipping...") continue ct_obj.dosemap.zero_out() for beam in p.beams: eng = gpumcd.Engine(sett, ct_obj, p.accelerator.machfile) eng.execute_segments(beam) print(eng.lasterror()) eng.get_dose(ct_obj.dosemap) if gpumcd_factor: ct_obj.dosemap.mul(d['plan'].NumberOfFractionsPlanned) else: # From what I've seen, dosemaps are exported per plan REGARDLESS of value of DoseSummationType. we try anyway. if d['dose'].DoseSummationType == 'PLAN': print( "Dose was computed for whole PLAN, multiplying GPUMCD dose with number of fractions." ) ct_obj.dosemap.mul(d['plan'].NumberOfFractionsPlanned) else: assert d['dose'].DoseSummationType == 'FRACTION' ct_obj.dosemap.saveas( path.join(casedir, "xdr", sopid, "dose_gpumcd.xdr"))
from os import path import gpumcd import medimage as image print('Start of program.') sett = gpumcd.Settings("d:\\postdoc\\gpumcd_data") print(sett.planSettings.goalSfom) casedir = "d:\\postdoc\\analyses\\gpumcd_python" ct_image=image.image(path.join(casedir,'ct.xdr')) ct_image.ct_to_hu(1000,1) ct_image.resample([3,3,3]) ct = gpumcd.CT(sett,ct_image) #for dicoms, dont set intercept,slope. machfile = "d:/postdoc/gpumcd_data/machines/machine_van_sami/brentAgility.beamlets.gpumdt" engine = gpumcd.Engine(sett,ct,machfile) print('gpumcd init done.') print (engine.lasterror()) start_time = time.time() frame1size = 5 frame2size = 3
# print ('brent',studyid,'\n') v['ct_im'].saveas(path.join(casedir,"xdr","ct_dump.xdr")) for sopid,d in v.items(): if isinstance(d,dict): gpumcd_factor = False try: tpsdosespecpt = d['dose_im'].get_value(d['plan'].BeamDoseSpecificationPoint) assert(d['plan'].BeamDose*0.9 < tpsdosespecpt < d['plan'].BeamDose*1.1) except: print("TPS dose it outside of expected planned dose per fraction in beamdosespecificationpoint. Your TPS probably exported the PLAN dose instead of FRACTION dose, GPUMCD dose will be multiplied with the number of fractions.") gpumcd_factor = True d['dose_im'].saveas(path.join(casedir,"xdr",sopid,"dose_tps.xdr")) ctcpy = v['ct_im'] ctcpy.crop_as(d['dose_im']) ctcpy.saveas(path.join(casedir,"xdr",sopid,"ct_on_dosegrid.xdr")) ct_obj = gpumcd.CT(sett,ctcpy) p=gpumcd.Rtplan(sett, d['plan']) ct_obj.dosemap.zero_out() for i,beam in enumerate(p.beams): eng=gpumcd.Engine(sett,ct_obj,p.accelerator.machfile) eng.execute_segments(beam) if eng.lasterror()[0] != 0: print (eng.lasterror()) eng.get_dose(ct_obj.dosemap) if gpumcd_factor: ct_obj.dosemap.mul(d['plan'].NumberOfFractionsPlanned) else: # From what I've seen, dosemaps are exported per plan REGARDLESS of value of DoseSummationType. we try anyway.