Electron Factor Modelling

Model insert factors and parameterise inserts as equivalent ellipses.

Available Functions

>>> from pymedphys.electronfactors import (
...     parameterise_insert, spline_model, calculate_deformability,
...     spline_model_with_deformability,
...     calculate_percent_prediction_differences,
...     visual_alignment_of_equivalent_ellipse)

API

pymedphys.electronfactors.parameterise_insert(x, y, callback=None)[source]

Return the parameterisation of an insert given x and y coords.

pymedphys.electronfactors.spline_model(width_test, ratio_perim_area_test, width_data, ratio_perim_area_data, factor_data)[source]

Return the result of the spline model.

The bounding box is chosen so as to allow extrapolation. The spline orders are two in the width direction and one in the perimeter/area direction. For justification on using this method for modelling electron insert factors see the Methods: Bivariate spline model section within <http://dx.doi.org/10.1016/j.ejmp.2015.11.002>.

Parameters:
width_test : np.ndarray

The width point(s) which are to have the electron insert factor interpolated.

ratio_perim_area_test : np.ndarray

The perimeter/area which are to have the electron insert factor interpolated.

width_data : np.ndarray

The width data points for the relevant applicator, energy and ssd.

ratio_perim_area_data : np.ndarray

The perimeter/area data points for the relevant applicator, energy and ssd.

factor_data : np.ndarray

The insert factor data points for the relevant applicator, energy and ssd.

Returns:
result : np.ndarray

The interpolated electron insert factors for width_test and ratio_perim_area_test.

pymedphys.electronfactors.calculate_deformability(x_test, y_test, x_data, y_data, z_data)[source]

Return the result of the deformability test.

This function takes an array of test points and loops over _single_calculate_deformability.

The deformability test applies a shift to the spline to determine whether or not sufficient information for modelling is available. For further details on the deformability test see the Methods: Defining valid prediction regions of the spline section within <http://dx.doi.org/10.1016/j.ejmp.2015.11.002>.

Parameters:
x_test : np.ndarray

The x coordinate of the point(s) to test

y_test : np.ndarray

The y coordinate of the point(s) to test

x_data : np.ndarray

The x coordinate of the model data to test

y_data : np.ndarray

The y coordinate of the model data to test

z_data : np.ndarray

The z coordinate of the model data to test

Returns:
deformability : float

The resulting deformability between 0 and 1 representing the ratio of deviation the spline model underwent at the point in question by introducing an outlier at the point in question.

pymedphys.electronfactors.spline_model_with_deformability(width_test, ratio_perim_area_test, width_data, ratio_perim_area_data, factor_data)[source]

Return the spline model for points with sufficient deformability.

Calls both spline_model and calculate_deformabilty and then adjusts the result so that points with deformability greater than 0.5 return np.nan.

Parameters:
width_test : np.ndarray

The width point(s) which are to have the electron insert factor interpolated.

ratio_perim_area_test : np.ndarray

The perimeter/area which are to have the electron insert factor interpolated.

width_data : np.ndarray

The width data points for the relevant applicator, energy and ssd.

ratio_perim_area_data : np.ndarray

The perimeter/area data points for the relevant applicator, energy and ssd.

factor_data : np.ndarray

The insert factor data points for the relevant applicator, energy and ssd.

Returns:
model_factor : np.ndarray

The interpolated electron insert factors for width_test and ratio_perim_area_test with points outside the valid prediction region set to np.nan.

pymedphys.electronfactors.calculate_percent_prediction_differences(width_data, ratio_perim_area_data, factor_data)[source]

Return the percent prediction differences.

Calculates the model factor for each data point with that point removed from the data set. Used to determine an estimated uncertainty for prediction.

Parameters:
width_data : np.ndarray

The width data points for a specific applicator, energy and ssd.

ratio_perim_area_data : np.ndarray

The perimeter/area data points for a specific applicator, energy and ssd.

factor_data : np.ndarray

The insert factor data points for a specific applicator, energy and ssd.

Returns:
percent_prediction_differences : np.ndarray

The predicted electron insert factors for each data point with that given data point removed.

pymedphys.electronfactors.visual_alignment_of_equivalent_ellipse(x, y, width, length, callback)[source]

Visually align the equivalent ellipse to the insert.