source: branches/fitshead-branch/mainDuchamp.cc @ 1441

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

Two sets of large changes:
1) Added reconDim, to select which dimension of reconstruction to use.
2) Changed the way the MW channels are dealt with -- now not set to 0. but

simply ignored for searching purposes.

Summary of changes for each file:
duchamp.hh -- added keyword info for reconDim
param.hh -- Introduced reconDim and flagUsingBlank and isInMW.
param.cc -- Introduced reconDim and flagUsingBlank: initialisation etc commands
InputComplete? -- Added reconDim info
mainDuchamp.cc -- Removed the removeMW call. Changed search function names
docs/Guide.tex -- New code to deal with changes: reconDim, MW removal,

up-to-date output examples, better hints & notes section

Detection/thresholding_functions.cc -- minor typo correction

Cubes/cubes.hh -- added isBlank and removeMW functions in Image class, and

renamed search function prototypes

Cubes/cubes.cc -- added removeMW function for Image class, cleaned up

Cube::removeMW as well (although now not used)

Cubes/outputSpectra.cc -- Improved use of isBlank and isInMW functions: now

show MW channels but don't use them in calculating
the flux range

Cubes/getImage.cc -- added line to indicate whether the Param's blank value

is being used, rather than the FITS header.

Cubes/cubicSearch.cc -- renamed functions: front end is now CubicSearch?, and

searching function is search3DArray.

-- Improved way MW removal is dealt with. Changed

location of stats calculations.

Cubes/saveImage.cc -- added code for saving reconDim info
Cubes/readRecon.cc -- added code for reading reconDim info (and added status

intialisations before all cfitsio commands)

ATrous/ReconSearch.cc -- renamed functions: front end is now ReconSearch?, and

searching function is searchReconArray.
Using reconDim to decide which reconstruction to use.

-- Improved way MW removal is dealt with. Changed

location of stats calculations.

ATrous/atrous_1d_reconstruct.cc -- using Median stats
ATrous/atrous_2d_reconstruct.cc -- made code up to date, to conform with 1- &

3-d code. Removed boundary conditions.

ATrous/atrous_3d_reconstruct.cc -- corrected typo (avGapY /= float(xdim)).

Using median stats.

Cubes/cubicSearchNMerge.cc -- Deleted. (not used)
Cubes/readParams.cc -- Deleted. (not used)

File size: 6.2 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 <Detection/detection.hh>
11#include <Cubes/cubes.hh>
12#include <Utils/utils.hh>
13#include <ATrous/atrous.hh>
14
15using std::ofstream;
16using std::string;
17
18Filter reconFilter;
19
20int main(int argc, char * argv[])
21{
22
23  string paramFile,fitsfile;
24  Cube *cube = new Cube;
25  Param *par = new Param;
26
27  if(argc==1){
28    std::cout << ERR_USAGE_MSG;
29    return 1;
30  }
31  else{
32    char c;
33    while( ( c = getopt(argc,argv,"p:f:hv") )!=-1){
34      switch(c) {
35      case 'p':
36        paramFile = optarg;
37        cube->readParam(paramFile);
38        break;
39      case 'f':
40        fitsfile = optarg;
41        par->setImageFile(fitsfile);
42        cube->saveParam(*par);
43        break;
44      case 'v':
45        std::cout << PROGNAME << " " << VERSION << std::endl;
46        return 1;
47        break;
48      case 'h':
49      default :
50        std::cout << ERR_USAGE_MSG;
51        return 1;
52        break;
53      }
54    }
55  }
56
57  delete par;
58
59  if(cube->pars().getImageFile().empty()){
60    std::cerr << "ERROR : No input image has been given!\n";
61    std::cerr << "        Use the imageFile parameter in "<< paramFile << " to specify the FITS file.\n";
62    std::cerr << "Exiting...\n\n";
63    return 1;
64  }
65
66  string fname = cube->pars().getImageFile();
67  if(cube->pars().getFlagSubsection()){
68    cube->pars().parseSubsection();
69    fname+=cube->pars().getSubsection();
70  }
71  std::cout << "Opening image: " << fname << std::endl;
72  if( cube->getCube(fname) == FAILURE){
73    std::cerr << "ERROR : Unable to open image file : " << fname << std::endl;
74    std::cerr << "Exiting...\n\n";
75    return 1;
76  }
77  else std::cout << "Opened successfully." << std::endl;
78
79  // If the reconstructed array is to be read in from disk
80  if( cube->pars().getFlagReconExists() && cube->pars().getFlagATrous() ){
81    std::cout << "Reading reconstructed array: "<<std::endl;
82    if( cube->readReconCube() == FAILURE){
83      std::cerr << "WARNING : Could not read in existing reconstructed array.\n"
84                << "          Will perform reconstruction using assigned parameters.\n";
85      cube->pars().setFlagReconExists(false);
86    }
87    else std::cout << "Reconstructed array available.\n";
88  }
89
90  // Filter needed for baseline removal and a trous reconstruction
91  if(cube->pars().getFlagATrous() || cube->pars().getFlagBaseline()){
92    reconFilter.define(cube->pars().getFilterCode());
93    cube->pars().setFilterName(reconFilter.getName());
94  }
95
96  // Write the parameters to screen.
97  std::cout << cube->pars();
98
99  if(cube->pars().getFlagLog()){
100    ofstream logfile(cube->pars().getLogFile().c_str());
101    logfile << "New run of the Duchamp sourcefinder: ";
102    time_t now = time(NULL);
103    logfile << asctime( localtime(&now) );
104    logfile << cube->pars();
105    logfile.close();
106  }
107
108  if(cube->pars().getFlagBlankPix()){
109    std::cout<<"Trimming the Blank Pixels from the edges...  "<<std::flush;
110    cube->trimCube();
111    std::cout<<"Done."<<std::endl;
112    std::cout << "New dimensions:  " << cube->getDimX();
113    if(cube->getNumDim()>1) std::cout << "x" << cube->getDimY();
114    if(cube->getNumDim()>2) std::cout << "x" << cube->getDimZ();
115    std::cout << std::endl;
116  }
117
118//   if(cube->pars().getFlagMW()){
119//     std::cout<<"Removing the Milky Way channels...  "<<std::flush;
120//     cube->removeMW();
121//     std::cout<<"Done."<<std::endl;
122//   }
123
124  if(cube->pars().getFlagBaseline()){
125    std::cout<<"Removing the baselines... "<<std::flush;
126    cube->removeBaseline();
127    std::cout<<" Done.                 "<<std::endl;
128  }
129
130  if(cube->getDimZ()==1) cube->pars().setMinChannels(0);  // special case for 2D images.
131
132  if(cube->pars().getFlagNegative()){
133    std::cout<<"Inverting the Cube... "<<std::flush;
134    cube->invert();
135    std::cout<<" Done."<<std::endl;
136  }
137
138  if(cube->pars().getFlagATrous()){
139    std::cout<<"Commencing search in reconstructed cube..."<<std::endl;
140    cube->ReconSearch();
141    std::cout<<"Done. Found "<<cube->getNumObj()<<" objects."<<std::endl;
142  }
143  else{
144    std::cout<<"Commencing search in cube..."<<std::endl;
145    cube->CubicSearch();
146    std::cout<<"Done. Found "<<cube->getNumObj()<<" objects."<<std::endl;
147  }
148
149  std::cout<<"Merging lists...  "<<std::flush;
150  cube->ObjectMerger();
151  std::cout<<"Done.                      "<<std::endl;
152  std::cout<<"Final object count = "<<cube->getNumObj()<<std::endl;
153
154  if(cube->pars().getFlagNegative()){
155    std::cout<<"Un-Inverting the Cube... "<<std::flush;
156    cube->reInvert();
157    std::cout<<" Done."<<std::endl;
158  }
159
160  cube->replaceBaseline();
161
162  if(cube->pars().getFlagCubeTrimmed()){
163    std::cout<<"Replacing the trimmed pixels on the edges...  "<<std::flush;
164    cube->unTrimCube();
165    std::cout<<"Done."<<std::endl;
166  }
167
168  if(cube->getNumObj()>0){
169
170    cube->calcObjectWCSparams();
171
172    cube->setObjectFlags();
173   
174    cube->sortDetections();
175   
176    cube->outputDetectionList();
177  }
178
179  std::cout<<"Creating the maps...  "<<std::flush;
180  cube->plotMomentMap("/xs");
181  if(cube->pars().getFlagMaps()){
182    cube->plotMomentMap(cube->pars().getMomentMap()+"/vcps");
183    cube->plotDetectionMap(cube->pars().getDetectionMap()+"/vcps");
184  }
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) std::cerr << "WARNING : Not plotting any spectra  -- no third dimension.\n";
193
194  cpgend();
195
196  if(cube->pars().getFlagATrous()&&
197     (cube->pars().getFlagOutputRecon()||cube->pars().getFlagOutputResid()) ){
198    std::cout << "Saving reconstructed cube... "<<std::flush;
199    cube->saveReconstructedCube();
200    std::cout << "done.\n";
201  }
202
203  if(cube->pars().getFlagLog() && (cube->getNumObj()>0)){
204    ofstream logfile(cube->pars().getLogFile().c_str(),std::ios::app);
205    logfile << "=-=-=-=-=-=-=-\nCube summary\n=-=-=-=-=-=-=-\n";
206    logfile << *cube;
207    logfile.close();
208  }
209
210  if(cube->pars().getFlagVOT()){
211    ofstream votfile(cube->pars().getVOTFile().c_str());
212    cube->outputDetectionsVOTable(votfile);
213    votfile.close();
214  }
215
216  if(cube->pars().getFlagKarma()){
217    ofstream karmafile(cube->pars().getKarmaFile().c_str());
218    cube->outputDetectionsKarma(karmafile);
219    karmafile.close();
220  }
221
222  delete cube;
223
224  return 0;
225}
226
Note: See TracBrowser for help on using the repository browser.