Skip to content

Commit 608a1c1

Browse files
numpydoc build for fromsequence.py (#99)
1 parent e7e53cb commit 608a1c1

File tree

1 file changed

+89
-23
lines changed

1 file changed

+89
-23
lines changed

src/diffpy/srmise/baselines/fromsequence.py

Lines changed: 89 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,37 @@ class FromSequence(BaselineFunction):
3030
interpolation domain. This baseline function permits no free parameters."""
3131

3232
def __init__(self, *args, **kwds):
33-
"""Initialize baseline corresponding to sequences x and y.
33+
"""Initialize a baseline object based on input sequences `x` and `y`.
3434
35-
Usage:
36-
FromSequence(xlist, ylist) or
37-
FromSequence(x=xlist, y=ylist)
35+
This class provides two ways to initialize: by directly providing the sequences or by
36+
specifying a file that contains the sequences.
3837
39-
FromSequence("filename") or
40-
FromSequence(file="filename")
38+
Parameters
39+
----------
40+
*args : tuple
41+
The variable length argument list. Can be used to pass `x` and `y` sequences directly.
42+
43+
**kwds : dict
44+
The arbitrary keyword arguments. Can be used to specify `x`, `y` sequences or a `file` name.
45+
46+
x : array_like, optional
47+
The sequence of x-values defining the baseline. Can be passed as a positional argument or via keyword.
48+
49+
y : array_like, optional
50+
The sequence of y-values defining the baseline. Must be provided alongside `x`.
4151
52+
file : str, optional
53+
The name of the file containing two columns: one for x-values and one for y-values.
4254
43-
Parameters/Keywords
44-
x: Sequence of x values defining baseline.
45-
y: Sequence of y values defining baseline.
46-
or
47-
file: Name of file with column of x values and column of y values.
55+
Usage
56+
-----
57+
1. Directly with sequences:
58+
- `FromSequence(xlist, ylist)`
59+
- `FromSequence(x=xlist, y=ylist)`
60+
61+
2. From a file:
62+
- `FromSequence("filename")`
63+
- `FromSequence(file="filename")`
4864
"""
4965
if len(args) == 1 and len(kwds) == 0:
5066
# load from file
@@ -88,8 +104,17 @@ def estimate_parameters(self, r, y):
88104
to estimate.
89105
90106
Parameters
91-
r: (Numpy array) Data along r from which to estimate, Ignored
92-
y: (Numpy array) Data along y from which to estimate, Ignored"""
107+
----------
108+
r : array-like
109+
The data along r from which to estimate, Ignored
110+
y : array-like
111+
The data along y from which to estimate, Ignored
112+
113+
Returns
114+
-------
115+
array-like
116+
The empty numpy array
117+
"""
93118
return np.array([])
94119

95120
def _jacobianraw(self, pars, r, free):
@@ -98,9 +123,19 @@ def _jacobianraw(self, pars, r, free):
98123
A FromSequence baseline has no parameters.
99124
100125
Parameters
101-
pars: Empty sequence
102-
r: sequence or scalar over which pars is evaluated
103-
free: Empty sequence."""
126+
----------
127+
pars :array-like
128+
The empty sequence
129+
r : array-like
130+
The sequence or scalar over which pars is evaluated
131+
free : array-like
132+
The empty sequence.
133+
134+
Returns
135+
-------
136+
array-like
137+
The empty numpy array
138+
"""
104139
if len(pars) != self.npars:
105140
emsg = "Argument pars must have " + str(self.npars) + " elements."
106141
raise ValueError(emsg)
@@ -113,12 +148,23 @@ def _transform_parametersraw(self, pars, in_format, out_format):
113148
"""Convert parameter values from in_format to out_format.
114149
115150
Parameters
116-
pars: Sequence of parameters
117-
in_format: A format defined for this class
118-
out_format: A format defined for this class
151+
----------
152+
pars : array-like
153+
The sequence of parameters
154+
in_format : str
155+
The format defined for this class
156+
out_format : str
157+
The format defined for this class
119158
120159
Defined Formats
121-
n/a, FromSequence has no parameters"""
160+
---------------
161+
n/a, FromSequence has no parameters
162+
163+
Returns
164+
-------
165+
array-like
166+
The sequence of parameters converted to out_format
167+
"""
122168
temp = np.array(pars)
123169

124170
# Convert to intermediate format "internal"
@@ -138,8 +184,17 @@ def _valueraw(self, pars, r):
138184
"""Return value of polynomial for the given parameters and r values.
139185
140186
Parameters
141-
pars: Empty sequence
142-
r: sequence or scalar over which pars is evaluated"""
187+
----------
188+
pars : array-like
189+
The empty sequence
190+
r : array-like
191+
The sequence or scalar over which pars is evaluated
192+
193+
Returns
194+
-------
195+
float
196+
The value of the polynomial for the given parameters
197+
"""
143198
if len(pars) != self.npars:
144199
emsg = "Argument pars must have " + str(self.npars) + " elements."
145200
raise ValueError(emsg)
@@ -163,7 +218,18 @@ def getmodule(self):
163218
return __name__
164219

165220
def xyrepr(self, var):
166-
"""Safe string output of x and y, compatible with eval()"""
221+
"""Safe string output of x and y, compatible with eval()
222+
223+
Parameters
224+
----------
225+
var : array-like
226+
The sequence or scalar over which to evaluate
227+
228+
Returns
229+
-------
230+
str
231+
The x and y values of the given variable
232+
"""
167233
return "[%s]" % ", ".join([repr(v) for v in var])
168234

169235
def readxy(self, filename):

0 commit comments

Comments
 (0)