replace values with np.nan if error
# limitations under the License.
+from pymedphys._imports import numpy as np
from pymedphys._imports import pandas as pd
from pymedphys._imports import plt, pylinac
from pymedphys._imports import streamlit as st
@@ -227,6 +228,11 @@ def _calculate_wlutz(image_path, algorithm, bb_diameter, edge_lengths, penumbra)
image_path, bb_diameter, edge_lengths, penumbra
)
+ if wlutz_input_parameters["field_rotation"] == np.nan:
+ field_centre = [np.nan, np.nan]
+ field_rotation = np.nan
+ bb_centre = [np.nan, np.nan]
+ else:
calculate_function = ALGORITHM_FUNCTION_MAP[algorithm]
field_centre, field_rotation, bb_centre = calculate_function(
**wlutz_input_parameters
@@ -263,6 +269,8 @@ def _pylinac_wlutz_calculate(
field, edge_lengths, penumbra, pymedphys_field_centre, field_rotation, **_
):
version_to_use = pylinac.__version__
+
+ try:
pylinac_results = pmp_pylinac_api.run_wlutz(
field,
edge_lengths,
@@ -278,6 +286,10 @@ def _pylinac_wlutz_calculate(
field_centre = pylinac_results[version_to_use]["field_centre"]
bb_centre = pylinac_results[version_to_use]["bb_centre"]
+ except ValueError:
+ field_centre = [np.nan, np.nan]
+ bb_centre = [np.nan, np.nan]
+
return field_centre, field_rotation, bb_centre
@@ -291,9 +303,14 @@ ALGORITHM_FUNCTION_MAP = {
def _get_pymedphys_field_centre_and_rotation(image_path, edge_lengths, penumbra):
x, y, image, field = _load_image_field_interpolator(image_path)
initial_centre = findfield.get_centre_of_mass(x, y, image)
+
+ try:
field_centre, field_rotation = findfield.field_centre_and_rotation_refining(
field, edge_lengths, penumbra, initial_centre, pylinac_tol=None
)
+ except ValueError:
+ field_centre = [np.nan, np.nan]
+ field_rotation = np.nan
return field_centre, field_rotation
