source: tags/release-1.1.4/src/mainDuchamp.cc @ 1441

Last change on this file since 1441 was 419, checked in by MatthewWhiting, 16 years ago

Some minor fixes to correct compilation warnings. Moved Object3D::order() into the .cc file.

File size: 8.1 KB
Line 
1// -----------------------------------------------------------------------
2// mainDuchamp.cc: Main program for Duchamp source finder.
3// -----------------------------------------------------------------------
4// Copyright (C) 2006, Matthew Whiting, ATNF
5//
6// This program is free software; you can redistribute it and/or modify it
7// under the terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 2 of the License, or (at your
9// option) any later version.
10//
11// Duchamp is distributed in the hope that it will be useful, but WITHOUT
12// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14// for more details.
15//
16// You should have received a copy of the GNU General Public License
17// along with Duchamp; if not, write to the Free Software Foundation,
18// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
19//
20// Correspondence concerning Duchamp may be directed to:
21//    Internet email: Matthew.Whiting [at] atnf.csiro.au
22//    Postal address: Dr. Matthew Whiting
23//                    Australia Telescope National Facility, CSIRO
24//                    PO Box 76
25//                    Epping NSW 1710
26//                    AUSTRALIA
27// -----------------------------------------------------------------------
28#include <iostream>
29#include <fstream>
30#include <string>
31#include <math.h>
32#include <unistd.h>
33#include <time.h>
34
35#include <duchamp/duchamp.hh>
36#include <duchamp/param.hh>
37#include <duchamp/pgheader.hh>
38#include <duchamp/Detection/detection.hh>
39#include <duchamp/Cubes/cubes.hh>
40#include <duchamp/Utils/utils.hh>
41#include <duchamp/ATrous/atrous.hh>
42
43using namespace duchamp;
44
45int main(int argc, char * argv[])
46{
47
48  std::string paramFile,fitsfile;
49  Cube *cube = new Cube;
50
51  if(cube->getopts(argc,argv)==FAILURE) return FAILURE;
52
53  if(cube->pars().getImageFile().empty()){
54    std::stringstream errmsg;
55    errmsg << "No input image has been given!\n"
56           << "Use the imageFile parameter in "
57           << paramFile << " to specify the FITS file.\nExiting...\n";
58    duchampError("Duchamp", errmsg.str());
59    return FAILURE;
60  }
61
62  if(cube->pars().getFlagSubsection() || cube->pars().getFlagStatSec()){
63    // make sure the subsection is OK.
64    if(cube->pars().verifySubsection() == FAILURE){
65      duchampError("Duchamp",
66                   "Unable to use the subsection provided.\nExiting...\n");
67      return FAILURE;
68    }
69  }     
70
71  std::cout << "Opening image: "
72            << cube->pars().getFullImageFile() << std::endl;
73
74  if( cube->getCube() == FAILURE){
75    std::stringstream errmsg;
76    errmsg << "Unable to open image file "
77           << cube->pars().getFullImageFile()
78           << "\nExiting...\n";
79    duchampError("Duchamp", errmsg.str());
80    return FAILURE;
81  }
82  else std::cout << "Opened successfully." << std::endl;
83
84  // Read in any saved arrays that are in FITS files on disk.
85  cube->readSavedArrays();
86
87  // special case for 2D images -- ignore the minChannels requirement
88  if(cube->getDimZ()==1) cube->pars().setMinChannels(0); 
89
90  // Write the parameters to screen.
91  std::cout << cube->pars();
92
93  if(cube->pars().getFlagLog()){
94    // Prepare the log file.
95    cube->prepareLogFile(argc, argv);
96  }
97
98  //if(cube->pars().getFlagBlankPix()){
99  if(cube->pars().getFlagTrim()){
100    // Trim any blank pixels from the edges, and report the new size
101    // 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().getFlagATrous()){
124    std::cout<<"Commencing search in reconstructed cube..."<<std::endl;
125    cube->ReconSearch();
126  } 
127  else if(cube->pars().getFlagSmooth()){
128    std::cout<<"Commencing search in smoothed cube..."<<std::endl;
129    cube->SmoothSearch();
130  }
131  else{
132    std::cout<<"Commencing search in cube..."<<std::endl;
133    cube->CubicSearch();
134  }
135  std::cout << "Done. Intermediate list has " << cube->getNumObj();
136  if(cube->getNumObj()==1) std::cout << " object.\n";
137  else std::cout << " objects.\n";
138
139  if(cube->getNumObj() > 1){
140    if(cube->pars().getFlagGrowth())
141      std::cout<<"Merging, Growing and Rejecting...  "<<std::flush;
142    else
143      std::cout<<"Merging and Rejecting...  "<<std::flush;
144    cube->ObjectMerger();
145    std::cout<<"Done.                      "<<std::endl;
146  }
147  std::cout<<"Final object count = "<<cube->getNumObj()<<std::endl;
148
149  if(cube->pars().getFlagNegative()){
150    std::cout<<"Un-Inverting the Cube... "<<std::flush;
151    cube->reInvert();
152    std::cout<<" Done."<<std::endl;
153  }
154
155  if(cube->pars().getFlagBaseline()){
156    std::cout<<"Replacing the baselines...  "<<std::flush;
157    cube->replaceBaseline();
158    std::cout<<"Done."<<std::endl;
159  }
160
161  if(cube->pars().getFlagCubeTrimmed()){
162    std::cout<<"Replacing the trimmed pixels on the edges...  "<<std::flush;
163    cube->unTrimCube();
164    std::cout<<"Done."<<std::endl;
165  }
166
167  cube->prepareOutputFile();
168
169  if(cube->getNumObj()>0){
170
171    cube->calcObjectWCSparams();
172
173    cube->setObjectFlags();
174   
175    cube->sortDetections();
176  }
177 
178  cube->outputDetectionList();
179
180  if(USE_PGPLOT){
181    std::cout<<"Creating the maps...  "<<std::flush;
182    std::vector<std::string> devices;
183    if(cube->pars().getFlagXOutput()) devices.push_back("/xs");
184    if(cube->pars().getFlagMaps())
185      devices.push_back(cube->pars().getMomentMap()+"/vcps");
186    cube->plotMomentMap(devices);
187    if(cube->pars().getFlagMaps())
188      cube->plotDetectionMap(cube->pars().getDetectionMap()+"/vcps");
189    std::cout << "Done.\n";
190   
191//     if((cube->getDimZ()>1) && (cube->getNumObj()>0)){
192    if(cube->getNumObj()>0){
193      std::cout << "Plotting the individual spectra... " << std::flush;
194      cube->outputSpectra();
195      std::cout << "Done.\n";
196    }
197//     else if(cube->getDimZ()<=1)
198//       duchampWarning("Duchamp",
199//                   "Not plotting any spectra : no third dimension.\n");
200  }
201  else{
202    std::cout << "PGPLOT has not been enabled, so no graphical output.\n";
203  }
204
205  if(cube->pars().getFlagATrous()&&
206     (cube->pars().getFlagOutputRecon()||cube->pars().getFlagOutputResid()) ){
207    std::cout << "Saving reconstructed cube to "
208              << cube->pars().outputReconFile() << "... "<<std::flush;
209    cube->saveReconstructedCube();
210    std::cout << "done.\n";
211  }
212  if(cube->pars().getFlagSmooth()&& cube->pars().getFlagOutputSmooth()){
213    std::cout << "Saving smoothed cube to "
214              << cube->pars().outputSmoothFile() << "... " <<std::flush;
215    cube->saveSmoothedCube();
216    std::cout << "done.\n";
217  }
218  if(cube->pars().getFlagOutputMask()){
219    std::cout << "Saving mask cube to "
220              << cube->pars().outputMaskFile() << "... " <<std::flush;
221    cube->saveMaskCube();
222    std::cout << "done.\n";
223  }
224
225  if(cube->pars().getFlagLog() && (cube->getNumObj()>0)){
226    std::ofstream logfile(cube->pars().getLogFile().c_str(),std::ios::app);
227    logfile << "=-=-=-=-=-=-=-\nCube summary\n=-=-=-=-=-=-=-\n";
228    logfile << *cube;
229    logfile.close();
230  }
231
232  if(cube->pars().getFlagVOT()){
233    std::ofstream votfile(cube->pars().getVOTFile().c_str());
234    cube->outputDetectionsVOTable(votfile);
235    votfile.close();
236  }
237
238  if(cube->pars().getFlagKarma()){
239    std::ofstream karmafile(cube->pars().getKarmaFile().c_str());
240    cube->outputDetectionsKarma(karmafile);
241    karmafile.close();
242  }
243
244  if(cube->pars().getFlagLog()){
245    // Open the logfile and write the time on the first line
246    std::ofstream logfile(cube->pars().getLogFile().c_str(),std::ios::app);
247    logfile << "Duchamp completed: ";
248    time_t now = time(NULL);
249    logfile << asctime( localtime(&now) );
250    logfile.close();
251  }
252
253
254  delete cube;
255
256  return SUCCESS;
257}
258
Note: See TracBrowser for help on using the repository browser.