Created
November 1, 2017 16:02
-
-
Save pavoljuhas/e892b0d4bee701a67272767ed095ddda to your computer and use it in GitHub Desktop.
fix estimate of standard deviations reported from PDFgui project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
import numpy | |
def getfitesd(fit): | |
import cStringIO | |
from diffpy.pdffit2 import redirect_stdout | |
# throw away any output from pdffit2 | |
redirect_stdout(cStringIO.StringIO()) | |
# set nyquist spacing for every dataset and redo the fit | |
for ds in fit.datasets: | |
ds.setFitSamplingType('Nyquist') | |
fit.run() | |
N = sum([len(ds.Gdiff) for ds in fit.datasets]) | |
ssq = sum([numpy.dot(ds.Gdiff, ds.Gdiff) for ds in fit.datasets]) | |
P = len([p for p in fit.parameters.values() if not p.fixed]) | |
dG = numpy.sqrt(ssq / (N - P)) | |
return dict(N=N, P=P, dG=dG, ssq=ssq) | |
def processddpfile(filename): | |
from diffpy.pdfgui.tui import LoadProject | |
print "Loading PDFgui project %r" % filename | |
prj = LoadProject(filename) | |
for fit in prj.getFits(): | |
print fit.name | |
e = getfitesd(fit) | |
print " number of datapoints on Nyquist grid N = %(N)i" % e | |
print " number of refined parameters P = %(P)i" % e | |
print " sum of squares on Nyquist grid = %(ssq)g" % e | |
print " estimated uncertainty dG = %(dG)g" % e | |
return | |
if __name__ == '__main__': | |
for f in sys.argv[1:]: | |
processddpfile(f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment