Skip to content

Commit 869d74e

Browse files
committed
Minor cleaning of examples.
1 parent e748b07 commit 869d74e

5 files changed

Lines changed: 47 additions & 27 deletions

File tree

doc/examples/Ag_multiplepeaks.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
to evaluate the model on an arbitrary grid.
2020
2121
The peaks extracted by this script are equivalent to those obtained running
22-
srmise data/Ag_nyquist_qmax30.gr --range 2. 10. --bsrmise=output/Ag_singlepeak.srmise --save output/Ag_multiplepeaks.srmise --pwa output/Ag_multiplepeaks.pwa --plot
22+
srmise data/Ag_nyquist_qmax30.gr --range 2. 10. \
23+
--bsrmise=output/Ag_singlepeak.srmise \
24+
--save output/Ag_multiplepeaks.srmise \
25+
--pwa output/Ag_multiplepeaks.pwa --plot
2326
at the command line.
2427
"""
2528

@@ -91,19 +94,23 @@ def run(plot=True):
9194
position = "%f +/- %f" %cov.get((0,0))
9295
width = "%f +/- %f" %cov.get((0,1))
9396
area = "%f +/- %f" %cov.get((0,2))
94-
print "Nearest-neighbor peak: position=%s, width=%s, area=%s" %(position, width, area)
95-
print "Covariance of width and area for nearest-neighbor peak: ", cov.getcovariance((0,1),(0,2))
97+
print "Nearest-neighbor peak: position=%s, width=%s, area=%s" \
98+
%(position, width, area)
99+
print "Covariance of width and area for nearest-neighbor peak: ", \
100+
cov.getcovariance((0,1),(0,2))
96101

97102
# It is also possible to iterate over peaks directly without using indices.
98103
# For example, to calculate the total peak area:
99104
total_area = 0
100105
for peak in cov.model[:-1]: # Exclude last element, which is the baseline.
101-
total_area += peak["area"] # The "position" and "width" keywords are also
102-
# available for the GaussianOverR peak function.
106+
total_area += peak["area"] # The "position" and "width" keywords are
107+
# also available for the GaussianOverR peak
108+
# function.
103109
print "Total area of extracted peaks: ", total_area
104110

105111
# Baseline parameters.
106-
print "The linear baseline B(r)=%f*r + %f" % tuple(par for par in cov.model[-1])
112+
print "The linear baseline B(r)=%f*r + %f" \
113+
% tuple(par for par in cov.model[-1])
107114

108115
# Highly-correlated parameters can indicate difficulties constraining the
109116
# fit. This function lists all pairs of parameters with an absolute value

doc/examples/Ag_singlepeak.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,17 @@
1919
parameters, running peak extraction, and saving the results.
2020
2121
This script is equivalent to running
22-
srmise data/Ag_nyquist_qmax30.gr --range 2. 3.5 --baseline=Polynomial(degree=1) --save output/Ag_singlepeak.srmise --pwa output/Ag_singlepeak.pwa --plot
22+
srmise data/Ag_nyquist_qmax30.gr --range 2. 3.5 \
23+
--baseline=Polynomial(degree=1) --save output/Ag_singlepeak.srmise \
24+
--pwa output/Ag_singlepeak.pwa --plot
2325
at the command line.
2426
"""
2527

2628
import matplotlib.pyplot as plt
2729

2830
from diffpy.srmise import PDFPeakExtraction
2931
from diffpy.srmise.baselines import Polynomial
32+
from diffpy.srmise.applications.plot import makeplot
3033

3134
def run(plot=True):
3235

@@ -77,10 +80,9 @@ def run(plot=True):
7780
# Display plot of extracted peak. It is also possible to plot an existing
7881
# .srmise file from the command line using
7982
# srmise output/Ag_singlepeak.srmise --no-extract --plot
80-
# or, for a somewhat prettier plot,
81-
# srmiseplot output/Ag_singlepeak.srmise --show
83+
# For additional plotting options, run "srmiseplot --help".
8284
if plot:
83-
ppe.plot()
85+
makeplot(ppe)
8486
plt.show()
8587

8688
if __name__ == '__main__':

doc/examples/C60_multimodelanalysis.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,20 @@ def run(plot=True):
9696
for m in bm:
9797
filename = "output/C60_multimodel"+str(m)+".pwa"
9898
cls = ms.classes_idx[m] # Get index of class to which model belongs.
99-
bestdgs = ms.modelbestdgs(m) # Get the uncertainties where this model has greatest Akaike probability.
100-
maxprob = np.max([ms.classprobs[dg][cls] for dg in bestdgs]) # Get the model's greatest Akaike probability.
99+
bestdgs = ms.modelbestdgs(m) # Get the uncertainties where this model
100+
# has greatest Akaike probability.
101+
102+
# Get the model's greatest Akaike probability.
103+
maxprob = np.max([ms.classprobs[dg][cls] for dg in bestdgs])
101104

102105
msg = ["This is a best model determined by MultiModelSelection",
103106
"Model: %i (of %i)",
104107
"Class: %i (of %i, tolerance=%f)",
105108
"Best model for uncertainties: %f-%f",
106109
"Max Akaike probability: %g"]
107-
msg = "\n".join(msg) %(m, len(ms.classes_idx), cls, len(ms.classes), tolerance, np.min(bestdgs), np.max(bestdgs), maxprob)
110+
msg = "\n".join(msg) %(m, len(ms.classes_idx), cls, len(ms.classes),
111+
tolerance, np.min(bestdgs), np.max(bestdgs),
112+
maxprob)
108113
ms.setcurrent(m) # Make this the active model.
109114
ms.ppe.writepwa(filename, msg)
110115

@@ -140,7 +145,7 @@ def run(plot=True):
140145
ms.setcurrent(bm)
141146
figdict = makeplot(ms, dcif)
142147
# Uncomment to save figure.
143-
#plt.savefig("output/C60_multimodel"+str(bm)+".png", format="png")
148+
# plt.savefig("output/C60_multimodel"+str(bm)+".png", format="png")
144149

145150

146151
if plot:

doc/examples/TiO2_initialpeaks.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# See LICENSE.txt for license information.
1111
#
1212
##############################################################################
13-
"""Example of peak extraction demonstrating non-default values for many extraction parameters.
13+
"""Peak extraction with non-default values for many extraction parameters.
1414
1515
This example shows how to specify initial peaks in order to guide the results of
1616
peak extraction.
@@ -61,9 +61,11 @@ def run(plot=True):
6161
# terms of position, width (fwhm), and area, and it is important to specify
6262
# that format is being used so they are correctly changed into the
6363
# internal parameterization.
64-
explicit_guess = [[6.25, .3, 3], [6.5, .3, 3], [6.85, 0.3, 10], [7.1, 0.3, 10], [7.45, 0.3, 20]]
65-
peak_function = ppe.pf[0]
66-
explicit_peaks = Peaks([peak_function.actualize(e, removable=False, in_format="pwa") for e in explicit_guess])
64+
explicit_guess = [[6.25, .3, 3], [6.5, .3, 3], [6.85, 0.3, 10],
65+
[7.1, 0.3, 10], [7.45, 0.3, 20]]
66+
pf = ppe.pf[0]
67+
explicit_peaks = Peaks([pf.actualize(e, removable=False, in_format="pwa") \
68+
for e in explicit_guess])
6769
ppe.addpeaks(explicit_peaks)
6870
if plot:
6971
plt.figure(2)

doc/examples/TiO2_parameterdetail.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,18 @@
1010
# See LICENSE.txt for license information.
1111
#
1212
##############################################################################
13-
"""Example of peak extraction demonstrating non-default values for many extraction parameters.
13+
"""Peak extraction with non-default values for many extraction parameters.
1414
1515
This example shows how to extract peaks from a crystalline PDF with unreliable
1616
uncertainties, and shows how various extraction variables may be set. In
17-
particular, choosing a peak function and defining baseline parameters explicitly.
17+
particular, choosing a peak function and defining baseline parameters
18+
explicitly.
1819
1920
This script is equivalent to running
20-
srmise data/TiO2_fine_qmax26.gr --range 1.5 10. --dg 0.35 --qmax 26 --resolution .05 --bpoly1=-0.65 0c --save output/TiO2_parameterdetail.srmise --pwa output/TiO2_parameterdetail.pwa --plot
21+
srmise data/TiO2_fine_qmax26.gr --range 1.5 10. --dg 0.35 --qmax 26 \
22+
--resolution .05 --bpoly1=-0.65 0c \
23+
--save output/TiO2_parameterdetail.srmise \
24+
--pwa output/TiO2_parameterdetail.pwa --plot
2125
at the command line.
2226
"""
2327

@@ -26,6 +30,7 @@
2630
from diffpy.srmise import PDFPeakExtraction
2731
from diffpy.srmise.baselines import Polynomial
2832
from diffpy.srmise.peaks import GaussianOverR
33+
from diffpy.srmise.applications.plot import makeplot
2934

3035
def run(plot=True):
3136

@@ -79,7 +84,8 @@ def run(plot=True):
7984
blfunc = Polynomial(degree=1)
8085
slope = -.65 # Play with this value!
8186
y_intercept = 0.
82-
kwds["baseline"] = blfunc.actualize([slope, y_intercept], free=[True, False])
87+
kwds["baseline"] = blfunc.actualize([slope, y_intercept],
88+
free=[True, False])
8389

8490
# The pf (peakfunction) parameter allows setting the shape of peaks to be
8591
# extracted. Termination effects are added automatically to the peak
@@ -102,8 +108,8 @@ def run(plot=True):
102108
# If the PDF does not report qmax, diffpy.srmise attempts to estimate it
103109
# directly from the data. This estimate can also be used by setting qmax
104110
# to "automatic". An infinite qmax can be specified by setting qmax to 0,
105-
# In that case the Nyquist rate is 0 (infinite resolution), and diffpy.srmise
106-
# does not consider Nyquist sampling or termination effects.
111+
# In that case the Nyquist rate is 0 (infinite resolution), and
112+
# diffpy.srmise does not consider Nyquist sampling or termination effects.
107113
kwds["qmax"] = 26.0
108114

109115
# This parameter governs whether diffpy.srmise attempts to find a model
@@ -160,10 +166,8 @@ def run(plot=True):
160166
# Display plot of extracted peak. It is also possible to plot an existing
161167
# .srmise file from the command line using
162168
# srmise output/TiO2_parameterdetail.srmise --no-extract --plot
163-
# or, for a somewhat prettier plot,
164-
# srmiseplot output/TiO2_parameterdetail.srmise --show
165169
if plot:
166-
ppe.plot()
170+
makeplot(ppe)
167171
plt.show()
168172

169173
if __name__ == '__main__':

0 commit comments

Comments
 (0)