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

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

Large commit, but mostly documentation-oriented.

Only non-doc-related changes are:

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