source: tags/release-0.9/mainDuchamp.cc @ 813

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

Changing the references in mainDuchamp.cc, saveImage.cc and getImage.cc (in
the v0.9 release) to fitsio.h so that they compile with the new version of
CFITSIO:
*remove reference to fitsio.h in mainDuchamp.cc
*move fitsio.h reference to after the wcslib include statements in other two
files.

File size: 5.3 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 <Detection/detection.hh>
11#include <Cubes/cubes.hh>
12#include <Utils/utils.hh>
13#include <ATrous/atrous.hh>
14
15using std::ofstream;
16using std::endl;
17
18Filter reconFilter;
19
20int main(int argc, char * argv[])
21{
22
23  string paramFile;
24  string err_usage_msg("Usage:: Duchamp.x -p [parameter file]\n");
25
26  if(argc==1){
27    std::cout << err_usage_msg;
28    exit(1);
29  }
30  else{
31    char c;
32    while( ( c = getopt(argc,argv,"p:h") )!=-1){
33      switch(c) {
34      case 'p':
35        paramFile = optarg;
36        break;
37      case 'h':
38      default :
39        std::cout << err_usage_msg;
40        exit(1);
41        break;
42      }
43    }
44  }
45
46  Cube *cube = new Cube;
47  cube->readParam(paramFile);
48  if(cube->pars().getImageFile().empty()){
49    std::cerr << "Error: No input image has been given!"<<endl;
50    std::cerr << "Use the imageFile parameter in "<< paramFile << " to specify the FITS file."<<endl;
51    std::cerr << "Exiting..." << endl;
52    exit(1);
53  }
54
55  // Filter needed for baseline removal and a trous reconstruction
56  if(cube->pars().getFlagATrous() || cube->pars().getFlagBaseline()){
57    reconFilter.define(cube->pars().getFilterCode());
58    cube->pars().setFilterName(reconFilter.getName());
59  }
60
61  string fname = cube->pars().getImageFile();
62  if(cube->pars().getFlagSubsection()){
63    cube->pars().parseSubsection();
64    fname+=cube->pars().getSubsection();
65  }
66  std::cout << "Opening image: " << fname << endl;
67  if( cube->getCube(fname) ){
68    std::cerr << "Error opening file : " << fname << endl;
69    std::cerr << "Exiting..." << endl;
70    exit(1);
71  }
72  else std::cout << "Opened successfully." << endl;
73  if(!cube->isWCS()) std::cerr << "Warning! WCS is not good enough to be used.\n";
74
75  std::cout << cube->pars();
76
77  if(cube->pars().getFlagLog()){
78    ofstream logfile(cube->pars().getLogFile().c_str());
79    logfile << "New run of the Duchamp sourcefinder: ";
80    logfile.close();
81    string syscall = "date >> " + cube->pars().getLogFile();
82    system(syscall.c_str());
83    logfile.open(cube->pars().getLogFile().c_str(),std::ios::app);
84    logfile << cube->pars();
85    logfile.close();
86  }
87
88  if(cube->pars().getFlagBlankPix()){
89    std::cout<<"Trimming the Blank Pixels from the edges...  "<<std::flush;
90    cube->trimCube();
91    std::cout<<"Done."<<endl;
92    std::cout << "New dimensions:  " << cube->getDimX();
93    if(cube->getNumDim()>1) std::cout << "x" << cube->getDimY();
94    if(cube->getNumDim()>2) std::cout << "x" << cube->getDimZ();
95    std::cout << endl;
96  }
97
98  if(cube->pars().getFlagMW()){
99    std::cout<<"Removing the Milky Way channels...  ";
100    cube->removeMW();
101    std::cout<<"Done."<<endl;
102  }
103
104  if(cube->pars().getFlagBaseline()){
105    std::cout<<"Removing the baselines... "<<std::flush;
106    cube->removeBaseline();
107    std::cout<<" Done.                 "<<std::endl;
108  }
109
110  if(cube->getDimZ()==1) cube->pars().setMinChannels(0);  // special case for 2D images.
111
112  if(cube->pars().getFlagATrous()){
113    std::cout<<"Commencing search in reconstructed cube..."<<endl;
114    cube->ReconSearch3D();
115    std::cout<<"Done. Found "<<cube->getNumObj()<<" objects."<<endl;
116  }
117  else{
118    std::cout<<"Commencing search in cube..."<<endl;
119    cube->SimpleSearch3D();
120    std::cout<<"Done. Found "<<cube->getNumObj()<<" objects."<<endl;
121  }
122
123  std::cout<<"Merging lists...  "<<std::flush;
124  cube->ObjectMerger();
125  std::cout<<"Done.                      "<<endl;
126  std::cout<<"Final object count = "<<cube->getNumObj()<<endl;
127
128  cube->replaceBaseline();
129
130  if(cube->pars().getFlagCubeTrimmed()){
131    std::cout<<"Replacing the trimmed pixels on the edges...  "<<std::flush;
132    cube->unTrimCube();
133    std::cout<<"Done."<<endl;
134  }
135
136  if(cube->getNumObj()>0){
137
138    cube->calcObjectWCSparams();
139   
140    cube->sortDetections();
141   
142    cube->outputDetectionList();
143  }
144
145//   cube->plotDetectionMap("/xs");
146    cube->plotMomentMap("/xs");
147
148  if(cube->pars().getFlagMaps()){
149    std::cout<<"Creating the maps...  "<<std::flush;
150    cube->plotMomentMap(cube->pars().getMomentMap()+"/vcps");
151    cube->plotDetectionMap(cube->pars().getDetectionMap()+"/vcps");
152    std::cout << "done.\n";
153  }
154
155  if(cube->isWCS() && (cube->getNumObj()>0)){
156    std::cout << "Plotting the individual spectra... " << std::flush;
157    cube->outputSpectra();
158    std::cout << "done.\n";
159  }
160  else if(!(cube->isWCS())) std::cout << "Not plotting any spectra due to bad WCS.\n";
161
162  cpgend();
163
164  if(cube->pars().getFlagATrous()&&
165     (cube->pars().getFlagOutputRecon()||cube->pars().getFlagOutputResid()) ){
166    std::cout << "Saving reconstructed cube... "<<std::flush;
167    cube->saveReconstructedCube();
168    std::cout << "done.\n";
169  }
170
171  if(cube->pars().getFlagLog() && (cube->getNumObj()>0)){
172    ofstream logfile(cube->pars().getLogFile().c_str(),std::ios::app);
173    logfile << "=-=-=-=-=-=-=-\nCube summary\n=-=-=-=-=-=-=-\n";
174    logfile << *cube;
175    logfile.close();
176  }
177
178  if(cube->pars().getFlagVOT()){
179    ofstream votfile(cube->pars().getVOTFile().c_str());
180    cube->outputDetectionsVOTable(votfile);
181    votfile.close();
182  }
183
184  if(cube->pars().getFlagKarma()){
185    ofstream karmafile(cube->pars().getKarmaFile().c_str());
186    cube->outputDetectionsKarma(karmafile);
187    karmafile.close();
188  }
189
190  delete cube;
191
192  return 0;
193}
194
Note: See TracBrowser for help on using the repository browser.