1 | // ----------------------------------------------------------------------- |
---|
2 | // mainSelavy: Selavy is a program to re-analyse detected objects from |
---|
3 | // a Duchamp run. |
---|
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 | #include <iostream> |
---|
30 | #include <fstream> |
---|
31 | #include <string> |
---|
32 | #include <cpgplot.h> |
---|
33 | #include <math.h> |
---|
34 | #include <unistd.h> |
---|
35 | #include <time.h> |
---|
36 | |
---|
37 | #include <duchamp/duchamp.hh> |
---|
38 | #include <duchamp/param.hh> |
---|
39 | #include <duchamp/PixelMap/Voxel.hh> |
---|
40 | #include <duchamp/Detection/detection.hh> |
---|
41 | #include <duchamp/Cubes/cubes.hh> |
---|
42 | #include <duchamp/Utils/utils.hh> |
---|
43 | #include <duchamp/ATrous/atrous.hh> |
---|
44 | |
---|
45 | using namespace PixelInfo; |
---|
46 | using namespace duchamp; |
---|
47 | |
---|
48 | int main(int argc, char * argv[]) |
---|
49 | { |
---|
50 | |
---|
51 | std::string paramFile,fitsfile,temp; |
---|
52 | Cube *cube = new Cube; |
---|
53 | |
---|
54 | if(cube->getopts(argc,argv,"Selavy")==FAILURE) return FAILURE; |
---|
55 | |
---|
56 | std::vector<int> plotObject = getObjectRequest(argc,argv); |
---|
57 | |
---|
58 | if(cube->pars().getImageFile().empty()){ |
---|
59 | std::stringstream errmsg; |
---|
60 | errmsg << "No input image has been given!\n" |
---|
61 | << "Use the imageFile parameter in " |
---|
62 | << paramFile << " to specify the FITS file.\nExiting...\n"; |
---|
63 | duchampError("Selavy", errmsg.str()); |
---|
64 | return FAILURE; |
---|
65 | } |
---|
66 | |
---|
67 | if(cube->pars().getFlagSubsection()){ |
---|
68 | // make sure the subsection is OK. |
---|
69 | if(cube->pars().verifySubsection() == FAILURE){ |
---|
70 | duchampError("Selavy", |
---|
71 | "Unable to use the subsection provided.\nExiting...\n"); |
---|
72 | return FAILURE; |
---|
73 | } |
---|
74 | } |
---|
75 | |
---|
76 | std::cout << "Opening image: " |
---|
77 | << cube->pars().getFullImageFile() << std::endl; |
---|
78 | |
---|
79 | if( cube->getCube() == FAILURE){ |
---|
80 | std::stringstream errmsg; |
---|
81 | errmsg << "Unable to open image file " |
---|
82 | << cube->pars().getFullImageFile() |
---|
83 | << "\nExiting...\n"; |
---|
84 | duchampError("Selavy", errmsg.str()); |
---|
85 | return FAILURE; |
---|
86 | } |
---|
87 | else std::cout << "Opened successfully." << std::endl; |
---|
88 | |
---|
89 | // Read in any saved arrays that are in FITS files on disk. |
---|
90 | cube->readSavedArrays(); |
---|
91 | |
---|
92 | |
---|
93 | std::ifstream logfile(cube->pars().getLogFile().c_str()); |
---|
94 | |
---|
95 | if(!logfile.is_open()){ |
---|
96 | std::cerr << "\aUnable to open file " |
---|
97 | << cube->pars().getLogFile() << "\nExiting...\n"; |
---|
98 | return 1; |
---|
99 | } |
---|
100 | |
---|
101 | // read down until first Detection # line |
---|
102 | cube->setCubeStats(); |
---|
103 | std::cerr << "Reading from logfile : " << cube->pars().getLogFile() << "\n"; |
---|
104 | while(getline(logfile,temp), temp.substr(0,11)!="Detection #"){ } |
---|
105 | int x1,x2, ypix, zpix; |
---|
106 | while(!logfile.eof()){ |
---|
107 | Detection obj; |
---|
108 | while(getline(logfile,temp), temp.substr(0,3)!="---"){ |
---|
109 | for(int i=0;i<temp.size();i++) |
---|
110 | if(temp[i]=='-' || temp[i]==',') temp[i] = ' '; |
---|
111 | std::stringstream ss; |
---|
112 | ss.str(temp); |
---|
113 | ss >> x1 >> x2 >> ypix >> zpix; |
---|
114 | Scan scn(ypix,x1,x2-x1+1); |
---|
115 | obj.pixels().addScan(scn,zpix); |
---|
116 | } |
---|
117 | obj.setOffsets(cube->pars()); |
---|
118 | obj.calcParams(); |
---|
119 | std::cerr << obj << "\n"; |
---|
120 | if(obj.getSize()>0) cube->addObject(obj); |
---|
121 | getline(logfile,temp); // reads next line -- should be Detection #... |
---|
122 | if(temp.substr(0,11)!="Detection #"){ |
---|
123 | // if it is, then read two lines to finish off the file. This should trigger the eof flag above. |
---|
124 | getline(logfile,temp); |
---|
125 | getline(logfile,temp); |
---|
126 | } |
---|
127 | } |
---|
128 | |
---|
129 | std::cout<<"Final object count = "<<cube->getNumObj()<<std::endl; |
---|
130 | |
---|
131 | cube->prepareOutputFile(); |
---|
132 | |
---|
133 | cube->calcObjectWCSparams(); |
---|
134 | cube->setObjectFlags(); |
---|
135 | cube->sortDetections(); |
---|
136 | |
---|
137 | cube->outputDetectionList(); |
---|
138 | |
---|
139 | if((cube->getDimZ()>1) && (cube->getNumObj()>0)){ |
---|
140 | std::cout << "Plotting the individual spectra... " << std::flush; |
---|
141 | cube->outputSpectra(); |
---|
142 | std::cout << "done.\n"; |
---|
143 | } |
---|
144 | |
---|
145 | } |
---|