source: trunk/src/mainDuchamp.cc @ 203

Last change on this file since 203 was 203, checked in by Matthew Whiting, 18 years ago
  • Explicitly defined the various template options for StatsContainer::madfmToSigma.
  • Added a new way to do the momentmap plots : plotMomentMap can now take a vector<string> as its argument, so that multiple plots can be written while only calculating the array values once. This speeds up this part of the program.
  • This mean some changes to the plots.hh file, so that we store the identifier for each plot/device, and have a new function that is a front-end to cpgslct.
  • More flexibility in the drawScale function, so that finer-scale images can be dealt with.
File size: 6.7 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
16using std::ofstream;
17using std::string;
18
19Filter reconFilter;
20
21int main(int argc, char * argv[])
22{
23
24  string paramFile,fitsfile;
25  Cube *cube = new Cube;
26
27  if(cube->getopts(argc,argv)==FAILURE) return FAILURE;
28
29  if(cube->pars().getImageFile().empty()){
30    std::stringstream errmsg;
31    errmsg << "No input image has been given!\n"
32           << "Use the imageFile parameter in "
33           << paramFile << " to specify the FITS file.\nExiting...\n";
34    duchampError("Duchamp", errmsg.str());
35    return FAILURE;
36  }
37
38  if(cube->pars().getFlagSubsection()){
39    // make sure the subsection is OK.
40    if(cube->pars().verifySubsection() == FAILURE){
41      duchampError("Duchamp",
42                   "Unable to use the subsection provided.\nExiting...\n");
43      return FAILURE;
44    }
45  }     
46
47  std::cout << "Opening image: "
48            << cube->pars().getFullImageFile() << std::endl;
49
50  if( cube->getCube() == FAILURE){
51    std::stringstream errmsg;
52    errmsg << "Unable to open image file "
53           << cube->pars().getFullImageFile()
54           << "\nExiting...\n";
55    duchampError("Duchamp", errmsg.str());
56    return FAILURE;
57  }
58  else std::cout << "Opened successfully." << std::endl;
59
60  // If the reconstructed array is to be read in from disk
61  if( cube->pars().getFlagReconExists() && cube->pars().getFlagATrous() ){
62    std::cout << "Reading reconstructed array: "<<std::endl;
63    if( cube->readReconCube() == FAILURE){
64      std::stringstream errmsg;
65      errmsg <<"Could not read in existing reconstructed array.\n"
66             <<"Will perform reconstruction using assigned parameters.\n";
67      duchampWarning("Duchamp", errmsg.str());
68      cube->pars().setFlagReconExists(false);
69    }
70    else std::cout << "Reconstructed array available.\n";
71  }
72
73  // Filter needed for baseline removal and a trous reconstruction
74  if(cube->pars().getFlagATrous() || cube->pars().getFlagBaseline()){
75    reconFilter.define(cube->pars().getFilterCode());
76    cube->pars().setFilterName(reconFilter.getName());
77  }
78
79  // special case for 2D images -- ignore the minChannels requirement
80  if(cube->getDimZ()==1) cube->pars().setMinChannels(0); 
81
82  // Write the parameters to screen.
83  std::cout << cube->pars();
84
85  if(cube->pars().getFlagLog()){
86    // Open the logfile and write the time on the first line
87    ofstream logfile(cube->pars().getLogFile().c_str());
88    logfile << "New run of the Duchamp sourcefinder: ";
89    time_t now = time(NULL);
90    logfile << asctime( localtime(&now) );
91    // Write out the command-line statement
92    logfile << "Executing statement : ";
93    for(int i=0;i<argc;i++) logfile << argv[i] << " ";
94    logfile << std::endl;
95    logfile << cube->pars();
96    logfile.close();
97  }
98
99  if(cube->pars().getFlagBlankPix()){
100    // Trim any blank pixels from the edges,
101    //  and report the new size of the cube
102    std::cout<<"Trimming the Blank Pixels from the edges...  "<<std::flush;
103    cube->trimCube();
104    std::cout<<"Done."<<std::endl;
105    std::cout << "New dimensions:  " << cube->getDimX();
106    if(cube->getNumDim()>1) std::cout << "x" << cube->getDimY();
107    if(cube->getNumDim()>2) std::cout << "x" << cube->getDimZ();
108    std::cout << std::endl;
109  }
110
111  if(cube->pars().getFlagBaseline()){
112    std::cout<<"Removing the baselines... "<<std::flush;
113    cube->removeBaseline();
114    std::cout<<" Done.                 "<<std::endl;
115  }
116
117  if(cube->pars().getFlagNegative()){
118    std::cout<<"Inverting the Cube... "<<std::flush;
119    cube->invert();
120    std::cout<<" Done."<<std::endl;
121  }
122
123  if(cube->pars().getFlagSmooth()){
124    std::cout<<"Commencing search in hanning smoothed cube..."<<std::endl;
125    cube->SmoothSearch();
126  }
127  else if(cube->pars().getFlagATrous()){
128    std::cout<<"Commencing search in reconstructed cube..."<<std::endl;
129    cube->ReconSearch();
130   }
131  else{
132    std::cout<<"Commencing search in cube..."<<std::endl;
133    cube->CubicSearch();
134  }
135  std::cout << "Done. Intermediate list has "
136            << cube->getNumObj();
137  if(cube->getNumObj()==1) std::cout << " object.\n";
138  else std::cout << " objects.\n";
139
140  if(cube->getNumObj() > 1){
141    std::cout<<"Merging lists...  "<<std::flush;
142    cube->ObjectMerger();
143    std::cout<<"Done.                      "<<std::endl;
144  }
145  std::cout<<"Final object count = "<<cube->getNumObj()<<std::endl;
146
147  if(cube->pars().getFlagNegative()){
148    std::cout<<"Un-Inverting the Cube... "<<std::flush;
149    cube->reInvert();
150    std::cout<<" Done."<<std::endl;
151  }
152
153  cube->replaceBaseline();
154
155  if(cube->pars().getFlagCubeTrimmed()){
156    std::cout<<"Replacing the trimmed pixels on the edges...  "<<std::flush;
157    cube->unTrimCube();
158    std::cout<<"Done."<<std::endl;
159  }
160
161  if(cube->getNumObj()>0){
162
163    cube->calcObjectWCSparams();
164
165    cube->setObjectFlags();
166   
167    cube->sortDetections();
168   
169    cube->outputDetectionList();
170  }
171
172  std::cout<<"Creating the maps...  "<<std::flush;
173//   if(cube->pars().getFlagXOutput()) cube->plotMomentMap("/xs");
174//   if(cube->pars().getFlagMaps()){
175//     cube->plotMomentMap(cube->pars().getMomentMap()+"/vcps");
176//     cube->plotDetectionMap(cube->pars().getDetectionMap()+"/vcps");
177//   }
178  vector<string> devices;
179  if(cube->pars().getFlagXOutput()) devices.push_back("/xs");
180  if(cube->pars().getFlagMaps())
181    devices.push_back(cube->pars().getMomentMap()+"/vcps");
182  cube->plotMomentMap(devices);
183  if(cube->pars().getFlagMaps())
184    cube->plotDetectionMap(cube->pars().getDetectionMap()+"/vcps");
185  std::cout << "done.\n";
186
187  if((cube->getDimZ()>1) && (cube->getNumObj()>0)){
188    std::cout << "Plotting the individual spectra... " << std::flush;
189    cube->outputSpectra();
190    std::cout << "done.\n";
191  }
192  else if(cube->getDimZ()<=1)
193    duchampWarning("Duchamp",
194                   "Not plotting any spectra  -- no third dimension.\n");
195
196  cpgend();
197
198  if(cube->pars().getFlagATrous()&&
199     (cube->pars().getFlagOutputRecon()||cube->pars().getFlagOutputResid()) ){
200    std::cout << "Saving reconstructed cube... "<<std::flush;
201    cube->saveReconstructedCube();
202    std::cout << "done.\n";
203  }
204
205  if(cube->pars().getFlagLog() && (cube->getNumObj()>0)){
206    ofstream logfile(cube->pars().getLogFile().c_str(),std::ios::app);
207    logfile << "=-=-=-=-=-=-=-\nCube summary\n=-=-=-=-=-=-=-\n";
208    logfile << *cube;
209    logfile.close();
210  }
211
212  if(cube->pars().getFlagVOT()){
213    ofstream votfile(cube->pars().getVOTFile().c_str());
214    cube->outputDetectionsVOTable(votfile);
215    votfile.close();
216  }
217
218  if(cube->pars().getFlagKarma()){
219    ofstream karmafile(cube->pars().getKarmaFile().c_str());
220    cube->outputDetectionsKarma(karmafile);
221    karmafile.close();
222  }
223
224  delete cube;
225
226  return SUCCESS;
227}
228
Note: See TracBrowser for help on using the repository browser.