def test_max_leaf_gap(): max_leaf_gap_init = 2 * np.max(np.abs(MLC)) grid_resolution = 2 how_many_to_test = 20 max_leaf_gap_init = ( np.ceil(max_leaf_gap_init / 2 / grid_resolution) * 2 * grid_resolution ) multiple_max_leaf_gaps = np.arange( max_leaf_gap_init, max_leaf_gap_init + how_many_to_test * 2 * grid_resolution, 2 * grid_resolution, ) init_mu_density = calc_mu_density( MU, MLC, JAW, leaf_pair_widths=LEAF_PAIR_WIDTHS, max_leaf_gap=max_leaf_gap_init, grid_resolution=grid_resolution, ) for i, max_leaf_gap in enumerate(multiple_max_leaf_gaps): mu_density = calc_mu_density( MU, MLC, JAW, leaf_pair_widths=LEAF_PAIR_WIDTHS, max_leaf_gap=max_leaf_gap, grid_resolution=grid_resolution, ) assert not np.all(mu_density == 0) if i != 0: assert np.all(mu_density[:, i:-i] == init_mu_density) with pytest.raises(ValueError): calc_mu_density( MU, MLC, JAW, leaf_pair_widths=LEAF_PAIR_WIDTHS, max_leaf_gap=max_leaf_gap_init + 1, grid_resolution=grid_resolution, )
def mu_density_from_delivery_data(delivery_data, grid_resolution=1): mu, mlc, jaw = (delivery_data.monitor_units, delivery_data.mlc, delivery_data.jaw) grid_xx, grid_yy, mu_density = calc_mu_density( mu, mlc, jaw, grid_resolution=grid_resolution ) return grid_xx, grid_yy, mu_density
def test_regression(): """The results of MU Density calculation should not change """ regress_test_arrays = np.load(DELIVERY_DATA_FILEPATH) mu = regress_test_arrays["mu"] mlc = regress_test_arrays["mlc"] jaw = regress_test_arrays["jaw"] cached_mu_density = regress_test_arrays["mu_density"] mu_density = calc_mu_density(mu, mlc, jaw) assert np.allclose(mu_density, cached_mu_density, atol=0.1)
from pymedphys_mudensity.mudensity import calc_mu_density, get_grid, display_mu_density leaf_pair_widths = (5, 5, 5) max_leaf_gap = 10 mu = [0, 2, 5, 10] mlc = [ [[1, 1], [2, 2], [3, 3]], [[2, 2], [3, 3], [4, 4]], [[-2, 3], [-2, 4], [-2, 5]], [[0, 0], [0, 0], [0, 0]], ] jaw = [[7.5, 7.5], [7.5, 7.5], [-2, 7.5], [0, 0]] grid = get_grid(max_leaf_gap=max_leaf_gap, leaf_pair_widths=leaf_pair_widths) mu_density = calc_mu_density(mu, mlc, jaw, max_leaf_gap=max_leaf_gap, leaf_pair_widths=leaf_pair_widths) display_mu_density(grid, mu_density)