source: tags/release-1.1.7/docs/executionFlow.tex @ 1455

Last change on this file since 1455 was 525, checked in by MatthewWhiting, 15 years ago

Changes related to ticket #17: allowing the specification of output names for the various fits files. Also associated documentation.

File size: 33.4 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
48pixel locations to quantities such as position on the sky, frequency,
49velocity, and so on.} information for the cube is also obtained from
50the FITS header by \textsc{wcslib} functions \citep{greisen02,
51calabretta02}, and this information, in the form of a \texttt{wcsprm}
52structure, is also stored in the same class.
53
54A sub-section of a cube can be requested by defining the subsection
55with the \texttt{subsection} parameter and setting
56\texttt{flagSubsection = true} -- this can be a good idea if the cube
57has very noisy edges, which may produce many spurious detections.
58
59There are two ways of specifying the \texttt{subsection} string. The
60first is the generalised form
61\texttt{[x1:x2:dx,y1:y2:dy,z1:z2:dz,...]}, as used by the
62\textsc{cfitsio} library. This has one set of colon-separated numbers
63for each axis in the FITS file. In this manner, the x-coordinates run
64from \texttt{x1} to \texttt{x2} (inclusive), with steps of
65\texttt{dx}. The step value can be omitted, so a subsection of the
66form \texttt{[2:50,2:50,10:1000]} is still valid. In fact, \duchamp
67does not make use of any step value present in the subsection string,
68and any that are present are removed before the file is opened.
69
70If the entire range of a coordinate is required, one can replace the
71range with a single asterisk, \eg \texttt{[2:50,2:50,*]}. Thus, the
72subsection string \texttt{[*,*,*]} is simply the entire cube. Note
73that the pixel ranges for each axis start at 1, so the full pixel
74range of a 100-pixel axis would be expressed as 1:100. A complete
75description of this section syntax can be found at the
76\textsc{fitsio} web site%
77\footnote{%
78\href%
79{http://heasarc.gsfc.nasa.gov/docs/software/fitsio/c/c\_user/node91.html}%
80{http://heasarc.gsfc.nasa.gov/docs/software/fitsio/c/c\_user/node91.html}}.
81
82
83Making full use of the subsection requires knowledge of the size of
84each of the dimensions. If one wants to, for instance, trim a certain
85number of pixels off the edges of the cube, without examining the cube
86to obtain the actual size, one can use the second form of the
87subsection string. This just gives a number for each axis, \eg
88\texttt{[5,5,5]} (which would trim 5 pixels from the start \emph{and}
89end of each axis).
90
91All types of subsections can be combined \eg \texttt{[5,2:98,*]}.
92
93Typically, the units of pixel brightness are given by the FITS file's
94BUNIT keyword. However, this may often be unwieldy (for instance, the
95units are Jy/beam, but the values are around a few mJy/beam). It is
96therefore possible to nominate new units, to which the pixel values
97will be converted, by using the \texttt{newFluxUnits} input
98parameter. The units must be directly translatable from the existing
99ones -- for instance, if BUNIT is Jy/beam, you cannot specify mJy, it
100must be mJy/beam. If an incompatible unit is given, the BUNIT value is
101used instead.
102
103\secB{Image modification}
104\label{sec-modify}
105
106Several modifications to the cube can be made that improve the
107execution and efficiency of \duchamp (their use is optional, governed
108by the relevant flags in the parameter file).
109
110\secC{BLANK pixel removal}
111\label{sec-blank}
112
113If the imaged area of a cube is non-rectangular (see the example in
114Fig.~\ref{fig-moment}, a cube from the HIPASS survey), BLANK pixels
115are used to pad it out to a rectangular shape. The value of these
116pixels is given by the FITS header keywords BLANK, BSCALE and
117BZERO. While these pixels make the image a nice shape, they will take
118up unnecessary space in memory, and so to potentially speed up the
119processing we can trim them from the edge. This is done when the
120parameter \texttt{flagTrim = true}. If the above keywords are not
121present, the trimming will not be done (in this case, a similar effect
122can be accomplished, if one knows where the ``blank'' pixels are, by
123using the subsection option).
124
125The amount of trimming is recorded, and these pixels are added back in
126once the source-detection is completed (so that quoted pixel positions
127are applicable to the original cube). Rows and columns are trimmed one
128at a time until the first non-BLANK pixel is reached, so that the
129image remains rectangular. In practice, this means that there will be
130some BLANK pixels left in the trimmed image (if the non-BLANK region
131is non-rectangular). However, these are ignored in all further
132calculations done on the cube.
133
134\secC{Baseline removal}
135
136Second, the user may request the removal of baselines from the
137spectra, via the parameter \texttt{flagBaseline}. This may be
138necessary if there is a strong baseline ripple present, which can
139result in spurious detections at the high points of the ripple. The
140baseline is calculated from a wavelet reconstruction procedure (see
141\S\ref{sec-recon}) that keeps only the two largest scales. This is
142done separately for each spatial pixel (\ie for each spectrum in the
143cube), and the baselines are stored and added back in before any
144output is done. In this way the quoted fluxes and displayed spectra
145are as one would see from the input cube itself -- even though the
146detection (and reconstruction if applicable) is done on the
147baseline-removed cube.
148
149The presence of very strong signals (for instance, masers at several
150hundred Jy) could affect the determination of the baseline, and would
151lead to a large dip centred on the signal in the baseline-subtracted
152spectrum. To prevent this, the signal is trimmed prior to the
153reconstruction process at some standard threshold (at $8\sigma$ above
154the mean). The baseline determined should thus be representative of
155the true, signal-free baseline. Note that this trimming is only a
156temporary measure which does not affect the source-detection.
157
158\secC{Ignoring bright Milky Way emission}
159\label{sec-MW}
160
161Finally, a single set of contiguous channels can be ignored -- these
162may exhibit very strong emission, such as that from the Milky Way as
163seen in extragalactic \hi cubes (hence the references to ``Milky
164Way'' in relation to this task -- apologies to Galactic
165astronomers!). Such dominant channels will produce many detections
166that are unnecessary, uninteresting (if one is interested in
167extragalactic \hi) and large (in size and hence in memory usage), and
168so will slow the program down and detract from the interesting
169detections.
170
171The use of this feature is controlled by the \texttt{flagMW}
172parameter, and the exact channels concerned are able to be set by the
173user (using \texttt{maxMW} and \texttt{minMW} -- these give an
174inclusive range of channels). When employed, these channels are
175ignored for the searching, and the scaling of the spectral output (see
176Fig.~\ref{fig-spect}) will not take them into account. They will be
177present in the reconstructed array, however, and so will be included
178in the saved FITS file (see \S\ref{sec-reconIO}). When the final
179spectra are plotted, the range of channels covered by these parameters
180is indicated by a green hashed box.
181
182\secB{Image reconstruction}
183\label{sec-recon}
184
185The user can direct \duchamp to reconstruct the data cube using the
186\atrous wavelet procedure. A good description of the procedure can be
187found in \citet{starck02:book}. The reconstruction is an effective way
188of removing a lot of the noise in the image, allowing one to search
189reliably to fainter levels, and reducing the number of spurious
190detections. This is an optional step, but one that greatly enhances
191the source-detection process, with the payoff that it can be
192relatively time- and memory-intensive.
193
194\secC{Algorithm}
195
196The steps in the \atrous reconstruction are as follows:
197\begin{enumerate}
198\item The reconstructed array is set to 0 everywhere.
199\item The input array is discretely convolved with a given filter
200  function. This is determined from the parameter file via the
201  \texttt{filterCode} parameter -- see Appendix~\ref{app-param} for
202  details on the filters available.
203\item The wavelet coefficients are calculated by taking the difference
204  between the convolved array and the input array.
205\item If the wavelet coefficients at a given point are above the
206  requested threshold (given by \texttt{snrRecon} as the number of
207  $\sigma$ above the mean and adjusted to the current scale -- see
208  Appendix~\ref{app-scaling}), add these to the reconstructed array.
209\item The separation between the filter coefficients is doubled. (Note
210  that this step provides the name of the procedure\footnote{\atrous
211  means ``with holes'' in French.}, as gaps or holes are created in
212  the filter coverage.)
213\item The procedure is repeated from step 2, using the convolved array
214  as the input array.
215\item Continue until the required maximum number of scales is reached.
216\item Add the final smoothed (\ie convolved) array to the
217  reconstructed array. This provides the ``DC offset'', as each of the
218  wavelet coefficient arrays will have zero mean.
219\end{enumerate}
220
221The range of scales at which the selection of wavelet coefficients is
222made is governed by the \texttt{scaleMin} and \texttt{scaleMax}
223parameters. The minimum scale used is given by \texttt{scaleMin},
224where the default value is 1 (the first scale). This parameter is
225useful if you want to ignore the highest-frequency features
226(e.g. high-frequency noise that might be present). Normally the
227maximum scale is calculated from the size of the input array, but it
228can be specified by using \texttt{scaleMax}. A value $\le0$ will
229result in the use of the calculated value, as will a value of
230\texttt{scaleMax} greater than the calculated value. Use of these two
231parameters can allow searching for features of a particular scale
232size, for instance searching for narrow absorption features.
233
234The reconstruction has at least two iterations. The first iteration
235makes a first pass at the wavelet reconstruction (the process outlined
236in the 8 stages above), but the residual array will likely have some
237structure still in it, so the wavelet filtering is done on the
238residual, and any significant wavelet terms are added to the final
239reconstruction. This step is repeated until the change in the measured
240standard deviation of the background (see note below on the evaluation
241of this quantity) is less than some fiducial amount.
242
243It is important to note that the \atrous decomposition is an example
244of a ``redundant'' transformation. If no thresholding is performed,
245the sum of all the wavelet coefficient arrays and the final smoothed
246array is identical to the input array. The thresholding thus removes
247only the unwanted structure in the array.
248
249Note that any BLANK pixels that are still in the cube will not be
250altered by the reconstruction -- they will be left as BLANK so that
251the shape of the valid part of the cube is preserved.
252
253\secC{Note on Statistics}
254
255The correct calculation of the reconstructed array needs good
256estimators of the underlying mean and standard deviation (or rms) of
257the background noise distribution. The methods used to estimate these
258quantities are detailed in \S\ref{sec-stats} -- the default behaviour
259is to use robust estimators, to avoid biasing due to bright pixels.
260
261%These statistics are estimated using
262%robust methods, to avoid corruption by strong outlying points. The
263%mean of the distribution is actually estimated by the median, while
264%the median absolute deviation from the median (MADFM) is calculated
265%and corrected assuming Gaussianity to estimate the underlying standard
266%deviation $\sigma$. The Gaussianity (or Normality) assumption is
267%critical, as the MADFM does not give the same value as the usual rms
268%or standard deviation value -- for a Normal distribution
269%$N(\mu,\sigma)$ we find MADFM$=0.6744888\sigma$, but this will change
270%for different distributions. Since this ratio is corrected for, the
271%user need only think in the usual multiples of the rms when setting
272%\texttt{snrRecon}. See Appendix~\ref{app-madfm} for a derivation of
273%this value.
274
275When thresholding the different wavelet scales, the value of the rms
276as measured from the wavelet array needs to be scaled to account for
277the increased amount of correlation between neighbouring pixels (due
278to the convolution). See Appendix~\ref{app-scaling} for details on
279this scaling.
280
281\secC{User control of reconstruction parameters}
282
283The most important parameter for the user to select in relation to the
284reconstruction is the threshold for each wavelet array. This is set
285using the \texttt{snrRecon} parameter, and is given as a multiple of
286the rms (estimated by the MADFM) above the mean (which for the wavelet
287arrays should be approximately zero). There are several other
288parameters that can be altered as well that affect the outcome of the
289reconstruction.
290
291By default, the cube is reconstructed in three dimensions, using a
2923-dimensional filter and 3-dimensional convolution. This can be
293altered, however, using the parameter \texttt{reconDim}. If set to 1,
294this means the cube is reconstructed by considering each spectrum
295separately, whereas \texttt{reconDim=2} will mean the cube is
296reconstructed by doing each channel map separately. The merits of
297these choices are discussed in \S\ref{sec-notes}, but it should be
298noted that a 2-dimensional reconstruction can be susceptible to edge
299effects if the spatial shape of the pixel array is not rectangular.
300
301The user can also select the minimum scale to be used in the
302reconstruction. The first scale exhibits the highest frequency
303variations, and so ignoring this one can sometimes be beneficial in
304removing excess noise. The default is to use all scales
305(\texttt{minscale = 1}).
306
307Finally, the filter that is used for the convolution can be selected
308by using \texttt{filterCode} and the relevant code number -- the
309choices are listed in Appendix~\ref{app-param}. A larger filter will
310give a better reconstruction, but take longer and use more memory when
311executing. When multi-dimensional reconstruction is selected, this
312filter is used to construct a 2- or 3-dimensional equivalent.
313
314\secB{Smoothing the cube}
315\label{sec-smoothing}
316
317An alternative to doing the wavelet reconstruction is to smooth the
318cube.  This technique can be useful in reducing the noise level
319slightly (at the cost of making neighbouring pixels correlated and
320blurring any signal present), and is particularly well suited to the
321case where a particular signal size (\ie a certain channel width or
322spatial size) is believed to be present in the data.
323
324There are two alternative methods that can be used: spectral
325smoothing, using the Hanning filter; or spatial smoothing, using a 2D
326Gaussian kernel. These alternatives are outlined below. To utilise the
327smoothing option, set the parameter \texttt{flagSmooth=true} and set
328\texttt{smoothType} to either \texttt{spectral} or \texttt{spatial}.
329
330\secC{Spectral smoothing}
331
332When \texttt{smoothType = spectral} is selected, the cube is smoothed
333only in the spectral domain. Each spectrum is independently smoothed
334by a Hanning filter, and then put back together to form the smoothed
335cube, which is then used by the searching algorithm (see below). Note
336that in the case of both the reconstruction and the smoothing options
337being requested, the reconstruction will take precedence and the
338smoothing will \emph{not} be done.
339
340There is only one parameter necessary to define the degree of
341smoothing -- the Hanning width $a$ (given by the user parameter
342\texttt{hanningWidth}). The coefficients $c(x)$ of the Hanning filter
343are defined by
344\[
345c(x) =
346  \begin{cases}
347   \frac{1}{2}\left(1+\cos(\frac{\pi x}{a})\right) &|x| \leq (a+1)/2\\
348   0                                               &|x| > (a+1)/2.
349  \end{cases},\ a,x \in \mathbb{Z}
350\]
351Note that the width specified must be an
352odd integer (if the parameter provided is even, it is incremented by
353one).
354
355\secC{Spatial smoothing}
356
357When \texttt{smoothType = spatial} is selected, the cube is smoothed
358only in the spatial domain. Each channel map is independently smoothed
359by a two-dimensional Gaussian kernel, put back together to form the
360smoothed cube, and used in the searching algorithm (see below). Again,
361reconstruction is always done by preference if both techniques are
362requested.
363
364The two-dimensional Gaussian has three parameters to define it,
365governed by the elliptical cross-sectional shape of the Gaussian
366function: the FWHM (full-width at half-maximum) of the major and minor
367axes, and the position angle of the major axis. These are given by the
368user parameters \texttt{kernMaj, kernMin} \& \texttt{kernPA}. If a
369circular Gaussian is required, the user need only provide the
370\texttt{kernMaj} parameter. The \texttt{kernMin} parameter will then
371be set to the same value, and \texttt{kernPA} to zero.  If we define
372these parameters as $a,b,\theta$ respectively, we can define the
373kernel by the function
374\[
375k(x,y) = \exp\left[-0.5 \left(\frac{X^2}{\sigma_X^2} +
376                              \frac{Y^2}{\sigma_Y^2}   \right) \right]
377\]
378where $(x,y)$ are the offsets from the central pixel of the gaussian
379function, and
380\begin{align*}
381X& = x\sin\theta - y\cos\theta&
382  Y&= x\cos\theta + y\sin\theta\\
383\sigma_X^2& = \frac{(a/2)^2}{2\ln2}&
384  \sigma_Y^2& = \frac{(b/2)^2}{2\ln2}\\
385\end{align*}
386
387\secB{Input/Output of reconstructed/smoothed arrays}
388\label{sec-reconIO}
389
390The smoothing and reconstruction stages can be relatively
391time-consuming, particularly for large cubes and reconstructions in
3923-D (or even spatial smoothing). To get around this, \duchamp provides
393a shortcut to allow users to perform multiple searches (\eg with
394different thresholds) on the same reconstruction/smoothing setup
395without re-doing the calculations each time.
396
397To save the reconstructed array as a FITS file, set
398\texttt{flagOutputRecon = true}. The file will be saved in the same
399directory as the input image, so the user needs to have write
400permissions for that directory.
401
402The name of the file can given by the \texttt{fileOutputRecon}
403parameter, but this can be ignored and \duchamp will present a name
404based on the reconstruction parameters. The filename will be derived
405from the input filename, with extra information detailing the
406reconstruction that has been done. For example, suppose
407\texttt{image.fits} has been reconstructed using a 3-dimensional
408reconstruction with filter \#2, thresholded at $4\sigma$ using all
409scales. The output filename will then be
410\texttt{image.RECON-3-2-4-1.fits} (\ie it uses the four parameters
411relevant for the \atrous reconstruction as listed in
412Appendix~\ref{app-param}). The new FITS file will also have these
413parameters as header keywords. If a subsection of the input image has
414been used (see \S\ref{sec-input}), the format of the output filename
415will be \texttt{image.sub.RECON-3-2-4-1.fits}, and the subsection that
416has been used is also stored in the FITS header.
417
418Likewise, the residual image, defined as the difference between the
419input and reconstructed arrays, can also be saved in the same manner
420by setting \texttt{flagOutputResid = true}. Its filename will be the
421same as above, with \texttt{RESID} replacing \texttt{RECON}.
422
423If a reconstructed image has been saved, it can be read in and used
424instead of redoing the reconstruction. To do so, the user should set
425the parameter \texttt{flagReconExists = true}. The user can indicate
426the name of the reconstructed FITS file using the \texttt{reconFile}
427parameter, or, if this is not specified, \duchamp searches for the
428file with the name as defined above. If the file is not found, the
429reconstruction is performed as normal. Note that to do this, the user
430needs to set \texttt{flagAtrous = true} (obviously, if this is
431\texttt{false}, the reconstruction is not needed).
432
433To save the smoothed array, set \texttt{flagOutputSmooth = true}. As
434for the reconstructed/residual arrays, the
435name of the file can given by the \texttt{fileOutputSmooth} parameter,
436but this can be ignored and \duchamp will present a name based on the
437method of smoothing used. It will be either
438\texttt{image.SMOOTH-1D-a.fits}, where a is replaced by the Hanning
439width used, or \texttt{image.SMOOTH-2D-a-b-c.fits}, where the Gaussian
440kernel parameters are a,b,c. Similarly to the reconstruction case, a
441saved file can be read in by setting \texttt{flagSmoothExists = true}
442and either specifying a file to be read with the \texttt{smoothFile}
443parameter or relying on \duchamp to find the file with the name as
444given above.
445
446
447\secB{Searching the image}
448\label{sec-detection}
449
450\secC{Technique}
451
452The basic idea behind detection in \duchamp is to locate sets of
453contiguous voxels that lie above some threshold. No size or shape
454requirement is imposed upon the detections -- that is, \duchamp does
455not fit \eg a Gaussian profile to each source. All it does is find
456connected groups of bright voxels.
457
458One threshold is calculated for the entire cube, enabling calculation
459of signal-to-noise ratios for each source (see
460Section~\ref{sec-output} for details). The user can manually specify a
461value (using the parameter \texttt{threshold}) for the threshold,
462which will override the calculated value. Note that this option
463overrides any settings of \texttt{snrCut} or FDR options (see below).
464
465The cube is searched one channel map at a time, using the
4662-dimensional raster-scanning algorithm of \citet{lutz80} that
467connects groups of neighbouring pixels. Such an algorithm cannot be
468applied directly to a 3-dimensional case, as it requires that objects
469are completely nested in a row (when scanning along a row, if an
470object finishes and other starts, you won't get back to the first
471until the second is completely finished for the
472row). Three-dimensional data does not have this property, hence the
473need to treat the data on a 2-dimensional basis.
474
475Although there are parameters that govern the minimum number of pixels
476in a spatial and spectral sense that an object must have
477(\texttt{minPix} and \texttt{minChannels} respectively), these
478criteria are not applied at this point. It is only after the merging
479and growing (see \S\ref{sec-merger}) is done that objects are rejected
480for not meeting these criteria.
481
482Finally, the search only looks for positive features. If one is
483interested instead in negative features (such as absorption lines),
484set the parameter \texttt{flagNegative = true}. This will invert the
485cube (\ie multiply all pixels by $-1$) prior to the search, and then
486re-invert the cube (and the fluxes of any detections) after searching
487is complete. All outputs are done in the same manner as normal, so
488that fluxes of detections will be negative.
489
490\secC{Calculating statistics}
491\label{sec-stats}
492
493A crucial part of the detection process (as well as the wavelet
494reconstruction: \S\ref{sec-recon}) is estimating the statistics that
495define the detection threshold. To determine a threshold, we need to
496estimate from the data two parameters: the middle of the noise
497distribution (the ``noise level''), and the width of the distribution
498(the ``noise spread''). The noise level is estimated by either the
499mean or the median, and the noise spread by the rms (or the standard
500deviation) or the median absolute deviation from the median
501(MADFM). The median and MADFM are robust statistics, in that they are
502not biased by the presence of a few pixels much brighter than the
503noise.
504
505All four statistics are calculated automatically, but the choice of
506parameters that will be used is governed by the input parameter
507\texttt{flagRobustStats}. This has the default value \texttt{true},
508meaning the underlying mean of the noise distribution is estimated by
509the median, and the underlying standard deviation is estimated by the
510MADFM. In the latter case, the value is corrected, under the
511assumption that the underlying distribution is Normal (Gaussian), by
512dividing by 0.6744888 -- see Appendix~\ref{app-madfm} for details. If
513\texttt{flagRobustStats=false}, the mean and rms are used instead.
514
515The choice of pixels to be used depend on the analysis method. If the
516wavelet reconstruction has been done, the residuals (defined
517in the sense of original $-$ reconstruction) are used to estimate the
518noise spread of the cube, since the reconstruction should pick out
519all significant structure. The noise level (the middle of the
520distribution) is taken from the original array.
521
522If smoothing of the cube has been done instead, all noise parameters
523are measured from the smoothed array, and detections are made with
524these parameters. When the signal-to-noise level is quoted for each
525detection (see \S\ref{sec-output}), the noise parameters of the
526original array are used, since the smoothing process correlates
527neighbouring pixels, reducing the noise level.
528
529If neither reconstruction nor smoothing has been done, then the
530statistics are calculated from the original, input array.
531
532The parameters that are estimated should be representative of the
533noise in the cube. For the case of small objects embedded in many
534noise pixels (\eg the case of \hi surveys), using the full cube will
535provide good estimators. It is possible, however, to use only a
536subsection of the cube by setting the parameter \texttt{flagStatSec =
537  true} and providing the desired subsection to the \texttt{StatSec}
538parameter. This subsection works in exactly the same way as the pixel
539subsection discussed in \S\ref{sec-input}. Note that this subsection
540applies only to the statistics used to determine the threshold. It
541does not affect the calculation of statistics in the case of the
542wavelet reconstruction. Note also that pixels flagged as BLANK or as
543part of the ``Milky Way'' range of channels are ignored in the
544statistics calculations.
545
546\secC{Determining the threshold}
547
548Once the statistics have been calculated, the threshold is determined
549in one of two ways. The first way is a simple sigma-clipping, where a
550threshold is set at a fixed number $n$ of standard deviations above
551the mean, and pixels above this threshold are flagged as detected. The
552value of $n$ is set with the parameter \texttt{snrCut}. The ``mean''
553and ``standard deviation'' here are estimated according to
554\texttt{flagRobustStats}, as discussed in \S\ref{sec-stats}. In this
555first case only, if the user specifies a threshold, using the
556\texttt{threshold} parameter, the sigma-clipped value is ignored.
557
558The second method uses the False Discovery Rate (FDR) technique
559\citep{miller01,hopkins02}, whose basis we briefly detail here. The
560false discovery rate (given by the number of false detections divided
561by the total number of detections) is fixed at a certain value
562$\alpha$ (\eg $\alpha=0.05$ implies 5\% of detections are false
563positives). In practice, an $\alpha$ value is chosen, and the ensemble
564average FDR (\ie $\langle FDR \rangle$) when the method is used will
565be less than $\alpha$.  One calculates $p$ -- the probability,
566assuming the null hypothesis is true, of obtaining a test statistic as
567extreme as the pixel value (the observed test statistic) -- for each
568pixel, and sorts them in increasing order. One then calculates $d$
569where
570\[
571d = \max_j \left\{ j : P_j < \frac{j\alpha}{c_N N} \right\},
572\]
573and then rejects all hypotheses whose $p$-values are less than or
574equal to $P_d$. (So a $P_i<P_d$ will be rejected even if $P_i \geq
575j\alpha/c_N N$.) Note that ``reject hypothesis'' here means ``accept
576the pixel as an object pixel'' (\ie we are rejecting the null
577hypothesis that the pixel belongs to the background).
578
579The $c_N$ value here is a normalisation constant that depends on the
580correlated nature of the pixel values. If all the pixels are
581uncorrelated, then $c_N=1$. If $N$ pixels are correlated, then their
582tests will be dependent on each other, and so $c_N = \sum_{i=1}^N
583i^{-1}$. \citet{hopkins02} consider real radio data, where the pixels
584are correlated over the beam. For the calculations done in \duchamp,
585$N=2B$, where $B$ is the beam size in pixels, calculated from the FITS
586header (if the correct keywords -- BMAJ, BMIN -- are not present, the
587size of the beam is taken from the parameter \texttt{beamSize}). The
588factor of 2 comes about because we treat neighbouring channels as
589correlated. In the case of a two-dimensional image, we just have
590$N=B$.
591
592The theory behind the FDR method implies a direct connection between
593the choice of $\alpha$ and the fraction of detections that will be
594false positives. These detections, however, are individual pixels,
595which undergo a process of merging and rejection (\S\ref{sec-merger}),
596and so the fraction of the final list of detected objects that are
597false positives will be much smaller than $\alpha$. See the discussion
598in \S\ref{sec-notes}.
599
600%\secC{Storage of detected objects in memory}
601%
602%It is useful to understand how \duchamp stores the detected objects in
603%memory while it is running. This makes use of nested C++ classes, so
604%that an object is stored as a class that includes the set of detected
605%pixels, plus all the various calculated parameters (fluxes, WCS
606%coordinates, pixel centres and extrema, flags,...). The set of pixels
607%are stored using another class, that stores 3-dimensional objects as a
608%set of channel maps, each consisting of a $z$-value and a
609%2-dimensional object (a spatial map if you like). This 2-dimensional
610%object is recorded using ``run-length'' encoding, where each row (a
611%fixed $y$ value) is stored by the starting $x$-value and the length
612
613\secB{Merging and growing detected objects}
614\label{sec-merger}
615
616The searching step produces a list of detected objects that will have
617many repeated detections of a given object -- for instance, spectral
618detections in adjacent pixels of the same object and/or spatial
619detections in neighbouring channels. These are then combined in an
620algorithm that matches all objects judged to be ``close'', according
621to one of two criteria.
622
623One criterion is to define two thresholds -- one spatial and one in
624velocity -- and say that two objects should be merged if there is at
625least one pair of pixels that lie within these threshold distances of
626each other. These thresholds are specified by the parameters
627\texttt{threshSpatial} and \texttt{threshVelocity} (in units of pixels
628and channels respectively).
629
630Alternatively, the spatial requirement can be changed to say that
631there must be a pair of pixels that are \emph{adjacent} -- a stricter,
632but perhaps more realistic requirement, particularly when the spatial
633pixels have a large angular size (as is the case for
634\hi surveys). This
635method can be selected by setting the parameter
636\texttt{flagAdjacent} to 1 (\ie \texttt{true}) in the parameter
637file. The velocity thresholding is done in the same way as the first
638option.
639
640Once the detections have been merged, they may be ``grown''. This is a
641process of increasing the size of the detection by adding nearby
642pixels (according to the \texttt{threshSpatial} and
643\texttt{threshVelocity} parameters) that are above some secondary
644threshold. This threshold should be lower than the one used for the
645initial detection, but above the noise level, so that faint pixels are
646only detected when they are close to a bright pixel. This
647threshold is specified via one of two input parameters. It can be
648given in terms of the noise statistics via \texttt{growthCut} (which
649has a default value of $3\sigma$), or it can be directly given via
650\texttt{growthThreshold}. Note that if you have given the detection
651threshold with the \texttt{threshold} parameter, the growth threshold
652\textbf{must} be given with \texttt{growthThreshold}.
653
654The use of the growth algorithm is controlled by the
655\texttt{flagGrowth} parameter -- the default value of which is
656\texttt{false}. If the detections are grown, they are sent through the
657merging algorithm a second time, to pick up any detections that now
658overlap or have grown over each other.
659
660Finally, to be accepted, the detections must span \emph{both} a
661minimum number of channels (enabling the removal of any spurious
662single-channel spikes that may be present), and a minimum number of
663spatial pixels. These numbers, as for the original detection step, are
664set with the \texttt{minChannels} and \texttt{minPix} parameters. The
665channel requirement means a source must have at least one set of
666\texttt{minChannels} consecutive channels to be
667accepted.
668
Note: See TracBrowser for help on using the repository browser.