Link to NIST Center for Neutron Research home page Link to National Institute of Standards & Technology home page
Link to Tcl/Tk information

EXPGUI top Next page (EXCLEDT) Previous page


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:


New! 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.

BKGEDIT screen image

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 "Edit Background" dialog box (invoked from the "Edit Background" button on the Histogram pane.) toolbar or
  1. 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.
  2. Press the "Add" button to add background points. Note the cursor changes from cross-hairs to an arrow, when the "Add" button is pressed.
  3. 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.
    Note that it is advisable to place many background points in areas where the background varies greatly.
    As background points are entered, they are saved in a file named EXPNAM.bkgN, where EXPNAM is the experiment name and N is the histogram number. If BKGEDIT is restarted at some later time, these points are reread.
  4. 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.
  5. Background points can also be edited by entering numbers into the "Background points" area.
  6. 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.
    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.
    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.
  7. Editing the Chebyschev terms is possible. The curve is reevaluated as changes are made.
  8. 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 provides a feel for the interaction between background values and displacement (thermal) parameters. 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, EXPNAM.bkgN, can be read into EXPEDT by typing "@R" at the initial prompt in EXPEDT:

   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.


Plot zooming 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

LIVEPLOT Screen snapshot 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 equation for cumulative chi2 function 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 statistically expected.

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.

LIVEPLOT Screen snapshot Reflection indices 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, but sometimes interferes with the zoom feature). Pressing "A" or "a" shows all reflections in the displayed region. The indices are shown on the screen for phases with tickmarks (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; alternately, pressing "D" or "d" deletes the hkl labels. Several aspects of reflection labeling can be customized, see the HKL labeling options for further information. LIVEPLOT Screen snapshot


A few of these options are omitted from BKGEDIT. LIVEPLOT Menu

File Menu

Checkbuttons are provided for each phase to determine if tick marks are shown. See the Options/"Configure Tickmarks"menu item for information on tickmarks
This allows a histogram to be selected to be loaded
Update Plot
The causes LIVEPLOT to read read the current histogram again from the datafile
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.


Options Menu

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 (Symbol Type)
This brings up a menu where the symbol type and size for the observed data points (and for BKGEDIT, the fixed background points) can be selected.
Symbol Color
The colors for all the displayed lines and symbols can be changed here.
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
  • Erase time: how long in seconds that hkl values are shown before they are erased (0 means that they are not erased),
  • Label size: the size of the labels in pixels,
  • Search Region: only reflections within this number of pixels of the mouse, when the "h" key is pressed (if any) are labeled,
  • Separate window: when this option is selected, reflection labels are shown in a text 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 plot entries
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.
Set screen font
This option is used to control the font used for menus, graphics and other aspects of windows.
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 displayed (as presented above).
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 present.
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.
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.
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 set automatically.

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 Windows and UNIX.

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.)

EXPGUI top Next page (EXCLEDT) Previous page

Brian Toby (Brian.Toby@NIST.GOV)
$Revision: 464 $ $Date: 2009-12-04 23:06:36 +0000 (Fri, 04 Dec 2009) $