source: branches/fitshead-branch/Detection/thresholding_functions.cc @ 1441

Last change on this file since 1441 was 96, checked in by Matthew Whiting, 18 years ago

Two sets of large changes:
1) Added reconDim, to select which dimension of reconstruction to use.
2) Changed the way the MW channels are dealt with -- now not set to 0. but

simply ignored for searching purposes.

Summary of changes for each file:
duchamp.hh -- added keyword info for reconDim
param.hh -- Introduced reconDim and flagUsingBlank and isInMW.
param.cc -- Introduced reconDim and flagUsingBlank: initialisation etc commands
InputComplete? -- Added reconDim info
mainDuchamp.cc -- Removed the removeMW call. Changed search function names
docs/Guide.tex -- New code to deal with changes: reconDim, MW removal,

up-to-date output examples, better hints & notes section

Detection/thresholding_functions.cc -- minor typo correction

Cubes/cubes.hh -- added isBlank and removeMW functions in Image class, and

renamed search function prototypes

Cubes/cubes.cc -- added removeMW function for Image class, cleaned up

Cube::removeMW as well (although now not used)

Cubes/outputSpectra.cc -- Improved use of isBlank and isInMW functions: now

show MW channels but don't use them in calculating
the flux range

Cubes/getImage.cc -- added line to indicate whether the Param's blank value

is being used, rather than the FITS header.

Cubes/cubicSearch.cc -- renamed functions: front end is now CubicSearch?, and

searching function is search3DArray.

-- Improved way MW removal is dealt with. Changed

location of stats calculations.

Cubes/saveImage.cc -- added code for saving reconDim info
Cubes/readRecon.cc -- added code for reading reconDim info (and added status

intialisations before all cfitsio commands)

ATrous/ReconSearch.cc -- renamed functions: front end is now ReconSearch?, and

searching function is searchReconArray.
Using reconDim to decide which reconstruction to use.

-- Improved way MW removal is dealt with. Changed

location of stats calculations.

ATrous/atrous_1d_reconstruct.cc -- using Median stats
ATrous/atrous_2d_reconstruct.cc -- made code up to date, to conform with 1- &

3-d code. Removed boundary conditions.

ATrous/atrous_3d_reconstruct.cc -- corrected typo (avGapY /= float(xdim)).

Using median stats.

Cubes/cubicSearchNMerge.cc -- Deleted. (not used)
Cubes/readParams.cc -- Deleted. (not used)

File size: 2.4 KB
Line 
1#include <iostream>
2#include <math.h>
3#include <Cubes/cubes.hh>
4
5bool Image::isDetection(long x, long y)
6{
7  if(this->par.getFlagFDR())
8    return ( this->pValue[y*axisDim[0]+x] < this->pCutLevel );
9  else
10    return ( ((this->array[y*axisDim[0]+x]-this->mean)/this->sigma) > this->cutLevel );
11}
12
13bool Image::isDetection(float value)
14{
15  return ( ((value - this->mean) / this->sigma) > this->cutLevel ) ;
16}
17
18bool Image::isDetectionFDR(float pvalue)
19{
20  return (  pvalue < this->pCutLevel ) ;
21
22}
23
24bool isDetection(float value, float mean, float sigma, float cut)
25{
26  return ( ((value - mean) / sigma) > cut ) ;
27}
28
29int Image::setupFDR()
30{
31  /**
32   *  Image::setupFDR()
33   *   Determines the critical Prob value for the False Discovery Rate
34   *    detection routine. All pixels with Prob less than this value will
35   *    be considered detections.
36   *   The Prob here is the probability, assuming a Normal distribution, of
37   *    obtaining a value as high or higher than the pixel value (ie. only the
38   *    positive tail of the PDF)
39   */
40
41  this->alpha = this->par.alphaFDR;
42
43  // first calculate p-value for each pixel, using mean and sigma
44  // assume Gaussian for now.
45  bool *isGood = new bool[this->numPixels];
46  for(int loopCtr=0;loopCtr<this->numPixels;loopCtr++)
47    isGood[loopCtr] = !(this->par.isBlank(this->array[loopCtr]));
48
49  for(int j=0;j<this->numPixels;j++){
50    if(isGood[j]){
51      float zStat = (this->array[j] - this->mean) / (this->sigma);
52      this->pValue[j] = 0.5 * erfc(zStat/M_SQRT2);
53      // Want the factor of 0.5 here, as we are only considering the positive tail
54      //  of the distribution. Don't care about negative detections.
55    }
56    else this->pValue[j] = 1.;  //need to make this high so that it won't be below the P cut level.
57  }
58
59  // now order them
60  float *orderedP = new float[this->numPixels];
61  int count = 0;
62  for(int loopCtr=0;loopCtr<this->numPixels;loopCtr++)
63    if(isGood[loopCtr])
64      orderedP[count++] = this->pValue[loopCtr];
65
66  sort(orderedP,0,count);
67 
68  // now find the maximum P value.
69  int max = -1;
70  float cN = 0.;
71  int psfCtr;
72  int numPix = int(this->par.getBeamSize());
73  for(psfCtr=1;psfCtr<=numPix;(psfCtr)++)
74    cN += 1./float(psfCtr);
75
76  for(int loopCtr=0;loopCtr<count;loopCtr++) {
77    if( orderedP[loopCtr] < (double(loopCtr+1)*this->alpha/(cN * double(count))) ) {
78      max = loopCtr;
79    }
80  }
81
82  this->pCutLevel = orderedP[max];
83
84  delete [] orderedP;
85  delete [] isGood;
86}
87
Note: See TracBrowser for help on using the repository browser.