Esempio n. 1
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)
Esempio n. 2
0
    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)
Esempio n. 3
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
Esempio n. 4
0
    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)
Esempio n. 5
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)