[3] | 1 | #include <iostream> |
---|
| 2 | #include <iomanip> |
---|
| 3 | #include <fstream> |
---|
| 4 | #include <vector> |
---|
| 5 | #include <Cubes/cubes.hh> |
---|
| 6 | #include <Utils/utils.hh> |
---|
| 7 | |
---|
[103] | 8 | void Cube::CubicSearch() |
---|
[3] | 9 | { |
---|
| 10 | /** |
---|
| 11 | * Cube::SimpleSearch3D() |
---|
| 12 | * A front end to the cubic searching routine that does not |
---|
| 13 | * involve any wavelet reconstruction. |
---|
[153] | 14 | * If baseline-removal is required that is done prior to searching. |
---|
[3] | 15 | * Once searching is complete, the detection map is updated and |
---|
| 16 | * the intermediate detections are logged in the log file. |
---|
| 17 | */ |
---|
| 18 | |
---|
[103] | 19 | this->objectList = search3DArray(this->axisDim,this->array,this->par); |
---|
[3] | 20 | |
---|
| 21 | this->updateDetectMap(); |
---|
| 22 | if(this->par.getFlagLog()) this->logDetectionList(); |
---|
| 23 | |
---|
| 24 | } |
---|
| 25 | |
---|
| 26 | |
---|
[103] | 27 | vector <Detection> search3DArray(long *dim, float *Array, Param &par) |
---|
[3] | 28 | { |
---|
| 29 | /** |
---|
| 30 | * cubicSearch |
---|
| 31 | * Takes a dimension array and data array as input (and Parameter set) |
---|
| 32 | * and searches for detections in a combination of 1D and 2D searches. |
---|
| 33 | * Returns a vector list of Detections. |
---|
| 34 | * No reconstruction is assumed to have taken place, so statistics are |
---|
| 35 | * calculated (using robust methods) from the data array itself. |
---|
| 36 | */ |
---|
| 37 | |
---|
| 38 | vector <Detection> outputList; |
---|
[103] | 39 | long zdim = dim[2]; |
---|
| 40 | long xySize = dim[0] * dim[1]; |
---|
| 41 | long fullSize = zdim * xySize; |
---|
[3] | 42 | int num = 0; |
---|
| 43 | |
---|
| 44 | float blankPixValue = par.getBlankPixVal(); |
---|
| 45 | bool *isGood = new bool[fullSize]; |
---|
[103] | 46 | for(int pos=0;pos<fullSize;pos++){ |
---|
| 47 | isGood[pos] = !par.isBlank(Array[pos]) && !par.isInMW(pos/xySize); |
---|
| 48 | } |
---|
| 49 | bool *doChannel = new bool[xySize]; |
---|
| 50 | int goodSize=0; |
---|
| 51 | for(int npix=0; npix<xySize; npix++){ |
---|
| 52 | for(int z=0;z<zdim;z++) if(isGood[z*xySize+npix]) goodSize++; |
---|
| 53 | if(goodSize==0) doChannel[npix] = false; |
---|
| 54 | else doChannel[npix] = true; |
---|
| 55 | } |
---|
[3] | 56 | |
---|
| 57 | // FIRST SEARCH -- IN EACH SPECTRUM. |
---|
| 58 | if(zdim>1){ |
---|
[146] | 59 | if(par.isVerbose()) std::cout << " 1D: | |" |
---|
| 60 | << std::flush; |
---|
[3] | 61 | |
---|
| 62 | for(int npix=0; npix<xySize; npix++){ |
---|
[86] | 63 | |
---|
[3] | 64 | if( par.isVerbose() && ((100*(npix+1)/xySize)%5 == 0) ){ |
---|
| 65 | std::cout << "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b|"; |
---|
| 66 | for(int i=0;i<(100*(npix+1)/xySize)/5;i++) std::cout << "#"; |
---|
| 67 | for(int i=(100*(npix+1)/xySize)/5;i<20;i++) std::cout << " "; |
---|
| 68 | std::cout << "|" << std::flush; |
---|
| 69 | } |
---|
| 70 | |
---|
[103] | 71 | if(doChannel[npix]){ |
---|
| 72 | |
---|
| 73 | float *spec = new float[zdim]; |
---|
| 74 | float specMedian,specSigma; |
---|
| 75 | goodSize=0; |
---|
| 76 | for(int z=0;z<zdim;z++) |
---|
| 77 | if(isGood[z*xySize+npix]) spec[goodSize++] = Array[z*xySize+npix]; |
---|
| 78 | findMedianStats(spec,goodSize,specMedian,specSigma); |
---|
| 79 | specSigma /= correctionFactor; |
---|
| 80 | |
---|
| 81 | |
---|
| 82 | long *specdim = new long[2]; |
---|
| 83 | specdim[0] = zdim; specdim[1]=1; |
---|
| 84 | Image *spectrum = new Image(specdim); |
---|
| 85 | delete specdim; |
---|
| 86 | spectrum->saveParam(par); |
---|
[146] | 87 | spectrum->pars().setBeamSize(2.); |
---|
| 88 | // beam size: for spectrum, only neighbouring channels correlated |
---|
[103] | 89 | spectrum->extractSpectrum(Array,dim,npix); |
---|
| 90 | spectrum->removeMW(); // only works if flagMW is true |
---|
| 91 | spectrum->setStats(specMedian,specSigma,par.getCut()); |
---|
| 92 | if(par.getFlagFDR()) spectrum->setupFDR(); |
---|
| 93 | spectrum->setMinSize(par.getMinChannels()); |
---|
| 94 | spectrum->spectrumDetect(); |
---|
[146] | 95 | num += spectrum->getNumObj(); |
---|
[103] | 96 | for(int obj=0;obj<spectrum->getNumObj();obj++){ |
---|
| 97 | Detection *object = new Detection; |
---|
| 98 | *object = spectrum->getObject(obj); |
---|
| 99 | for(int pix=0;pix<object->getSize();pix++) { |
---|
| 100 | // Fix up coordinates of each pixel to match original array |
---|
| 101 | object->setZ(pix, object->getX(pix)); |
---|
| 102 | object->setX(pix, npix%dim[0]); |
---|
| 103 | object->setY(pix, npix/dim[0]); |
---|
| 104 | } |
---|
| 105 | object->addOffsets(par); |
---|
| 106 | object->calcParams(); |
---|
| 107 | mergeIntoList(*object,outputList,par); |
---|
| 108 | delete object; |
---|
[3] | 109 | } |
---|
[103] | 110 | delete spectrum; |
---|
[3] | 111 | } |
---|
[103] | 112 | } |
---|
[3] | 113 | |
---|
[146] | 114 | // num = outputList.size(); |
---|
[3] | 115 | if(par.isVerbose()) |
---|
[153] | 116 | std::cout <<"\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\bFound " |
---|
| 117 | << num <<";" << std::flush; |
---|
[3] | 118 | |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | // SECOND SEARCH -- IN EACH CHANNEL |
---|
[146] | 122 | if(par.isVerbose()) std::cout << " 2D: | |" |
---|
| 123 | << std::flush; |
---|
| 124 | num = 0; |
---|
[3] | 125 | |
---|
| 126 | for(int z=0; z<zdim; z++){ |
---|
| 127 | |
---|
| 128 | if( par.isVerbose() && ((100*(z+1)/zdim)%5 == 0) ){ |
---|
| 129 | std::cout << "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b|"; |
---|
| 130 | for(int i=0;i<(100*(z+1)/zdim)/5;i++) std::cout << "#"; |
---|
| 131 | for(int i=(100*(z+1)/zdim)/5;i<20;i++) std::cout << " "; |
---|
| 132 | std::cout << "|" << std::flush; |
---|
| 133 | } |
---|
| 134 | |
---|
[103] | 135 | if(!par.isInMW(z)){ |
---|
[3] | 136 | |
---|
[103] | 137 | float *image = new float[xySize]; |
---|
| 138 | float imageMedian, imageSigma; |
---|
| 139 | goodSize=0; |
---|
[153] | 140 | for(int npix=0; npix<xySize; npix++) { |
---|
| 141 | if(isGood[z*xySize + npix]) |
---|
| 142 | image[goodSize++] = Array[z*xySize + npix]; |
---|
| 143 | } |
---|
[103] | 144 | findMedianStats(image,goodSize,imageMedian,imageSigma); |
---|
| 145 | imageSigma /= correctionFactor; |
---|
| 146 | |
---|
[3] | 147 | long *imdim = new long[2]; |
---|
| 148 | imdim[0] = dim[0]; imdim[1] = dim[1]; |
---|
| 149 | Image *channelImage = new Image(imdim); |
---|
[86] | 150 | delete imdim; |
---|
[3] | 151 | channelImage->saveParam(par); |
---|
[53] | 152 | channelImage->extractImage(Array,dim,z); |
---|
[103] | 153 | channelImage->setStats(imageMedian,imageSigma,par.getCut()); |
---|
[3] | 154 | if(par.getFlagFDR()) channelImage->setupFDR(); |
---|
[13] | 155 | channelImage->setMinSize(par.getMinPix()); |
---|
[3] | 156 | channelImage->lutz_detect(); |
---|
[146] | 157 | num += channelImage->getNumObj(); |
---|
[3] | 158 | for(int obj=0;obj<channelImage->getNumObj();obj++){ |
---|
| 159 | Detection *object = new Detection; |
---|
| 160 | *object = channelImage->getObject(obj); |
---|
| 161 | // Fix up coordinates of each pixel to match original array |
---|
| 162 | for(int pix=0;pix<object->getSize();pix++) object->setZ(pix, z); |
---|
| 163 | object->addOffsets(par); |
---|
| 164 | object->calcParams(); |
---|
| 165 | mergeIntoList(*object,outputList,par); |
---|
| 166 | delete object; |
---|
| 167 | } |
---|
| 168 | delete channelImage; |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | } |
---|
| 172 | |
---|
| 173 | if(par.isVerbose()) |
---|
[146] | 174 | std::cout << "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\bFound " |
---|
| 175 | << num |
---|
| 176 | << ". " |
---|
| 177 | << std::endl << std::flush; |
---|
[3] | 178 | |
---|
| 179 | delete [] isGood; |
---|
| 180 | delete [] doChannel; |
---|
[86] | 181 | |
---|
[3] | 182 | return outputList; |
---|
| 183 | } |
---|