source: trunk/src/mainDuchamp.cc @ 195

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

Implemented a request (from ticket:1) for the ability to not display the pgplot
window showing the moment map. This is now switched on and off by the
flagXOutput parameter.
Updated code and documentation.

File size: 6.4 KB
RevLine 
[3]1#include <iostream>
2#include <fstream>
3#include <string>
4#include <cpgplot.h>
5#include <math.h>
6#include <unistd.h>
[80]7#include <time.h>
[57]8
9#include <duchamp.hh>
[142]10#include <param.hh>
[3]11#include <Detection/detection.hh>
12#include <Cubes/cubes.hh>
13#include <Utils/utils.hh>
14#include <ATrous/atrous.hh>
15
16using std::ofstream;
[103]17using std::string;
[3]18
19Filter reconFilter;
20
21int main(int argc, char * argv[])
22{
23
[85]24  string paramFile,fitsfile;
25  Cube *cube = new Cube;
[3]26
[168]27  if(cube->getopts(argc,argv)==FAILURE) return FAILURE;
[3]28
29  if(cube->pars().getImageFile().empty()){
[139]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";
[168]34    duchampError("Duchamp", errmsg.str());
35    return FAILURE;
[3]36  }
37
[168]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  }     
[164]46
[139]47  std::cout << "Opening image: "
48            << cube->pars().getFullImageFile() << std::endl;
49
[106]50  if( cube->getCube() == FAILURE){
[139]51    std::stringstream errmsg;
52    errmsg << "Unable to open image file "
53           << cube->pars().getFullImageFile()
54           << "\nExiting...\n";
[168]55    duchampError("Duchamp", errmsg.str());
56    return FAILURE;
[3]57  }
[103]58  else std::cout << "Opened successfully." << std::endl;
[3]59
[71]60  // If the reconstructed array is to be read in from disk
[76]61  if( cube->pars().getFlagReconExists() && cube->pars().getFlagATrous() ){
[103]62    std::cout << "Reading reconstructed array: "<<std::endl;
[71]63    if( cube->readReconCube() == FAILURE){
[120]64      std::stringstream errmsg;
65      errmsg <<"Could not read in existing reconstructed array.\n"
66             <<"Will perform reconstruction using assigned parameters.\n";
[168]67      duchampWarning("Duchamp", errmsg.str());
[71]68      cube->pars().setFlagReconExists(false);
69    }
[103]70    else std::cout << "Reconstructed array available.\n";
[71]71  }
72
[103]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
[139]79  // special case for 2D images -- ignore the minChannels requirement
80  if(cube->getDimZ()==1) cube->pars().setMinChannels(0); 
81
[103]82  // Write the parameters to screen.
[3]83  std::cout << cube->pars();
84
85  if(cube->pars().getFlagLog()){
[106]86    // Open the logfile and write the time on the first line
[3]87    ofstream logfile(cube->pars().getLogFile().c_str());
88    logfile << "New run of the Duchamp sourcefinder: ";
[80]89    time_t now = time(NULL);
90    logfile << asctime( localtime(&now) );
[120]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;
[3]95    logfile << cube->pars();
96    logfile.close();
97  }
98
99  if(cube->pars().getFlagBlankPix()){
[139]100    // Trim any blank pixels from the edges,
101    //  and report the new size of the cube
[3]102    std::cout<<"Trimming the Blank Pixels from the edges...  "<<std::flush;
103    cube->trimCube();
[103]104    std::cout<<"Done."<<std::endl;
[3]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();
[103]108    std::cout << std::endl;
[3]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
[60]117  if(cube->pars().getFlagNegative()){
118    std::cout<<"Inverting the Cube... "<<std::flush;
119    cube->invert();
120    std::cout<<" Done."<<std::endl;
121  }
122
[76]123  if(cube->pars().getFlagATrous()){
[103]124    std::cout<<"Commencing search in reconstructed cube..."<<std::endl;
125    cube->ReconSearch();
[146]126    std::cout << "Done. Intermediate list has "
127              << cube->getNumObj();
128    if(cube->getNumObj()==1) std::cout << " object.\n";
129    else std::cout << " objects.\n";
[3]130  }
131  else{
[103]132    std::cout<<"Commencing search in cube..."<<std::endl;
133    cube->CubicSearch();
[146]134    std::cout << "Done. Intermediate list has "
135              << cube->getNumObj();
136    if(cube->getNumObj()==1) std::cout << " object.\n";
137    else std::cout << " objects.\n";
[3]138  }
139
[146]140  if(cube->getNumObj() > 1){
141    std::cout<<"Merging lists...  "<<std::flush;
142    cube->ObjectMerger();
143    std::cout<<"Done.                      "<<std::endl;
144  }
[103]145  std::cout<<"Final object count = "<<cube->getNumObj()<<std::endl;
[3]146
[60]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
[3]153  cube->replaceBaseline();
154
155  if(cube->pars().getFlagCubeTrimmed()){
156    std::cout<<"Replacing the trimmed pixels on the edges...  "<<std::flush;
157    cube->unTrimCube();
[103]158    std::cout<<"Done."<<std::endl;
[3]159  }
160
161  if(cube->getNumObj()>0){
162
163    cube->calcObjectWCSparams();
[87]164
165    cube->setObjectFlags();
[3]166   
167    cube->sortDetections();
168   
169    cube->outputDetectionList();
170  }
171
[87]172  std::cout<<"Creating the maps...  "<<std::flush;
[195]173  if(cube->pars().getFlagXOutput()) cube->plotMomentMap("/xs");
174
[3]175  if(cube->pars().getFlagMaps()){
176    cube->plotMomentMap(cube->pars().getMomentMap()+"/vcps");
177    cube->plotDetectionMap(cube->pars().getDetectionMap()+"/vcps");
178  }
[87]179  std::cout << "done.\n";
[3]180
[49]181  if((cube->getDimZ()>1) && (cube->getNumObj()>0)){
[3]182    std::cout << "Plotting the individual spectra... " << std::flush;
183    cube->outputSpectra();
184    std::cout << "done.\n";
185  }
[120]186  else if(cube->getDimZ()<=1)
[168]187    duchampWarning("Duchamp",
188                   "Not plotting any spectra  -- no third dimension.\n");
[3]189
190  cpgend();
191
192  if(cube->pars().getFlagATrous()&&
193     (cube->pars().getFlagOutputRecon()||cube->pars().getFlagOutputResid()) ){
194    std::cout << "Saving reconstructed cube... "<<std::flush;
195    cube->saveReconstructedCube();
196    std::cout << "done.\n";
197  }
198
199  if(cube->pars().getFlagLog() && (cube->getNumObj()>0)){
200    ofstream logfile(cube->pars().getLogFile().c_str(),std::ios::app);
201    logfile << "=-=-=-=-=-=-=-\nCube summary\n=-=-=-=-=-=-=-\n";
202    logfile << *cube;
203    logfile.close();
204  }
205
206  if(cube->pars().getFlagVOT()){
207    ofstream votfile(cube->pars().getVOTFile().c_str());
208    cube->outputDetectionsVOTable(votfile);
209    votfile.close();
210  }
211
[20]212  if(cube->pars().getFlagKarma()){
213    ofstream karmafile(cube->pars().getKarmaFile().c_str());
214    cube->outputDetectionsKarma(karmafile);
215    karmafile.close();
216  }
217
[3]218  delete cube;
219
[168]220  return SUCCESS;
[3]221}
222
Note: See TracBrowser for help on using the repository browser.