LIVEPLOT and BKGEDIT
This page documents the LIVEPLOT and BKGEDIT utility programs
in the EXPGUI package.
LIVEPLOT and BKGEDIT are actually the same program, but perform
different functions, depending on how they are invoked.
LIVEPLOT is used to display the quality of the diffraction fit, while
BKGEDIT is used to fit a background function to fixed background points
that have been input by the user.
Both LIVEPLOT and BKGEDIT get the current diffraction information
by running the TCLDUMP program, if installed, or
HSTDUMP otherwise. The TCLDUMP program has been optimized for use
with LIVEPLOT and offers a number of extra
options that are not available when HSTDUMP is used. Since TCLDUMP has been
included in GSAS since April of 2000, it is assumed that this is now the case.
LIVEPLOT is started by pressing the LIVEPLOT button on the toolbar
or via the Graphs/liveplot menu item.
Some of the features available in LIVEPLOT are:
- The plot is updated automatically after each refinement run
- The plot can be zoomed, by clicking on the corners of the
area to be magnified.
The units used for plotting histograms can be selected. Choices are:
native units (2Theta/TOF/KeV); d-space (A) or Q (A-1)
The background (fixed plus fitted) can be plotted or can be subtracted.
Reflection tickmarks can be displayed in a variety of formats
LIVEPLOT can be coupled to the LOGIC or CMPR programs, so that
peak positions from an ICDD entry or for an arbitrary unit cell and
spacegroup can be shown superimposed on the "Rietveld plot."
Reflection indices (hkl values) can be shown for tickmarks
The cumulative chi2 function can be plotted.
For most refinements, it is possible to simply select a background
function (I find that the type 1 function,
shifted Chebyschev polynomials, work well)
and then refine, adding terms until a good fit is obtained.
On occasion, poor initial fits are obtained in this manner. This is
most common in cases where large numbers of peaks are poorly fit. Since
significant sections of the data are not well fit, the refinement results in
an unreasonable background function, because this yields better agreement
with the observed data.
In these cases,
it may be best to fix the background to follow a "reasonable" curve in the
initial stages and then refine the background in the final stages of
refinement, when a good model has been obtained.
The BKGEDIT program, as shown below, is used to input a set a background
points via the mouse. The points are then used to determine a type 1
(Chebyschev) background function that fits the input background points. These
terms can then be saved in the experiment file creating a background that
is good enough for the initial stages of refinement and that can be
refined once the model is adequate for the task.
Steps in fitting a background function
The BKGEDIT program is started from
via the Powder/bkgedit menu item or by pressing the
"Fit Background Graphically" button on the
dialog box (invoked from the "Edit Background" button on the
- Zoom in on the lower intensity section of the
plot, so that the background is clearly discernible. In some cases, the
data will need to be handled in sections.
- Press the "Add" button to add background points.
Note the cursor changes from cross-hairs to an arrow,
when the "Add" button is pressed.
- Move the mouse to the first location
where a background point will be added and click with the left
mouse button. A magenta triangle will appear at the location.
Points can be added in any order. It is best to make sure that the fixed points
are placed over the entire range of the data, e.g. near the maximum and minimum
data points in TOF, 2theta, etc.
As background points are entered, they are saved in a file named
EXPNAM is the experiment name and N is the histogram number.
If BKGEDIT is restarted at some later time, these points are reread.
Note that it is advisable to place many background points in areas where
the background varies greatly.
- If any points are placed in incorrect positions, they can be deleted by
pressing the "Delete" button. The mouse cursor changes to a circle. When
the mouse left clicked, the fixed background point closest to the mouse
position (which may be outside the zoom range) is deleted.
- Background points can also be edited by entering numbers into the
"Background points" area.
- After enough background points have been entered, the
"Start Fit" button turns from gray to black. When pressed, the Chebyschev
polynomial is fitted and the resulting curve is shown as a blue dashed line.
The "Improve Fit" button is black when the fit did not
converge or the number of terms has been changed. "Improve Fit" causes the
fit to be refined starting from the previous values.
It is suggested that you start with relatively few
terms and add terms and background points as needed.
Note that the maximum number of Chebyschev terms increases as
more background points are entered.
- Editing the Chebyschev terms is possible. The curve is reevaluated as
changes are made.
- Once a good background function is determined, it can be saved in the
experiment file by pressing the "Save in EXP file & Exit" button. This will
set the background type to 1, and save the Chebyschev terms.
It will also turn off
the background refinement flag for the appropriate histogram so that the
terms are not refined inadvertently.
Note that POWPREF must be run at least once before BKGEDIT can be used,
however, use of
GENLES before BKGEDIT is optional. If the data range is changed, for example
by excluding a section of the data at the lower end, or changing tmax (dmin),
the Chebyschev polynomial terms must change to generate the same
background values, so both POWPREF and BKGEDIT should be rerun to
regenerate the Chebyschev terms.
Why not use fixed background points?
I personally feel that
a refined background function is preferrable to use of a fixed model,
if at all possible.
One reason for this is that Rietveld refinements usually achieve better fits
when the background is optimized. A second reason refining the background
feel for the interaction between background values and displacement
Usually, background and displacement parameters are fairly independent, but
for some materials, where the high Q (high 2theta) portion of the pattern
has many completely overlapped peaks, it is impossible to uniquely
determine where the
background should be placed, either by refinement or by manual placement.
Under these circumstances, the background should be refined with the
displacement parameters fixed at an appropriate value for the material. The
background should then be fixed for all future refinements
and the displacement parameters can then be refined. Of course this
means you have predjudiced the refinement to result in the expected
average displacement parameter and this must be noted
any publication. However, if this is necessary, the data simply do not
contain sufficient information to independently determine
background and displacement parameters. Use of fixed background points
would not demonstrate this and would lead the researcher to a false
sense of security (or fear, if the values are unreasonable)
that the displacement parameters actually mean something.
If you still want to use fixed background points, despite this tirade,
be sure to set the estimated
error on those points to be 0.0. Use of non-zero estimated errors, can
result in artificially lowered R-factors and chi-squared values.
In one test, I was able to lower the Rwp and
reduced chi2 values,
from the correct values of 0.042 and 3.0, respectively, to misleading
values of 0.036 and 0.8,
respectively. [As expected, the R(F2) stayed constant at 0.045;
FYI, refining the background caused R(F2) to drop to 0.036.]
If the background is so truly irregular that only use of fixed background
points will do,
BKGEDIT can be used to generate these fixed background points.
The file used by BKGEDIT to save these points,
can be read into EXPEDT by typing "@R" at the initial prompt
Is this the file you wish to use? (>,D,K,Q,R,Y) >@r
prompt and then supplying the name of the file, in response to the next prompt:
Enter the name of your macro file: GARNET.bkg1
And this will enter the background points entered into BKGEDIT as GSAS
fixed background points. If you do this you do not want to fit and enter
Note that you are allowed to use both fixed and a refined background together,
though this is seldom done.
When the left (usual) mouse button is pressed, this defines one corner
of a region to be magnified, as is shown to the right.
If the mouse is then moved, the diagonal
corner of this magnification region is defined. When the left mouse button
is pressed a second time, the selected section of the plot is magnified to
fill the entire plot.
Zoom settings are saved.
If the right mouse button is pressed, the previous zoom setting is used,
so that the left mouse button is used to "zoom in" and the right mouse
button is used to "zoom out."
Features in LIVEPLOT only
The cumulative chi2
function was first suggested by
Bill David as a way to see which reflections have the greatest influence on
chi2 [W.I.F. David, Accuracy in Powder Diffraction-III, 2001].
It is defined for point j as
where yobs,i and ycalc,i are the observed and computed
data points and sigmai is the expected error. Thus, the statistically
expected value for
[(yobs,i-ycalc,i)/sigmai]2 is 1
and this function should rise in a smooth line if all points are fitted as
In the plot to the right, the cumulative chi2 function is shown in
purple. Note that first peak is not well fit, but the low angle "shoulder" is
as important as the peak misfitting, with respect to the chi2.
are be displayed by pressing "H" or "h" while the
mouse is near a reflection (holding the shift key while
pressing the left mouse button also works). The indices are shown
on the screen for phases with tick marks (as shown to the right).
Indices are listed in the "Separate window for hkl labels"
(as seen below) for all phases, regardless of the tickmark settings.
Displayed indices will remain on the screen for a preset time and
then will be deleted, unless the labeling options are changed.
LIVEPLOT/BKGEDIT Menu Contents
A few of these options are omitted from BKGEDIT.
- Checkbuttons are provided for each phase to determine if tick marks
are shown. See the Options/"Configure Tickmarks"menu item for information
- This allows a histogram to be selected to be loaded
- Update Plot
- The causes LIVEPLOT to read read the current histogram again from
- Make PostScript
- Creates a low quality PostScript file containing the LIVEPLOT
output. See the Options/"Set PS output" button for where the file is created.
- Configure Tickmarks
- Tickmarks can be placed automatically, similar to their
placement in POWPLOT or can be drawn one height to another. The default
is for lines to be draw from "-Inf" to "Inf", which creates lines from the
bottom to the top of the plot. The options for each phase allow the line to be changed between solid and dashed, color of the line can be specified and
the vertical placement of the tickmarks can be specified. The "show" flag,
set in the File/Tickmarks menu can also be changed here.
- Obs symbol
- This brings up a menu where the symbol type and size for the
observed data points can be selected.
- X units
- The x units can be selected here. The choices are
"as collected" (2Theta/TOF/KeV), d-space (A) or Q (A-1)
- Y units
- The intensity values can be normalized by the incident spectrum
(for energy dispersive methods).
- HKL labeling
- This brings up a menu that selects how long hkl values are shown
before they are erased (0 means that they are not erased), the size of the
labels and the width around the mouse that is searched for matching
reflections. If requested using the "Separate window for hkl labels"
option, labels are also show in a separate window.
- Subtract background
- The background is always shown, even when subtracted
- Include legend
- The legend is the optional box in the upper left that defines the
- Set PS output
- For UNIX this allows the file to be sent directly to a printer
or can be saved in a file. For Windows, a file must be written.
- Raise on update
- This causes the plot to be placed on top of other windows, if partially
obscured, when the plot is updated. At this time, this option does not
work in Windows-NT and -2000.
- Cumulative Chi2
- The causes the Cumulative chi2 function to be defined
- Save Options
- Causes many of the options set in this menu to be saved in the .gsas_config file.
Customization of LIVEPLOT & BKGEDIT
The localconfig and .gsas_config files are read, if present.
The following variables control how LIVEPLOT, and in most cases BKGEDIT,
function and can be
customized by changing their values in the
localconfig and .gsas_config files.
Note that some of these options are relevant only if the tcldump program is
The following variables are written to .gsas_config when
"Save Options" is used. These variables are all set from the GUI and therefore
do not need to be edited manually.
These variables define if peak positions will be shown
for reflections in phase "n". Reflections will be shown if
the value is non-zero.
These variables define the default colors for
reflections in phase "n"
These variables define if peaks will be dashed for
reflections in phase "n" (UNIX only). Lines will be dashed if
the value is non-zero.
- peakinfo(minn) and peakinfo(maxn)
These variables dictate the placement vertical position for reflection
markers, when manually placed (see expgui(autotick), below). To draw
to the edge of the screen, use -Inf and Inf.
This is set to 1 if PostScript files
will be printed and 0 if they will be written to disk (for Windows all
files should be written to disk).
This is the default for the file name used
when PostScript files will be written to disk.
This is the default for the command used
to print PostScript files (Unix only).
Sets the default value for display of the legend in LIVEPLOT and widplt.
This option shows up in the options menu item as "Raise on update."
When set to non-zero, the LIVEPLOT window is raised
(placed on top of any other overlapping) windows
each time it is updated.
This option does not seem to work in Windows-NT, but this may depend on
the version of Tcl/Tk.
Symbol for observed data points. Valid choices are square, circle, diamond,
plus, cross, splus and scross.
Size for the symbol for observed data points. A value of 1 corresponds to about 1/8 inch
(about 3 mm).
When hkl values are loaded (using tcldump) and reflections are labeled, reflections
can be labeled using a Shift-Left-Mouse click. All labeled reflections within expgui(pixelregion)
pixels of the mouse position are assumed to be overlapped and are labeled.
The time in seconds before reflection labels are removed. A value of zero means that reflections
must be deleted manually (Shift-Right-Mouse).
A size for reflections labels in pixels.
If this variable is non-zero, reflection indices are shown in a box.
If this variable is non-zero, reflection markers positions are
Installation details/External Programs
Using TCLDUMP with LIVEPLOT.
LIVEPLOT works with the standard GSAS program HSTDMP, but it works faster and is more
powerful when used with the TCLDUMP program.
Note that as of the April 2000 releases, GSAS is now distributed with TCLDUMP
included. For older versions of GSAS, note the
instructions for downloading this file can in the installation notes for
Combining CMPR and LIVEPLOT.
If you have CMPR
installed on your computer, you can use superimpose on the GSAS results
the peaks for an arbitrary unit cell. If desired, space group extinctions
can even be shown.
This is pretty neat! To enable this feature, you must have a version
of CMPR downloaded after 4 May 1998
(see the CMPR installation instructions.)
Combining LOGIC and LIVEPLOT.
If you have LOGIC
installed on your computer, you can superimpose peaks
for a entry from the ICDD/JCPDS database on a pattern in LIVEPLOT.
This is also pretty neat!
To enable this feature, you must have
a version of LOGIC downloaded after 4 May 1998
(see the LOGIC installation instructions.)
Brian Toby (Brian.Toby@NIST.GOV)
$Revision: 406 $ $Date: 2009-12-04 23:05:38 +0000 (Fri, 04 Dec 2009) $