Skip to content

Commit 09a8e1c

Browse files
authored
Merge pull request #132 from ycexiao/fix-docs
chore: fix docstrings to generate API page.
2 parents e368e57 + 703f538 commit 09a8e1c

25 files changed

+288
-140
lines changed

docs/source/conf.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@
6969
# The master toctree document.
7070
master_doc = "index"
7171

72+
napoleon_custom_sections = [
73+
("Managed Parameters", "Attributes"),
74+
("Usable Metadata", "Attributes"),
75+
("General Metadata", "Attributes"),
76+
("Metadata", "Attributes"),
77+
("Properties", "Attributes"),
78+
("Operator Attributes", "Attributes"),
79+
("Managed ParameterSets", "Attributes"),
80+
]
81+
7282
# General information about the project.
7383
project = "diffpy.srfit"
7484
copyright = "%Y, The Trustees of Columbia University in the City of New York"

news/fix-docs.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
**Added:**
2+
3+
* No news added: Fix docstrings manually.
4+
5+
**Changed:**
6+
7+
* <news item>
8+
9+
**Deprecated:**
10+
11+
* <news item>
12+
13+
**Removed:**
14+
15+
* <news item>
16+
17+
**Fixed:**
18+
19+
* <news item>
20+
21+
**Security:**
22+
23+
* <news item>

src/diffpy/srfit/fitbase/fitcontribution.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ def addProfileGenerator(self, gen, name=None):
177177
A name for the calculator. If name is None (default), then
178178
the ProfileGenerator's name attribute will be used.
179179
180+
180181
Raises ValueError if the ProfileGenerator has no name.
181182
Raises ValueError if the ProfileGenerator has the same name as some
182183
other managed object.
@@ -220,6 +221,7 @@ def setEquation(self, eqstr, ns={}):
220221
A dictionary of Parameters, indexed by name, that are used
221222
in the eqstr, but not registered (default {}).
222223
224+
223225
Raises ValueError if ns uses a name that is already used for a
224226
variable.
225227
"""
@@ -266,6 +268,7 @@ def setResidualEquation(self, eqstr):
266268
used, or the chi2 residual will be used if that does not
267269
exist.
268270
271+
269272
Two residuals are preset for convenience, "chiv" and "resv".
270273
chiv is defined such that dot(chiv, chiv) = chi^2.
271274
resv is defined such that dot(resv, resv) = Rw^2.

src/diffpy/srfit/fitbase/fitrecipe.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ def popFitHook(self, fithook=None, index=-1):
187187
index
188188
Index of FitHook instance to remove (default -1).
189189
190+
190191
Raises ValueError if fithook is not None, but is not present in the
191192
sequence.
192193
Raises IndexError if the sequence is empty or index is out of range.
@@ -214,6 +215,7 @@ def addContribution(self, con, weight=1.0):
214215
con
215216
The FitContribution to be stored.
216217
218+
217219
Raises ValueError if the FitContribution has no name
218220
Raises ValueError if the FitContribution has the same name as some
219221
other managed object.
@@ -236,6 +238,7 @@ def addParameterSet(self, parset):
236238
parset
237239
The ParameterSet to be stored.
238240
241+
239242
Raises ValueError if the ParameterSet has no name.
240243
Raises ValueError if the ParameterSet has the same name as some other
241244
managed object.
@@ -506,7 +509,12 @@ def addVar(
506509
A list of tags (default []). Both tag and tags can be
507510
applied.
508511
509-
Returns the ParameterProxy (variable) for the passed Parameter.
512+
513+
Returns
514+
-------
515+
vars
516+
ParameterProxy (variable) for the passed Parameter.
517+
510518
511519
Raises ValueError if the name of the variable is already taken by
512520
another managed object.
@@ -549,6 +557,7 @@ def delVar(self, var):
549557
var
550558
A variable of the FitRecipe.
551559
560+
552561
Raises ValueError if var is not part of the FitRecipe.
553562
"""
554563

@@ -592,6 +601,7 @@ def newVar(self, name, value=None, fixed=False, tag=None, tags=[]):
592601
A list of tags (default []). Both tag and tags can be
593602
applied.
594603
604+
595605
Returns the new variable (Parameter instance).
596606
"""
597607
# This will fix the Parameter
@@ -798,6 +808,7 @@ def constrain(self, par, con, ns={}):
798808
A dictionary of Parameters, indexed by name, that are used
799809
in the eqstr, but not part of this object (default {}).
800810
811+
801812
Raises ValueError if ns uses a name that is already used for a
802813
variable.
803814
Raises ValueError if eqstr depends on a Parameter that is not part of

src/diffpy/srfit/fitbase/fitresults.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class FitResults(object):
9090
The derivatives of the constraint equations with respect to
9191
the variables. This is used internally.
9292
93+
9394
Each of these attributes, except the recipe, are created or updated when
9495
the update method is called.
9596
"""
@@ -338,7 +339,10 @@ def formatResults(self, header="", footer="", update=False):
338339
update
339340
Flag indicating whether to call update() (default False).
340341
341-
Returns a string containing the formatted results.
342+
Returns
343+
-------
344+
out
345+
a string containing the formatted results.
342346
"""
343347
if update:
344348
self.update()
@@ -515,7 +519,7 @@ def formatResults(self, header="", footer="", update=False):
515519
def printResults(self, header="", footer="", update=False):
516520
"""Format and print the results.
517521
518-
Attributes
522+
Parameters
519523
----------
520524
header
521525
A header to add to the output (default "")
@@ -533,8 +537,10 @@ def __str__(self):
533537
def saveResults(self, filename, header="", footer="", update=False):
534538
"""Format and save the results.
535539
536-
filename - Name of the save file.
540+
Parameters
537541
----------------------------------
542+
filename
543+
Name of the save file.
538544
header
539545
A header to add to the output (default "")
540546
footer

src/diffpy/srfit/fitbase/parameter.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def __init__(self, name, value=None, const=False):
7272
A flag inticating whether the Parameter is a constant (like
7373
pi).
7474
75+
7576
Raises ValueError if the name is not a valid attribute identifier
7677
"""
7778
self.constrained = False
@@ -94,7 +95,10 @@ def setValue(self, val):
9495
The upper bounds for the bounds list. If this is None
9596
(default), then the upper bound will not be alterered.
9697
97-
Returns self so that mutators can be chained.
98+
Returns
99+
-------
100+
self
101+
Returns self so that mutators can be chained.
98102
"""
99103
Argument.setValue(self, val)
100104
return self
@@ -112,7 +116,10 @@ def setConst(self, const=True, value=None):
112116
is not None, then the parameter will get a new value,
113117
constant or otherwise.
114118
115-
Returns self so that mutators can be chained.
119+
Returns
120+
-------
121+
self
122+
Returns self so that mutators can be chained.
116123
"""
117124
self.const = bool(const)
118125
if value is not None:
@@ -129,7 +136,10 @@ def boundRange(self, lb=None, ub=None):
129136
ub
130137
The upper bound for the bounds list.
131138
132-
Returns self so that mutators can be chained.
139+
Returns
140+
-------
141+
self
142+
Returns self so that mutators can be chained.
133143
"""
134144
if lb is not None:
135145
self.bounds[0] = lb
@@ -150,7 +160,10 @@ def boundWindow(self, lr=0, ur=None):
150160
value + ur. If this is None (default), then the value of the
151161
lower radius is used.
152162
153-
Returns self so that mutators can be chained.
163+
Returns
164+
-------
165+
self
166+
Returns self so that mutators can be chained.
154167
"""
155168
val = self.getValue()
156169
lb = val - lr
@@ -199,6 +212,7 @@ def __init__(self, name, par):
199212
par
200213
The Parameter this is a proxy for.
201214
215+
202216
Raises ValueError if the name is not a valid attribute identifier
203217
"""
204218
validateName(name)
@@ -312,6 +326,7 @@ def __init__(self, name, obj, getter=None, setter=None, attr=None):
312326
parameter. If attr is None (default), then both getter and
313327
setter must be specified.
314328
329+
315330
Raises ValueError if exactly one of getter or setter is not None, or if
316331
getter, setter and attr are all None.
317332
"""

src/diffpy/srfit/fitbase/parameterset.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ def addParameterSet(self, parset):
9595
parset
9696
The ParameterSet to be stored.
9797
98+
9899
Raises ValueError if the ParameterSet has no name.
99100
Raises ValueError if the ParameterSet has the same name as some other
100101
managed object.

src/diffpy/srfit/fitbase/profile.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,14 @@ def loadtxt(self, *args, **kw):
319319
Raises ValueError if the call to numpy.loadtxt returns fewer
320320
than 2 arrays.
321321
322-
Returns the x, y and dy arrays loaded from the file
322+
Returns
323+
-------
324+
x
325+
x array loaded from the file.
326+
y
327+
y array loaded from the file.
328+
dy
329+
dy array loaded from the file.
323330
"""
324331
if len(args) == 8 and not args[-1]:
325332
args = list(args)
@@ -423,9 +430,13 @@ def rebinArray(A, xold, xnew):
423430
xnew
424431
New sampling array
425432
433+
426434
This uses cubic spline interpolation.
427435
428-
Returns: A new array over the new sampling array.
436+
Returns
437+
-------
438+
array
439+
A new array over the new sampling array.
429440
"""
430441
if numpy.array_equal(xold, xnew):
431442
return A

src/diffpy/srfit/fitbase/profilegenerator.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,23 @@
2020
2121
To define a ProfileGenerator, one must implement the required Parameters
2222
and ParameterSets as well as overload the __call__ method with the
23-
calculation. A very simple example is > class
24-
Gaussian(ProfileGenerator): > > def __init__(self): > #
25-
Initialize and give this a name > ProfileGenerator.__init__(self,
26-
"g") > # Add amplitude, center and width parameters >
27-
self.newParameter("amp", 0) > self.newParameter("center", 0) >
28-
self.newParameter("width", 0) > > def __call__(self, x): > a =
29-
self.amp.getValue() > x0 = self.center.getValue() > w =
30-
self.width.getValue() > return a * exp(-0.5*((x-x0)/w)**2)
23+
calculation. A very simple example is
24+
25+
.. code:: python
26+
27+
class Gaussian(ProfileGenerator):
28+
def __init__(self):
29+
# Initialize and give this a name
30+
ProfileGenerator.__init__(self, "g")
31+
# Add amplitude, center and width parameters
32+
self.newParameter("amp", 0)
33+
self.newParameter("center", 0)
34+
self.newParameter("width", 0)
35+
def __call__(self, x):
36+
a = self.amp.getValue()
37+
x0 = self.center.getValue()
38+
w = self.width.getValue()
39+
return a * exp(-0.5*((x-x0)/w)**2)
3140
3241
More examples can be found in the example directory of the
3342
documentation.

src/diffpy/srfit/fitbase/profileparser.py

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
class ProfileParser(object):
3030
"""Class for parsing data from a or string.
3131
32-
Attributes
33-
3432
Attributes
3533
----------
3634
_format
@@ -41,20 +39,20 @@ class ProfileParser(object):
4139
The data from each bank. Each bank contains a (x, y, dx,
4240
dy)
4341
tuple:
44-
x
45-
A numpy array containing the independent
46-
variable read from the file.
47-
y
48-
A numpy array containing the profile
49-
from the file.
50-
dx
51-
A numpy array containing the uncertainty in x
52-
read from the file. This is None if the
53-
uncertainty cannot be read.
54-
dy
55-
A numpy array containing the uncertainty read
56-
from the file. This is None if the uncertainty
57-
cannot be read.
42+
x
43+
A numpy array containing the independent
44+
variable read from the file.
45+
y
46+
A numpy array containing the profile
47+
from the file.
48+
dx
49+
A numpy array containing the uncertainty in x
50+
read from the file. This is None if the
51+
uncertainty cannot be read.
52+
dy
53+
A numpy array containing the uncertainty read
54+
from the file. This is None if the uncertainty
55+
cannot be read.
5856
_x
5957
Independent variable from the chosen bank
6058
_y
@@ -66,10 +64,9 @@ class ProfileParser(object):
6664
_meta
6765
A dictionary containing metadata read from the file.
6866
69-
General Metadata
7067
71-
Attributes
72-
----------
68+
General Metadata
69+
----------------
7370
filename
7471
The name of the file from which data was parsed. This key
7572
will not exist if data was not read from file.

0 commit comments

Comments
 (0)