Skip to content

Commit 03b18c1

Browse files
numpydoc build for gaussianoverr.py (#91)
* numpydoc build for gaussianoverr.py * [pre-commit.ci] auto fixes from pre-commit hooks * fix pre-commit --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 4cb462e commit 03b18c1

File tree

1 file changed

+107
-39
lines changed

1 file changed

+107
-39
lines changed

Diff for: src/diffpy/srmise/peaks/gaussianoverr.py

+107-39
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,19 @@ def estimate_parameters(self, r, y):
7878
"""Estimate parameters for single peak from data provided.
7979
8080
Parameters
81-
r: (Numpy array) Data along r from which to estimate
82-
y: (Numpy array) Data along y from which to estimate
83-
84-
Returns Numpy array of parameters in the default internal format.
85-
Raises SrMiseEstimationError if parameters cannot be estimated for any
86-
reason."""
81+
----------
82+
r : array-like
83+
Data along r from which to estimate
84+
y : array-like
85+
Data along y from which to estimate
86+
87+
Returns
88+
-------
89+
array-like
90+
Numpy array of parameters in the default internal format.
91+
Raises SrMiseEstimationError if parameters cannot be estimated for any
92+
reason.
93+
"""
8794
if len(r) != len(y):
8895
emsg = "Arrays r, y must have equal length."
8996
raise SrMiseEstimationError(emsg)
@@ -154,9 +161,19 @@ def scale_at(self, pars, x, scale):
154161
SrMiseScalingError if the parameters cannot be scaled.
155162
156163
Parameters
157-
pars: (Array) Parameters corresponding to a single peak
158-
x: (float) Position of the border
159-
scale: (float > 0) Size of scaling at x."""
164+
----------
165+
pars : array-like
166+
Parameters corresponding to a single peak
167+
x : float
168+
Position of the border
169+
scale : float
170+
Size of scaling at x. Must be positive.
171+
172+
Returns
173+
-------
174+
array-like
175+
The sequence of scaled parameters.
176+
"""
160177
if scale <= 0:
161178
emsg = "".join(["Cannot scale by ", str(scale), "."])
162179
raise SrMiseScalingError(emsg)
@@ -204,19 +221,37 @@ def scale_at(self, pars, x, scale):
204221
return tpars
205222

206223
def _jacobianraw(self, pars, r, free):
207-
"""Return Jacobian of width-limited Gaussian/r.
208-
209-
pars: Sequence of parameters for a single width-limited Gaussian
210-
pars[0]=peak position
211-
pars[1]=effective width, up to fwhm=maxwidth as par[1] -> inf.
212-
=tan(pi/2*fwhm/maxwidth)
213-
pars[2]=multiplicative constant a, equivalent to peak area
214-
r: sequence or scalar over which pars is evaluated
215-
free: sequence of booleans which determines which derivatives are
216-
needed. True for evaluation, False for no evaluation.
224+
"""
225+
Compute the Jacobian of a width-limited Gaussian/r function.
226+
227+
This method calculates the partial derivatives of a Gaussian/r function
228+
with respect to its parameters, considering a limiting width. The Gaussian/r's
229+
width approaches its maximum FWHM (maxwidth) as the effective width parameter
230+
(`pars[1]`) tends to infinity.
231+
232+
Parameters
233+
----------
234+
pars : array-like
235+
Sequence of parameters defining a single width-limited Gaussian:
236+
- pars[0]: Peak position.
237+
- pars[1]: Effective width, which scales up to the full width at half maximum (fwhm=maxwidth) as
238+
`pars[1]` approaches infinity. It is mathematically represented as `tan(pi/2 * fwhm / maxwidth)`.
239+
- pars[2]: Multiplicative constant 'a', equivalent to the peak area.
240+
r : array-like or scalar
241+
The sequence or scalar over which the Gaussian parameters `pars` are evaluated.
242+
free : array-like of bools
243+
Determines which derivatives need to be computed. A `True` value indicates that the derivative
244+
with respect to the corresponding parameter in `pars` should be calculated;
245+
`False` indicates no evaluation is needed.
246+
Returns
247+
-------
248+
jacobian : ndarray
249+
The Jacobian matrix, where each column corresponds to the derivative of the Gaussian/r function
250+
with respect to one of the input parameters `pars`, evaluated at points `r`.
251+
Only columns corresponding to `True` values in `free` are computed.
217252
"""
218253
jacobian = [None, None, None]
219-
if (free is False).sum() == self.npars:
254+
if np.sum(np.logical_not(free)) == self.npars:
220255
return jacobian
221256

222257
# Optimization
@@ -304,18 +339,28 @@ def _transform_derivativesraw(self, pars, in_format, out_format):
304339
def _transform_parametersraw(self, pars, in_format, out_format):
305340
"""Convert parameter values from in_format to out_format.
306341
307-
Also restores parameters to a preferred range if it permits multiple
308-
values that correspond to the same physical result.
342+
This method convert parameter values from one format to another and optionally restore
343+
them to a preferred range if the target format supports multiple values
344+
representing the same physical result.
309345
310346
Parameters
311-
pars: Sequence of parameters
312-
in_format: A format defined for this class
313-
out_format: A format defined for this class
314-
315-
Defined Formats
316-
internal: [position, parameterized width-squared, area]
317-
pwa: [position, full width at half maximum, area]
318-
mu_sigma_area: [mu, sigma, area]
347+
----------
348+
pars : array_like
349+
Sequence of parameters in the `in_format`.
350+
in_format : str, optional
351+
The input format of the parameters. Supported formats are:
352+
- 'internal': [position, parameterized width-squared, area]
353+
- 'pwa': [position, full width at half maximum, area]
354+
- 'mu_sigma_area': [mu, sigma, area]
355+
Default is 'internal'.
356+
out_format : str, optional
357+
The desired output format of the parameters. Same options as `in_format`.
358+
Default is 'pwa'.
359+
360+
Returns
361+
-------
362+
array_like
363+
The transformed parameters in the `out_format`.
319364
"""
320365
temp = np.array(pars)
321366

@@ -367,14 +412,27 @@ def _transform_parametersraw(self, pars, in_format, out_format):
367412
return temp
368413

369414
def _valueraw(self, pars, r):
370-
"""Return value of width-limited Gaussian/r for the given parameters and r values.
371-
372-
pars: Sequence of parameters for a single width-limited Gaussian
373-
pars[0]=peak position
374-
pars[1]=effective width, up to fwhm=maxwidth as par[1] -> inf.
375-
=tan(pi/2*fwhm/maxwidth)
376-
pars[2]=multiplicative constant a, equivalent to peak area
377-
r: sequence or scalar over which pars is evaluated
415+
"""Compute the value of a width-limited Gaussian/r for the specified parameters at given radial distances.
416+
417+
This function calculates the value of a Gaussian/r distribution,
418+
where its effective width is constrained and related to the maxwidth. As `pars[1]` approaches infinity,
419+
the effective width reaches `FWHM` (maxwidth). The returned values represent the Gaussian's intensity
420+
across the provided radial coordinates `r`.
421+
422+
Parameters
423+
----------
424+
pars : array_like
425+
A sequence of parameters defining the Gaussian shape:
426+
- pars[0]: Peak position of the Gaussian.
427+
- pars[1]: Effective width factor, approaching infinity implies the FWHM equals `maxwidth`.
428+
It is related to the FWHM by `tan(pi/2*FWHM/maxwidth)`.
429+
- pars[2]: Multiplicative constant 'a', equivalent to the peak area of the Gaussian when integrated.
430+
r : array_like or float
431+
Radial distances or a single value at which the Gaussian is to be evaluated.
432+
Returns
433+
-------
434+
float
435+
The value of a width-limited Gaussian for the specified parameters at given radial distances.
378436
"""
379437
return (
380438
np.abs(pars[2])
@@ -388,7 +446,17 @@ def getmodule(self):
388446
# Other methods ####
389447

390448
def max(self, pars):
391-
"""Return position and height of the peak maximum."""
449+
"""Return position and height of the peak maximum.
450+
451+
Parameters
452+
----------
453+
pars : array_like
454+
The sequence of parameters defining the Gaussian shape.
455+
456+
Returns
457+
-------
458+
array-like
459+
The sequence of position and height of the peak maximum."""
392460
# TODO: Reconsider this behavior
393461
if len(pars) == 0:
394462
return None

0 commit comments

Comments
 (0)