Program: QFIT Purpose: Interactive fit of 2-D gaussians Category: ANALYSIS, PROFILES, MODELS, FITTING File: qfit.c Author: M. Vogelaar Keywords: FILENAME= Name of output ASCII file: [No output to file] If a name is specified, an ASCII file is created where fit parameters are listed in a row. If you press carriage return, there will be no output to an ASCII file. APPEND= File exists, ok to append? [Y]/N The file specified in FILENAME= already exists. You can append to this file with APPEND=Y. If APPEND=N you will be prompted for another name. ==== Next keywords are asked in a loop, to be ==== ==== aborted with INSET= ==== INSET= Give input set, subset(s): [STOP Program] Maximum number of subsets is 2048. For each subset a fit is made with the same parameters as the first subset. The INSET= keyword is asked in a loop that is aborted with carriage return ( ). AUTOVIEW= Do you want to display input set in GIDS? Y/[N] For interactive fitting it is convenient to determine a 'fitbox' on the display. If AUTOVIEW=Y, the program VIEW will be started to display the current INSET= (See also keywords in 'VIEW' like CLIP=, NEXT=) ==== Next keywords are asked in a loop, to be ==== ==== aborted with BOX= ==== BOX= Frame for input subsets. [STOP] Total number of pixels in box must not exceed 128x128 . Keyword is prompted in a loop which is aborted with BOX= For each box, all specified subsets are examined before asking the next box. Estimates and fixed values ========================== The following keywords are used to give a value to the parameters that are kept fixed in the fit, or to give a reasonable initial estimate for the free parameters. AMPLITUDE= Amplitude (map units): [Calculated] BEAM= Beam, fwhm in x & y: [Calculated] If indicated, in seconds of arc. X0Y0= Centre in grids: [Calculated] ANGLE= Angle of FWHM in x wrt. pos. X-axis (deg): [Calculated] ZERO= Zero level (map units): [Calculated] MASK= Mask (0=fixed,1=free): [parameter list] ** TOLERANCE= Convergence criterion. [0.01] Relative tolerance. Fitting of the function stops when successive iterations fail to produce a decrement in reduced chi-squared less than TOLERANCE. If its value is less than the minimum tolerance possible, it will be set to this value. This means that maximum accuracy can be obtained by setting TOLERANCE=0.0. ** LAB= Mixing parameter: [0.01] Mixing parameter, LAB determines the initial weight of steepest descent method relative to the Taylor method. LAB should be a small value (i.e. 0.01). ** CLIPLOHI= Give clip levels: [Include all data] Examples: 1) CLIPLOHI= include all data 2) CLIPLOHI=3 include all data >= 3 3) CLIPLOHI=3 5 include all data >=3 and <= 5 Description: QFIT fits 2-dim gaussian to data from INSET= in a given box in BOX= with a limit of 128x128 pixels. The program can be used for example as an flexible alternative for ANTPAT to find beam parameters or to find the exact position of a source. The 2d-gaussian is: F(x,y) = par(0) * EXP( -4.0*ALOG(2.0) * [(xr / par(1))**2 + (yr / par(2))**2] + par(6) where: xr = xo * cos(par(5)) + yo * sin(par(5)) yr = -xo * sin(par(5)) + yo * cos(par(5)) and: xo = x - par(3) yo = y - par(4) The gauss parameters are: 1. Amplitude in Map units 2. FWHMx in arcs 3. FWHMy in arcs 4. X0, center of gauss in grids 5. Y0, center of gauss in grids 6. Rotation angle deg. wrt. pos. x-axis. 7. Zero level in map units The fit routine needs estimates for all parameters. If you use the default of the AMPLITUDE=, BEAM=, X0Y0=, ANGLE= and ZERO= keywords, then, in most circumstances you are using reasonable values. The estimated zero level is the mean of all the pixels on the borders of your selected box (BOX=). The estimated amplitude is the calculated maximum of the data in the box minus the zero level. The estimated FWHM's and position angle are calculated from the data. The center positions are copied from the positions of the calculated maximum. If you want to change these estimates, specify alternative values for one or more keywords. If, for example, you try to fit a 2d-gaussian for which the major axis equals the minor axis but leaving the rotation angle free (in this case the PA has no meaning), there will be probably an error in the fit. In this case you want to do the fit with the rotation angle fixed. Parameters can be used as fixed or free parameters depending on the setting in MASK= To fix a parameter use 0. A free parameter is indicated with 1. The keywords TOLERANCE= and LAB= are fine tuning parameters for a least squares routine. The table, created in the ASCII file (FILENAME=) has a layout set by the user which can easily be changed to suit personal whishes.. Example: Fit gaussian in set 'n4736ave' subset 1. Put results in ASCII file with name 'data'. Use box -4 -10 9 5 and let all parameters be free in the fit: qfit QFIT FILENAME=data QFIT APPEND= QFIT AUTOVIEW=y QFIT INSET=n4736ave 1 Set n4736ave has 3 axes RA from -20 to 20 DEC from -31 to 20 LAMBDA from 0 to 1 BOX range for set n4736ave : RA from -20 to 20 DEC from -31 to 20 QFIT CLIPLOHI= QFIT BOX=-4 -10 9 5 BOX range for set n4736ave : RA from -4 to 9 DEC from -10 to 5 Initial estimates (inserted without the units): Amplitude: 347.534729 (MJY / S) FWHMx: 123.429893 (ARCSEC) FWHMy: 63.259651 (ARCSEC) X0: 2.000000 (grids) Y0: -1.000000 (grids) Angle: 84.357887 (deg) wrt pos. x-axis: Zero level: 10.616884 (MJY / S) QFIT AMPLITUDE= QFIT BEAM= QFIT X0Y0= QFIT ANGLE= QFIT ZERO= QFIT MASK=1 1 1 1 1 1 1 Fitted Gaussian in box: [-4 -10, 9 5] in set: n4736ave (iters:4) ======================================================================= (free) Amplitude: 356.619019 +/- 5.177855 (MJY / S) (free) FWHMx: 120.598099 +/- 2.123478 (ARCSEC) (free) FWHMy: 117.960548 +/- 2.053111 (ARCSEC) (free) Center X0: 1.82 +/- 0.04 (grids) = 192.119869 (DEGREE) = 192d 7m 11.5s = 12h 48m 28.77s (free) Center Y0: -1.87 +/- 0.04 (grids) = 41.389586 (DEGREE) = 41d 23m 22.5s (free) PA major axis: 1.22 +/- 25.28 (deg) wrt to North (free) Zero level: 8.160992 +/- 1.876477 (MJY / S) No offset rotation in header, 0 is assumed. Grid spacing x-direction: -20.00 (ARCSEC) Grid spacing y-direction: 20.00 (ARCSEC) Level: (*,*,0.0001 METER) Tolerance = 0.010000, mixing factor lab = 0.010000 ======================================================================= QFIT BOX= QFIT INSET= QFIT +++ FINISHED +++ Updates: Feb 3, 1992: VOG, Document created Apr 1, 1992: VOG, Rewritten in C Sep 21, 1992: VOG, New FITGAUSS2D routine implemented. May 19, 1993: FL, Coordinate output improved. Sep 20, 1995: VOG, Minor improvements. Documentation updated. Feb 1, 2000: JPT, Increased number of subsets.