Skip to content

Commit 4d3d8ff

Browse files
numpydoc documentation build for ModelCluster class (#86)
1 parent df43be6 commit 4d3d8ff

File tree

1 file changed

+105
-22
lines changed

1 file changed

+105
-22
lines changed

Diff for: src/diffpy/srmise/modelcluster.py

+105-22
Original file line numberDiff line numberDiff line change
@@ -887,11 +887,27 @@ def replacepeaks(self, newpeaks, delslice=slice(0, 0)):
887887
return
888888

889889
def deletepeak(self, idx):
890-
"""Delete the peak at the given index."""
890+
"""Delete the peak at the given index.
891+
892+
Parameters
893+
----------
894+
idx : int
895+
Index of peak to delete.
896+
897+
Returns
898+
-------
899+
None
900+
"""
891901
self.replacepeaks([], slice(idx, idx + 1))
892902

893903
def estimatepeak(self):
894-
"""Attempt to add single peak to empty cluster. Return True if successful."""
904+
"""Attempt to add single peak to empty cluster. Return True if successful.
905+
906+
Returns
907+
-------
908+
bool
909+
True if successful, False otherwise.
910+
"""
895911
# STUB!!! ###
896912
# Currently only a single peak function is supported. Dynamic
897913
# selection from multiple types may require additional support
@@ -926,16 +942,26 @@ def fit(
926942
"""Perform a chi-square fit of the model to data in cluster.
927943
928944
Parameters
929-
justify - Revert to initial model (if one exists) if new model
930-
has only a single peak and the quality of the fit suggests
931-
additional peaks are present.
932-
ntrials - The maximum number of function evaluations.
933-
'0' indicates the fitting algorithm's default.
934-
fitbaseline - Whether to fit baseline along with peaks
935-
estimate - Estimate a single peak from data if model is empty.
936-
cov - Optional ModelCovariance object preserves covariance information.
937-
cov_format - Parameterization to use in cov.
945+
----------
946+
justify : bool
947+
Revert to initial model (if one exists) if new model
948+
has only a single peak and the quality of the fit suggests
949+
additional peaks are present. Default is False.
950+
ntrials : int
951+
The maximum number of function evaluations.
952+
'0' indicates the fitting algorithm's default.
953+
fitbaseline : bool
954+
Whether to fit baseline along with peaks. Default is False.
955+
estimate : bool
956+
Estimate a single peak from data if model is empty. Default is True.
957+
cov : ModelCovariance or None
958+
Optional ModelCovariance object preserves covariance information.
959+
cov_format : str
960+
Parameterization to use in cov.
938961
962+
Returns
963+
-------
964+
ModelEvaluator or None
939965
If fitting changes a model, return ModelEvaluator instance. Otherwise
940966
return None.
941967
"""
@@ -1040,10 +1066,16 @@ def contingent_fit(self, minpoints, growth_threshold):
10401066
"""Fit cluster if it has grown sufficiently large since its last fit.
10411067
10421068
Parameters
1043-
minpoints - The minimum number of points an empty cluster requires to fit.
1044-
growth_threshold - Fit non-empty model if (currentsize/oldsize) >= this value.
1069+
----------
1070+
minpoints : int
1071+
The minimum number of points an empty cluster requires to fit.
1072+
growth_threshold : float
1073+
Fit non-empty model if (currentsize/oldsize) >= this value.
10451074
1046-
Return ModelEvaluator instance if fit changed, otherwise None.
1075+
Returns
1076+
-------
1077+
ModelEvaluator or None
1078+
Return ModelEvaluator instance if fit changed, otherwise None.
10471079
"""
10481080
if self.never_fit:
10491081
return None
@@ -1115,10 +1147,16 @@ def reduce_to(self, x, y):
11151147
a maximum very close to x may prevent optimal results.
11161148
11171149
Parameters
1118-
x - Position at which to match
1119-
y - Height to match.
1150+
----------
1151+
x : array-like
1152+
The position at which to match
1153+
y : array-like
1154+
The height to match.
11201155
1121-
Return ModelEvaluator instance if fit changed, otherwise None."""
1156+
Returns
1157+
-------
1158+
ModelEvaluator or None
1159+
Return ModelEvaluator instance if fit changed, otherwise None."""
11221160
# No reduction neccessary
11231161
if self.model.value(x) < y:
11241162
logger.debug("reduce_to: No reduction necessary.")
@@ -1142,7 +1180,19 @@ def reduce_to(self, x, y):
11421180
return quality
11431181

11441182
def value(self, r=None):
1145-
"""Return value of baseline+model over cluster."""
1183+
"""Return value of baseline+model over cluster.
1184+
1185+
Parameters
1186+
----------
1187+
r : array-like, optional
1188+
value(s) over which to calculate the baseline's value.
1189+
The default is over the entire cluster.
1190+
1191+
Returns
1192+
-------
1193+
float
1194+
The value of baseline+model over cluster.
1195+
"""
11461196
if len(self.model) == 0:
11471197
return self.valuebl(r)
11481198
else:
@@ -1157,8 +1207,14 @@ def valuebl(self, r=None):
11571207
If no baseline exists its value is 0 everywhere.
11581208
11591209
Parameters
1210+
----------
11601211
r - value(s) over which to calculate the baseline's value.
11611212
The default is over the entire cluster.
1213+
1214+
Returns
1215+
-------
1216+
float
1217+
The value of baseline's value.
11621218
"""
11631219
if self.baseline is None:
11641220
if r is None:
@@ -1183,10 +1239,18 @@ def quality(self, evaluator=None, **kwds):
11831239
details see ModelEvaluator documentation.
11841240
11851241
Parameters
1186-
evaluator - A ModelEvaluator class (not instance) to use instead of default.
1242+
----------
1243+
evaluator : ModelEvaluator class or None
1244+
The ModelEvaluator class to use. Default is None.
11871245
11881246
Keywords
1247+
--------
11891248
kwds - Keyword arguments passed the the ModelEvaluator's evaluate() method.
1249+
1250+
Returns
1251+
-------
1252+
ModelEvaluator instance
1253+
The ModelEvaluator instance with quality calculated
11901254
"""
11911255
if evaluator is None:
11921256
evaluator_inst = self.error_method()
@@ -1199,7 +1263,14 @@ def plottable(self, joined=False):
11991263
"""Return sequence suitable for plotting cluster model+baseline with matplotlib.
12001264
12011265
Parameters
1202-
joined - Return sum of all peaks, or each one individually.
1266+
----------
1267+
joined : bool
1268+
Return sum of all peaks if joined is True, or each one individually if False.
1269+
1270+
Returns
1271+
-------
1272+
array-like
1273+
A sequence of plottable objects.
12031274
"""
12041275
if joined:
12051276
return [self.r_cluster, self.y_cluster, self.r_cluster, self.value()]
@@ -1212,14 +1283,26 @@ def plottable(self, joined=False):
12121283
return toreturn
12131284

12141285
def plottable_residual(self):
1215-
"""Return sequence suitable for plotting cluster residual with matplotlib."""
1286+
"""Return sequence suitable for plotting cluster residual with matplotlib.
1287+
1288+
Returns
1289+
-------
1290+
array-like
1291+
A sequence of plottable clusters and residuals.
1292+
"""
12161293
return [self.r_cluster, self.residual()]
12171294

12181295
def augment(self, source):
12191296
"""Add peaks from another ModelCluster that improve this one's quality.
12201297
12211298
Parameters
1222-
source - A ModelCluster instance
1299+
----------
1300+
source : ModelCluster instance
1301+
The ModelCluster instance to augment the model's quality.
1302+
1303+
Returns
1304+
-------
1305+
None
12231306
"""
12241307
best_model = self.model.copy()
12251308
best_qual = self.quality()

0 commit comments

Comments
 (0)