Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 11 additions & 20 deletions src/sas/sascalc/invariant/invariant.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,14 @@ class of type Transform that performs operations related to guinier
function
"""

def __init__(self, scale=1, radius=60):
def __init__(self, scale=1, Rg_squared=3600):
Transform.__init__(self)
self.scale = scale
self.radius = radius
self.Rg_squared = Rg_squared
## Uncertainty of scale parameter
self.dscale = 0
## Unvertainty of radius parameter
self.dradius = 0
## Uncertainty of Rg squared parameter
self.dRg_squared = 0

def linearize_q_value(self, value):
"""
Expand All @@ -137,18 +137,12 @@ def extract_model_parameters(self, constant, slope, dconstant=0, dslope=0):
assign new value to the scale and the radius
"""
self.scale = math.exp(constant)
if slope > 0:
slope = 0.0
self.radius = math.sqrt(-3 * slope)
self.Rg_squared = -3.0 * slope
# Errors
self.dscale = math.exp(constant) * dconstant
if slope == 0.0:
n_zero = -1.0e-24
self.dradius = -3.0 / 2.0 / math.sqrt(-3 * n_zero) * dslope
else:
self.dradius = -3.0 / 2.0 / math.sqrt(-3 * slope) * dslope
self.dRg_squared = 3.0 * dslope

return [self.radius, self.scale], [self.dradius, self.dscale]
return [self.Rg_squared, self.scale], [self.dRg_squared, self.dscale]

def evaluate_model(self, x):
r"""
Expand All @@ -165,10 +159,10 @@ def evaluate_model_errors(self, x):

:param x: array of q-values
"""
p1 = np.array([self.dscale * math.exp(-((self.radius * q) ** 2 / 3)) for q in x])
p1 = np.array([self.dscale * math.exp(-(self.Rg_squared * q**2 / 3.0)) for q in x])
p2 = np.array(
[
self.scale * math.exp(-((self.radius * q) ** 2 / 3)) * (-(q**2 / 3)) * 2 * self.radius * self.dradius
self.scale * math.exp(-(self.Rg_squared * q**2 / 3.0)) * (-(q**2 / 3.0)) * self.dRg_squared
for q in x
]
)
Expand All @@ -185,16 +179,13 @@ def _guinier(self, x):

Also uses:
- self.scale: $s$, the scale value
- self.radius: $r$, the guinier radius value
- self.Rg_squared: $r$, the guinier radius value squared

:return: F(x)
"""
# transform the radius of coming from the inverse guinier function to a
# a radius of a guinier function
if self.radius <= 0:
msg = "Rg expected positive value, but got %s" % self.radius
raise ValueError(msg)
value = np.array([math.exp(-((self.radius * i) ** 2 / 3)) for i in x])
value = np.array([math.exp(-(self.Rg_squared * i**2 / 3.0)) for i in x])
return self.scale * value


Expand Down
8 changes: 4 additions & 4 deletions test/sasinvariant/utest_data_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,8 @@ def test_low_q(self):
power=inv._low_extrapolation_power)
self.assertAlmostEqual(self.scale,
inv._low_extrapolation_function.scale, 6)
self.assertAlmostEqual(self.rg,
inv._low_extrapolation_function.radius, 6)
self.assertAlmostEqual(self.rg**2,
inv._low_extrapolation_function.Rg_squared, 6)


class TestPowerLawExtrapolation(unittest.TestCase):
Expand Down Expand Up @@ -573,8 +573,8 @@ def test_low_q(self):
power=inv._low_extrapolation_power)
self.assertAlmostEqual(self.scale,
inv._low_extrapolation_function.scale, 6)
self.assertAlmostEqual(self.rg,
inv._low_extrapolation_function.radius, 6)
self.assertAlmostEqual(self.rg**2,
inv._low_extrapolation_function.Rg_squared, 6)

qstar = inv.get_qstar(extrapolation='low')
test_y = inv._low_extrapolation_function.evaluate_model(x=self.data.x)
Expand Down