source: trunk/mainDuchamp.cc @ 82

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

docs/cover_image.ps,pdf -- new image for the front page of the Guide
docs/Guide.tex -- redrafted several sections, and added a new image on the front
param.cc -- changed the defaults of output files and growthCut to match those

given in the Guide

mainDuchamp.cc -- changed the way the time of execution is called : now using

time.h functions, rather than a system call

Cubes/detectionIO.cc -- removed the system call to date, and added some new

PARAM lines to the VOTable output.

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