Interactive mode¶
The interactive mode is activated by using either the
-i, --interact
option or a non-empty
--plot
option. In the interactive mode
the program starts an IPython interactive shell and pre-loads several
functions and variables related to the PDF calculation. It also defines
a %pdfgetx3
macro, which can be used with the same command-line syntax
as the pdfgetx3 program from a system shell. The interactive
session is also initialized with all functions from the matplotlib
pylab
module for convenient plotting. The functions and
variables related to PDF processing are:
-
pdfgetter
()¶ Instance of the
PDFGetter
class which serves as a low-level function that calculates the PDF. This is a callable object, which takes as an argument a pair of input arrays for (two-theta, intensity). It can be also called with a keyword argumentfilename=FILE
, which would read the input arrays from the specified file. When called with no arguments, it calculates PDF from the last input data.Returns: A pair of output arrays (r, G).
-
config
¶ Instance of the
PDFConfig
class that stores the parameters and input files for the program. Useprint(config)
to display the current configuration values. This is the same object aspdfgetter.config
. Configuration may be changed by setting a respective attribute of theconfig
object, for example:In [1]: config.qmax = 21
The
config
values may be also changed by calling thepdfgetter()
orprocessFiles()
function with a corresponding keyword argument, for exampleprocessFiles(qmax=20, force="once")
.
-
iraw
¶ -
iq
¶ -
sq
¶ -
fq
¶ -
gr
¶ These variables are assigned the input raw intensities and the intermediate results, stored as matrix rows. The matrix rows correspond to twotheta1, intensity1, twotheta2, intensity2, etc. Because matrices are iterated row first, the raw intensities from all input files can be plotted with the matplotlib plot function as
plot(*iraw)
.These variables should be considered read-only and are reset with subsequent PDF calculations.
-
tuneconfig
(plotids=None, pdfgetter=None, axeslist=None)¶ Show a GUI dialog for interactive tuning of configuration variables.
Parameters: - plotids – string or iterable that specify what interactive plots should be
tuned. By default the same as config.plot. Can be also an
integer index or name of a transformation in pdfgetter or a
reference to a
Transformation
object. - pdfgetter – optional PDFGetter object to be tuned. This is by default
the interactive
pdfgetter()
object. - axeslist – optional list of matplotlib Axes for displaying the interactive plots. When None, use subplot(N, 1, i) to create the parent axes.
Note
Changes from
tuneconfig()
apply only to the configuration and results in memory. Use theprocessFiles()
function to save them to disk.See also
Interactive tuning of parameters tutorial
- plotids – string or iterable that specify what interactive plots should be
tuned. By default the same as config.plot. Can be also an
integer index or name of a transformation in pdfgetter or a
reference to a
-
processFiles
(filename=None, **kwargs)¶ Process all input files again with the current configuration values. This is a higher-level function than
pdfgetter()
, as it also saves output files and produces plots as specified by theconfig
object.Parameters: - filename – One or more input files to be converted to PDFs and saved or
plotted according to the
config
settings. Use the previous list of input files when not specified. - kwargs – optional keyword arguments that are applied to the
config
object, for example(force="once", qmax=18)
.
This function updates the
config.inputfiles
list and theiraw
,iq
,sq
,fq
andgr
interactive variables.- filename – One or more input files to be converted to PDFs and saved or
plotted according to the
-
clearSession
()¶ Clear all elements from the
config.inputfiles
and also theiraw
,iq
,sq
,fq
andgr
variables.Returns: No return value.
-
loadData
(filename, minrows=10, usecols=None, **kwargs)¶ Find and load data from a text file.
The data reading starts at the first matrix block of at least minrows rows and constant number of columns. This seems to work for most of the datafiles including those generated by PDFGetX2.
Parameters: - filename (str) – Name of the file to load the text data from.
- minrows (int, optional) – Minimum number of rows in the first data block, by default 10. All rows must have the same number of floating point values.
- usecols (int, str, slice, iterable, optional) – Indices or names of the columns to be loaded from the data block,
the default is all columns. Data blocks that do not contain
sufficient number of columns are skipped. When usecols contain
string items, they are translated to column indices by looking
up a header line preceding the data block. String items formatted
as
i:j:k
are converted to slice objects. When usecols type is string it is split to a list of names at comma and whitespace characters. - unpack (bool, optional) – Return data as a sequence of columns that allows tuple unpacking
such as
x, y = loadData(FILENAME, unpack=True)
. Note that transposing the loaded array asloadData(FILENAME).T
has the same effect. The default is False. - kwargs (misc, optional) – Extra keyword arguments that are passed to numpy.loadtxt.
Returns: data (numpy.ndarray) – The data block loaded from the text file.
See also
-
plotdata
(filenames, style=None, x=None, y=None, log=None, ax=None, **kwargs)¶ Plot one or more text data files.
The files are searched for data blocks which have enough columns to satisfy both x and y selectors of the plotted data. This may result in an empty plot when file has none wide-enough data block (e.g., when
y=100
).Parameters: - filenames (str or an iterable of string file names) – One or more text data files to be plotted.
- style (str) – Optional style argument for the matplotlib
plot()
function. - x (int, str, or iterable, optional) – The column to be used for the x data. This can be a zero-based index of the desired column or a column name from data header. A special symbol “.” can be used for a sequential data index. When not specified, use the first column.
- y (int, str, iterable, or slice, optional) – One or more columns to be used for the y data. This can be a single zero-based index of the desired column or an iterable of several indices. The y value can be also a string which is split at commas and converted to integers, column names or slice objects, e.g. “0,sine,4:7”. The slice instances are applied to the entire data block from each loaded file. Use the second column when not specified.
- log ({‘x’, ‘y’}, optional) – Set logarithmic scaling for the specified axis and linear scaling
for all others. For example,
log="y"
applies linear scaling to the x-axis and logarithmic to the y-axis. Keep the current axis scaling when not specified. - ax (matplotlib.axes.Axes, optional) – The axes to plot to. The plotting will be performed using the
ax.plot
method. The default ispyplot.gca()
. - kwargs (misc, optional) – Keyword arguments for the matplotlib
plot()
function.
Returns: lines (list) – The matplotlib
Line2D
objects added to the current axis.See also
This function is defined in the
diffpy.pdfgetx.plotdata
module.
-
findfiles
(patterns=(), path=None)¶ Find files in the working directory that match all specified patterns.
Pattern syntax:
^start
- match “start” only at the beginning of the string.end$
- match “end” only at the end of string.<7>
- match number 7 preceded by any number of leading zeros.<1-34>
- match an integer range from 1 to 34 inclusive.<7->
- match an integer greater or equal 7.<->
- match any integer.
All integer ranges
<N-M>
above allow one or more leading zeros. The range syntax does not support matching of negative numbers.Parameters: - patterns (iterable of strings or str, optional) – String patterns that must all match in returned filenames. Can be also a single string with patterns separated by whitespace characters. When empty match all files in the current directory or in the path.
- path (iterable of strings or str, optional) – Directories to be searched instead of the current directory. Repeated path entries are ignored. When string take it as a single directory path.
Returns: filenames (IPython.SList) – The list of matching filenames. Return all files when patterns were not specified.
See also