예제 #1
0
    def load_let(self, path):
        if hasattr(self, "letcube"):
            if self.letcube is not None:
                self.remove_let(self.letcube)
        let = LETCube()
        let.read(os.path.splitext(path)[0] + ".dos")

        self.letcube = let
        return let
예제 #2
0
파일: plan.py 프로젝트: osama-ammar/pytrip
    def load_let(self, path):
        """ Load and append a new LET cube from path to self.letcubes.
        """

        let = LETCube()
        let.read(os.path.splitext(path)[0] + ".dos")

        # TODO: check if cube is already loaded, if so, dont load.
        # UUID for LET cubes would be useful then?
        self.letcubes.append(let)
예제 #3
0
    def test_read(self):
        l = LETCube()
        l.read(self.let001)

        v = create_sphere(l, name="sph", center=[10, 10, 10], radius=8)
        self.assertIsNotNone(v)

        logger.info("Calculating DVH")
        result = l.calculate_lvh(v)
        self.assertIsNotNone(result)
        lvh, min_l, max_l, mean, area = result
        self.assertGreater(area, 2.0)
        self.assertEqual(len(lvh.shape), 1)
        self.assertEqual(lvh.shape[0], 3000)
        self.assertEqual(min_l, 0.0)
        self.assertEqual(max_l, 1.0)

        self.assertGreater(l.get_max(), 30.0)

        fd, outfile = tempfile.mkstemp()
        os.close(fd)  # Windows needs it
        os.remove(outfile)  # we need only temp filename, not the file
        l.write(outfile)
        hed_file = outfile + LETCube.header_file_extension
        dos_file = outfile + LETCube.data_file_extension
        self.assertTrue(os.path.exists(hed_file))
        self.assertTrue(os.path.exists(dos_file))
        logger.info("Checking if output file " + hed_file + " is not empty")
        self.assertGreater(os.path.getsize(hed_file), 1)
        logger.info("Checking if output file " + dos_file + " is not empty")
        self.assertGreater(os.path.getsize(dos_file), 1)
        os.remove(hed_file)
        os.remove(dos_file)
예제 #4
0
    def _finish(self, plan):
        """ return requested results, copy them back in to plan._working_dir
        """

        for _file_name in plan._out_files:
            _path = os.path.join(plan._temp_dir, _file_name)

            # only copy files back, if we actually have been running TRiP
            if self._norun:
                logger.info("dummy run: would now copy {:s} to {:s}".format(
                    _path, plan._working_dir))
            else:
                logger.info("copy {:s} to {:s}".format(_path,
                                                       plan._working_dir))
                shutil.copy(_path, plan._working_dir)

        for _file_name in plan._out_files:
            _path = os.path.join(plan._temp_dir, _file_name)
            if ".phys.dos" in _file_name:
                _ctx_cube = DosCube()
                if not self._norun:
                    _ctx_cube.read(_path)
                    plan.dosecubes.append(_ctx_cube)

            if ".bio.dos" in _file_name:
                _ctx_cube = CtxCube()
                if not self._norun:
                    _ctx_cube.read(_path)
                    plan.dosecubes.append(_ctx_cube)

            if ".dosemlet.dos" in _file_name:
                _let_cube = LETCube()
                if not self._norun:
                    _let_cube.read(_path)
                    plan.letcubes.append(_let_cube)

            if ".rst" in _file_name:
                logger.warning(
                    "attaching fields to class not implemented yet {:s}".
                    format(_path))
                # TODO
                # need to access the RstClass here for each rst file. This will then need to be attached
                # to the proper field in the list of fields.

        if self._cleanup:
            logger.debug("Delete {:s}".format(plan._temp_dir))
            shutil.rmtree(plan._temp_dir)
예제 #5
0
    def post_process(self):
        phys_dose = None
        bio_dose = None
        dose_mean_let = None
        temp_dos = None
        for projectile in self.projectiles:
            name = os.path.join(
                self.path,
                self.plan_name) + "_" + self.projectiles[projectile]["name"]
            factor = float(self.projectile_dose_level[projectile]) / 1000
            factor = 1
            if os.path.exists(name +
                              ".bio.dos") and self.plan.get_out_bio_dose():
                path = os.path.join(name + ".bio.dos")
                temp = DosCube()
                temp.read(path)
                temp *= factor
                if self.mult_proj:
                    self.plan.add_dose(temp, "bio_%s" % projectile)
                if bio_dose is None:
                    bio_dose = temp
                else:
                    bio_dose += temp

            if os.path.exists(name +
                              ".phys.dos") and self.plan.get_out_phys_dose():
                path = os.path.join(name + ".phys.dos")
                temp_dos = DosCube()
                temp_dos.read(path)
                temp_dos *= factor
                if self.mult_proj:
                    self.plan.add_dose(temp_dos, "phys_%s" % projectile)
                if phys_dose is None:
                    phys_dose = temp_dos
                else:
                    phys_dose += temp_dos
            if os.path.exists(name + ".dosemlet.dos"
                              ) and self.plan.get_out_dose_mean_let():

                path = os.path.join(name + ".dosemlet.dos")
                temp = LETCube()
                temp.read(path)
                if not self.mult_proj:
                    dose_mean_let = temp
                else:
                    if dose_mean_let is None:
                        dose_mean_let = temp * temp_dos
                    else:
                        dose_mean_let = dose_mean_let + temp * temp_dos
        out_path = os.path.join(self.path, self.plan_name)
        if bio_dose is not None:
            bio_dose.write(out_path + ".bio.dos")
        if phys_dose is not None:
            phys_dose.write(out_path + ".phys.dos")
        if dose_mean_let is not None:
            if self.mult_proj:
                dose_mean_let /= phys_dose

            dose_mean_let.write(out_path + ".hed")
예제 #6
0
파일: test_let.py 프로젝트: pytrip/pytrip
    def test_read(self):
        let = LETCube()
        let.read(self.let001)

        v = create_sphere(let, name="sph", center=[10, 10, 10], radius=8)
        self.assertIsNotNone(v)

        logger.info("Calculating DVH")
        result = let.calculate_lvh(v)
        self.assertIsNotNone(result)
        lvh, min_l, max_l, mean, area = result
        self.assertGreater(area, 2.0)
        self.assertEqual(len(lvh.shape), 1)
        self.assertEqual(lvh.shape[0], 3000)
        self.assertEqual(min_l, 0.0)
        self.assertEqual(max_l, 1.0)

        self.assertGreater(let.get_max(), 30.0)

        fd, outfile = tempfile.mkstemp()
        os.close(fd)  # Windows needs it
        os.remove(outfile)  # we need only temp filename, not the file
        let.write(outfile)
        hed_file = outfile + LETCube.header_file_extension
        dos_file = outfile + LETCube.data_file_extension
        self.assertTrue(os.path.exists(hed_file))
        self.assertTrue(os.path.exists(dos_file))
        logger.info("Checking if output file " + hed_file + " is not empty")
        self.assertGreater(os.path.getsize(hed_file), 1)
        logger.info("Checking if output file " + dos_file + " is not empty")
        self.assertGreater(os.path.getsize(dos_file), 1)
        os.remove(hed_file)
        os.remove(dos_file)