source: trunk/docs/executionFlow.tex @ 1249

Last change on this file since 1249 was 1249, checked in by MatthewWhiting, 11 years ago

Updating the documentation to describe the new flaggedChannels functionality.

File size: 42.8 KB
Line 
1% -----------------------------------------------------------------------
2% executionFlow.tex: Section detailing each of the main algorithms
3%                    used by Duchamp.
4% -----------------------------------------------------------------------
5% Copyright (C) 2006, Matthew Whiting, ATNF
6%
7% This program is free software; you can redistribute it and/or modify it
8% under the terms of the GNU General Public License as published by the
9% Free Software Foundation; either version 2 of the License, or (at your
10% option) any later version.
11%
12% Duchamp is distributed in the hope that it will be useful, but WITHOUT
13% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14% FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15% for more details.
16%
17% You should have received a copy of the GNU General Public License
18% along with Duchamp; if not, write to the Free Software Foundation,
19% Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
20%
21% Correspondence concerning Duchamp may be directed to:
22%    Internet email: Matthew.Whiting [at] atnf.csiro.au
23%    Postal address: Dr. Matthew Whiting
24%                    Australia Telescope National Facility, CSIRO
25%                    PO Box 76
26%                    Epping NSW 1710
27%                    AUSTRALIA
28% -----------------------------------------------------------------------
29\secA{What \duchamp is doing}
30\label{sec-flow}
31
32Each of the steps that \duchamp goes through in the course of its
33execution are discussed here in more detail. This should provide
34enough background information to fully understand what \duchamp is
35doing and what all the output information is. For those interested in
36the programming side of things, \duchamp is written in C/C++ and makes
37use of the \textsc{cfitsio}, \textsc{wcslib} and \textsc{pgplot}
38libraries.
39
40\secB{Image input}
41\label{sec-input}
42
43The cube is read in using basic \textsc{cfitsio} commands, and stored
44as an array in a special C++ class. This class keeps track of the list
45of detected objects, as well as any reconstructed arrays that are made
46(see \S\ref{sec-recon}). The World Coordinate System
47(WCS)\footnote{This is the information necessary for translating the
48  pixel locations to quantities such as position on the sky,
49  frequency, velocity, and so on.} information for the cube is also
50obtained from the FITS header by \textsc{wcslib} functions
51\citep{greisen02, calabretta02,greisen06}, and this information, in
52the form of a \texttt{wcsprm} structure, is also stored in the same
53class. See \S\ref{sec-wcs} for more details.
54
55A sub-section of a cube can be requested by defining the subsection
56with the \texttt{subsection} parameter and setting
57\texttt{flagSubsection = true} -- this can be a good idea if the cube
58has very noisy edges, which may produce many spurious detections.
59
60There are two ways of specifying the \texttt{subsection} string. The
61first is the generalised form
62\texttt{[x1:x2:dx,y1:y2:dy,z1:z2:dz,...]}, as used by the
63\textsc{cfitsio} library. This has one set of colon-separated numbers
64for each axis in the FITS file. In this manner, the x-coordinates run
65from \texttt{x1} to \texttt{x2} (inclusive), with steps of
66\texttt{dx}. The step value can be omitted, so a subsection of the
67form \texttt{[2:50,2:50,10:1000]} is still valid. In fact, \duchamp
68does not make use of any step value present in the subsection string,
69and any that are present are removed before the file is opened.
70
71If the entire range of a coordinate is required, one can replace the
72range with a single asterisk, \eg \texttt{[2:50,2:50,*]}. Thus, the
73subsection string \texttt{[*,*,*]} is simply the entire cube. Note
74that the pixel ranges for each axis start at 1, so the full pixel
75range of a 100-pixel axis would be expressed as 1:100. A complete
76description of this section syntax can be found at the
77\textsc{fitsio} web site%
78\footnote{%
79\href%
80{http://heasarc.gsfc.nasa.gov/docs/software/fitsio/c/c\_user/node91.html}%
81{http://heasarc.gsfc.nasa.gov/docs/software/fitsio/c/c\_user/node91.html}}.
82
83
84Making full use of the subsection requires knowledge of the size of
85each of the dimensions. If one wants to, for instance, trim a certain
86number of pixels off the edges of the cube, without examining the cube
87to obtain the actual size, one can use the second form of the
88subsection string. This just gives a number for each axis, \eg
89\texttt{[5,5,5]} (which would trim 5 pixels from the start \emph{and}
90end of each axis).
91
92All types of subsections can be combined \eg \texttt{[5,2:98,*]}.
93
94Typically, the units of pixel brightness are given by the FITS file's
95BUNIT keyword. However, this may often be unwieldy (for instance, the
96units are Jy/beam, but the values are around a few mJy/beam). It is
97therefore possible to nominate new units, to which the pixel values
98will be converted, by using the \texttt{newFluxUnits} input
99parameter. The units must be directly translatable from the existing
100ones -- for instance, if BUNIT is Jy/beam, you cannot specify mJy, it
101must be mJy/beam. If an incompatible unit is given, the BUNIT value is
102used instead.
103
104\secB{World Coordinate System}
105\label{sec-wcs}
106
107\duchamp uses the \textsc{wcslib} package to handle the conversions
108between pixel and world coordinates. This package uses the
109transformations described in the WCS papers
110\citep{greisen02,calabretta02,greisen06}. The same package handles the
111WCS axes in the spatial plots. The conversions used are governed by
112the information in the FITS header -- this is parsed by
113\textsc{wcslib} to create the appropriate transformations.
114
115For the spectral axis, however, \duchamp provides the ability to change the
116type of transformation used, so that different spectral quantities can
117be calculated. By using the parameter \texttt{spectralType}, the user
118can change from the type given in the FITS header. This should be done
119in line with the conventions outlined in \citet{greisen06}. The
120spectral type can be either a full 8-character string (\eg
121'VELO-F2V'), or simply the 4-character ``S-type'' (\eg 'VELO'), in
122which case \textsc{wcslib} will handle the conversion.
123
124The rest frequency can be provided as well. This may be necessary, if
125the FITS header does not specify one and you wish to transform to
126velocity. Alternatively, you may want to make your measurements based
127on a different spectral line (\eg OH1665 instead of
128H\textsc{i}-21cm). The input parameter \texttt{restFrequency} is used,
129and this will override the FITS header value.
130
131Finally, the user may also request different spectral units from those
132in the FITS file, or from the defaults arising from the
133\textsc{wcslib} transformation. The input parameter
134\texttt{spectralUnits} should be used, and \citet{greisen02} should be
135consulted to ensure the syntax is appropriate.
136
137\secB{Image modification}
138\label{sec-modify}
139
140Several modifications to the cube can be made that improve the
141execution and efficiency of \duchamp (their use is optional, governed
142by the relevant flags in the parameter file).
143
144\secC{BLANK pixel removal}
145\label{sec-blank}
146
147If the imaged area of a cube is non-rectangular (see the example in
148Fig.~\ref{fig-moment}, a cube from the HIPASS survey), BLANK pixels
149are used to pad it out to a rectangular shape. The value of these
150pixels is given by the FITS header keywords BLANK, BSCALE and
151BZERO. While these pixels make the image a nice shape, they will take
152up unnecessary space in memory, and so to potentially speed up the
153processing we can trim them from the edge. This is done when the
154parameter \texttt{flagTrim = true}. If the above keywords are not
155present, the trimming will not be done (in this case, a similar effect
156can be accomplished, if one knows where the ``blank'' pixels are, by
157using the subsection option).
158
159The amount of trimming is recorded, and these pixels are added back in
160once the source-detection is completed (so that quoted pixel positions
161are applicable to the original cube). Rows and columns are trimmed one
162at a time until the first non-BLANK pixel is reached, so that the
163image remains rectangular. In practice, this means that there will be
164some BLANK pixels left in the trimmed image (if the non-BLANK region
165is non-rectangular). However, these are ignored in all further
166calculations done on the cube.
167
168\secC{Baseline removal}
169\label{sec-baseline}
170
171Second, the user may request the removal of baselines from the
172spectra, via the parameter \texttt{flagBaseline}. This may be
173necessary if there is a strong baseline ripple present, which can
174result in spurious detections at the high points of the ripple. The
175baseline is calculated from a wavelet reconstruction procedure (see
176\S\ref{sec-recon}) that keeps only the two largest scales. This is
177done separately for each spatial pixel (\ie for each spectrum in the
178cube), and the baselines are stored and added back in before any
179output is done. In this way the quoted fluxes and displayed spectra
180are as one would see from the input cube itself -- even though the
181detection (and reconstruction if applicable) is done on the
182baseline-removed cube.
183
184The presence of very strong signals (for instance, masers at several
185hundred Jy) could affect the determination of the baseline, and would
186lead to a large dip centred on the signal in the baseline-subtracted
187spectrum. To prevent this, the signal is trimmed prior to the
188reconstruction process at some standard threshold (at $8\sigma$ above
189the mean). The baseline determined should thus be representative of
190the true, signal-free baseline. Note that this trimming is only a
191temporary measure which does not affect the source-detection.
192
193The baseline values can be saved to a FITS file for later
194examination. See \S\ref{sec-baselineOut} for details.
195
196%\secC{Ignoring bright Milky Way emission}
197%\label{sec-MW}
198%
199%Finally, a single set of contiguous channels can be ignored -- these
200%may exhibit very strong emission, such as that from the Milky Way as
201%seen in extragalactic \hi cubes (hence the references to ``Milky
202%Way'' in relation to this task -- apologies to Galactic
203%astronomers!). Such dominant channels will produce many detections
204%that are unnecessary, uninteresting (if one is interested in
205%extragalactic \hi) and large (in size and hence in memory usage), and
206%so will slow the program down and detract from the interesting
207%detections.
208%
209%The use of this feature is controlled by the \texttt{flagMW}
210%parameter, and the exact channels concerned are able to be set by the
211%user (using \texttt{maxMW} and \texttt{minMW} -- these give an
212%inclusive range of channels). These channels refer to the channel
213%numbers of \textbf{the full cube}, before any subsection is applied.
214%
215%The effect is to ignore detections that lie within these channels. If
216%a spatial search is being conducted (\ie one channel map at a time),
217%these channels are simply not searched. If a spectral search is being
218%conducted, those channels will be flagged so that no detection is made
219%within them. The spectral output (see Fig.~\ref{fig-spect}) will
220%ignore them as far as scaling the plot goes, and the channel range
221%will be indicated by a green hatched box.
222%
223%Note that these channels will be included in any smoothing or
224%reconstruction that is done on the array, and so will be included in
225%any saved FITS file (see \S\ref{sec-reconIO}).
226%
227
228\secC{Flagging channels}
229\label{sec-flagging}
230
231Finally, it is possible to flag particular channels so that they are
232not included in the search. This is an extension of the old ``Milky
233Way'' channel range. That allowed the specification of a single
234contiguous block of channels, and was aimed at excluding Galactic
235emission in extragalactic \hi cubes.
236
237The new flagging approach allows the specification of a series of
238channels and channel ranges. This allows the user to block the
239detection of known regions of RFI, or known but uninteresting emission
240(\eg Galactic \hi emission if you are searching for extragalactic
241sources).
242
243Flagged channels are specified using the \texttt{flaggedChannels}
244parameter, and can be given by a comma-separated list of single values
245or ranges. For instance: \texttt{flaggedChannels  5,6,12-20,87}. These
246channels refer to channel numbers in the \textbf{the full cube},
247before any subsection is applied. Also note that \textbf{the channel
248  numbering starts at zero}, that is, channel 0 is the first channel
249of the cube.
250
251The effect is to ignore detections that lie within these channels. If
252a spatial search is being conducted (\ie one channel map at a time),
253these channels are simply not searched. If a spectral search is being
254conducted, those channels will be flagged so that no detection is made
255within them. The spectral output (see Fig.~\ref{fig-spect}) will
256ignore them as far as scaling the plot goes, and the channel range
257will be indicated by a green hatched box.
258
259Note that these channels will be included in any smoothing or
260reconstruction that is done on the array, and so will be included in
261any saved FITS file (see \S\ref{sec-reconIO}).
262
263\secB{Image reconstruction}
264\label{sec-recon}
265
266The user can direct \duchamp to reconstruct the data cube using the
267multi-resolution \atrous wavelet algorithm. A good description of the
268procedure can be found in \citet{starck02a}. The reconstruction is an
269effective way of removing a lot of the noise in the image, allowing
270one to search reliably to fainter levels, and reducing the number of
271spurious detections. This is an optional step, but one that greatly
272enhances the reliability of the resulting catalogue, at the cost of
273additional CPU and memory usage (see \S\ref{sec-notes} for
274discussion).
275
276\secC{Algorithm}
277
278The steps in the \atrous reconstruction are as follows:
279\begin{enumerate}
280\item The reconstructed array is set to 0 everywhere.
281\item The input array is discretely convolved with a given filter
282  function. This is determined from the parameter file via the
283  \texttt{filterCode} parameter -- see Appendix~\ref{app-param} for
284  details on the filters available. Edges are dealt with by assuming
285  reflection at the boundary.
286\item The wavelet coefficients are calculated by taking the difference
287  between the convolved array and the input array.
288\item If the wavelet coefficients at a given point are above the
289  requested reconstruction threshold (given by \texttt{snrRecon} as
290  the number of $\sigma$ above the mean and adjusted to the current
291  scale -- see Appendix~\ref{app-scaling}), add these to the
292  reconstructed array.
293\item The separation between the filter coefficients is doubled. (Note
294  that this step provides the name of the procedure\footnote{\atrous
295  means ``with holes'' in French.}, as gaps or holes are created in
296  the filter coverage.)
297\item The procedure is repeated from step 2, using the convolved array
298  as the input array.
299\item Continue until the required maximum number of scales is reached.
300\item Add the final smoothed (\ie convolved) array to the
301  reconstructed array. This provides the ``DC offset'', as each of the
302  wavelet coefficient arrays will have zero mean.
303\end{enumerate}
304
305The range of scales at which the selection of wavelet coefficients is
306made is governed by the \texttt{scaleMin} and \texttt{scaleMax}
307parameters. The minimum scale used is given by \texttt{scaleMin},
308where the default value is 1 (the first scale). This parameter is
309useful if you want to ignore the highest-frequency features
310(e.g. high-frequency noise that might be present). Normally the
311maximum scale is calculated from the size of the input array, but it
312can be specified by using \texttt{scaleMax}. A value $\le0$ will
313result in the use of the calculated value, as will a value of
314\texttt{scaleMax} greater than the calculated value. Use of these two
315parameters can allow searching for features of a particular scale
316size, for instance searching for narrow absorption features.
317
318The reconstruction has at least two iterations. The first iteration
319makes a first pass at the wavelet reconstruction (the process outlined
320in the 8 stages above), but the residual array will likely have some
321structure still in it, so the wavelet filtering is done on the
322residual, and any significant wavelet terms are added to the final
323reconstruction. This step is repeated until the relative change in the
324measured standard deviation of the residual (see note below on the
325evaluation of this quantity) is less than some value, given by the
326\texttt{reconConvergence} parameter.
327
328It is important to note that the \atrous decomposition is an example
329of a ``redundant'' transformation. If no thresholding is performed,
330the sum of all the wavelet coefficient arrays and the final smoothed
331array is identical to the input array. The thresholding thus removes
332only the unwanted structure in the array.
333
334Note that any BLANK pixels that are still in the cube will not be
335altered by the reconstruction -- they will be left as BLANK so that
336the shape of the valid part of the cube is preserved.
337
338\secC{Note on Statistics}
339
340The correct calculation of the reconstructed array needs good
341estimators of the underlying mean and standard deviation (or rms) of
342the background noise distribution. The methods used to estimate these
343quantities are detailed in \S\ref{sec-stats} -- the default behaviour
344is to use robust estimators, to avoid biasing due to bright pixels.
345
346When thresholding the different wavelet scales, the value of the rms
347as measured from the wavelet array needs to be scaled to account for
348the increased amount of correlation between neighbouring pixels (due
349to the convolution). See Appendix~\ref{app-scaling} for details on
350this scaling.
351
352\secC{User control of reconstruction parameters}
353
354The most important parameter for the user to select in relation to the
355reconstruction is the threshold for each wavelet array. This is set
356using the \texttt{snrRecon} parameter, and is given as a multiple of
357the rms (estimated by the MADFM) above the mean (which for the wavelet
358arrays should be approximately zero). There are several other
359parameters that can be altered as well that affect the outcome of the
360reconstruction.
361
362By default, the cube is reconstructed in three dimensions, using a
363three-dimensional filter and three-dimensional convolution. This can be
364altered, however, using the parameter \texttt{reconDim}. If set to 1,
365this means the cube is reconstructed by considering each spectrum
366separately, whereas \texttt{reconDim=2} will mean the cube is
367reconstructed by doing each channel map separately. The merits of
368these choices are discussed in \S\ref{sec-notes}, but it should be
369noted that a 2-dimensional reconstruction can be susceptible to edge
370effects if the spatial shape of the pixel array is not rectangular.
371
372The user can also select the minimum and maximum scales to be used in
373the reconstruction. The first scale exhibits the highest frequency
374variations, and so ignoring this one can sometimes be beneficial in
375removing excess noise. The default is to use all scales
376(\texttt{minscale = 1}).
377
378The convergence of the \atrous iterations is governed by the
379\texttt{reconConvergence} parameter, which is the fractional decrease
380in the standard deviation of the residuals from one iteration to the
381next. \duchamp will do at least two iterations, and then continue
382until the decrease is less than the value of this parameter.
383
384Finally, the filter that is used for the convolution can be selected
385by using \texttt{filterCode} and the relevant code number -- the
386choices are listed in Appendix~\ref{app-param}. A larger filter will
387give a better reconstruction, but take longer and use more memory when
388executing. When multi-dimensional reconstruction is selected, this
389filter is used to construct a 2- or 3-dimensional equivalent.
390
391\secB{Smoothing the cube}
392\label{sec-smoothing}
393
394An alternative to doing the wavelet reconstruction is to smooth the
395cube.  This technique can be useful in reducing the noise level (at
396the cost of making neighbouring pixels correlated and blurring any
397signal present), and is particularly well suited to the case where a
398particular signal size (\ie a certain channel width or spatial size)
399is believed to be present in the data.
400
401There are two alternative methods that can be used: spectral
402smoothing, using the Hanning filter; or spatial smoothing, using a 2D
403Gaussian kernel. These alternatives are outlined below. To utilise the
404smoothing option, set the parameter \texttt{flagSmooth=true} and set
405\texttt{smoothType} to either \texttt{spectral} or \texttt{spatial}.
406
407\secC{Spectral smoothing}
408
409When \texttt{smoothType = spectral} is selected, the cube is smoothed
410only in the spectral domain. Each spectrum is independently smoothed
411by a Hanning filter, and then put back together to form the smoothed
412cube, which is then used by the searching algorithm (see below). Note
413that in the case of both the reconstruction and the smoothing options
414being requested, the reconstruction will take precedence and the
415smoothing will \emph{not} be done.
416
417There is only one parameter necessary to define the degree of
418smoothing -- the Hanning width $a$ (given by the user parameter
419\texttt{hanningWidth}). The coefficients $c(x)$ of the Hanning filter
420are defined by
421\[
422c(x) =
423  \begin{cases}
424   \frac{1}{2}\left(1+\cos(\frac{\pi x}{a})\right) &|x| < (a+1)/2\\
425   0                                               &|x| \geq (a+1)/2.
426  \end{cases},\ a,x \in \mathbb{Z}
427\]
428Note that the width specified must be an
429odd integer (if the parameter provided is even, it is incremented by
430one).
431
432\secC{Spatial smoothing}
433
434When \texttt{smoothType = spatial} is selected, the cube is smoothed
435only in the spatial domain. Each channel map is independently smoothed
436by a two-dimensional Gaussian kernel, put back together to form the
437smoothed cube, and used in the searching algorithm (see below). Again,
438reconstruction is always done by preference if both techniques are
439requested.
440
441The two-dimensional Gaussian has three parameters to define it,
442governed by the elliptical cross-sectional shape of the Gaussian
443function: the FWHM (full-width at half-maximum) of the major and minor
444axes, and the position angle of the major axis. These are given by the
445user parameters \texttt{kernMaj, kernMin} \& \texttt{kernPA}. If a
446circular Gaussian is required, the user need only provide the
447\texttt{kernMaj} parameter. The \texttt{kernMin} parameter will then
448be set to the same value, and \texttt{kernPA} to zero.  If we define
449these parameters as $a,b,\theta$ respectively, we can define the
450kernel by the function
451\[
452k(x,y) = \frac{1}{2\pi\sigma_X\sigma_Y} \exp\left[-0.5
453  \left(\frac{X^2}{\sigma_X^2} + \frac{Y^2}{\sigma_Y^2} \right)
454\right]
455\]
456where $(x,y)$ are the offsets from the central pixel of the gaussian
457function, and
458\begin{align*}
459X& = x\sin\theta - y\cos\theta&
460  Y&= x\cos\theta + y\sin\theta\\
461\sigma_X^2& = \frac{(a/2)^2}{2\ln2}&
462  \sigma_Y^2& = \frac{(b/2)^2}{2\ln2}\\
463\end{align*}
464
465\secB{Input/Output of reconstructed/smoothed arrays}
466\label{sec-reconIO}
467
468The smoothing and reconstruction stages can be relatively
469time-consuming, particularly for large cubes and reconstructions in
4703-D (or even spatial smoothing). To get around this, \duchamp provides
471a shortcut to allow users to perform multiple searches (\eg with
472different thresholds) on the same reconstruction/smoothing setup
473without re-doing the calculations each time.
474
475To save the reconstructed array as a FITS file, set
476\texttt{flagOutputRecon = true}. The file will be saved in the same
477directory as the input image, so the user needs to have write
478permissions for that directory.
479
480The name of the file can given by the \texttt{fileOutputRecon}
481parameter, but this can be ignored and \duchamp will present a name
482based on the reconstruction parameters. The filename will be derived
483from the input filename, with extra information detailing the
484reconstruction that has been done. For example, suppose
485\texttt{image.fits} has been reconstructed using a 3-dimensional
486reconstruction with filter \#2, thresholded at $4\sigma$ using all
487scales from 1 to 5, with a convergence criterion of 0.005. The output
488filename will then be \texttt{image.RECON-3-2-4-1-5-0.005.fits} (\ie
489it uses the six parameters relevant for the \atrous reconstruction as
490listed in Appendix~\ref{app-param}). The new FITS file will also have
491these parameters as header keywords. If a subsection of the input
492image has been used (see \S\ref{sec-input}), the format of the output
493filename will be \texttt{image.sub.RECON-3-2-4-1-5-0.005.fits}, and the
494subsection that has been used is also stored in the FITS header.
495
496Likewise, the residual image, defined as the difference between the
497input and reconstructed arrays, can also be saved in the same manner
498by setting \texttt{flagOutputResid = true}. Its filename will be the
499same as above, with \texttt{RESID} replacing \texttt{RECON}.
500
501If a reconstructed image has been saved, it can be read in and used
502instead of redoing the reconstruction. To do so, the user should set
503the parameter \texttt{flagReconExists = true}. The user can indicate
504the name of the reconstructed FITS file using the \texttt{reconFile}
505parameter, or, if this is not specified, \duchamp searches for the
506file with the name as defined above. If the file is not found, the
507reconstruction is performed as normal. Note that to do this, the user
508needs to set \texttt{flagAtrous = true} (obviously, if this is
509\texttt{false}, the reconstruction is not needed).
510
511To save the smoothed array, set \texttt{flagOutputSmooth = true}. As
512for the reconstructed/residual arrays, the name of the file can given
513by the parameter \texttt{fileOutputSmooth}, but this can be ignored
514and \duchamp will present a name that indicates the both the type and
515the details of the smoothing method used. It will be either
516\texttt{image.SMOOTH-1D-a.fits}, where a is replaced by the Hanning
517width used, or \texttt{image.SMOOTH-2D-a-b-c.fits}, where the Gaussian
518kernel parameters are a,b,c. Similarly to the reconstruction case, a
519saved file can be read in by setting \texttt{flagSmoothExists = true}
520and either specifying a file to be read with the \texttt{smoothFile}
521parameter or relying on \duchamp to find the file with the name as
522given above.
523
524
525\secB{Searching the image}
526\label{sec-detection}
527
528\secC{Representation of detected objects}
529\label{sec-scan}
530
531\begin{figure}
532\includegraphics[width=\textwidth]{exampleObject}
533\caption{An example of the run-length encoding method of storing
534pixel information. The scans used to encode the image are listed
535alongside the relevant row. The pixels are colour-coded by
536nominal pixel values, but note that the pixel values themselves
537do not form part of the encoding and are not kept as part of the
538object class. }
539\label{fig-objExample}
540\end{figure}
541
542The principle aim of \duchamp is to provide a catalogue of sources
543located in the image. While running, \duchamp needs to maintain for
544each source several data structures that will contribute to the memory
545footprint: a record of which pixels contribute to the source; a set of
546measured parameters that will go into the catalogue; and a separate
547two-dimensional map showing the spatial location of detected pixels
548(carrying this around makes the computation of detection maps easier
549-- see \S\ref{sec-spatialmaps}).
550
551To keep track of the set of detected pixels, \duchamp
552employs specialised techniques that keep the memory usage
553manageable. A naive method could be to store each single pixel, but
554this results in a lot of redundant information being stored in memory.
555
556To reduce the storage requirements, the run-length encoding method is
557used for storing the spatial information. In this fashion, an object
558in 2D is stored as a series of ``runs'', encoded by a row number (the
559$y$-value), the starting column (the minimum $x$-value) and the run
560length ($\ell_x$: the number of contiguous pixels in that row
561connected to the starting pixel). A single set of $(y,x,\ell_x)$
562values is called a ``scan''. A two-dimensional image is therefore made
563up of a set of scans. An example can be seen in
564Fig.~\ref{fig-objExample}. Note that the object shown has fourteen
565pixels, and so would require 28 integers to record the positions of
566all pixels. The run-length encoding uses just 18 integers to record
567the same information. The longer the runs are in each scan, the
568greater the saving of storage over the naive method.
569
570A 3D object is stored as a set of channel maps, with a channel map
571being a 2D plane with constant $z$-value. Each channel map is itself a
572set of scans showing the $(x,y)$ position of the pixels. The
573additional detection map is stored as a separate channel map, also
574made up of scans.
575
576Note that these pixel map representations do not carry the flux
577information with them. They store just the pixel locations and need to
578be combined with an array of flux values to provide parameters such as
579integrated flux. The advantage of this approach is that the pixel
580locations can be easily applied to different flux arrays as the need
581permits (for instance, defining them using the reconstructed array,
582yet evaluating parameters on the original array).
583
584This scan-based run-length encoding is how the individual detections
585are stored in the binary catalogue described in \S\ref{sec-bincat}.
586
587\secC{Technique}
588\label{sec-searchTechnique}
589
590The basic idea behind detection in \duchamp is to locate sets of
591contiguous voxels that lie above some threshold. No size or shape
592requirement is imposed upon the detections, and no fitting (for
593instance, fitting Gaussian profiles) is done on the sources. All
594\duchamp does is find connected groups of bright voxels and report
595their locations and basic parameters.
596
597One threshold is calculated for the entire cube, enabling calculation
598of signal-to-noise ratios for each source (see
599\S\ref{sec-output} for details). The user can manually specify a
600value (using the parameter \texttt{threshold}) for the threshold,
601which will override the calculated value. Note that this option
602overrides any settings of \texttt{snrCut} or FDR options (see below).
603
604The cube can be searched in one of two ways, governed by the input
605parameter \texttt{searchType}. If \texttt{searchType=spatial}, the
606cube is searched one channel map at a time, using the 2-dimensional
607raster-scanning algorithm of \citet{lutz80} that connects groups of
608neighbouring pixels. Such an algorithm cannot be applied directly to a
6093-dimensional case, as it requires that objects are completely nested
610in a row (when scanning along a row, if an object finishes and other
611starts, you won't get back to the first until the second is completely
612finished for the row). Three-dimensional data does not have this
613property, hence the need to treat the data on a 2-dimensional basis at
614most.
615
616Alternatively, if \texttt{searchType=spectral}, the searching is done
617in one dimension on each individual spatial pixel's spectrum. This is
618a simpler search, but there are potentially many more of them.
619
620Although there are parameters that govern the minimum number of pixels
621in a spatial, spectral and total senses that an object must have
622(\texttt{minPix}, \texttt{minChannels} and \texttt{minVoxels}
623respectively), these criteria are not applied at this point - see
624\S\ref{sec-reject} for details.
625
626Finally, the search only looks for positive features. If one is
627interested instead in negative features (such as absorption lines),
628set the parameter \texttt{flagNegative = true}. This will invert the
629cube (\ie multiply all pixels by $-1$) prior to the search, and then
630re-invert the cube (and the fluxes of any detections) after searching
631is complete. If the reconstructed or smoothed array has been read in
632from disk, this will also be inverted at the same time. All outputs
633are done in the same manner as normal, so that fluxes of detections
634will be negative.
635
636\secC{Calculating statistics}
637\label{sec-stats}
638
639A crucial part of the detection process (as well as the wavelet
640reconstruction: \S\ref{sec-recon}) is estimating the statistics that
641define the detection threshold. To determine a threshold, we need to
642estimate from the data two parameters: the middle of the noise
643distribution (the ``noise level''), and the width of the distribution
644(the ``noise spread''). The noise level is estimated by either the
645mean or the median, and the noise spread by the rms (or the standard
646deviation) or the median absolute deviation from the median
647(MADFM). The median and MADFM are robust statistics, in that they are
648not biased by the presence of a few pixels much brighter than the
649noise.
650
651All four statistics are calculated automatically, but the choice of
652parameters that will be used is governed by the input parameter
653\texttt{flagRobustStats}. This has the default value \texttt{true},
654meaning the underlying mean of the noise distribution is estimated by
655the median, and the underlying standard deviation is estimated by the
656MADFM. In the latter case, the value is corrected, under the
657assumption that the underlying distribution is Normal (Gaussian), by
658dividing by 0.6744888 -- see Appendix~\ref{app-madfm} for details. If
659\texttt{flagRobustStats=false}, the mean and rms are used instead.
660
661The choice of pixels to be used depend on the analysis method. If the
662wavelet reconstruction has been done, the residuals (defined
663in the sense of original $-$ reconstruction) are used to estimate the
664noise spread of the cube, since the reconstruction should pick out
665all significant structure. The noise level (the middle of the
666distribution) is taken from the original array.
667
668If smoothing of the cube has been done instead, all noise parameters
669are measured from the smoothed array, and detections are made with
670these parameters. When the signal-to-noise level is quoted for each
671detection (see \S\ref{sec-output}), the noise parameters of the
672original array are used, since the smoothing process correlates
673neighbouring pixels, reducing the noise level.
674
675If neither reconstruction nor smoothing has been done, then the
676statistics are calculated from the original, input array.
677
678The parameters that are estimated should be representative of the
679noise in the cube. For the case of small objects embedded in many
680noise pixels (\eg the case of \hi surveys), using the full cube will
681provide good estimators. It is possible, however, to use only a
682subsection of the cube by setting the parameter \texttt{flagStatSec =
683  true} and providing the desired subsection to the \texttt{StatSec}
684parameter. This subsection works in exactly the same way as the pixel
685subsection discussed in \S\ref{sec-input}. The \texttt{StatSec} will
686be trimmed if necessary so that it lies wholly within the image
687subsection being used (\ie that given by the \texttt{subsection}
688parameter - this governs what pixels are read in and so are able to be
689used in the calculations).
690
691Note that \texttt{StatSec} applies only to the statistics used to
692determine the threshold. It does not affect the calculation of
693statistics in the case of the wavelet reconstruction. Note also that
694pixels flagged as BLANK or as part of the ``Milky Way'' range of
695channels are ignored in the statistics calculations.
696
697\secC{Determining the threshold}
698
699Once the statistics have been calculated, the threshold is determined
700in one of two ways. The first way is a simple sigma-clipping, where a
701threshold is set at a fixed number $n$ of standard deviations above
702the mean, and pixels above this threshold are flagged as detected. The
703value of $n$ is set with the parameter \texttt{snrCut}. The ``mean''
704and ``standard deviation'' here are estimated according to
705\texttt{flagRobustStats}, as discussed in \S\ref{sec-stats}. In this
706first case only, if the user specifies a threshold, using the
707\texttt{threshold} parameter, the sigma-clipped value is ignored.
708
709The second method uses the False Discovery Rate (FDR) technique
710\citep{miller01,hopkins02}, whose basis we briefly detail here. The
711false discovery rate (given by the number of false detections divided
712by the total number of detections) is fixed at a certain value
713$\alpha$ (\eg $\alpha=0.05$ implies 5\% of detections are false
714positives). In practice, an $\alpha$ value is chosen, and the ensemble
715average FDR (\ie $\langle FDR \rangle$) when the method is used will
716be less than $\alpha$.  One calculates $p$ -- the probability,
717assuming the null hypothesis is true, of obtaining a test statistic as
718extreme as the pixel value (the observed test statistic) -- for each
719pixel, and sorts them in increasing order. One then calculates $d$
720where
721\[
722d = \max_j \left\{ j : P_j < \frac{j\alpha}{c_N N} \right\},
723\]
724and then rejects all hypotheses whose $p$-values are less than or
725equal to $P_d$. (So a $P_i<P_d$ will be rejected even if $P_i \geq
726j\alpha/c_N N$.) Note that ``reject hypothesis'' here means ``accept
727the pixel as an object pixel'' (\ie we are rejecting the null
728hypothesis that the pixel belongs to the background).
729
730The $c_N$ value here is a normalisation constant that depends on the
731correlated nature of the pixel values. If all the pixels are
732uncorrelated, then $c_N=1$. If $N$ pixels are correlated, then their
733tests will be dependent on each other, and so $c_N = \sum_{i=1}^N
734i^{-1}$. \citet{hopkins02} consider real radio data, where the pixels
735are correlated over the beam. For the calculations done in \duchamp,
736$N = B \times C$, where $B$ is the beam area in pixels, calculated
737from the FITS header (if the correct keywords -- BMAJ, BMIN -- are not
738present, the size of the beam is taken from the input parameters - see
739discussion in \S\ref{sec-results}, and if these parameters are not
740given, $B=1$), and $C$ is the number of neighbouring channels that can
741be considered to be correlated.
742
743The use of the FDR method is governed by the \texttt{flagFDR} flag,
744which is \texttt{false} by default. To set the relevant parameters,
745use \texttt{alphaFDR} to set the $\alpha$ value, and
746\texttt{FDRnumCorChan} to set the $C$ value discussed above. These
747have default values of 0.01 and 2 respectively.
748
749The theory behind the FDR method implies a direct connection between
750the choice of $\alpha$ and the fraction of detections that will be
751false positives. These detections, however, are individual pixels,
752which undergo a process of merging and rejection (\S\ref{sec-merger}),
753and so the fraction of the final list of detected objects that are
754false positives will be much smaller than $\alpha$. See the discussion
755in \S\ref{sec-notes}.
756
757%\secC{Storage of detected objects in memory}
758%
759%It is useful to understand how \duchamp stores the detected objects in
760%memory while it is running. This makes use of nested C++ classes, so
761%that an object is stored as a class that includes the set of detected
762%pixels, plus all the various calculated parameters (fluxes, WCS
763%coordinates, pixel centres and extrema, flags,...). The set of pixels
764%are stored using another class, that stores 3-dimensional objects as a
765%set of channel maps, each consisting of a $z$-value and a
766%2-dimensional object (a spatial map if you like). This 2-dimensional
767%object is recorded using ``run-length'' encoding, where each row (a
768%fixed $y$ value) is stored by the starting $x$-value and the length
769
770\secB{Merging, growing and rejecting detected objects}
771\label{sec-merger}
772
773\secC{Merging}
774
775The searches described above are either 1- or 2-dimensional only. They
776do not know anything about the third dimension that is likely to be
777present. To build up 3D sources, merging of detections must be
778done. This is done via an algorithm that matches objects judged to be
779``close'', according to one of two criteria.
780
781One criterion is to define two thresholds -- one spatial and one in
782velocity -- and say that two objects should be merged if there is at
783least one pair of pixels that lie within these threshold distances of
784each other. These thresholds are specified by the parameters
785\texttt{threshSpatial} and \texttt{threshVelocity} (in units of pixels
786and channels respectively).
787
788Alternatively, the spatial requirement can be changed to say that
789there must be a pair of pixels that are \emph{adjacent} -- a stricter,
790but perhaps more realistic requirement, particularly when the spatial
791pixels have a large angular size (as is the case for \hi
792surveys). This method can be selected by setting the parameter
793\texttt{flagAdjacent=true} in the parameter file. The velocity
794thresholding is always done with the \texttt{threshVelocity} test.
795
796
797\secC{Stages of merging}
798
799This merging can be done in two stages. The default behaviour is for
800each new detection to be compared with those sources already detected,
801and for it to be merged with the first one judged to be close. No
802other examination of the list is done at this point.
803
804This step can be turned off by setting
805\texttt{flagTwoStageMerging=false}, so that new detections are simply
806added to the end of the list, leaving all merging to be done in the
807second stage.
808
809The second, main stage of merging is more thorough, Once the searching
810is completed, the list is iterated through, looking at each pair of
811objects, and merging appropriately. The merged objects are then
812included in the examination, to see if a merged pair is suitably close
813to a third.
814
815\secC{Growing}
816
817Once the detections have been merged, they may be ``grown'' (this is
818essentially the process known elsewhere as ``floodfill''). This is a
819process of increasing the size of the detection by adding nearby
820pixels (according to the \texttt{threshSpatial} and
821\texttt{threshVelocity} parameters) that are above some secondary
822threshold and not already part of a detected object. This threshold
823should be lower than the one used for the initial detection, but above
824the noise level, so that faint pixels are only detected when they are
825close to a bright pixel. This threshold is specified via one of two
826input parameters. It can be given in terms of the noise statistics via
827\texttt{growthCut} (which has a default value of $3\sigma$), or it can
828be directly given via \texttt{growthThreshold}. Note that if you have
829given the detection threshold with the \texttt{threshold} parameter,
830the growth threshold \textbf{must} be given with
831\texttt{growthThreshold}. If \texttt{growthThreshold} is not provided
832in this situation, the growing will not be done.
833
834The use of the growth algorithm is controlled by the
835\texttt{flagGrowth} parameter -- the default value of which is
836\texttt{false}. If the detections are grown, they are sent through the
837merging algorithm a second time, to pick up any detections that should
838be merged at the new lower threshold (\ie they have grown into each
839other).
840
841\secC{Rejecting}
842\label{sec-reject}
843
844Finally, to be accepted, the detections must satisfy minimum size
845criteria, relating to the number of channels, spatial pixels and
846voxels occupied by the object. These criteria are set using the
847\texttt{minChannels}, \texttt{minPix} and \texttt{minVoxels}
848parameters respectively. The channel requirement means a source must
849have at least one set of \texttt{minChannels} consecutive channels to
850be accepted. The spatial pixels (\texttt{minPix}) requirement refers
851to distinct spatial pixels (which are possibly in different channels),
852while the voxels requirement refers to the total number of voxels
853detected. If the \texttt{minVoxels} parameter is not provided, it
854defaults to \texttt{minPix}$+$\texttt{minChannels}-1.
855
856It is possible to do this rejection stage before the main merging and
857growing stage. This could be done to remove narrow (hopefully
858spurious) sources from the list before growing them, to reduce the
859number of false positives in the final list. This mode can be selected
860by setting the input parameter \texttt{flagRejectBeforeMerge=true} --
861caution is urged if you use this in conjunction with
862\texttt{flagTwoStageMerging=false}, as you can throw away parts of
863objects that you may otherwise wish to keep.
864
865%%% Local Variables:
866%%% mode: latex
867%%% TeX-master: "Guide"
868%%% End:
Note: See TracBrowser for help on using the repository browser.