1
2
3 """This module defines functions within IPython session to simulate
4 the old pdffit2 interactive session.
5
6 Usage: %load_ext diffpy.pdffit2.ipy_ext
7 """
20
23 """Convenience functions for accessing and plotting PDFfit2 data.
24 """
25
27 self._pdffit = pdffit_instance
28 return
29
30 @property
32 "R-grid for PDF simulation."
33 return self._asarray(self._pdffit.getR(), dtype=float)
34
35 @property
39
40 @property
44
45 @property
47 "Difference between the observed and simulated PDF."
48 return self.Gobs - self.Gcalc
49
51 """Plot observed and simulated PDFs and the difference curve.
52
53 offset -- offset for the difference curve.
54
55 No return value.
56 """
57 from matplotlib.pyplot import gca
58 from math import floor
59 cr = self.r
60 cGobs = self.Gobs
61 cGcalc = self.Gcalc
62 cGdiff = self.Gdiff
63 if offset is None:
64 offset = floor(min([min(cGobs), min(cGcalc)]) - max(cGdiff))
65 ax = gca()
66 ax.plot(cr, cGobs, 'r.', cr, cGcalc, 'b-', cr, cGdiff + offset, 'g-')
67 xl = ax.xaxis.get_label().get_text()
68 yl = ax.yaxis.get_label().get_text()
69 if xl == "":
70 ax.set_xlabel('r (A)')
71 if yl == "":
72 ax.set_ylabel('G (A**-2)')
73 return
74
76 "Plot cumulative Rw."
77 from matplotlib.pyplot import gca
78 cRw = self._asarray(self._pdffit.getcrw())
79 ax = gca()
80 ax.plot(self.r, cRw)
81 ax.set_title('Cumulative Rw = %.4f' % cRw[-1])
82 ax.set_xlabel('r')
83 ax.set_ylabel('Rw')
84 return
85
86 @staticmethod
88 import numpy
89 return numpy.asarray(x, dtype=dtype)
90
91
92