Skip to content

Commit

Permalink
add parameter formatting and units
Browse files Browse the repository at this point in the history
  • Loading branch information
alanphys committed Feb 25, 2021
1 parent 252a524 commit ec69253
Show file tree
Hide file tree
Showing 4 changed files with 182 additions and 119 deletions.
33 changes: 24 additions & 9 deletions pylinac/core/hillreg.py
@@ -1,20 +1,35 @@
"""Perform non-linear regression using a Hill function"""
import numpy as np
import math
from scipy.optimize import curve_fit
from scipy.optimize import differential_evolution
import warnings


def hill_reg(xData: np.ndarray, yData: np.ndarray):
def hill_func(x, a, b, c, d): # Hill function
""" Calculates the Hill function at x
a: sigmoid low level
b: sigmoid high level
c: approximate inflection point
d: slope of the sigmoid
"""
return a + (b - a) / (1.0 + (c / x) ** d)


def inv_hill_func(y, a, b, c, d): # Inverse Hill function
""" Calculates the inverse Hill function at y
a: sigmoid low level
b: sigmoid high level
c: approximate inflection point
d: slope of the sigmoid
"""
if (y > min(a, b)) and (y < max(a, b)) and (d != 0):
return c*math.pow((y - a)/(b - y), 1/d)
else:
return 0

def hill_func(x, a, b, c, d): # Hill function
"""
a: sigmoid low level
b: sigmoid high level
c: approximate inflection point
d: slope of the sigmoid
"""
return a + (b-a)/(1.0 + (c/x)**d)

def hill_reg(xData: np.ndarray, yData: np.ndarray):

# function for genetic algorithm to minimize (sum of squared error)
def sumOfSquaredError(parameterTuple):
Expand Down
19 changes: 19 additions & 0 deletions pylinac/core/profile.py
Expand Up @@ -323,6 +323,25 @@ def penumbra_width(self, lower: int=20, upper: int=80) -> Tuple[float, float]:
right_penum = np.abs(upper_peak_props['right_ips'][0] - lower_peak_props['right_ips'][0])
return left_penum, right_penum

@argue.options(side=('left', 'right'))
def penumbra_values(self, side: str):
cax_idx = self.center()[0]
if side == 'left':
left_edge_idx = np.argmax(np.diff(self.values[:int(cax_idx)]))
end_idx = int(left_edge_idx * 2) # take profile values around left edge
if end_idx > cax_idx:
end_idx = round(cax_idx)
values = self.values[:end_idx]
indices = self._indices[:end_idx]
else:
right_edge_idx = np.argmin(np.diff(self.values[int(cax_idx):])) + round(cax_idx)
start_idx = int(right_edge_idx * 2 - self.values.shape[0]) # take profile values around right edge
if start_idx < cax_idx:
start_idx = round(cax_idx)
values = self.values[start_idx:]
indices = self._indices[start_idx:]
return indices, values

@argue.bounds(field_width=(0, 1))
def field_values(self, field_width: float=0.8) -> np.ndarray:
"""Return a subarray of the values of the profile for the given field width.
Expand Down

0 comments on commit ec69253

Please sign in to comment.