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
IPython commands %pdfgetx3
and %pdfgetn3
, which can be used with
the same syntax as the pdfgetx3 and pdfgetn3 in
system shell.
The interactive session is also initialized with all functions from the
matplotlib.pyplot
module for convenient plotting.
The functions and variables related to PDF processing are:
-
pdfgetter
(x=None, y=None, filename='', **kwargs)¶ 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 (Q, intensity) or (2Θ, intensity) depending ondataformat
. 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.Parameters: - x (numpy.ndarray, optional) – The Q or 2Θ values in powder diffraction pattern.
- y (numpy.ndarray, optional) – The scattered intensities in powder diffraction pattern
- filename (str, optional) – The text data file for loading the x, y values when they are not specified.
- kwargs (misc, optional) –
Extra keyword arguments that are applied to
the
config
object, for exampleqmax=20
.
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 – The string or iterable that specify what interactive plots should be
tuned. By default the same as
config.plot
. It can be also an integer index or name of a transformation inpdfgetter()
or a reference to aTransformation
object. - pdfgetter – The optional
PDFGetter
object to be tuned. This is by default the interactivepdfgetter()
object. - axeslist – An optional list of matplotlib Axes for showing interactive plots.
When None, use
subplot(N, 1, i)
to create any necessary 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 – The string or iterable that specify what interactive plots should be
tuned. By default the same as
-
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 – An optional keyword arguments to set for 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
This function can be imported from the
diffpy.pdfgetx
module.
-
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 can be imported from the
diffpy.pdfgetx.plotdata
module.
-
findfiles
(patterns=(), path='.', dotfiles=False)¶ Find files 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.+
- start a new group of patterns to match more files.dir/
- set search path effective from the current pattern group.
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. A single
+
starts a new pattern group for additional matches. Each pattern group may have one entry containing/
, for example,dir/
or./
, which sets the search directory for this and subsequent pattern groups. When pattern group contains only the path entry it reuses file patterns from the previous group. - path (str, optional) – Directory to be searched for the files. The default is “.” to search the current directory.
- dotfiles (bool, optional) – When True search also the hidden “.” starting files. These
files are by default ignored, but can be explicitly selected
by adding the
^.
pattern.
Returns: filenames (list) – The list of matching filenames. Return all files when patterns are not specified.
This function can be imported from the
diffpy.pdfgetx
module.