Actually there is no principle difference between fitting a 2D or a 1D data set. The only theory function of 2D data currently available in KUPLOT is a set of N 2D Gaussians as defined in equation 8.5. Each Gaussian is defined by eight parameters, peak height p1,n, peak position p2,n and p3,n in x- and y-direction, half widths p4,n, p5,n and asymmetry parameters p7,n, p8,n for each direction and a new parameter p6,n that defines the angle between the main axes of the Gaussian and the coordinate system. One additional parameter describes a flat overall background.
This equation certainly looks more complex than the 1D equivalent and we
will illustrate the fitting of three 2D Gaussians to a section of the
diffuse scattering data used in the 2D examples before. The data and the
fit result are shown in Figure 8.2. The observed data are shown
in the top view graph. The maxima used to determine the starting values
for the fit are marked by black circles. One of the major mistakes when
using the fit routine of KUPLOT are wrong starting values. The
calculated data are shown in the middle view graph using identical
contour line settings as for the data. The bottom view graph finally
shows the difference between observed and calculated data. The solid
black line is the zero level, red lines mark negative values and blue
lines stand for positive contour levels. Note that the contour line
interval used for the difference plot is only
of the
interval used for the observed and calculated data in order to make
the differences more visible.
The macro file used for this example file is shown below. Again we assume the observed data are already loaded as data set one.
1 fit 1
2 #
3 mfen 3
4 func gau2,3
5 par
6 #
7 run
8 #
9 par 7,1
10 par 23,1
11 #
12 run
13 save
14 #
15 exit
First we enter the fit sublevel (line 1) to fit the theory function to data set one. Before we select three 2D Gaussian theory functions in line 4 we set the window size for determination for maxima used as starting values to 3 data points. This will result in the three maxima marked in Figure 8.2. Line 5 displays the current parameter settings for checking. Next (line 7) the fit is started. As default the parameter p6,n determining the angle between the principle axes of the Gaussian and the coordinate axes and the asymmetry parameters p7,n and p8,n will be kept fixed. After the first fit, the orientation of the Gaussian (parameter p6,n) for Gaussians one and three (the two strong peaks) are refined as well (lines 9-12). Finally the data sets containing the calculated data and the difference as well as the resulting parameters are saved. When fitting interactively the command 'plot' within the fit sublevel will plot the current fit on the screen.
Finally we want to have a look at the produced text file containing the fit
results (file extension .erg) for this example fit. The line
numbers are given for reference and as for the macro files not part of the
actual output file. The first part contains general information about the
fit such as a title (lines 2-3), the used theory function (line 4), the
data file used (line 5), the number of data points and parameters (lines
6-7). Note that this is the total number of parameters including those
not actually refined. Lines 8-10 show the current URF (see 8.1),
the maximum number of iterations, the setting for maxima determinations and
the used weighting scheme, in our case
.
The next
block of data in the output file show details of the fitting process itself.
Line 14 lists the value for
for the
last and the previous iteration step. The difference between both is shown
in the next line 15. A big difference normally indicates a 'crashed' fit.
The value of URF changes during the refinement and the final value is shown
in line 16. If this value is not close to 1.0 at the end of the fit
something has gone wrong. The next line shows the resulting R value and
the expected R value. The ration of these values is also known as the
goodness-of-fit. Finally all correlations between fitted parameters that
are greater than 0.8 are listed. We are lucky because our fit contains no
highly correlated variables.
1 General fit parameter settings :
2 Title : KUPLOT 2D fit demonstration
3 January 1998
4 Fit function : Gaussian (2D)
5 Data file name : test.fit
6 # of data pts. : 561
7 # of parameters : 25
8 Urf : .1000
9 Max. cycle : 30
10 MFEN for maxima : 3
11 Weighting scheme : w(i) = 1.0/i
12
13 Information about the fit :
14 Sum n-1 : 1038.98 Sum n : 1040.29
15 Difference : 1.31653
16 Urf final : 1.00047
17 R4 value : .106378 R exp : .077327
18
19 Correlations larger than 0.8 :
20 ** none **
21
All remaining information of the output file are results of the parameters used in the theory function. In line 22 the number and type of functions fitted are shown. Next we have the result for the overall background p1 and its standard deviation (line 24). The 'pinc' in the last column indicates whether the parameter was refined (pinc = 1) or kept fixed to its starting value (pinc = 0). The values for each parameter and the corresponding 'pinc' value can be altered via the command 'par'.
22 Fitted 3 Gaussian(s) :
23
24 p( 1) : backgr. 1 : 69.2818 +- .998061 pinc : 1.
25
The rest of the output file contains three identical blocks with the resulting parameters of the three Gaussians fitted to the observed data. We show here just the results for Gaussian 1 (left maximum).
26 Gaussian : 1
27
28 p( 2) : peak : 407.332 +- 11.3879 pinc : 1.
29 p( 3) : position x: .665616 +- .002372 pinc : 1.
30 p( 4) : position y: 3.74364 +- .002798 pinc : 1.
31 p( 5) : fwhm a : .237793 +- .005545 pinc : 1.
32 p( 6) : fwhm b : .235389 +- .005938 pinc : 1.
33 p( 7) : angle a,x : -98.8801 +- 85.1452 pinc : 1.
34 p( 8) : asym. a : 1.00000 +- .000000 pinc : 0.
35 p( 9) : asym. b : 1.00000 +- .000000 pinc : 0.
36 integral : 25.8344 +- 1.97653
Note that the asymmetry parameters were not refined, thus kept at the
default setting for a symmetric function. The orientation for this
Gaussian (line 7) has a very large error which can be understood from the
resulting half width parameters (lines 31-32) which show a nearly isotropic
result. Thus the definition of an orientation is quite arbitrary. This
result is displayed here for demonstration purposes, normally the fit needs
to be repeated with a fixed orientation parameter for this Gaussian. The
third Gaussian however (right maxima) has a significant orientation
parameter of
.
Finally (line 36) the integral for
each Gaussian with its standard deviation is given.