source: trunk/src/mainDuchamp.cc @ 290

Last change on this file since 290 was 290, checked in by Matthew Whiting, 17 years ago
  • SmoothCube?() function, to handle the switching to the proper smoothing function.
  • Other new Cube/Image? functions: clearDetectMap(), Simple3DSearch(), Simple3DSearchRecon(), Simple3DSearchSmooth() (primarily for use by analysis/development software).
  • Changed the Cube::plotMomentMap(std::string) function to be a simple redirection to the Cube::plotMomentMap(std::vector<std::string>) function.
  • Tidying up of comments
File size: 6.4 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() || cube->pars().getFlagStatSec()){
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  // special case for 2D images -- ignore the minChannels requirement
59  if(cube->getDimZ()==1) cube->pars().setMinChannels(0); 
60
61  // Write the parameters to screen.
62  std::cout << cube->pars();
63
64  if(cube->pars().getFlagLog()){
65    // Open the logfile and write the time on the first line
66    std::ofstream logfile(cube->pars().getLogFile().c_str());
67    logfile << "New run of the Duchamp sourcefinder: ";
68    time_t now = time(NULL);
69    logfile << asctime( localtime(&now) );
70    // Write out the command-line statement
71    logfile << "Executing statement : ";
72    for(int i=0;i<argc;i++) logfile << argv[i] << " ";
73    logfile << std::endl;
74    logfile << cube->pars();
75    logfile.close();
76  }
77
78  //if(cube->pars().getFlagBlankPix()){
79  if(cube->pars().getFlagTrim()){
80    // Trim any blank pixels from the edges, and report the new size
81    // of the cube
82    std::cout<<"Trimming the Blank Pixels from the edges...  "<<std::flush;
83    cube->trimCube();
84    std::cout<<"Done."<<std::endl;
85    std::cout << "New dimensions:  " << cube->getDimX();
86    if(cube->getNumDim()>1) std::cout << "x" << cube->getDimY();
87    if(cube->getNumDim()>2) std::cout << "x" << cube->getDimZ();
88    std::cout << std::endl;
89  }
90
91  if(cube->pars().getFlagBaseline()){
92    std::cout<<"Removing the baselines... "<<std::flush;
93    cube->removeBaseline();
94    std::cout<<" Done.                 "<<std::endl;
95  }
96
97  if(cube->pars().getFlagNegative()){
98    std::cout<<"Inverting the Cube... "<<std::flush;
99    cube->invert();
100    std::cout<<" Done."<<std::endl;
101  }
102
103  if(cube->pars().getFlagATrous()){
104    std::cout<<"Commencing search in reconstructed cube..."<<std::endl;
105    cube->ReconSearch();
106  } 
107  else if(cube->pars().getFlagSmooth()){
108    std::cout<<"Commencing search in smoothed cube..."<<std::endl;
109    cube->SmoothSearch();
110  }
111  else{
112    std::cout<<"Commencing search in cube..."<<std::endl;
113    cube->CubicSearch();
114  }
115  std::cout << "Done. Intermediate list has " << cube->getNumObj();
116  if(cube->getNumObj()==1) std::cout << " object.\n";
117  else std::cout << " objects.\n";
118
119  if(cube->getNumObj() > 1){
120    if(cube->pars().getFlagGrowth())
121      std::cout<<"Merging, Growing and Rejecting...  "<<std::flush;
122    else
123      std::cout<<"Merging and Rejecting...  "<<std::flush;
124    cube->ObjectMerger();
125    std::cout<<"Done.                      "<<std::endl;
126  }
127  std::cout<<"Final object count = "<<cube->getNumObj()<<std::endl;
128
129  if(cube->pars().getFlagNegative()){
130    std::cout<<"Un-Inverting the Cube... "<<std::flush;
131    cube->reInvert();
132    std::cout<<" Done."<<std::endl;
133  }
134
135  if(cube->pars().getFlagBaseline()){
136    std::cout<<"Replacing the baselines...  "<<std::flush;
137    cube->replaceBaseline();
138    std::cout<<"Done."<<std::endl;
139  }
140
141  if(cube->pars().getFlagCubeTrimmed()){
142    std::cout<<"Replacing the trimmed pixels on the edges...  "<<std::flush;
143    cube->unTrimCube();
144    std::cout<<"Done."<<std::endl;
145  }
146
147  cube->prepareOutputFile();
148
149  if(cube->getNumObj()>0){
150
151    cube->calcObjectWCSparams();
152
153    cube->setObjectFlags();
154   
155    cube->sortDetections();
156   
157    cube->outputDetectionList();
158  }
159
160  std::cout<<"Creating the maps...  "<<std::flush;
161  std::vector<std::string> devices;
162  if(cube->pars().getFlagXOutput()) devices.push_back("/xs");
163  if(cube->pars().getFlagMaps())
164    devices.push_back(cube->pars().getMomentMap()+"/vcps");
165  cube->plotMomentMap(devices);
166  if(cube->pars().getFlagMaps())
167    cube->plotDetectionMap(cube->pars().getDetectionMap()+"/vcps");
168  std::cout << "Done.\n";
169
170  if((cube->getDimZ()>1) && (cube->getNumObj()>0)){
171    std::cout << "Plotting the individual spectra... " << std::flush;
172    cube->outputSpectra();
173    std::cout << "Done.\n";
174  }
175  else if(cube->getDimZ()<=1)
176    duchampWarning("Duchamp",
177                   "Not plotting any spectra : no third dimension.\n");
178
179  cpgend();
180
181  if(cube->pars().getFlagATrous()&&
182     (cube->pars().getFlagOutputRecon()||cube->pars().getFlagOutputResid()) ){
183    std::cout << "Saving reconstructed cube to "
184              << cube->pars().outputReconFile() << "... "<<std::flush;
185    cube->saveReconstructedCube();
186    std::cout << "done.\n";
187  }
188  if(cube->pars().getFlagSmooth()&& cube->pars().getFlagOutputSmooth()){
189    std::cout << "Saving smoothed cube to "
190              << cube->pars().outputSmoothFile() << "... " <<std::flush;
191    cube->saveSmoothedCube();
192    std::cout << "done.\n";
193  }
194
195  if(cube->pars().getFlagLog() && (cube->getNumObj()>0)){
196    std::ofstream logfile(cube->pars().getLogFile().c_str(),std::ios::app);
197    logfile << "=-=-=-=-=-=-=-\nCube summary\n=-=-=-=-=-=-=-\n";
198    logfile << *cube;
199    logfile.close();
200  }
201
202  if(cube->pars().getFlagVOT()){
203    std::ofstream votfile(cube->pars().getVOTFile().c_str());
204    cube->outputDetectionsVOTable(votfile);
205    votfile.close();
206  }
207
208  if(cube->pars().getFlagKarma()){
209    std::ofstream karmafile(cube->pars().getKarmaFile().c_str());
210    cube->outputDetectionsKarma(karmafile);
211    karmafile.close();
212  }
213
214  delete cube;
215
216  return SUCCESS;
217}
218
Note: See TracBrowser for help on using the repository browser.