Skip to content

numpydoc build for nanospherical.py #98

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 23, 2024
Merged
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
122 changes: 94 additions & 28 deletions src/diffpy/srmise/baselines/nanospherical.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ def __init__(self, Cache=None):
"""Initialize a spherical nanoparticle baseline.

Parameters
Cache - A class (not instance) which implements caching of BaseFunction
evaluations.
----------
Cache : class
THe class (not instance) which implements caching of BaseFunction
evaluations.
"""
# Define parameterdict
parameterdict = {"scale": 0, "radius": 1}
Expand Down Expand Up @@ -74,12 +76,21 @@ def _jacobianraw(self, pars, r, free):
"""Return the Jacobian of the spherical baseline.

Parameters
pars - Sequence of parameters for a spherical baseline
pars[0] = scale
pars[1] = radius
r - sequence or scalar over which pars is evaluated.
free - sequence of booleans which determines which derivatives are
needed. True for evaluation, False for no evaluation.
----------
pars : array-like
The Sequence of parameters for a spherical baseline
pars[0] = scale
pars[1] = radius
r : array-like
The sequence or scalar over which pars is evaluated.
free : bool
The sequence of booleans which determines which derivatives are
needed. True for evaluation, False for no evaluation.

Returns
-------
array-like
The Jacobian of the nanospherical baseline.
"""
if len(pars) != self.npars:
emsg = "Argument pars must have " + str(self.npars) + " elements."
Expand Down Expand Up @@ -116,10 +127,18 @@ def _jacobianrawscale(self, pars, r):
"""Return partial Jacobian wrt scale without bounds checking.

Parameters
pars - Sequence of parameters for a spherical baseline
pars[0] = scale
pars[1] = radius
r - sequence or scalar over which pars is evaluated.
----------
pars : array-like
The sequence of parameters for a spherical baseline
pars[0] = scale
pars[1] = radius
r : array-like
The sequence or scalar over which pars is evaluated.

Returns
-------
array-like
The partial Jacobian of the nanoparticle baseline wrt scale without bounds checking.
"""
np.abs(pars[0])
R = np.abs(pars[1])
Expand All @@ -134,10 +153,18 @@ def _jacobianrawradius(self, pars, r):
"""Return partial Jacobian wrt radius without bounds checking.

Parameters
pars - Sequence of parameters for a spherical baseline
pars[0] = scale
pars[1] = radius
r - sequence or scalar over which pars is evaluated.
----------
pars : array-like
The Sequence of parameters for a spherical baseline
pars[0] = scale
pars[1] = radius
r : array-like
The sequence or scalar over which pars is evaluated.

Returns
-------
array-like
The partial Jacobian of the nanoparticle baseline wrt radius without bounds checking.
"""
s = np.abs(pars[0])
R = np.abs(pars[1])
Expand All @@ -150,12 +177,22 @@ def _transform_parametersraw(self, pars, in_format, out_format):
"""Convert parameter values from in_format to out_format.

Parameters
pars - Sequence of parameters
in_format - A format defined for this class
out_format - A format defined for this class
----------
pars : array-like
The sequence of parameters
in_format : str
The format defined for this class
out_format : str
The format defined for this class

Defined Formats
---------------
internal - [scale, radius]

Returns
-------
array-like
The transformed parameter values with out_format.
"""
temp = np.array(pars)

Expand All @@ -180,10 +217,18 @@ def _valueraw(self, pars, r):
Outside the interval [0, radius] the baseline is 0.

Parameters
pars - Sequence of parameters for a spherical baseline
pars[0] = scale
pars[1] = radius
r - sequence or scalar over which pars is evaluated.
----------
pars : array-like
The sequence of parameters for a spherical baseline
pars[0] = scale
pars[1] = radius
r : array-like
The sequence or scalar over which pars is evaluated.

Returns
-------
float
The value of the spherical baseline.
"""
if len(pars) != self.npars:
emsg = "Argument pars must have " + str(self.npars) + " elements."
Expand All @@ -203,18 +248,39 @@ def _valueraw2(self, pars, r):
"""Return value of spherical baseline without bounds checking for given parameters and r values.

Parameters
pars - Sequence of parameters for a spherical baseline
pars[0] = scale
pars[1] = radius
r - sequence or scalar over which pars is evaluated.
----------
pars : array-like
The sequence of parameters for a spherical baseline
pars[0] = scale
pars[1] = radius
r : array-like
The sequence or scalar over which pars is evaluated.

Returns
-------
float
The value of spherical baseline without bounds checking for given parameters and r values
"""
s = np.abs(pars[0])
R = np.abs(pars[1])
rdivR = r / R
return -s * r * (1 - (3.0 / 4.0) * rdivR + (1.0 / 16.0) * rdivR**3)

def _getdomain(self, pars, r):
"""Return slice object for which r > 0 and r < twice the radius"""
"""Return slice object for which r > 0 and r < twice the radius

Parameters
----------
pars : array-like
The sequence of parameters for a spherical baseline
r : array-like
The sequence or scalar over which pars is evaluated.

Returns
-------
slice object
The slice object for which r > 0 and r < twice the radius
"""
low = r.searchsorted(0.0, side="right")
high = r.searchsorted(2.0 * pars[1], side="left")
return slice(low, high)
Expand Down
Loading