Exemplo n.º 1
0
class TestTlogFluence(TestCase):

    def setUp(self):
        self.log = MachineLog()
        self.log.load_demo_trajectorylog()

    def test_fluence(self):
        fluence = self.log.fluence
        fluence.gamma.calc_map()
        self.assertAlmostEqual(fluence.gamma.pass_prcnt, 100, delta=0.1)
        self.assertAlmostEqual(fluence.gamma.avg_gamma, 0.001, delta=0.005)
        self.assertAlmostEqual(fluence.gamma.histogram()[0][0], 240000, delta=100)

    def test_plotting(self):
        # raise error if map hasn't yet been calc'ed.
        with self.assertRaises(AttributeError):
            self.log.fluence.actual.plot_map()

        self.log.fluence.actual.calc_map()
        self.log.fluence.actual.plot_map()

    def test_saving_plots(self):
        self.log.fluence.gamma.calc_map()
        save_file('test.png', self.log.fluence.gamma.save_map)

    def test_subbeam_data(self):
        """Test accessing the subbeam data."""
        expected_vals = [310, 180, 3.7, 3.4, 3.8, 3.9]
        for item, expval in zip(('gantry_angle', 'collimator_angle', 'jaw_x1', 'jaw_x2', 'jaw_y1', 'jaw_y2'), expected_vals):
            val = getattr(self.log.subbeams[0], item)
            self.assertAlmostEqual(val.actual, expval, delta=0.1)
Exemplo n.º 2
0
    def test_trajectorylog(self):
        tlog_file = osp.join(self.anon_folder, 'PatientID_4DC Treatment_JST90_TX_20140712094246.bin')
        tlog = MachineLog(tlog_file)
        tlog.anonymize()

        files = tlog.anonymize(inplace=True, suffix='inplace')
        self.assertIsInstance(files, list)
        for file in files:
            self.assertTrue('inplace' in file)
Exemplo n.º 3
0
    def test_mlc(self):
        mlc = self.log.axis_data.mlc
        self.assertTrue(mlc.hdmlc)
        self.assertEqual(mlc.num_leaves, 120)
        self.assertEqual(mlc.num_pairs, 60)
        self.assertEqual(mlc.num_snapshots, 1021)

        log_no_exclusion = MachineLog()
        log_no_exclusion.load_demo_trajectorylog(exclude_beam_off=False)
        self.assertEqual(log_no_exclusion.axis_data.mlc.num_snapshots, 5200)
Exemplo n.º 4
0
    def test_trajectorylog(self):
        tlog_file = osp.join(
            self.anon_folder,
            'PatientID_4DC Treatment_JST90_TX_20140712094246.bin')
        tlog = MachineLog(tlog_file)
        tlog.anonymize()

        files = tlog.anonymize(inplace=True, suffix='inplace')
        self.assertIsInstance(files, list)
        for file in files:
            self.assertTrue('inplace' in file)
Exemplo n.º 5
0
    def test_dynalog(self):
        # test making an anonymized copy
        dlog_file = osp.join(self.anon_folder, 'A1234_patientid.dlg')
        dlog = MachineLog(dlog_file)
        dlog.anonymize()

        # test doing inplace anonymization
        files = dlog.anonymize(inplace=True, suffix='inplace')
        self.assertIsInstance(files, list)
        for file in files:
            self.assertTrue('inplace' in file)
Exemplo n.º 6
0
    def test_dynalog(self):
        # test making an anonymized copy
        dlog_file = osp.join(self.anon_folder, 'A1234_patientid.dlg')
        dlog = MachineLog(dlog_file)
        dlog.anonymize()

        # test doing inplace anonymization
        files = dlog.anonymize(inplace=True, suffix='inplace')
        self.assertIsInstance(files, list)
        for file in files:
            self.assertTrue('inplace' in file)
Exemplo n.º 7
0
class Test_Tlog_Fluence(TestCase):
    def setUp(self):
        self.log = MachineLog()
        self.log.load_demo_trajectorylog()

    def test_fluence(self):
        fluence = self.log.fluence
        fluence.gamma.calc_map()
        self.assertAlmostEqual(fluence.gamma.pass_prcnt, 100, delta=0.1)
        self.assertAlmostEqual(fluence.gamma.avg_gamma, 0.001, delta=0.005)
        self.assertAlmostEqual(fluence.gamma.histogram()[0][0], 240000, delta=100)
Exemplo n.º 8
0
    def test_dynalog_loading(self):
        a_file = osp.join(TEST_DIR, 'dlogs', 'Adlog1.dlg')
        MachineLog(a_file)

        b_file = osp.join(TEST_DIR, 'dlogs', 'Bdlog1.dlg')
        MachineLog(b_file)

        a_but_not_b_dir = osp.join(TEST_DIR, 'a_no_b_dir', 'Adlog1.dlg')
        self.assertRaises(FileNotFoundError, MachineLog, a_but_not_b_dir)
        b_but_not_a_dir = osp.join(TEST_DIR, 'b_no_a_dir', 'Bdlog1.dlg')
        self.assertRaises(FileNotFoundError, MachineLog, b_but_not_a_dir)

        bad_name_dlg = osp.join(TEST_DIR, 'bad_names', 'bad_name_dlg.dlg')
        self.assertRaises(ValueError, MachineLog, bad_name_dlg)
Exemplo n.º 9
0
    def test_loading(self):
        """Test that loading the badly-named dynalog still loads and identifies properly."""
        test_tlog = osp.join(self.test_dir, 'tlogs', "qqq2106_4DC Treatment_JS0_TX_20140712095629.bin")
        # should produce no errors
        # load method 1
        MachineLog(test_tlog)
        # load method 2
        log = MachineLog()
        self.assertFalse(log.is_loaded)
        log.load(test_tlog)
        self.assertTrue(log.is_loaded)

        # throw an error for files that aren't logs
        not_a_file = test_tlog.replace(".bin", 'blahblah.bin')
        self.assertRaises(FileExistsError, MachineLog, not_a_file)
        not_a_log = osp.join(osp.dirname(__file__), 'test_files', 'VMAT', 'DRGSmlc-105-example.dcm')
        self.assertRaises(IOError, MachineLog, not_a_log)
Exemplo n.º 10
0
    def test_txt_file_also_loads_if_around(self):
        # has a .txt file
        log_with_txt = osp.join(
            TEST_DIR, 'mixed_types',
            "Anonymous_4DC Treatment_JST90_TX_20140712094246.bin")

        log = MachineLog(log_with_txt)
        self.assertTrue(hasattr(log, 'txt'))
        self.assertIsInstance(log.txt, dict)
        self.assertEqual(log.txt['Patient ID'], 'Anonymous')

        # DOESN'T have a txt file
        log_no_txt = osp.join(
            TEST_DIR, 'tlogs',
            "Anonymous_4DC Treatment_JS0_TX_20140712095629.bin")

        log = MachineLog(log_no_txt)
        self.assertFalse(hasattr(log, 'txt'))
Exemplo n.º 11
0
class TestLogPlottingSaving(TestCase):
    """Test the plotting methods and plot saving methods."""
    tlog = MachineLog.from_demo_trajectorylog()
    dlog = MachineLog.from_demo_dynalog()

    def test_save_tlog_to_csv(self):
        save_file(self.tlog.to_csv)

    def test_plot_axes(self):
        for methodname in ('plot_actual', 'plot_expected', 'plot_difference'):
            method = getattr(self.tlog.axis_data.gantry, methodname)
            method()  # shouldn't raise

    def test_save_axes(self):
        for methodname in ('save_plot_actual', 'save_plot_expected',
                           'save_plot_difference'):
            # save matplotlib figures
            method = getattr(self.tlog.axis_data.gantry, methodname)
            save_file(method)

            # save MPLD3 HTML
            save_file(method, interactive=True, as_file_object='str')

    def test_fluence_plotting(self):
        # raise error if map hasn't yet been calc'ed.
        with self.assertRaises(AttributeError):
            self.dlog.fluence.actual.plot_map()

        self.dlog.fluence.actual.calc_map()
        self.dlog.fluence.actual.plot_map()
        self.dlog.fluence.gamma.calc_map()
        self.dlog.fluence.gamma.histogram()
        self.dlog.fluence.gamma.plot_histogram()
        self.dlog.fluence.gamma.plot_passfail_map()

    def test_saving_fluence_plots(self):
        self.dlog.fluence.gamma.calc_map()
        save_file(self.dlog.fluence.gamma.save_map)
        save_file(self.dlog.fluence.gamma.save_histogram)

    def test_save_summary(self):
        self.tlog.fluence.gamma.calc_map()
        save_file(self.tlog.save_summary)
Exemplo n.º 12
0
class TestDlogFluence(TestCase):

    def setUp(self):
        self.log = MachineLog()
        self.log.load_demo_dynalog()

    def test_demo(self):
        self.log.run_dlog_demo()

    def test_fluence(self):
        fluence = self.log.fluence

        self.assertFalse(fluence.actual.map_calced)
        self.assertFalse(fluence.expected.map_calced)
        self.assertFalse(fluence.gamma.map_calced)
        self.assertRaises(AttributeError, fluence.actual.plot_map)

        # do repeating fluence calcs; ensure semi-lazy property
        start = time.time()
        fluence.actual.calc_map()
        end = time.time()
        first_calc_time = end - start
        start = time.time()
        fluence.actual.calc_map()
        end = time.time()
        second_calc_time = end - start
        self.assertLess(second_calc_time, first_calc_time)

        # same for gamma
        start = time.time()
        fluence.gamma.calc_map(resolution=0.15)
        end = time.time()
        first_calc_time = end - start
        start = time.time()
        fluence.gamma.calc_map(resolution=0.15)
        end = time.time()
        second_calc_time = end - start
        self.assertLess(second_calc_time, first_calc_time)

        self.assertAlmostEqual(fluence.gamma.pass_prcnt, 99.85, delta=0.1)
        self.assertAlmostEqual(fluence.gamma.avg_gamma, 0.019, delta=0.005)
        self.assertAlmostEqual(fluence.gamma.histogram()[0][0], 155804, delta=100)
Exemplo n.º 13
0
    def test_loading(self):
        """Test that loading the badly-named dynalog still loads and identifies properly."""
        test_tlog = osp.join(
            TEST_DIR, 'tlogs',
            "Anonymous_4DC Treatment_JS0_TX_20140712095629.bin")
        # should produce no errors
        MachineLog(test_tlog)

        # throw an error for files that aren't logs
        not_a_file = test_tlog.replace(".bin", 'blahblah.bin')
        self.assertRaises(IOError, MachineLog, not_a_file)
        not_a_log = osp.join(osp.dirname(__file__), 'test_files', 'VMAT',
                             'DRGSmlc-105-example.dcm')
        self.assertRaises(IOError, MachineLog, not_a_log)
Exemplo n.º 14
0
    def test_append(self):
        # append a directory
        logs = MachineLogs(self.logs_altdir)
        logs.append(self.logs_altdir)
        self.assertEqual(logs.num_logs, 8)
        # append a file string
        single_file = osp.join(
            self.logs_altdir,
            'Anonymous_4DC Treatment_JST90_TX_20140712094246.bin')
        logs.append(single_file)
        # append a MachineLog
        single_log = MachineLog(single_file)
        logs.append(single_log)

        # try to append something that's not a Log
        log = None
        with self.assertRaises(TypeError):
            logs.append(log)
Exemplo n.º 15
0
 def test_bad_name(self):
     """Test that a log with a bad name (no underscore) fails gracefully."""
     dlog_file = osp.join(self.anon_folder, 'A1234patientid.dlg')
     dlog = MachineLog(dlog_file)
     with self.assertRaises(NameError):
         dlog.anonymize()
Exemplo n.º 16
0
 def setUpClass(cls):
     cls.log = MachineLog(cls.get_filename())
     cls.log.fluence.gamma.calc_map()
Exemplo n.º 17
0
 def test_demo(self):
     """Test the run demo method."""
     # shouldn't raise
     MachineLog.run_tlog_demo()
Exemplo n.º 18
0
 def setUpClass(cls):
     cls.log = MachineLog.from_demo_trajectorylog()
     cls.log.fluence.gamma.calc_map()
Exemplo n.º 19
0
 def test_from_url(self):
     url = 'https://s3.amazonaws.com/assuranceqa-staging/uploads/imgs/Tlog2.bin'
     log = MachineLog.from_url(url)
Exemplo n.º 20
0
 def setUp(self):
     self.log = MachineLog()
     self.log.load_demo_trajectorylog()
Exemplo n.º 21
0
 def setUpClass(cls):
     cls.log = MachineLog.from_demo_trajectorylog()
     cls.log.fluence.gamma.calc_map()
Exemplo n.º 22
0
 def test_demo(self):
     """Test the run demo method."""
     # shouldn't raise
     MachineLog.run_tlog_demo()
Exemplo n.º 23
0
 def setUp(self):
     self.log = MachineLog()
     self.log.load_demo_dynalog()
Exemplo n.º 24
0
 def test_destination(self):
     tlog_file = osp.join(
         self.anon_folder,
         'PatientID_4DC Treatment_JST90_TX_20140712094246.bin')
     tlog = MachineLog(tlog_file)
     tlog.anonymize(destination=self.anon_folder)  # shouldn't raise
Exemplo n.º 25
0
 def test_destination(self):
     tlog_file = osp.join(self.anon_folder, 'PatientID_4DC Treatment_JST90_TX_20140712094246.bin')
     tlog = MachineLog(tlog_file)
     tlog.anonymize(destination=self.anon_folder)  # shouldn't raise
Exemplo n.º 26
0
 def test_bad_name(self):
     """Test that a log with a bad name (no underscore) fails gracefully."""
     dlog_file = osp.join(self.anon_folder, 'A1234patientid.dlg')
     dlog = MachineLog(dlog_file)
     with self.assertRaises(NameError):
         dlog.anonymize()
Exemplo n.º 27
0
 def test_from_stream(self):
     """Anonymizing a log that was loaded from a stream should fail (no filename to replace)."""
     url = 'https://s3.amazonaws.com/assuranceqa-staging/uploads/imgs/Tlog2.bin'
     tlog = MachineLog.from_url(url)
     with self.assertRaises(IOError):
         tlog.anonymize()