source: trunk/src/mainDuchamp.cc @ 424

Last change on this file since 424 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
RevLine 
[299]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// -----------------------------------------------------------------------
[3]28#include <iostream>
29#include <fstream>
30#include <string>
31#include <math.h>
32#include <unistd.h>
[80]33#include <time.h>
[57]34
[393]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>
[3]42
[378]43using namespace duchamp;
44
[3]45int main(int argc, char * argv[])
46{
47
[232]48  std::string paramFile,fitsfile;
[85]49  Cube *cube = new Cube;
[3]50
[168]51  if(cube->getopts(argc,argv)==FAILURE) return FAILURE;
[3]52
53  if(cube->pars().getImageFile().empty()){
[139]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";
[168]58    duchampError("Duchamp", errmsg.str());
59    return FAILURE;
[3]60  }
61
[258]62  if(cube->pars().getFlagSubsection() || cube->pars().getFlagStatSec()){
[168]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  }     
[164]70
[139]71  std::cout << "Opening image: "
72            << cube->pars().getFullImageFile() << std::endl;
73
[106]74  if( cube->getCube() == FAILURE){
[139]75    std::stringstream errmsg;
76    errmsg << "Unable to open image file "
77           << cube->pars().getFullImageFile()
78           << "\nExiting...\n";
[168]79    duchampError("Duchamp", errmsg.str());
80    return FAILURE;
[3]81  }
[103]82  else std::cout << "Opened successfully." << std::endl;
[3]83
[208]84  // Read in any saved arrays that are in FITS files on disk.
85  cube->readSavedArrays();
[71]86
[139]87  // special case for 2D images -- ignore the minChannels requirement
88  if(cube->getDimZ()==1) cube->pars().setMinChannels(0); 
89
[103]90  // Write the parameters to screen.
[3]91  std::cout << cube->pars();
92
93  if(cube->pars().getFlagLog()){
[418]94    // Prepare the log file.
[419]95    cube->prepareLogFile(argc, argv);
[3]96  }
97
[285]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
[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
[208]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()){
[275]128    std::cout<<"Commencing search in smoothed cube..."<<std::endl;
[201]129    cube->SmoothSearch();
130  }
[3]131  else{
[103]132    std::cout<<"Commencing search in cube..."<<std::endl;
133    cube->CubicSearch();
[3]134  }
[258]135  std::cout << "Done. Intermediate list has " << cube->getNumObj();
[201]136  if(cube->getNumObj()==1) std::cout << " object.\n";
137  else std::cout << " objects.\n";
[3]138
[146]139  if(cube->getNumObj() > 1){
[265]140    if(cube->pars().getFlagGrowth())
141      std::cout<<"Merging, Growing and Rejecting...  "<<std::flush;
142    else
143      std::cout<<"Merging and Rejecting...  "<<std::flush;
[146]144    cube->ObjectMerger();
145    std::cout<<"Done.                      "<<std::endl;
146  }
[103]147  std::cout<<"Final object count = "<<cube->getNumObj()<<std::endl;
[3]148
[60]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
[258]155  if(cube->pars().getFlagBaseline()){
156    std::cout<<"Replacing the baselines...  "<<std::flush;
157    cube->replaceBaseline();
158    std::cout<<"Done."<<std::endl;
159  }
[3]160
161  if(cube->pars().getFlagCubeTrimmed()){
162    std::cout<<"Replacing the trimmed pixels on the edges...  "<<std::flush;
163    cube->unTrimCube();
[103]164    std::cout<<"Done."<<std::endl;
[3]165  }
166
[275]167  cube->prepareOutputFile();
168
[3]169  if(cube->getNumObj()>0){
170
171    cube->calcObjectWCSparams();
[87]172
173    cube->setObjectFlags();
[3]174   
175    cube->sortDetections();
176  }
[312]177 
178  cube->outputDetectionList();
[3]179
[315]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");
[258]189    std::cout << "Done.\n";
[315]190   
[367]191//     if((cube->getDimZ()>1) && (cube->getNumObj()>0)){
192    if(cube->getNumObj()>0){
[315]193      std::cout << "Plotting the individual spectra... " << std::flush;
194      cube->outputSpectra();
195      std::cout << "Done.\n";
196    }
[367]197//     else if(cube->getDimZ()<=1)
198//       duchampWarning("Duchamp",
199//                   "Not plotting any spectra : no third dimension.\n");
[3]200  }
[315]201  else{
202    std::cout << "PGPLOT has not been enabled, so no graphical output.\n";
203  }
[3]204
205  if(cube->pars().getFlagATrous()&&
206     (cube->pars().getFlagOutputRecon()||cube->pars().getFlagOutputResid()) ){
[258]207    std::cout << "Saving reconstructed cube to "
[208]208              << cube->pars().outputReconFile() << "... "<<std::flush;
[3]209    cube->saveReconstructedCube();
210    std::cout << "done.\n";
211  }
[208]212  if(cube->pars().getFlagSmooth()&& cube->pars().getFlagOutputSmooth()){
[290]213    std::cout << "Saving smoothed cube to "
[208]214              << cube->pars().outputSmoothFile() << "... " <<std::flush;
215    cube->saveSmoothedCube();
216    std::cout << "done.\n";
217  }
[379]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  }
[3]224
225  if(cube->pars().getFlagLog() && (cube->getNumObj()>0)){
[232]226    std::ofstream logfile(cube->pars().getLogFile().c_str(),std::ios::app);
[3]227    logfile << "=-=-=-=-=-=-=-\nCube summary\n=-=-=-=-=-=-=-\n";
228    logfile << *cube;
229    logfile.close();
230  }
231
[349]232  if(cube->pars().getFlagVOT()){
[232]233    std::ofstream votfile(cube->pars().getVOTFile().c_str());
[3]234    cube->outputDetectionsVOTable(votfile);
235    votfile.close();
236  }
237
[349]238  if(cube->pars().getFlagKarma()){
[232]239    std::ofstream karmafile(cube->pars().getKarmaFile().c_str());
[20]240    cube->outputDetectionsKarma(karmafile);
241    karmafile.close();
242  }
243
[313]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
[3]254  delete cube;
255
[168]256  return SUCCESS;
[3]257}
258
Note: See TracBrowser for help on using the repository browser.