## NAME

ncfit -- Interactively perform non-linear curve fitting.

## DESCRIPTION

`ncfit` is a set of non-linear curve fitting tools that are based closely
on the IRAF `icfit` package. `icfit` is, however, specifically layered
on top of the `curfit` package, which is intended for linear functions
only. Interactive, graphical, non-linear curve fitting begins by graphing
the data points and the user's first guess for the function (in one of five
formats). When the cursor appears, the user may modify the graph, the function
coefficients, and the control parameters in a number of ways using cursor
mode keystrokes and colon commands. The user then starts the fitting
process. Cursor keystrokes and colon commands are described below.

CURSOR MODE

- ?
- Clear the screen and display a list of cursor key and colon commands.

- a
- Abort present fit (don't write to table).

- b
- Two cursor positions read in sequence are used to compute a linear slope baseline for Gaussian fitting.

- c
- The coordinates of the data point nearest the cursor and the fitted value are printed on the status line.

- d
- The data point nearest the cursor and not previously deleted is marked with an X. It will not be used in further fits unless it is undeleted.

- f
- A curve is refit to the data and the new fit is graphed in the current format.

- g
- Redefine the graph keys "h-l" from their defaults. A prompt is given for the
graph key which is to be redefined and then for the graph desired.
A
`?`to either prompt prints help information. A graph is given by a pair of commas separated data types. The first data type defines the horizontal axis and the second defines the vertical axis. Any of the data types may be graphed along either axis. The data types arex Independent variable y Dependent variable f Fitted value r Residual (y - f) d Ratio (y / f) n Non-linear component

- h, i, j, k, l
- Each key produces a different graph. The graphs are described by the data
which is graphed along each axis as defined above. The default graph keys
(which may be redefined with the
`g`key) are h=(x,y), i=(y,x), j=(x,r), k=(x,d), l=(x,n).

- o
- Overplot the next fit provided the graph format is not changed.

- p
- Define amplitudes and positions (centers) of Gaussians with single keystrokes.
Set the cursor at the top of the first Gaussian before typing
`p`. Move the cursor to the other Gaussians, typing any key to enter the position. End with`q`or two consecutive carriage returns. This will fill up the coefficient array with the values extracted from the graph. FWHM values will be the same for all Gaussians, and equal to the FWHM of the first Gaussian (:coef 3) before entering the loop. The number of Gaussians will also be reset.

- q
- Exit from the interactive curve fitting. Two consecutive carriage returns (cursor end-of-file) may also be used.

- r
- Redraw the current graph. Must be used after changes in function type, coefficient values, sample ranges, and any other data that affect the drawing.

- s
- Select a sample range. Set the cursor at one end point of the sample before
typing
`s`and then set the cursor to the other endpoint and type any key in response to the prompt "again:". Sample ranges are intersected unless the sample ranges have been initialized to all the points with the key`t`.

- t
- Initialize the sample to include all data points.

- u
- Undelete the data point nearest the cursor which was previously deleted.

- w
- Set the graph window (range along each axis to be graphed). This is a
`gtools`option which prints the prompt "window:". The set of cursor keys is printed with`?`and help is available under the keyword GTOOLS.

- x
- Change the X value of the point nearest the cursor.

- y
- Change the Y value of the point nearest the cursor.

- z
- The coordinates of the cursor are printed on the status line.

- I
- Exit.

COLON COMMANDS

Colon commands are used to show or set the values of parameters. The parameter names may be abbreviated as may the function type.

- :function [value]
- Show the current value or set the function type. The functions types are
"powerlaw", "bbody", "twobbody", "composite", "galprof",
"Gaussians", "cgauss" or "user". Note that change between certain function
types is forbidden. See
`:ngauss`command below.

- :user [value]
- Show the current value of, or set the user function expression. Only works when the user function type is selected.

- :coef i [value]
- Show the current value or set the value of the i-th function coefficient. Also shows the coefficient error and status. "i" is a mandatory parameter.

- :var [i]
- Allows the i-th coefficient to be varied on subsequent fits. If i not supplied, vary all coefficients.

- :fix [i]
- Hold fixed the i-th coefficient on subsequent fits. If i not supplied, fix all coefficients.

- :ngauss [value]
- Show or set the current number of Gaussians being fitted simultaneously. Works only when function type is "Gaussians" or "cgauss".

- :rms
- Show the current value of the fit's chi-square.

- :chisq
- Show the current value of the fit's chi-square.

- :show [file]
- Show the current values of all the fitting parameters, coefficients and errors. The default output is the terminal (STDOUT) and the screen is cleared before the information is output. If a file is specified then the information is appended to the named file.

- :vshow [file]
- A verbose version of "show" which includes the data points.

- :ltype [value]
- Show or set the line type which is used to plot the data points. Two options are possible: "continuous", which draw solid line segments between points, and "boxes", which draw each point as a square box. In this case, and if the data points have error bars associated to them, the error bars are superposed on each box.

- :pcomp [y/n]
- Switch to enable or disable plotting of individual function components (in the case of composite, twobbody, Gaussians or cgauss functions).

- :xaxis [value]
- Show or set the independent variable axis. Possible values: "linear, "log". Notice that only the plot changes; internal data and function coefficients are kept in their original units.

- :yaxis [value]
- Show or set the dependent variable axis. Possible values: "linear, "log", "mag". Notice that only the plot changes; internal data and function coefficients are kept in their original units.

- :mag[value]
- Show or set the value of the real constant used in the y magnitude axis calculation (mag = mag0 - 2.5 * log10( y ))

- :resample [y/n]
- Enable or disable coefficient error estimation by resampling.

- :verbose [y/n]
- Enable or disable printing of iteration info during convergency.

- :method [value]
- Set or show current fitting method.

- :maxit [value]
- Set or show maximum number of iterations in fitting method.

- :restart [value]
- Set or show maximum number of fitting restarts.

- :replic [value]
- Set or show number of replicas used in coefficient error evaluation.

- :alpha, :beta, :gama [value]
- Set or show the simplex control constants.

- :grow [value]
- Show the current value or set the rejection growing radius. Any points within this distance of rejected points are also rejected.

- :naverage [value]
- Show the current value or set the number of points to average or median to form fitting points. A positive value select an mean and negative values select a median. The averaged points are also shown in the graphs.

- :low_reject [value], :high_reject [value]
- Show the current values or set the rejection limits. When a fit is made if the rejection threshold is greater than zero then the sigma of the residuals about the fit is computed. Points with residuals greater than this number times the sigma are removed from the final fit. These points are marked on the graphs with diamonds.

- :niterate [value]
- Show the current value or set a new value for the number of rejection iterations.

- :sample [value]
- Show the current value or set the sample points to use in the fits. This
parameter is a string consisting of single points, colon separated ranges,
or "*" to indicate all points. The sample ranges may also be set with
the cursor mode key
`s`.

FEATURES

A one dimensional non-linear function is fit to a set of x and y data points. The function may be a power-law, Planck (black-body), two simultaneous Planck functions, a composite Planck + powerlaw, a galaxy brightness profile, a set of N Gaussians or a user-specified function.

The algorithm in the `nlfit` package needs a first guess for the function
coefficients. These can be input and modified interactively through
COEF, FIX, and VAR. The meaning of each coefficient is function
dependent, and is described in the `funcform` help page.

The independent variable axis can be plotted in linear or log scales, and the dependent variable axis can be plotted in linear, log or magnitude scales. For this last one, a constant can be specified. The scale transformations are local to the graphics routines, however, and the original data and function coefficients are always expressed in their original units.

Two types of data plotting are supported. The default is a solid line segment linking adjacent points. In the optional mode, points are symbolized by square boxes, and, if there are error bars associated with each datum, they are superposed on the boxes. If plotting in magnitude scale, negative error bars are not drawn, and negative intensities are plotted as small crosses at the window bottom.

In the case of two Planck functions, composite function, multiple Gaussians,
or galaxy brightness profile (bulge + disk), individual components can be
graphed simultaneously with the data by the use of `pcomp`.

There are five types or formats of graphs selected by the keys `h`, `i`, `j`,
`k` and `l`. The graphs are defined by what is plotted on each axis of the
graph. There are five data types, any of which may be plotted on either axis.
These data types are the independent data points (x), the dependent data points
(y), the fitted values (f), the residuals (r=y-f), the ratio of the data to the
fit (d=y/f) and the data with a linear component removed (n=y/(ax+b)). The
default graph keys are shown in the cursor key section though the definitions
may be modified by the application. The user may also redefine the graph keys
using the `g` key.

It is important to remember that changing the value of a fitting parameter
does not change the fit until `f` is typed.

FUNCTION COEFFICIENTS

Function coefficients specified by [i] in the colon commands :COEF, :VAR and :FIX are specific of each functional form, in the following way:

i POWERLAW BBODY TWOBBODY COMPOSITE 1 exponent temperature temp. 1 p.l. exponent 2 amplitude amplitude ampl. 1 p.l. amplitude 3 ref. x ref. lambda ref. 1 p.l. ref. lambda 4 temp. 2 b.b. temperature 5 ampl. 2 b.b. amplitude 6 ref. 2 b.b. ref. lambda i GAUSSIANS CGAUSS GALPROF 1 zero zero se - bulge bright. 2 slope slope re - bulge radius 3 ampl. 1 ampl. 1 s0 - disk bright. 4 cent. 1 cent. 1 r0 - disk radius 5 fwhm 1 fwhm 1 r1 - "hole" radius 6 ampl. 2 ampl. 2 (relative) backgr- background 7 cent. 2 cent. 2 (relative) 8 fwhm 2 fwhm 2 . ... ...

## BUGS

When the Y data range being plotted is near zero, the `log` axis
option can generate weird results. This is due to the use of the
`elog` (extended log) function in gtools, instead of the standard `log`.
Try the `mag` y axis option instead.

The :/xlabel and :/ylabel in gio do not work properly yet.