source: trunk/src/Detection/columns.cc @ 221

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

More documentation being added to source code, with a new file (src/Utils/Hanning.cc) added as well.

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