Getting Started Documentation Glish Learn More Programming Contact Us
Version 1.9 Build 1488
News FAQ
Search Home


next up previous contents index
Next: imageprofilefitter - Constructor Up: images - Module Previous: imagefittertest - Function


imageprofilefitter - Tool



Package general
Module images


Postscript file available

Fit models to 1D profiles from images

include "imageprofilefitter.g"

Constructors
imageprofilefitter Construct an imageprofilefitter
Functions
done Destroy this imageprofilefitter tool
getestimate Recover the estimate
getfit Recover the fit
getprofiles Get data, estimate and fit as vectors
getstore Recover all fits added to internal store
gui Start the GUI interface
setimage Set a new image
type What type is this tool ?

The imageprofilefitter tool offers interactive fitting of 1D models (or components) to profiles from an image. You control the process from a GUI interface. The tool is self contained so that the display is built into the interface.

You may provide one or two images (primary in keyword infile and secondary in keyword infile2). If you only provide the primary image, it must have at least 3 dimensions. Then, a zeroth-order moment secondary image (simple average of all pixels along profile with 3-sigma clip) is automatically made for you along the specified profile axis (and removed when you destory the Imageprofilefitter tool or exit from Glish). This secondary image is then displayed and from it you interactively specify profiles to fit.

If you provide the secondary image as well, it could be a pre-computed moment image (you might not like the automatically provided one). The secondary image does not actually have to be generated from the primary It is only its world coordinates that are used. For example, it could be an optical image from which you specify a direction and the profile is then extracted from the primary image (which might be a spectral-line neutral Hydrogen cube).



Example
- pf := imageprofilefitter(infile='ngc1313.cube', axis=3)
Specify just the primary image.



Example
- pf2 := imageprofilefitter(infile='ngc1313.cube', infile2='ngc1313.mom', axis=3)
Specify the primary and secondary images.

The display of the secondary image looks like:

Figure 1.7: The main imageprofilefitter GUI
\begin{figure}
\begin{center}
\epsfig{file=imageprofilefittergui1.ps,width=6in}\end{center}\end{figure}

There are now two ways to drive the fitting process. You can either interactively fit individual profiles one at a time, or you can automatically fit all profiles in a selected region.


Individual Profiles

From the Viewer control buttons (buttons to the left of the display of the image), select the position handling button. Now go to the image display, position the cursor somewhere and double click. This will cause a second GUI to appear as below.

Figure 1.8: The secondary imageprofilefitter GUI
\begin{figure}
\begin{center}
\epsfig{file=imageprofilefittergui2.ps,width=6in}\end{center}\end{figure}

The profile is extracted from the nearest pixel and plotted in the secondary GUI. If you wish, the profile can be spatially averaged, rather than just being a single-pixel profile. Just enter the half-width (in pixels) in the entry box of the main GUI (defaults to 0; no averaging). The title of the plot includes the world and center pixel coordinate of the profile.

A profile can also be generated by selecting one of the region generation tools (rectangle or polygon) from the Viewer control buttons. If the Region Usage menu has 'Average' selected, then the profile will be spatially averaged over the region. Generate the region on the image display by dragging out the box or marking the polygon. As always, double click within the region to emit it.

There are various buttons and menus beneath the plot of the profile. You can select different x-axis units, absolute or relative units etc. From here the process is simple. You select the number of components you want to fit with the slider. For each component, a parameters panel is generated (you access different components with the TAB-widget buttons). Then for each component you specify the type of component you wish to fit. For each component you need an estimate before fitting.

You can either do this interactively or automatically. To make an interactive estimate, select the component from the TAB-widget. Then press the 'Inter' button and follow the instructions in the message widget at the bottom of the GUI.

To make an automatic estimate, just press the 'Estimate' button at the bottom of the GUI. It will make an estimate for as many components as you have specified (i.e. you don't do it for each component separately).

The estimate is plotted for you. Then you can press the 'Fit profile' button and the fit will be done. The fit and residual will be plotted.

If you don't want to see all of the plots (data, estimate, fit, residual), you can select what you want from the 'File' menu of the menubar at the top of the GUI.

That's it ! If you want to fix parameters of the fit at the estimate value, check the 'Fix' button for the appropriate component parameter. You can transfer the fit solution to the estimate for each parameter by pressing the left-pointing arrow.

The results are presently stored in a Glish record. You can copy it to the defaultclipboard tool by pressing the 'Copy' button at the bottom the GUI. You can then access the results from Glish by pasting from the clipboard.

- r := dcb.paste()      # Paste from clipboard to record
- print field_names(r)
estimate fit position
- print field_names(r.fit)
elements xunit xabs yunit doppler nmax baseline

Presently, the results are held in a Glish record with fields 'estimate', 'fit' and 'position' (the structure of this record is very likely to change in the future). There are a variety of subfields with obvious names. To access the results of the fit you would look at the fit.elements field of the record (above). This record is indexed by the number of components (although Glish record indexing is rather perversely named; you see funny field names like *445, *446 - ignore these). What you would do to see the individual components, assuming say, you fitted two components to your spectrum would be

- print r.fit.elements[1]
[type=GAUSSIAN, parameters=[0.60423172 1.4136544 0.00022220827] , 
                errors=[0.042635564 7.6873681e-06 1.8104964e-05] ] 
- print r.fit.elements[2]
[type=GAUSSIAN, parameters=[0.13442206 1.4142888 4.6772192e-05] , 
                errors=[0.093013123 1.588148e-05 3.7512798e-05] ]

You can also add the result from each fit to an internal store via the 'Store' button at the bottom of the GUI. The internal store of all the fits can be recovered with the function getstore.


Fitting many profiles in a region

This mode is active when you have selected the Region Usage menu to say 'Fit all profiles'.

From the Viewer control buttons (buttons to the left of the display of the image), select one of the region handling buttons (box or polygon). Now go to the image display, and generate the region by dragging out the box or marking the polygon. As always, double click within the region to emit it. This will cause a second GUI to appear. Is is the same GUI as described above for fitting individual profiles.

The spectrum that is plotted, is the spectrum at the bottom-left corner of your region. You use this GUI to indicate how many components you want to fit, what parameters are fixed and if you wish, and to set an initial estimate for the first profile. Thereafter, an automatic (independent) estimate is made for each profile.

When you press the 'Fit region' button, all profiles in the delineated region are automatically fit. Two new output images are created for you. They have the same name as the input image but with .fit and .resid appended to them. These images hold the evaluated fit and resdidual.


Non-interactve profile selection

Imageprofilefitter also has a mode where the image is not displayed (showimage=F in constructor). This means you cannot interactively select the spatial location at which the next profile will be extracted.

What happens then is that the current image (set in the constructor or via function setimage) is used to generate a profile averaged over the entire image (for the non-profile axes). It is used in this way in Dish; each single-dish spectrum is put into a 1-D image and passed to Imageprofilefitter.


Frame conversions

At the moment, when you plot profiles, you will find that spectral frame conversions are disabled because that functionality is not yet implemented in the fitter (although the plotter can handle it). If you really need to fit in a different reference frame, you can do something like the following:



Example
- im := image('ngc1313.cube')
- cs := im.coordsys()
- cs.setconversiontype (spectral='TOPO')       # Convert from native frame to TOPO
- im.setcoordsys(cs)
- cs.done()
- im.done()
- p := imageprofilefitter('ngc1313.cube')

and now the plotting and fitting will be done in the TOPOcentric frame.


Future Enhancements

This is the first version of this tool. Future improvements will include

  • Enable and handle reference frame changes (e.g. LSRK to BARY etc)

  • Line shapes other than Gaussian (e.g. Zeeman, Voigt)

  • Line-ratio constraints

  • Interactive capability when fitting many profiles in the region

  • Robust estimates of line parameters

  • Zooming in and out of the profile display and setting ranges




next up previous contents index
Next: imageprofilefitter - Constructor Up: images - Module Previous: imagefittertest - Function   Contents   Index
Please send questions or comments about AIPS++ to aips2-request@nrao.edu.
Copyright © 1995-2000 Associated Universities Inc., Washington, D.C.

Return to AIPS++ Home Page
2006-08-01