source: trunk/mainDuchamp.cc @ 85

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

A new command line option added so that the user can specify a FITS file to
be searched with the default parameters, rather than giving a full parameter
file. Help info in duchamp.hh fixed accordingly. Use of this feature detailed
in Guide, as well as altered text on the length of the scale bar in the
moment cutouts (missed on previous commit).

File size: 6.0 KB
Line 
1#include <iostream>
2#include <iomanip>
3#include <sstream>
4#include <fstream>
5#include <vector>
6#include <string>
7#include <cpgplot.h>
8#include <math.h>
9#include <unistd.h>
10#include <time.h>
11
12#include <duchamp.hh>
13#include <Detection/detection.hh>
14#include <Cubes/cubes.hh>
15#include <Utils/utils.hh>
16#include <ATrous/atrous.hh>
17
18using std::ofstream;
19using std::endl;
20
21Filter reconFilter;
22
23int main(int argc, char * argv[])
24{
25
26  string paramFile,fitsfile;
27  Cube *cube = new Cube;
28  Param *par = new Param;
29
30  if(argc==1){
31    std::cout << ERR_USAGE_MSG;
32    return 1;
33  }
34  else{
35    char c;
36    while( ( c = getopt(argc,argv,"p:f:hv") )!=-1){
37      switch(c) {
38      case 'p':
39        paramFile = optarg;
40        cube->readParam(paramFile);
41        break;
42      case 'f':
43        fitsfile = optarg;
44        par->setImageFile(fitsfile);
45        cube->saveParam(*par);
46        break;
47      case 'v':
48        std::cout << PROGNAME << " " << VERSION << std::endl;
49        return 1;
50        break;
51      case 'h':
52      default :
53        std::cout << ERR_USAGE_MSG;
54        return 1;
55        break;
56      }
57    }
58  }
59
60  delete par;
61
62  if(cube->pars().getImageFile().empty()){
63    std::cerr << "ERROR : No input image has been given!\n";
64    std::cerr << "        Use the imageFile parameter in "<< paramFile << " to specify the FITS file.\n";
65    std::cerr << "Exiting...\n\n";
66    return 1;
67  }
68
69  // Filter needed for baseline removal and a trous reconstruction
70  if(cube->pars().getFlagATrous() || cube->pars().getFlagBaseline()){
71    reconFilter.define(cube->pars().getFilterCode());
72    cube->pars().setFilterName(reconFilter.getName());
73  }
74
75  string fname = cube->pars().getImageFile();
76  if(cube->pars().getFlagSubsection()){
77    cube->pars().parseSubsection();
78    fname+=cube->pars().getSubsection();
79  }
80  std::cout << "Opening image: " << fname << endl;
81  if( cube->getCube(fname) == FAILURE){
82    std::cerr << "ERROR : Unable to open image file : " << fname << endl;
83    std::cerr << "Exiting...\n\n";
84    return 1;
85  }
86  else std::cout << "Opened successfully." << endl;
87
88  // If the reconstructed array is to be read in from disk
89  if( cube->pars().getFlagReconExists() && cube->pars().getFlagATrous() ){
90    if( cube->readReconCube() == FAILURE){
91      std::cerr << "WARNING : Could not read in existing reconstructed array.\n"
92                << "          Will perform reconstruction using assigned parameters.\n";
93      cube->pars().setFlagReconExists(false);
94    }
95  }
96
97  std::cout << cube->pars();
98
99  if(cube->pars().getFlagLog()){
100    ofstream logfile(cube->pars().getLogFile().c_str());
101    logfile << "New run of the Duchamp sourcefinder: ";
102    time_t now = time(NULL);
103    logfile << asctime( localtime(&now) );
104    logfile << cube->pars();
105    logfile.close();
106  }
107
108  if(cube->pars().getFlagBlankPix()){
109    std::cout<<"Trimming the Blank Pixels from the edges...  "<<std::flush;
110    cube->trimCube();
111    std::cout<<"Done."<<endl;
112    std::cout << "New dimensions:  " << cube->getDimX();
113    if(cube->getNumDim()>1) std::cout << "x" << cube->getDimY();
114    if(cube->getNumDim()>2) std::cout << "x" << cube->getDimZ();
115    std::cout << endl;
116  }
117
118  if(cube->pars().getFlagMW()){
119    std::cout<<"Removing the Milky Way channels...  ";
120    cube->removeMW();
121    std::cout<<"Done."<<endl;
122  }
123
124  if(cube->pars().getFlagBaseline()){
125    std::cout<<"Removing the baselines... "<<std::flush;
126    cube->removeBaseline();
127    std::cout<<" Done.                 "<<std::endl;
128  }
129
130  if(cube->getDimZ()==1) cube->pars().setMinChannels(0);  // special case for 2D images.
131
132  if(cube->pars().getFlagNegative()){
133    std::cout<<"Inverting the Cube... "<<std::flush;
134    cube->invert();
135    std::cout<<" Done."<<std::endl;
136  }
137
138  if(cube->pars().getFlagATrous()){
139    std::cout<<"Commencing search in reconstructed cube..."<<endl;
140    cube->ReconSearch3D();
141    std::cout<<"Done. Found "<<cube->getNumObj()<<" objects."<<endl;
142  }
143  else{
144    std::cout<<"Commencing search in cube..."<<endl;
145    cube->SimpleSearch3D();
146    std::cout<<"Done. Found "<<cube->getNumObj()<<" objects."<<endl;
147  }
148
149  std::cout<<"Merging lists...  "<<std::flush;
150  cube->ObjectMerger();
151  std::cout<<"Done.                      "<<endl;
152  std::cout<<"Final object count = "<<cube->getNumObj()<<endl;
153
154  if(cube->pars().getFlagNegative()){
155    std::cout<<"Un-Inverting the Cube... "<<std::flush;
156    cube->reInvert();
157    std::cout<<" Done."<<std::endl;
158  }
159
160  cube->replaceBaseline();
161
162  if(cube->pars().getFlagCubeTrimmed()){
163    std::cout<<"Replacing the trimmed pixels on the edges...  "<<std::flush;
164    cube->unTrimCube();
165    std::cout<<"Done."<<endl;
166  }
167
168  if(cube->getNumObj()>0){
169
170    cube->calcObjectWCSparams();
171   
172    cube->sortDetections();
173   
174    cube->outputDetectionList();
175  }
176
177//   cube->plotDetectionMap("/xs");
178    cube->plotMomentMap("/xs");
179
180  if(cube->pars().getFlagMaps()){
181    std::cout<<"Creating the maps...  "<<std::flush;
182    cube->plotMomentMap(cube->pars().getMomentMap()+"/vcps");
183    cube->plotDetectionMap(cube->pars().getDetectionMap()+"/vcps");
184    std::cout << "done.\n";
185  }
186
187//   if(cube->isWCS() && (cube->getNumObj()>0)){
188  if((cube->getDimZ()>1) && (cube->getNumObj()>0)){
189    std::cout << "Plotting the individual spectra... " << std::flush;
190    cube->outputSpectra();
191    std::cout << "done.\n";
192  }
193  else if(cube->getDimZ()<=1) std::cout << "Not plotting any spectra  -- no third dimension.\n";
194
195  cpgend();
196
197  if(cube->pars().getFlagATrous()&&
198     (cube->pars().getFlagOutputRecon()||cube->pars().getFlagOutputResid()) ){
199    std::cout << "Saving reconstructed cube... "<<std::flush;
200    cube->saveReconstructedCube();
201    std::cout << "done.\n";
202  }
203
204  if(cube->pars().getFlagLog() && (cube->getNumObj()>0)){
205    ofstream logfile(cube->pars().getLogFile().c_str(),std::ios::app);
206    logfile << "=-=-=-=-=-=-=-\nCube summary\n=-=-=-=-=-=-=-\n";
207    logfile << *cube;
208    logfile.close();
209  }
210
211  if(cube->pars().getFlagVOT()){
212    ofstream votfile(cube->pars().getVOTFile().c_str());
213    cube->outputDetectionsVOTable(votfile);
214    votfile.close();
215  }
216
217  if(cube->pars().getFlagKarma()){
218    ofstream karmafile(cube->pars().getKarmaFile().c_str());
219    cube->outputDetectionsKarma(karmafile);
220    karmafile.close();
221  }
222
223  delete cube;
224
225  return 0;
226}
227
Note: See TracBrowser for help on using the repository browser.