Skip to content

Commit 253b118

Browse files
committed
Modifying demos (should have done this before migration to SrFit repo
1 parent a1daade commit 253b118

File tree

2 files changed

+76
-15
lines changed

2 files changed

+76
-15
lines changed

demo/coscript.py

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,26 @@ def runfit(fit):
1010
import difscript
1111

1212
# Do the rietveld refinement first (it's more tempermental)
13-
difscript.runfit(fit)
13+
difscript.initialize(fit)
1414
difcomp = fit.getComponent(0)
15+
# Let's see where we're starting
16+
if 1:
17+
calc = difcomp.getCalculator()
18+
calc._prepareSrRietUI()
19+
calc.calculate()
20+
from pylab import plot, show, title, xlabel, ylabel, legend
21+
x0,y0,u0 = difcomp.getFitDataArrays()
22+
x1,y1 = difcomp.getFitArrays()
23+
dy = y0-y1
24+
dy -= 1.5*( abs(min(dy)) + abs(min(y0)))
25+
plot(x1, y0, 'bo', x1, y1, 'r-', x1, dy, 'g--')
26+
title("Initial Rietveld configuration")
27+
xlabel("Q (A^-1)")
28+
ylabel("I (arb.)")
29+
legend(("data", "fit (R = %f)"%difcomp.getR(), "difference"))
30+
show()
31+
print "Rietveld fit"
32+
difscript.runfit(fit)
1533

1634
###############################################################################
1735
# PDF #
@@ -65,15 +83,66 @@ def runfit(fit):
6583
pdfpha.getAtom(2).x = pdfpha.getAtom(2).z = 0.5
6684
pdfpha.getAtom(3).x = pdfpha.getAtom(3).y = 0.5
6785

86+
# Check where we're at
87+
if 1:
88+
calc = pdfcomp.getCalculator()
89+
calc.calculate()
90+
from pylab import plot, show, title, xlabel, ylabel, legend
91+
x0,y0,u0 = pdfcomp.getFitDataArrays()
92+
x1,y1 = pdfcomp.getFitArrays()
93+
dy = y0-y1
94+
dy -= 1.5*( abs(min(dy)) + abs(min(y0)))
95+
plot(x1, y0, 'bo', x1, y1, 'r-', x1, dy, 'g--')
96+
title("Initial PDF configuration")
97+
xlabel("r (A)")
98+
ylabel("G (A^-2)")
99+
legend(("data", "fit (R = %f)"%pdfcomp.getR(), "difference"))
100+
show()
101+
raw_input("Press any key to continue ... ")
102+
68103
# Fitting
69104
fit.setWeight(pdfcomp, 0.5)
70105
fit.setWeight(difcomp, 0.5)
106+
print "Rietveld+PDF fit"
71107
fit.refine()
72108
fit.printResults()
73109
fit.saveResults("ni.co.res")
74110
pdfcomp.saveFitArrays("ni.co.pdf.fit")
75111
difcomp.saveFitArrays("ni.co.dif.fit")
76112

113+
# Show final Rietveld fit
114+
if 1:
115+
from pylab import plot, show, title, xlabel, ylabel, legend
116+
x0,y0,u0 = difcomp.getFitDataArrays()
117+
x1,y1 = difcomp.getFitArrays()
118+
dy = y0-y1
119+
dy -= 1.5*( abs(min(dy)) + abs(min(y0)))
120+
plot(x1, y0, 'bo', x1, y1, 'r-', x1, dy, 'g--')
121+
title("Rietveld fit from co-refinement")
122+
xlabel("Q (A^-1)")
123+
ylabel("I (arb.)")
124+
legend(("data", "fit (R = %f)"%difcomp.getR(), "difference"))
125+
show()
126+
raw_input("Press any key to continue ... ")
127+
128+
129+
# Show final PDF fit
130+
if 1:
131+
calc = pdfcomp.getCalculator()
132+
calc.calculate()
133+
from pylab import plot, show, title, xlabel, ylabel, legend
134+
x0,y0,u0 = pdfcomp.getFitDataArrays()
135+
x1,y1 = pdfcomp.getFitArrays()
136+
dy = y0-y1
137+
dy -= 1.5*( abs(min(dy)) + abs(min(y0)))
138+
plot(x1, y0, 'bo', x1, y1, 'r-', x1, dy, 'g--')
139+
title("PDF fit from co-refinement")
140+
xlabel("r (A)")
141+
ylabel("G (A^-2)")
142+
legend(("data", "fit (R = %f)"%pdfcomp.getR(), "difference"))
143+
show()
144+
raw_input("Press any key to continue ... ")
145+
77146
if __name__ == "__main__":
78147
from SrRietveld import Fit
79148
fit = Fit()

demo/difscript.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@
77

88
from SrRietveld import *
99

10-
def runfit(fit):
11-
12-
# Fit
13-
#from RefinementAPI.park.ParkOptimizer import ParkOptimizer
14-
#fit.setOptimizer(ParkOptimizer())
10+
def initialize(fit):
1511
# Set the number of refinement cycles
1612
fit.setNumCycles(-1)
1713

@@ -114,6 +110,10 @@ def runfit(fit):
114110
fit.mapVP("v_W", prof1, "W")
115111
fit.mapVP("v_X", prof1, "X")
116112

113+
114+
def runfit(fit):
115+
116+
comp = fit.getComponent(0)
117117
# Fitting
118118
stage1(fit)
119119
stage2(fit)
@@ -131,15 +131,6 @@ def runfit(fit):
131131
fit.saveResults("ni.dif.res")
132132
comp.saveFitArrays("ni.dif.fit")
133133

134-
if 0:
135-
from pylab import plot, show
136-
x0,y0,u0 = comp.getDataArrays()
137-
x1,y1 = comp.getFitArrays()
138-
from RefinementAPI.utils import rebinArray
139-
y0i = rebinArray(y0, x0, x1)
140-
plot(x1, y0i, x1, y1)
141-
show()
142-
143134
def stage1(fit):
144135
print "stage 1"
145136
fit.fixAll()
@@ -281,4 +272,5 @@ def stage11(fit):
281272

282273
if __name__ == "__main__":
283274
fit = Fit()
275+
initialize(fit)
284276
runfit(fit)

0 commit comments

Comments
 (0)