1 | #include <iostream> |
---|
2 | #include <math.h> |
---|
3 | #include <Cubes/cubes.hh> |
---|
4 | |
---|
5 | bool 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 | |
---|
13 | bool Image::isDetection(float value) |
---|
14 | { |
---|
15 | return ( ((value - this->mean) / this->sigma) > this->cutLevel ) ; |
---|
16 | } |
---|
17 | |
---|
18 | bool Image::isDetectionFDR(float pvalue) |
---|
19 | { |
---|
20 | return ( pvalue < this->pCutLevel ) ; |
---|
21 | |
---|
22 | } |
---|
23 | |
---|
24 | bool isDetection(float value, float mean, float sigma, float cut) |
---|
25 | { |
---|
26 | return ( ((value - mean) / sigma) > cut ) ; |
---|
27 | } |
---|
28 | |
---|
29 | int Image::setupFDR() |
---|
30 | { |
---|
31 | this->alpha = this->par.alphaFDR; |
---|
32 | |
---|
33 | // first calculate p-value for each pixel, using mean and sigma |
---|
34 | // assume Gaussian for now. |
---|
35 | bool *isGood = new bool[this->numPixels]; |
---|
36 | int *loopCtr = new int; |
---|
37 | for(*loopCtr=0;*loopCtr<this->numPixels;(*loopCtr)++) |
---|
38 | isGood[*loopCtr] = !(this->par.isBlank(this->array[*loopCtr])); |
---|
39 | |
---|
40 | float *rootTwo = new float; |
---|
41 | *rootTwo=sqrt(2.); |
---|
42 | for(int j=0;j<this->numPixels;j++){ |
---|
43 | if(isGood[j]) |
---|
44 | this->pValue[j] = 0.5*erfc((this->array[j] - this->mean) / (*rootTwo * this->sigma)); |
---|
45 | else |
---|
46 | this->pValue[j] = 1.; //need to make this high so that it won't be below the P cut level. |
---|
47 | } |
---|
48 | delete rootTwo; |
---|
49 | |
---|
50 | // now order them |
---|
51 | float *orderedP = new float[this->numPixels]; |
---|
52 | int *count = new int; |
---|
53 | *count = 0; |
---|
54 | for(*loopCtr=0;*loopCtr<this->numPixels;(*loopCtr)++) |
---|
55 | if(isGood[*loopCtr]) |
---|
56 | orderedP[(*count)++] = this->pValue[*loopCtr]; |
---|
57 | |
---|
58 | sort(orderedP,0,(*count-1)); |
---|
59 | |
---|
60 | // now find the maximum P value. |
---|
61 | int *max = new int; |
---|
62 | *max = -1; |
---|
63 | float *cN = new float; |
---|
64 | *cN = 0.; |
---|
65 | int *psfCtr = new int; |
---|
66 | int *numPix = new int; |
---|
67 | *numPix = int(this->par.getBeamSize()); |
---|
68 | for(*psfCtr=1;*psfCtr<=*numPix;(*psfCtr)++) |
---|
69 | *cN += 1./float(*psfCtr); |
---|
70 | delete psfCtr; |
---|
71 | delete numPix; |
---|
72 | |
---|
73 | for(*loopCtr=0;*loopCtr<*count;(*loopCtr)++) { |
---|
74 | if( orderedP[*loopCtr] < (double(*loopCtr+1)*this->alpha/(*cN * double(*count))) ) |
---|
75 | *max = *loopCtr; |
---|
76 | } |
---|
77 | |
---|
78 | this->pCutLevel = orderedP[*max]; |
---|
79 | |
---|
80 | delete [] orderedP; |
---|
81 | delete [] isGood; |
---|
82 | delete max; |
---|
83 | delete cN; |
---|
84 | delete count; |
---|
85 | delete loopCtr; |
---|
86 | } |
---|
87 | |
---|