source: trunk/mainDuchamp.cc @ 9

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

This is the first full import of all working code to
the Duchamp repository.
Made three directories at top level:

branches/ tags/ trunk/

and trunk/ has the full set of code:
ATrous/ Cubes/ Detection/ InputComplete? InputExample? README Utils/ docs/ mainDuchamp.cc param.cc param.hh

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