def test_collimator_270(self): source = Source("varian_clinac_6MV") source.collimator(270) correct_rot = np.array([0, 0, np.pi * 3 / 2]) np.testing.assert_array_almost_equal(correct_rot, source.rotation, decimal=5)
def test_gantry_270(self): source = Source("varian_clinac_6MV") source.gantry(270) correct_pos = np.array([-100, 0, 0]) np.testing.assert_array_almost_equal(correct_pos, source.position, decimal=5) correct_rot = np.array([0, np.pi / 2, 0]) np.testing.assert_array_almost_equal(correct_rot, source.rotation, decimal=5)
def test_gantry_225(self): source = Source("varian_clinac_6MV") source.gantry(225) correct_pos = np.array( [-np.cos(np.pi / 4) * 100, 0, -np.cos(np.pi / 4) * 100]) np.testing.assert_array_almost_equal(correct_pos, source.position, decimal=5) correct_rot = np.array([0, np.pi * 3 / 4, 0]) np.testing.assert_array_almost_equal(correct_rot, source.rotation, decimal=5)
def test_global_to_beam_G0_C90(self): """ Test at G0, C90 """ source = Source("varian_clinac_6MV") source.gantry(0) source.collimator(90) global_coords = np.array([.1, .2, .3]) beam_coords = global_to_beam(global_coords, source.position, source.rotation) correct = np.array([.2, -.1, -99.7]) np.testing.assert_array_almost_equal(correct, beam_coords, decimal=5)
def test_beam_to_global_G0_C0(self): """ Test at G0, C0 """ source = Source("varian_clinac_6MV") source.gantry(0) source.collimator(0) beam_coords = np.array([.1, .2, .3]) global_coords = beam_to_global(beam_coords, source.position, source.rotation) correct = np.array([.1, .2, 100.3]) np.testing.assert_array_almost_equal(correct, global_coords, decimal=5)
def test_global_to_beam_G270_C270(self): """ Test at G270, C270 """ source = Source("varian_clinac_6MV") source.gantry(270) source.collimator(270) global_coords = np.array([.1, .2, .3]) beam_coords = global_to_beam(global_coords, source.position, source.rotation) correct = np.array([-.2, .3, -100.1]) np.testing.assert_array_almost_equal(correct, beam_coords, decimal=5)
def test_global_to_beam_G90_C0(self): """ Test at G90, C0 """ source = Source("varian_clinac_6MV") source.gantry(90) source.collimator(0) global_coords = np.array([.1, .2, .3]) transform = Transform(source.position, source.rotation) beam_coords = transform.global_to_beam(global_coords) correct = np.array([-.3, .2, -99.9]) np.testing.assert_array_almost_equal(correct, beam_coords, decimal=5)
def test_beam_to_global_G270_C270(self): """ Test at G270, C270 """ source = Source("varian_clinac_6MV") source.gantry(270) source.collimator(270) beam_coords = np.array([.1, .2, .3]) transform = Transform(source.position, source.rotation) global_coords = transform.beam_to_global(beam_coords) correct = np.array([-100.3, -.1, .2]) np.testing.assert_array_almost_equal(correct, global_coords, decimal=5)
def test_SAD(self): SAD = 50 source = Source("varian_clinac_6MV", SAD=SAD) assert (source.SAD == 50)
def test_source_not_implemented_error(self): with pytest.raises(NotImplementedError): Source("varian_clinac_10MV")
from conehead.source import Source from conehead.block import Block from conehead.phantom import Phantom from conehead.conehead import Conehead # Choose source source = Source("varian_clinac_6MV") source.gantry(0) source.collimator(0) # Create 10 cm x 10 cm collimator opening block = Block(source.rotation) block.set_square(10) # Simple phantom phantom = Phantom() # Calculation settings settings = { 'stepSize': 0.1, # Stepsize when raytracing effective depth 'sPri': 1.0, # Primary source strength (photons/mm^2) 'softRatio': 0.0025, # mm^-1 'softLimit': 20, # cm 'eLow': 0.01, # MeV 'eHigh': 7.0, # MeV 'eNum': 500, # Spectrum samples } conehead = Conehead() conehead.calculate(source, block, phantom, settings) conehead.plot()