source: branches/NewStructure/src/Finder/Searcher.cc @ 1441

Last change on this file since 1441 was 1406, checked in by MatthewWhiting, 10 years ago

Adding implementation of some of Searcher's functions

File size: 3.1 KB
Line 
1#include <iostream>
2#include <duchamp/duchamp.hh>
3#include <duchamp/Finder/Searcher.hh>
4#include <duchamp/Finder/DuchampFinder.hh>
5#include <duchamp/DataArrays/AstroImage.hh>
6#include <duchamp/Detection/detection.hh>
7#include <duchamp/Utils/feedback.hh>
8
9namespace duchamp
10{
11
12    Searcher::Searcher()
13    {
14    }
15
16    Searcher::Searcher(DuchampFinder& finder)
17    {
18        this->itsParam = finder.par();
19        this->itsStats = finder.stats();
20
21        if(finder.par()->getFlagATrous())
22            this->itsImage = finder.recon();
23        else if(finder.par()->getFlagSmooth())
24            this->itsImage = finder.recon();
25        else this->itsImage = finder.image();
26    }
27
28    Searcher::Searcher(const Searcher& other)
29    {
30        this->operator=(other);
31    }
32
33    Searcher& Searcher::operator= (const Searcher& other)
34    {
35        if ( this == &other) return *this;
36        this->itsImage = other.itsImage;
37        this->itsDetectionList = other.itsDetectionList;
38        this->itsParam = other.itsParam;
39        this->itsStats = other.itsStats;
40        return *this;
41    }
42
43    void Searcher::search()
44    {
45        if(this->itsParam->getSearchType() == "spatial") 
46            this->spatialSearch();
47        else
48            this->spectralSearch();
49    }
50   
51    void Searcher::spatialSearch()
52    {
53    }
54
55    void Searcher::spectralSearch()
56    {
57        std::vector<size_t> dim = this->itsImage->dim();
58        size_t zdim = dim[2];
59        size_t xySize = dim[0] * dim[1];
60        int num = 0;
61
62        if(zdim>1){
63   
64            ProgressBar bar;
65            if(this->itsParam->isVerbose()) bar.init(xySize);
66
67            bool *doPixel = new bool[xySize];
68            for(size_t npix=0; npix<xySize; npix++){
69                doPixel[npix] = false;
70                for(size_t z=0;z<zdim || doPixel[npix];z++){
71                    doPixel[npix] = doPixel[npix] ||
72                        (!this->itsParam->isBlank(Array[npix+xySize*z]) && !this->itsParam->isFlaggedChannel(z));
73                }
74                // doPixel[i] is false only when there are no good pixels in spectrum
75                //  of pixel #i.
76            }
77
78            size_t *specdim = new size_t[2];
79            specdim[0] = zdim; specdim[1]=1;
80            Image *spectrum = new Image(specdim);
81            delete [] specdim;
82            spectrum->saveParam(par);
83            spectrum->saveStats(stats);
84            //    spectrum->setMinSize(this->itsParam->getMinChannels());
85            spectrum->setMinSize(1);
86
87            for(size_t y=0; y<dim[1]; y++){
88                for(size_t x=0; x<dim[0]; x++){
89
90                    size_t npix = y*dim[0] + x;
91                    if( this->itsParam->isVerbose() ) bar.update(npix+1);
92       
93                    if(doPixel[npix]){
94                        spectrum->extractSpectrum(Array,dim,npix);
95                        spectrum->removeFlaggedChannels();
96                        std::vector<Scan> objlist = spectrum->findSources1D();
97                        std::vector<Scan>::iterator obj;
98                        num += objlist.size();
99                        for(obj=objlist.begin();obj<objlist.end();obj++){
100                            Detection newObject;
101                            // Fix up coordinates of each pixel to match original array
102                            for(int z=obj->getX();z<=obj->getXmax();z++) {
103                                newObject.addPixel(x,y,z);
104                            }
105                            newObject.setOffsets(par);
106                            if(this->itsParam->getFlagTwoStageMerging()) mergeIntoList(newObject,outputList,par);
107                            else outputList.push_back(newObject);
108                        }
109                    }
110                }
111            }
112
113            delete spectrum;
114            delete [] doPixel;
115 
116
117            if(this->itsParam->isVerbose()){
118                bar.remove();
119                std::cout << "Found " << num << ".\n";
120            }
121
122        }
123
124        return outputList;
125
126    }
127
128}
129
Note: See TracBrowser for help on using the repository browser.