source: branches/pixel-map-branch/src/Detection/columns.cc @ 1213

Last change on this file since 1213 was 232, checked in by Matthew Whiting, 17 years ago

Large raft of changes. Most are minor ones related to fixing up the use of std::string and std::vector (whether they are declared as using, or not...). Other changes include:

  • Moving the reconstruction filter class Filter into its own header/implementation files filter.{hh,cc}. As a result, the atrous.cc file is removed, but atrous.hh remains with just the function prototypes.
  • Incorporating a Filter object into the Param set, so that the reconstruction routines can see it without the messy "extern" call. The define() function is now called in both the Param() and Param::readParams() functions, and no longer in the main body.
  • Col functions in columns.cc moved into the Column namespace, while the template function printEntry is moved into the columns.hh file -- it would not compile on delphinus with it in the columns.cc, even though all the implementations were present.
  • Improved the introductory section of the Guide, with a bit more detail about each of the execution steps. This way the reader can read this section and have a reasonably good idea about what is happening.
  • Other minor changes to the Guide.
File size: 12.9 KB
Line 
1#include <iostream>
2#include <sstream>
3
4#include <math.h>
5#include <duchamp.hh>
6#include <param.hh>
7#include <vector>
8#include <string>
9#include <Detection/detection.hh>
10#include <Detection/columns.hh>
11
12using std::string;
13using std::vector;
14using namespace Column;
15
16namespace Column
17{
18
19  Col::Col(){
20    width=1;
21    precision=0;
22    name=" ";
23    units=" ";
24  };
25
26  Col::~Col(){}
27
28  Col::Col(int num)
29  {
30    /**
31     * A specialised constructor that defines one of the default
32     *  columns, as defined in the Column namespace
33     * \param num The number of the column to be constructed.
34     *            Corresponds to the order of the columns in the const
35     *            arrays in the Column namespace.
36     */
37    if((num>=0)&&(num<numColumns)){
38      this->width =     defaultWidth[num];
39      this->precision = defaultPrec[num];
40      this->name =      defaultName[num];
41      this->units =     defaultUnits[num];
42    }
43    else{
44      std::stringstream errmsg;
45      errmsg << "Incorrect value for Col(num) --> num="<<num
46             << ", should be between 0 and " << numColumns-1 << ".\n";
47      duchampError("Col constructor", errmsg.str());
48      this->width = 1;
49      this->precision = 0;
50      this->name = " ";
51      this->units = " ";
52    }
53  }
54
55//   template <class T> void Col::printEntry(std::ostream &stream, T value)
56//   {
57//     stream << std::setprecision(this->precision)
58//         << std::setw(this->width)
59//         << std::setfill(' ')
60//         << value;
61//   }
62//   template void Col::printEntry<int>(std::ostream &stream, int value);
63//   template void Col::printEntry<long>(std::ostream &stream, long value);
64//   template void Col::printEntry<unsigned>(std::ostream &stream, unsigned value);
65//   template void Col::printEntry<float>(std::ostream &stream, float value);
66//   template void Col::printEntry<double>(std::ostream &stream, double value);
67//   template void Col::printEntry<std::string>(std::ostream &stream, std::string value);
68
69}
70
71vector<Col> getFullColSet(vector<Detection> &objectList, FitsHeader &head)
72{
73  /**
74   *  A function that returns a vector of Col objects containing
75   *  information on the columns necessary for output to the results
76   *  file:
77   *    Obj#,NAME,X,Y,Z,RA,DEC,VEL,w_RA,w_DEC,w_VEL,F_tot,F_int,F_peak,
78   *                X1,X2,Y1,Y2,Z1,Z2,Npix,Flag
79   *
80   *   Each object in the provided objectList is checked to see if it
81   *   requires any column to be widened, or for that column to have
82   *   its precision increased.
83   *
84   *   Both Ftot and Fint are provided -- it is up to the calling
85   *   function to determine which to use.
86   *
87   * \param objectList A vector list of Detection objects that the
88   * columns need to fit.
89   * \param head The FitsHeader object defining the World Coordinate
90   * System.
91   * \return A vector list of Col definitions.
92   */
93
94  vector<Col> newset;
95
96  // set up the default columns
97
98  newset.push_back( Col(NUM) );
99  newset.push_back( Col(NAME) );
100  newset.push_back( Col(X) );
101  newset.push_back( Col(Y) );
102  newset.push_back( Col(Z) );
103  newset.push_back( Col(RA) );
104  newset.push_back( Col(DEC) );
105  newset.push_back( Col(VEL) );
106  newset.push_back( Col(WRA) );
107  newset.push_back( Col(WDEC) );
108  newset.push_back( Col(WVEL) );
109  newset.push_back( Col(FINT) );
110  newset.push_back( Col(FTOT) );
111  newset.push_back( Col(FPEAK) );
112  newset.push_back( Col(SNRPEAK) );
113  newset.push_back( Col(X1) );
114  newset.push_back( Col(X2) );
115  newset.push_back( Col(Y1) );
116  newset.push_back( Col(Y2) );
117  newset.push_back( Col(Z1) );
118  newset.push_back( Col(Z2) );
119  newset.push_back( Col(NPIX) );
120  newset.push_back( Col(FLAG) );
121
122  // Now test each object against each new column
123  for( int obj = 0; obj < objectList.size(); obj++){
124    std::string tempstr;
125    int tempwidth;
126    float val,minval;
127
128    // Obj#
129    tempwidth = int( log10(objectList[obj].getID()) + 1) +
130      newset[NUM].getPrecision() + 1;
131    for(int i=newset[NUM].getWidth();i<tempwidth;i++) newset[NUM].widen();
132
133    // Name
134    tempwidth = objectList[obj].getName().size() + 1;
135    for(int i=newset[NAME].getWidth();i<tempwidth;i++) newset[NAME].widen();
136
137    // X position
138    val = objectList[obj].getXcentre();
139    tempwidth = int( log10(val) + 1) + newset[X].getPrecision() + 2;
140    for(int i=newset[X].getWidth();i<tempwidth;i++) newset[X].widen();
141    if((val<1.)&&(val>0.)){
142      minval = pow(10, -1. * newset[X].getPrecision()+1);
143      if(val < minval) newset[X].upPrec();
144    }
145    // Y position
146    val = objectList[obj].getYcentre();
147    tempwidth = int( log10(val) + 1) + newset[Y].getPrecision() + 2;
148    for(int i=newset[Y].getWidth();i<tempwidth;i++) newset[Y].widen();
149    if((val<1.)&&(val>0.)){
150      minval = pow(10, -1. * newset[Y].getPrecision()+1);
151      if(val < minval) newset[Y].upPrec();
152    }
153    // Z position
154    val = objectList[obj].getZcentre();
155    tempwidth = int( log10(val) + 1) + newset[Z].getPrecision() + 2;
156    for(int i=newset[Z].getWidth();i<tempwidth;i++) newset[Z].widen();
157    if((val<1.)&&(val>0.)){
158      minval = pow(10, -1. * newset[Z].getPrecision()+1);
159      if((val>0.)&&(val < minval)) newset[Z].upPrec();
160    }
161
162    if(head.isWCS()){ 
163      // RA -- assign correct title. Check width but should be ok by definition
164      tempstr = head.getWCS()->lngtyp;
165      newset[RA].setName(tempstr);
166      tempwidth = objectList[obj].getRAs().size() + 1;
167      for(int i=newset[RA].getWidth();i<tempwidth;i++) newset[RA].widen();
168     
169      // Dec -- assign correct title. Check width, should be ok by definition
170      tempstr = head.getWCS()->lattyp;
171      newset[DEC].setName(tempstr);
172      tempwidth = objectList[obj].getDecs().size() + 1;
173      for(int i=newset[DEC].getWidth();i<tempwidth;i++) newset[DEC].widen();
174
175      // Vel -- check width, title and units.
176      if(head.getWCS()->restfrq == 0) // using frequency, not velocity
177        newset[VEL].setName("FREQ");
178      newset[VEL].setUnits("[" + head.getSpectralUnits() + "]");
179      tempwidth = newset[VEL].getUnits().size() + 1;
180      for(int i=newset[VEL].getWidth();i<tempwidth;i++) newset[VEL].widen();
181
182      val = objectList[obj].getVel();
183      tempwidth = int( log10(fabs(val)) + 1) + newset[VEL].getPrecision() + 2;
184      if(val<0) tempwidth++;
185      for(int i=newset[VEL].getWidth();i<tempwidth;i++) newset[VEL].widen();
186      if((fabs(val) < 1.)&&(val>0.)){
187        minval = pow(10, -1. * newset[VEL].getPrecision()+1);
188        if(val < minval) newset[VEL].upPrec();
189      }
190
191      // w_RA -- check width & title. leave units for the moment.
192      tempwidth = newset[RA].getUnits().size() + 1;
193      for(int i=newset[RA].getWidth();i<tempwidth;i++) newset[RA].widen();
194      val = objectList[obj].getRAWidth();
195      tempwidth = int( log10(fabs(val)) + 1) + newset[WRA].getPrecision() + 2;
196      if(val<0) tempwidth++;
197      for(int i=newset[WRA].getWidth();i<tempwidth;i++) newset[WRA].widen();
198      if((fabs(val) < 1.)&&(val>0.)){
199        minval = pow(10, -1. * newset[WRA].getPrecision()+1);
200        if(val < minval) newset[WRA].upPrec();
201      }
202
203      // w_DEC -- check width & title. leave units for the moment.
204      tempwidth = newset[DEC].getUnits().size() + 1;
205      for(int i=newset[DEC].getWidth();i<tempwidth;i++) newset[DEC].widen();
206      val = objectList[obj].getDecWidth();
207      tempwidth = int( log10(fabs(val)) + 1) + newset[WDEC].getPrecision() + 2;
208      if(val<0) tempwidth++;
209      for(int i=newset[WDEC].getWidth();i<tempwidth;i++) newset[WDEC].widen();
210      if((fabs(val) < 1.)&&(val>0.)){
211        minval = pow(10, -1. * newset[WDEC].getPrecision()+1);
212        if(val < minval) newset[WDEC].upPrec();
213      }
214
215      // w_Vel -- check width, title and units.
216      if(head.getWCS()->restfrq == 0) // using frequency, not velocity
217        newset[WVEL].setName("w_FREQ");
218      newset[WVEL].setUnits("[" + head.getSpectralUnits() + "]");
219      tempwidth = newset[WVEL].getUnits().size() + 1;
220      for(int i=newset[WVEL].getWidth();i<tempwidth;i++) newset[WVEL].widen();
221      val = objectList[obj].getVel();
222      tempwidth = int( log10(fabs(val)) + 1) + newset[WVEL].getPrecision() + 2;
223      if(val<0) tempwidth++;
224      for(int i=newset[WVEL].getWidth();i<tempwidth;i++) newset[WVEL].widen();
225      if((fabs(val) < 1.)&&(val>0.)){
226        minval = pow(10, -1. * newset[WVEL].getPrecision()+1);
227        if(val < minval) newset[WVEL].upPrec();
228      }
229
230      // F_int -- check width & units
231      newset[FINT].setUnits("[" + head.getIntFluxUnits() + "]");
232      tempwidth = newset[FINT].getUnits().size() + 1;
233      for(int i=newset[FINT].getWidth();i<tempwidth;i++) newset[FINT].widen();
234      val = objectList[obj].getIntegFlux();
235      tempwidth = int( log10(fabs(val)) + 1) + newset[FINT].getPrecision() + 2;
236      if(val<0) tempwidth++;
237      for(int i=newset[FINT].getWidth();i<tempwidth;i++) newset[FINT].widen();
238      if((fabs(val) < 1.)&&(val>0.)){
239        minval = pow(10, -1. * newset[FINT].getPrecision()+1);
240        if(val < minval) newset[FINT].upPrec();
241      }
242    }
243
244    // F_tot
245    newset[FTOT].setUnits("[" + head.getFluxUnits() + "]");
246    tempwidth = newset[FTOT].getUnits().size() + 1;
247    for(int i=newset[FTOT].getWidth();i<tempwidth;i++) newset[FTOT].widen();
248    val = objectList[obj].getTotalFlux();
249    tempwidth = int( log10(fabs(val)) + 1) + newset[FTOT].getPrecision() + 2;
250    if(val<0) tempwidth++;
251    for(int i=newset[FTOT].getWidth();i<tempwidth;i++) newset[FTOT].widen();
252    if((fabs(val) < 1.)&&(val>0.)){
253      minval = pow(10, -1. * newset[FTOT].getPrecision()+1);
254      if(val < minval) newset[FTOT].upPrec();
255    }
256
257    // F_peak
258    newset[FPEAK].setUnits("[" + head.getFluxUnits() + "]");
259    tempwidth = newset[FPEAK].getUnits().size() + 1;
260    for(int i=newset[FPEAK].getWidth();i<tempwidth;i++) newset[FPEAK].widen();
261    val = objectList[obj].getPeakFlux();
262    tempwidth = int( log10(fabs(val)) + 1) + newset[FPEAK].getPrecision() + 2;
263    if(val<0) tempwidth++;
264    for(int i=newset[FPEAK].getWidth();i<tempwidth;i++) newset[FPEAK].widen();
265    if((fabs(val) < 1.)&&(val>0.)){
266      minval = pow(10, -1. * newset[FPEAK].getPrecision()+1);
267      if(val < minval) newset[FPEAK].upPrec();
268    }
269
270    // S/N_peak
271    val = objectList[obj].getPeakSNR();
272    tempwidth = int( log10(fabs(val)) + 1) + newset[SNRPEAK].getPrecision() +2;
273    if(val<0) tempwidth++;
274    for(int i=newset[SNRPEAK].getWidth();i<tempwidth;i++)
275      newset[SNRPEAK].widen();
276    if((fabs(val) < 1.)&&(val>0.)){
277      minval = pow(10, -1. * newset[SNRPEAK].getPrecision()+1);
278      if(val < minval) newset[SNRPEAK].upPrec();
279    }
280
281    // X1 position
282    tempwidth = int( log10(objectList[obj].getXmin()) + 1) +
283      newset[X1].getPrecision() + 1;
284    for(int i=newset[X1].getWidth();i<tempwidth;i++) newset[X1].widen();
285    // X2 position
286    tempwidth = int( log10(objectList[obj].getXmax()) + 1) +
287      newset[X2].getPrecision() + 1;
288    for(int i=newset[X2].getWidth();i<tempwidth;i++) newset[X2].widen();
289    // Y1 position
290    tempwidth = int( log10(objectList[obj].getYmin()) + 1) +
291      newset[Y1].getPrecision() + 1;
292    for(int i=newset[Y1].getWidth();i<tempwidth;i++) newset[Y1].widen();
293    // Y2 position
294    tempwidth = int( log10(objectList[obj].getYmax()) + 1) +
295      newset[Y2].getPrecision() + 1;
296    for(int i=newset[Y2].getWidth();i<tempwidth;i++) newset[Y2].widen();
297    // Z1 position
298    tempwidth = int( log10(objectList[obj].getZmin()) + 1) +
299      newset[Z1].getPrecision() + 1;
300    for(int i=newset[Z1].getWidth();i<tempwidth;i++) newset[Z1].widen();
301    // Z2 position
302    tempwidth = int( log10(objectList[obj].getZmax()) + 1) +
303      newset[Z2].getPrecision() + 1;
304    for(int i=newset[Z2].getWidth();i<tempwidth;i++) newset[Z2].widen();
305
306    // Npix
307    tempwidth = int( log10(objectList[obj].getSize()) + 1) +
308      newset[NPIX].getPrecision() + 1;
309    for(int i=newset[NPIX].getWidth();i<tempwidth;i++) newset[NPIX].widen();
310   
311  }
312
313  return newset;
314
315}
316
317vector<Col> getLogColSet(vector<Detection> &objectList, FitsHeader &head)
318{
319  /**
320   *  A function that returns a vector of Col objects containing
321   *    information on the columns necessary for logfile output:
322   *    Obj#,X,Y,Z,F_tot,F_peak,X1,X2,Y1,Y2,Z1,Z2,Npix
323   *
324   *   Each object in the provided objectList is checked to see if
325   *    it requires any column to be widened, or for that column to
326   *    have its precision increased.
327   *
328   * \param objectList A vector list of Detection objects that the columns need to fit.
329   * \param head The FitsHeader object defining the World Coordinate System.
330   * \return A vector list of Col definitions.
331   */
332
333  vector<Col> newset,tempset;
334 
335  // set up the default columns:
336  //  get from FullColSet, and select only the ones we want.
337  tempset = getFullColSet(objectList,head);
338
339  newset.push_back( tempset[NUM] );
340  newset.push_back( tempset[X] );
341  newset.push_back( tempset[Y] );
342  newset.push_back( tempset[Z] );
343  newset.push_back( tempset[FTOT] );
344  newset.push_back( tempset[FPEAK] );
345  newset.push_back( tempset[SNRPEAK] );
346  newset.push_back( tempset[X1] );
347  newset.push_back( tempset[X2] );
348  newset.push_back( tempset[Y1] );
349  newset.push_back( tempset[Y2] );
350  newset.push_back( tempset[Z1] );
351  newset.push_back( tempset[Z2] );
352  newset.push_back( tempset[NPIX] );
353
354  return newset;
355
356}
Note: See TracBrowser for help on using the repository browser.