Skip to content

Instantly share code, notes, and snippets.

@pavoljuhas
Created November 1, 2017 16:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pavoljuhas/e892b0d4bee701a67272767ed095ddda to your computer and use it in GitHub Desktop.
Save pavoljuhas/e892b0d4bee701a67272767ed095ddda to your computer and use it in GitHub Desktop.
fix estimate of standard deviations reported from PDFgui project
#!/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