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

Last change on this file since 1441 was 208, checked in by Matthew Whiting, 18 years ago
  • Enabled saving and reading in of a smoothed array, in manner directly analogous to that for the recon array.
    • New file : src/Cubes/readSmooth.cc
    • The other new functions go in existing files eg. saveImage.cc
    • Renamed some functions (like writeHeader...) to be more obvious what they do.
    • The reading in is taken care of by new function Cube::readSavedArrays() -- handles both smoothed and recon'd arrays.
    • Associated parameters in Param class
    • Clarified names of FITS header strings in duchamp.hh.
  • Updated the documentation to describe the ability to smooth a cube.
  • Added description of feedback mechanisms in the Install appendix.
  • Also, Hanning class improved to guard against memory leaks.


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