コード例 #1
0
ファイル: test_exec.py プロジェクト: carlosqueiroz/pytrip
    def test_exec(self):
        """ Prepare and execute a dry-run test using the Executer.
        """
        logger.info("Test norun TRiP98 execution")

        logger.debug("Load CtxCube {:s}".format(self.ctx_path))
        c = pt.CtxCube()
        c.read(self.ctx_path)

        logger.debug("Load VdxCube {:s}".format(self.vdx_path))
        v = pt.VdxCube(c)
        v.read(self.vdx_path)

        print(v.get_voi_names())

        plan = pte.Plan(basename=self.patient_name)
        self.assertIsNotNone(plan)

        plan.ddd_dir = "~/TRiP98/base/DATA/DDD/12C/RF3MM/*"
        plan.spc_dir = "~/TRiP98/base/DATA/SPC/12C/RF3MM/*"
        plan.sis_path = "~/TRiP98/base/DATA/SIS/12C.sis"
        plan.hlut_path = "~/TRiP98/base/DATA/HLUT/19990218.hlut"
        plan.dedx_path = "~/TRiP98/base/DATA/DEDX/20040607.dedx"
        plan.working_dir = "."  # working dir must exist.

        # add the target voi to the plan
        plan.voi_target = v.get_voi_by_name('target')

        plan.rifi = 3.0
        plan.bolus = 0.0
        plan.offh2o = 1.873

        # create a field and add it to the plan
        field = pte.Field()
        self.assertIsNotNone(field)
        field.basename = self.patient_name
        field.gantry = 10.0
        field.couch = 90.0  # degrees
        field.fwhm = 4.0  # spot size in [mm]
        field.projectile = 'C'

        plan.fields.append(field)

        # flags for what output should be generated
        plan.want_phys_dose = True
        plan.want_bio_dose = False
        plan.want_dlet = True
        plan.want_rst = False

        t = pte.Execute(c, v)
        self.assertIsNotNone(t)
        t.trip_bin_path = self.trip_path
        print(self.trip_path)
        if os.name != 'nt':  # skip running fake TRiP98 on Windows as it is not supported there
            t.execute(
                plan, False
            )  # setup and make a dry-run, since TRiP98 is not installed.

        executer_str = str(t)
        self.assertGreater(len(executer_str), 1)
コード例 #2
0
    def execute(self, patient, plan):
        plan = copy.deepcopy(plan)

        plan.working_dir = self.trip_config.wdir_path
        plan.dedx_path = self.trip_config.dedx_path
        plan.hlut_path = self.trip_config.hlut_path

        te = pte.Execute(patient.ctx, patient.vdx)
        if self.trip_config.remote_execution:
            te.remote = True
            te.servername = self.trip_config.host_name
            te.username = self.trip_config.user_name
            te.password = self.trip_config.password
            te.pkey_path = self.trip_config.pkey_path
            te.remote_base_dir = self.trip_config.wdir_remote_path + '/'

        te.trip_bin_path = self.trip_config.trip_path + '/' + 'TRiP98'

        if self.logger:
            te.add_executor_logger(self.logger)

        try:
            te.execute(plan, use_default_logger=False)
        except BaseException as e:
            logger.error(e.__str__())
            sys.exit(-1)

        results = SimulationResults(patient, plan, plan.basename)

        return results
コード例 #3
0
    def execute_plan(self):
        logger.debug("execute_plan".format())
        plan = self._node_obj

        import tempfile
        import os
        self.model.wdir = tempfile.gettempdir() + "/pytripgui/"

        try:
            os.mkdir(self.model.wdir)
        except OSError:
            pass

        logger.debug("Temporary dir:{}".format(self.model.wdir))

        plan.working_dir = self.model.wdir

        import pytrip.tripexecuter as pte

        current_field = plan.fields[0]
        plan.projectile = current_field.kernel.projectile.iupac
        plan.projectile_a = current_field.kernel.projectile.a
        plan.rifi = current_field.kernel.rifi_thickness
        plan.ddd_dir = current_field.kernel.ddd_path
        plan.spc_dir = current_field.kernel.spc_path
        plan.sis_path = current_field.kernel.sis_path
        plan.dedx_path = "$TRIP98/DATA/DEDX/20000830.dedx"

        te = pte.Execute(self.model.ctx, self.model.vdx)

        try:
            te.execute(plan)
        except RuntimeError:
            pass
コード例 #4
0
    def execute_plan(self):
        logger.debug("execute_plan".format())
        plan = self._node_obj

        logger.debug("Temporary dir:{}".format(self.model.wdir))

        plan.working_dir = self.model.trip_config.wdir_path

        import pytrip.tripexecuter as pte

        current_field = plan.fields[0]
        plan.projectile = current_field.kernel.projectile.iupac
        plan.projectile_a = current_field.kernel.projectile.a
        plan.rifi = current_field.kernel.rifi_thickness
        plan.ddd_dir = current_field.kernel.ddd_path
        plan.spc_dir = current_field.kernel.spc_path
        plan.sis_path = current_field.kernel.sis_path

        plan.dedx_path = self.model.trip_config.dedx_path
        plan.hlut_path = self.model.trip_config.hlut_path

        import os
        te = pte.Execute(self.model.ctx, self.model.vdx)
        te.trip_bin_path = os.path.join(self.model.trip_config.trip_path, 'TRiP98')

        try:
            te.execute(plan)
        except RuntimeError:
            logger.error("TRiP98 executer: Runtime error")
            exit(-1)

        if plan.want_phys_dose:
            dos_path = os.path.join(plan.working_dir, plan.basename + '.phys.dos')
            logger.debug("Loading dose file {}".format(dos_path))
            dos = self.model.dos_container.import_from_file(dos_path)
            self.ctrl.tree.update_tree()
            self.model.plot.dos = dos
            self.ctrl.plot.update_viewcanvas()

        if plan.want_dlet:
            let_path = os.path.join(plan.working_dir, plan.basename + '.dosemlet.dos')
            logger.debug("Loading dose let file {}".format(let_path))
            let = self.model.let_container.import_from_file(let_path)
            self.ctrl.tree.update_tree()
            self.model.plot.let = let
            self.ctrl.plot.update_viewcanvas()
コード例 #5
0
field.fwhm = 4.0  # spot size in [mm]
field.projectile = 'C'

print(field)  # We can print all parameters of this field, for checking.
plan.fields.append(
    field)  # attach field to plan. You may attach multiple fields.

# Next, set the flags for what output should be generated, when the plan has completed.
plan.want_phys_dose = True  # We want a physical dose cube, "TST000000.dos"
plan.want_bio_dose = False  # No biological cube (Dose * RBE)
plan.want_dlet = True  # We want to have the dose-averaged LET cube
plan.want_rst = False  # Print the raster scan files (.rst) for all fields.

# print(plan)  # this will print all plan parameters

te = pte.Execute(
    c, v)  # get the executer object, based on the given Ctx and Vdx cube.

# in the case that TRiP98 is not installed locally, you may have to enable remote execution:
# te.remote = True
# te.servername = "titan.phys.au.dk"
# te.username = "******"
# te.password = "******"  # you can set a password, but this is strongly discouraged. Better to exchange SSH keys!
# te.remote_base_dir = "/home/bassler/test"
# depending on the remote .bashrc_profile setup, it may be needed to specify the full path
# for the remote TRiP installation. On some systems the $PATH is set, so this line can be omitted,
# or shortened to just "TRiP98"
# te.trip_bin_path = "/opt/aptg/TRiP98/bin/TRiP98"

te.execute(plan)  # this will run TRiP
# te.execute(plan, False)  # set to False, if TRiP98 should not be executed. Good for testing.