source: trunk/src/mainDuchamp.cc @ 236

Last change on this file since 236 was 232, checked in by Matthew Whiting, 17 years ago

Large raft of changes. Most are minor ones related to fixing up the use of std::string and std::vector (whether they are declared as using, or not...). Other changes include:

  • Moving the reconstruction filter class Filter into its own header/implementation files filter.{hh,cc}. As a result, the atrous.cc file is removed, but atrous.hh remains with just the function prototypes.
  • Incorporating a Filter object into the Param set, so that the reconstruction routines can see it without the messy "extern" call. The define() function is now called in both the Param() and Param::readParams() functions, and no longer in the main body.
  • Col functions in columns.cc moved into the Column namespace, while the template function printEntry is moved into the columns.hh file -- it would not compile on delphinus with it in the columns.cc, even though all the implementations were present.
  • Improved the introductory section of the Guide, with a bit more detail about each of the execution steps. This way the reader can read this section and have a reasonably good idea about what is happening.
  • Other minor changes to the Guide.
File size: 6.5 KB
Line 
1#include <iostream>
2#include <fstream>
3#include <string>
4#include <cpgplot.h>
5#include <math.h>
6#include <unistd.h>
7#include <time.h>
8
9#include <duchamp.hh>
10#include <param.hh>
11#include <Detection/detection.hh>
12#include <Cubes/cubes.hh>
13#include <Utils/utils.hh>
14#include <ATrous/atrous.hh>
15
16int main(int argc, char * argv[])
17{
18
19  std::string paramFile,fitsfile;
20  Cube *cube = new Cube;
21
22  if(cube->getopts(argc,argv)==FAILURE) return FAILURE;
23
24  if(cube->pars().getImageFile().empty()){
25    std::stringstream errmsg;
26    errmsg << "No input image has been given!\n"
27           << "Use the imageFile parameter in "
28           << paramFile << " to specify the FITS file.\nExiting...\n";
29    duchampError("Duchamp", errmsg.str());
30    return FAILURE;
31  }
32
33  if(cube->pars().getFlagSubsection()){
34    // make sure the subsection is OK.
35    if(cube->pars().verifySubsection() == FAILURE){
36      duchampError("Duchamp",
37                   "Unable to use the subsection provided.\nExiting...\n");
38      return FAILURE;
39    }
40  }     
41
42  std::cout << "Opening image: "
43            << cube->pars().getFullImageFile() << std::endl;
44
45  if( cube->getCube() == FAILURE){
46    std::stringstream errmsg;
47    errmsg << "Unable to open image file "
48           << cube->pars().getFullImageFile()
49           << "\nExiting...\n";
50    duchampError("Duchamp", errmsg.str());
51    return FAILURE;
52  }
53  else std::cout << "Opened successfully." << std::endl;
54
55  // Read in any saved arrays that are in FITS files on disk.
56  cube->readSavedArrays();
57
58  // Filter needed for baseline removal and a trous reconstruction
59//   if(cube->pars().getFlagATrous() || cube->pars().getFlagBaseline()){
60//     reconFilter.define(cube->pars().getFilterCode());
61//     cube->pars().setFilterName(reconFilter.getName());
62//   }
63
64  // special case for 2D images -- ignore the minChannels requirement
65  if(cube->getDimZ()==1) cube->pars().setMinChannels(0); 
66
67  // Write the parameters to screen.
68  std::cout << cube->pars();
69
70  if(cube->pars().getFlagLog()){
71    // Open the logfile and write the time on the first line
72    std::ofstream logfile(cube->pars().getLogFile().c_str());
73    logfile << "New run of the Duchamp sourcefinder: ";
74    time_t now = time(NULL);
75    logfile << asctime( localtime(&now) );
76    // Write out the command-line statement
77    logfile << "Executing statement : ";
78    for(int i=0;i<argc;i++) logfile << argv[i] << " ";
79    logfile << std::endl;
80    logfile << cube->pars();
81    logfile.close();
82  }
83
84  if(cube->pars().getFlagBlankPix()){
85    // Trim any blank pixels from the edges,
86    //  and report the new size of the cube
87    std::cout<<"Trimming the Blank Pixels from the edges...  "<<std::flush;
88    cube->trimCube();
89    std::cout<<"Done."<<std::endl;
90    std::cout << "New dimensions:  " << cube->getDimX();
91    if(cube->getNumDim()>1) std::cout << "x" << cube->getDimY();
92    if(cube->getNumDim()>2) std::cout << "x" << cube->getDimZ();
93    std::cout << std::endl;
94  }
95
96  if(cube->pars().getFlagBaseline()){
97    std::cout<<"Removing the baselines... "<<std::flush;
98    cube->removeBaseline();
99    std::cout<<" Done.                 "<<std::endl;
100  }
101
102  if(cube->pars().getFlagNegative()){
103    std::cout<<"Inverting the Cube... "<<std::flush;
104    cube->invert();
105    std::cout<<" Done."<<std::endl;
106  }
107
108  if(cube->pars().getFlagATrous()){
109    std::cout<<"Commencing search in reconstructed cube..."<<std::endl;
110    cube->ReconSearch();
111  } 
112  else if(cube->pars().getFlagSmooth()){
113    std::cout<<"Commencing search in hanning smoothed cube..."<<std::endl;
114    cube->SmoothSearch();
115  }
116  else{
117    std::cout<<"Commencing search in cube..."<<std::endl;
118    cube->CubicSearch();
119  }
120  std::cout << "Done. Intermediate list has "
121            << cube->getNumObj();
122  if(cube->getNumObj()==1) std::cout << " object.\n";
123  else std::cout << " objects.\n";
124
125  if(cube->getNumObj() > 1){
126    std::cout<<"Merging lists...  "<<std::flush;
127    cube->ObjectMerger();
128    std::cout<<"Done.                      "<<std::endl;
129  }
130  std::cout<<"Final object count = "<<cube->getNumObj()<<std::endl;
131
132  if(cube->pars().getFlagNegative()){
133    std::cout<<"Un-Inverting the Cube... "<<std::flush;
134    cube->reInvert();
135    std::cout<<" Done."<<std::endl;
136  }
137
138  cube->replaceBaseline();
139
140  if(cube->pars().getFlagCubeTrimmed()){
141    std::cout<<"Replacing the trimmed pixels on the edges...  "<<std::flush;
142    cube->unTrimCube();
143    std::cout<<"Done."<<std::endl;
144  }
145
146  if(cube->getNumObj()>0){
147
148    cube->calcObjectWCSparams();
149
150    cube->setObjectFlags();
151   
152    cube->sortDetections();
153   
154    cube->outputDetectionList();
155  }
156
157  std::cout<<"Creating the maps...  "<<std::flush;
158//   if(cube->pars().getFlagXOutput()) cube->plotMomentMap("/xs");
159//   if(cube->pars().getFlagMaps()){
160//     cube->plotMomentMap(cube->pars().getMomentMap()+"/vcps");
161//     cube->plotDetectionMap(cube->pars().getDetectionMap()+"/vcps");
162//   }
163  std::vector<std::string> devices;
164  if(cube->pars().getFlagXOutput()) devices.push_back("/xs");
165  if(cube->pars().getFlagMaps())
166    devices.push_back(cube->pars().getMomentMap()+"/vcps");
167  cube->plotMomentMap(devices);
168  if(cube->pars().getFlagMaps())
169    cube->plotDetectionMap(cube->pars().getDetectionMap()+"/vcps");
170  std::cout << "done.\n";
171
172  if((cube->getDimZ()>1) && (cube->getNumObj()>0)){
173    std::cout << "Plotting the individual spectra... " << std::flush;
174    cube->outputSpectra();
175    std::cout << "done.\n";
176  }
177  else if(cube->getDimZ()<=1)
178    duchampWarning("Duchamp",
179                   "Not plotting any spectra  -- no third dimension.\n");
180
181  cpgend();
182
183  if(cube->pars().getFlagATrous()&&
184     (cube->pars().getFlagOutputRecon()||cube->pars().getFlagOutputResid()) ){
185    std::cout << "Saving reconstructed cube"
186              << cube->pars().outputReconFile() << "... "<<std::flush;
187    cube->saveReconstructedCube();
188    std::cout << "done.\n";
189  }
190  if(cube->pars().getFlagSmooth()&& cube->pars().getFlagOutputSmooth()){
191    std::cout << "Saving Hanning-smoothed cube to"
192              << cube->pars().outputSmoothFile() << "... " <<std::flush;
193    cube->saveSmoothedCube();
194    std::cout << "done.\n";
195  }
196
197  if(cube->pars().getFlagLog() && (cube->getNumObj()>0)){
198    std::ofstream logfile(cube->pars().getLogFile().c_str(),std::ios::app);
199    logfile << "=-=-=-=-=-=-=-\nCube summary\n=-=-=-=-=-=-=-\n";
200    logfile << *cube;
201    logfile.close();
202  }
203
204  if(cube->pars().getFlagVOT()){
205    std::ofstream votfile(cube->pars().getVOTFile().c_str());
206    cube->outputDetectionsVOTable(votfile);
207    votfile.close();
208  }
209
210  if(cube->pars().getFlagKarma()){
211    std::ofstream karmafile(cube->pars().getKarmaFile().c_str());
212    cube->outputDetectionsKarma(karmafile);
213    karmafile.close();
214  }
215
216  delete cube;
217
218  return SUCCESS;
219}
220
Note: See TracBrowser for help on using the repository browser.