source: branches/pixelmap-refactor-branch/src/Detection/columns.cc @ 1441

Last change on this file since 1441 was 558, checked in by MatthewWhiting, 15 years ago

Making a few function calls more explicit in Detection class. Cleaning up some unwanted cerr outputs and commented-out code.

File size: 25.7 KB
Line 
1// -----------------------------------------------------------------------
2// columns.cc: Define a set of columns for Duchamp output.
3// -----------------------------------------------------------------------
4// Copyright (C) 2006, Matthew Whiting, ATNF
5//
6// This program is free software; you can redistribute it and/or modify it
7// under the terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 2 of the License, or (at your
9// option) any later version.
10//
11// Duchamp is distributed in the hope that it will be useful, but WITHOUT
12// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14// for more details.
15//
16// You should have received a copy of the GNU General Public License
17// along with Duchamp; if not, write to the Free Software Foundation,
18// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
19//
20// Correspondence concerning Duchamp may be directed to:
21//    Internet email: Matthew.Whiting [at] atnf.csiro.au
22//    Postal address: Dr. Matthew Whiting
23//                    Australia Telescope National Facility, CSIRO
24//                    PO Box 76
25//                    Epping NSW 1710
26//                    AUSTRALIA
27// -----------------------------------------------------------------------
28#include <iostream>
29#include <sstream>
30
31#include <math.h>
32#include <duchamp/duchamp.hh>
33#include <duchamp/fitsHeader.hh>
34#include <vector>
35#include <string>
36#include <duchamp/Detection/detection.hh>
37#include <duchamp/Detection/columns.hh>
38
39namespace duchamp
40{
41
42  namespace Column
43  {
44
45
46    Col::Col()
47    {
48      /// @brief Set the default values for the parameters.
49      this->width=1;
50      this->precision=0;
51      this->name=" ";
52      this->units=" ";
53      this->type=UNKNOWN;
54    }
55
56    Col::~Col(){}
57
58    Col::Col(const Col& c)
59    {
60      operator=(c);
61    }
62
63    Col& Col::operator=(const Col& c)
64    {
65      if(this==&c) return *this;
66      this->width = c.width;
67      this->precision = c.precision;
68      this->name = c.name;
69      this->units = c.units;
70      this->type = c.type;
71      return *this;
72    }
73
74    Col::Col(int num, int prec)
75    {
76      /// A specialised constructor that defines one of the default
77      ///  columns, as defined in the Column namespace
78      /// \param num The number of the column to be constructed.
79      ///            Corresponds to the order of the columns in the const
80      ///            arrays in the Column namespace.
81      /// \param prec The precision to use, if not the default. A value
82      /// <0 or no value given results in the default being used.
83
84      if((num>=0)&&(num<numColumns)){
85        this->width     = defaultWidth[num];
86        if(prec<0) this->precision = defaultPrec[num];
87        else this->precision = prec;
88        this->name      = defaultName[num];
89        this->units     = defaultUnits[num];
90        this->type = COLNAME(num);
91      }
92      else{
93        std::stringstream errmsg;
94        errmsg << "Incorrect value for Col(num) --> num="<<num
95               << ", should be between 0 and " << numColumns-1 << ".\n";
96        duchampError("Column constructor", errmsg.str());
97        this->width = 1;
98        this->precision = 0;
99        this->name = " ";
100        this->units = " ";
101        this->type=UNKNOWN;
102      }
103    }
104
105    Col::Col(std::string name, std::string units, int width, int prec)
106    {
107      /// A generic constructor designed to make a Column other than
108      /// the predefined ones listed in the Column namespace
109      /// \param name The title of the column
110      /// \param units What units the column takes
111      /// \param width The starting width
112      /// \param prec The starting precision
113
114      this->width = width;
115      this->precision = prec;
116      this->name = name;
117      this->units = units;
118      this->type = UNKNOWN;
119    }
120
121    //------------------------------------------------------------
122
123    void Col::changePrec(int p)
124    {
125      /// A direct way to alter the precision without having to use
126      /// Col::upPrec(). If the precision increases, the width will
127      /// increase by the same amount. If it decreases, no change is
128      /// made to the width.
129      /// \param p The new precision value.
130
131      if(p > this->precision) this->width += (p-this->precision);
132      this->precision = p;
133
134    }
135   
136    //------------------------------------------------------------
137    void Col::printTitle(std::ostream &stream)
138    {
139      stream << std::setw(this->width)
140             << std::setfill(' ')
141             << this->name;
142    }
143
144    void Col::printUnits(std::ostream &stream)
145    {
146      stream << std::setw(this->width)
147             << std::setfill(' ')
148             << this->units;
149    }
150 
151    void Col::printDash (std::ostream &stream)
152    {
153      stream << std::setw(this->width)
154             << std::setfill('-')
155             << ""
156             << std::setfill(' ');
157    }
158
159    void Col::printBlank(std::ostream &stream)
160    {
161      stream << std::setw(this->width)
162             << std::setfill(' ')
163             << "";
164    }
165 
166    template <class T> void Col::printEntry(std::ostream &stream, T value)
167    {
168      ///  \param stream Where the printing is done.
169      ///  \param value  The value to be printed.
170
171      stream << std::setprecision(this->precision)
172             << std::setw(this->width)
173             << std::setfill(' ')
174             << value;
175    }
176    template void Col::printEntry<int>(std::ostream &stream, int value);
177    template void Col::printEntry<long>(std::ostream &stream, long value);
178    template void Col::printEntry<unsigned>(std::ostream &stream, unsigned value);
179    template void Col::printEntry<float>(std::ostream &stream, float value);
180    template void Col::printEntry<double>(std::ostream &stream, double value);
181    template void Col::printEntry<std::string>(std::ostream &stream, std::string value);
182
183 
184    bool Col::doCol(std::string tableType, bool flagFint)
185    {
186      ///  @details Uses the info in the isFile etc arrays to
187      ///  determine whether a given column, referenced by the
188      ///  enumeration COLNAME, is used for a given table type.
189      /// \param tableType The type of table: one of file, screen, log, votable.
190      /// \param flagFint Whether to use FINT (true) or FTOT
191      /// (false). This defaults to true, so need not be given. It only
192      /// applies to the screen and votable cases -- both are written for the
193      /// results file case.
194      /// \return True if column is used for given table type. False
195      /// otherwise. False if tableType not one of four listed.
196     
197      if(tableType == "file") return isFile[this->type];
198      else if(tableType == "screen"){
199        if(flagFint && this->type==FTOT) return false;
200        if(!flagFint && this->type==FINT) return false;
201        return isScreen[this->type];
202      }
203      else if(tableType == "log") return isLog[this->type];
204      else if(tableType == "votable"){
205        if(flagFint && this->type==FTOT) return false;
206        if(!flagFint && this->type==FINT) return false;
207        return isVOTable[this->type];
208      }
209      else return false;
210    }
211
212 
213
214    std::vector<Col> getFullColSet(std::vector<Detection> &objectList,
215                                   FitsHeader &head)
216    {
217      ///  @details A function that returns a std::vector of Col
218      ///  objects containing information on the columns necessary for
219      ///  output to the results file:
220      ///    Obj#,NAME,X,Y,Z,RA,DEC,VEL,w_RA,w_DEC,w_VEL,F_tot,F_int,F_peak,
221      ///                X1,X2,Y1,Y2,Z1,Z2,Npix,Flag,
222      ///                XAV,YAV,ZAV,XCENT,YCENT,ZCENT,XPEAK,YPEAK,ZPEAK
223      ///
224      ///   Each object in the provided objectList is checked to see if it
225      ///   requires any column to be widened, or for that column to have
226      ///   its precision increased.
227      ///
228      ///   Both Ftot and Fint are provided -- it is up to the calling
229      ///   function to determine which to use.
230      ///
231      /// \param objectList A std::vector list of Detection objects that the
232      /// columns need to fit.
233      /// \param head The FitsHeader object defining the World Coordinate
234      /// System.
235      /// \return A std::vector list of Col definitions.
236
237      std::vector<Col> newset;
238
239      // desired precisions for fluxes, velocities and SNR value
240      int precVel,precFlux,precSNR;
241      if(objectList.size()>0){
242        precVel=objectList[0].getVelPrec();
243        precFlux=objectList[0].getFpeakPrec(); // same as FintPrec at this point.
244        precSNR=objectList[0].getSNRPrec();
245      }
246      else {
247        precVel = prVEL;
248        precFlux = prFLUX;
249        precSNR = prSNR;
250      }
251
252      // set up the default columns
253      newset.push_back( Col(NUM) );
254      newset.push_back( Col(NAME) );
255      newset.push_back( Col(X) );
256      newset.push_back( Col(Y) );
257      newset.push_back( Col(Z) );
258      newset.push_back( Col(RA) );
259      newset.push_back( Col(DEC) );
260      newset.push_back( Col(RAJD) );
261      newset.push_back( Col(DECJD) );
262      newset.push_back( Col(VEL, precVel) );
263      newset.push_back( Col(WRA) );
264      newset.push_back( Col(WDEC) );
265      newset.push_back( Col(W50, precVel) );
266      newset.push_back( Col(W20, precVel) );
267      newset.push_back( Col(WVEL, precVel) );
268      newset.push_back( Col(FINT, precFlux) );
269      newset.push_back( Col(FTOT, precFlux) );
270      newset.push_back( Col(FPEAK, precFlux) );
271      newset.push_back( Col(SNRPEAK, precSNR) );
272      newset.push_back( Col(X1) );
273      newset.push_back( Col(X2) );
274      newset.push_back( Col(Y1) );
275      newset.push_back( Col(Y2) );
276      newset.push_back( Col(Z1) );
277      newset.push_back( Col(Z2) );
278      newset.push_back( Col(NPIX) );
279      newset.push_back( Col(FLAG) );
280      newset.push_back( Col(XAV) );
281      newset.push_back( Col(YAV) );
282      newset.push_back( Col(ZAV) );
283      newset.push_back( Col(XCENT) );
284      newset.push_back( Col(YCENT) );
285      newset.push_back( Col(ZCENT) );
286      newset.push_back( Col(XPEAK) );
287      newset.push_back( Col(YPEAK) );
288      newset.push_back( Col(ZPEAK) );
289
290
291      // Now test each object against each new column
292      for( unsigned int obj = 0; obj < objectList.size(); obj++){
293        std::string tempstr;
294        int tempwidth;
295        float val,minval;
296
297        // Obj#
298        tempwidth = int( log10(objectList[obj].getID()) + 1) + 1;
299        for(int i=newset[NUM].getWidth();i<tempwidth;i++) newset[NUM].widen();
300
301        // Name
302        tempwidth = objectList[obj].getName().size() + 1;
303        for(int i=newset[NAME].getWidth();i<tempwidth;i++) newset[NAME].widen();
304
305        // X position
306        val = objectList[obj].getXcentre()
307          + objectList[obj].getXOffset();
308        if((val<1.)&&(val>0.)){
309          minval = pow(10, -1. * (newset[X].getPrecision()+1));
310          if(val < minval) newset[X].upPrec();
311        }
312        tempwidth = int( log10(val) + 1) + newset[X].getPrecision() + 2;
313        for(int i=newset[X].getWidth();i<tempwidth;i++) newset[X].widen();
314        // Y position
315        val = objectList[obj].getYcentre() + objectList[obj].getYOffset();
316        if((val<1.)&&(val>0.)){
317          minval = pow(10, -1. * (newset[Y].getPrecision()+1));
318          if(val < minval) newset[Y].upPrec();
319        }
320        tempwidth = int( log10(val) + 1) + newset[Y].getPrecision() + 2;
321        for(int i=newset[Y].getWidth();i<tempwidth;i++) newset[Y].widen();
322        // Z position
323        val = objectList[obj].getZcentre() + objectList[obj].getZOffset();
324        if((val<1.)&&(val>0.)){
325          minval = pow(10, -1. * (newset[Z].getPrecision()+1));
326          if((val>0.)&&(val < minval)) newset[Z].upPrec();
327        }
328        tempwidth = int( log10(val) + 1) + newset[Z].getPrecision() + 2;
329        for(int i=newset[Z].getWidth();i<tempwidth;i++) newset[Z].widen();
330
331        if(head.isWCS()){ 
332          // RA -- assign correct title. Check width but should be ok by definition
333          tempstr = head.WCS().lngtyp;
334          newset[RA].setName(tempstr);
335          tempwidth = objectList[obj].getRAs().size() + 1;
336          for(int i=newset[RA].getWidth();i<tempwidth;i++) newset[RA].widen();
337     
338          // Dec -- assign correct title. Check width, should be ok by definition
339          tempstr = head.WCS().lattyp;
340          newset[DEC].setName(tempstr);
341          tempwidth = objectList[obj].getDecs().size() + 1;
342          for(int i=newset[DEC].getWidth();i<tempwidth;i++) newset[DEC].widen();
343
344          // RA decimal degrees -- assign correct title. Check width but should be OK
345          tempstr = head.WCS().lngtyp;
346          newset[RAJD].setName(tempstr);
347          val = objectList[obj].getRA();
348          tempwidth = int( log10(fabs(val)) + 1) + newset[RAJD].getPrecision() + 2;
349          for(int i=newset[RAJD].getWidth();i<tempwidth;i++) newset[RAJD].widen();
350     
351          // Dec decimal degrees -- assign correct title. Check width but should be OK
352          tempstr = head.WCS().lattyp;
353          newset[DECJD].setName(tempstr);
354          val = objectList[obj].getDec();
355          tempwidth = int( log10(fabs(val)) + 1) + newset[DECJD].getPrecision() + 2;
356          for(int i=newset[DECJD].getWidth();i<tempwidth;i++) newset[DECJD].widen();
357
358          // Vel -- check width, title and units.
359          //if(head.isSpecOK()){
360          if(head.canUseThirdAxis()){
361            if(head.WCS().spec < 0)  // if it's not a spectral axis
362              newset[VEL].setName( head.WCS().ctype[2] );
363//          else if(head.WCS().restfrq == 0) // using frequency, not velocity
364            else if(head.getSpectralDescription()==duchamp::duchampSpectralDescription[FREQUENCY]) // using frequency, not velocity
365              newset[VEL].setName("FREQ");
366            if(head.getSpectralUnits().size()>0)
367              newset[VEL].setUnits("[" + head.getSpectralUnits() + "]");
368            tempwidth = newset[VEL].getUnits().size() + 1;
369            for(int i=newset[VEL].getWidth();i<tempwidth;i++) newset[VEL].widen();
370       
371            val = objectList[obj].getVel();
372            if((fabs(val) < 1.)&&(val>0.)){
373              minval = pow(10, -1. * (newset[VEL].getPrecision()+1));
374              if(val < minval) newset[VEL].upPrec();
375            }
376            tempwidth = int(log10(fabs(val)) + 1) + newset[VEL].getPrecision() + 2;
377            if(val<0) tempwidth++;
378            for(int i=newset[VEL].getWidth();i<tempwidth;i++) newset[VEL].widen();
379          }
380
381          // w_RA -- check width & title. leave units for the moment.
382          tempwidth = newset[RA].getUnits().size() + 1;
383          for(int i=newset[RA].getWidth();i<tempwidth;i++) newset[RA].widen();
384          val = objectList[obj].getRAWidth();
385          if((fabs(val) < 1.)&&(val>0.)){
386            minval = pow(10, -1. * (newset[WRA].getPrecision()+1));
387            if(val < minval) newset[WRA].upPrec();
388          }
389          tempwidth = int( log10(fabs(val)) + 1) + newset[WRA].getPrecision() + 2;
390          if(val<0) tempwidth++;
391          for(int i=newset[WRA].getWidth();i<tempwidth;i++) newset[WRA].widen();
392
393          // w_DEC -- check width & title. leave units for the moment.
394          tempwidth = newset[DEC].getUnits().size() + 1;
395          for(int i=newset[DEC].getWidth();i<tempwidth;i++) newset[DEC].widen();
396          val = objectList[obj].getDecWidth();
397          if((fabs(val) < 1.)&&(val>0.)){
398            minval = pow(10, -1. * (newset[WDEC].getPrecision()+1));
399            if(val < minval) newset[WDEC].upPrec();
400          }
401          tempwidth = int( log10(fabs(val)) + 1) + newset[WDEC].getPrecision() + 2;
402          if(val<0) tempwidth++;
403          for(int i=newset[WDEC].getWidth();i<tempwidth;i++) newset[WDEC].widen();
404
405          // w_50 -- check width, title and units.
406          if(head.canUseThirdAxis()){
407            if(head.getSpectralUnits().size()>0)
408              newset[W50].setUnits("[" + head.getSpectralUnits() + "]");
409            tempwidth = newset[W50].getUnits().size() + 1;
410            for(int i=newset[W50].getWidth();i<tempwidth;i++) newset[W50].widen();
411            val = objectList[obj].getW50();
412            if((fabs(val) < 1.)&&(val>0.)){
413              minval = pow(10, -1. * (newset[W50].getPrecision()+1));
414              if(val < minval) newset[W50].upPrec();
415            }
416            tempwidth = int( log10(fabs(val)) + 1) + newset[W50].getPrecision() + 2;
417            if(val<0) tempwidth++;
418            for(int i=newset[W50].getWidth();i<tempwidth;i++) newset[W50].widen();
419          }
420
421          // w_20 -- check width, title and units.
422          if(head.canUseThirdAxis()){
423            if(head.getSpectralUnits().size()>0)
424              newset[W20].setUnits("[" + head.getSpectralUnits() + "]");
425            tempwidth = newset[W20].getUnits().size() + 1;
426            for(int i=newset[W20].getWidth();i<tempwidth;i++)newset[W20].widen();
427            val = objectList[obj].getW20();
428            if((fabs(val) < 1.)&&(val>0.)){
429              minval = pow(10, -1. * (newset[W20].getPrecision()+1));
430              if(val < minval) newset[W20].upPrec();
431            }
432            tempwidth = int( log10(fabs(val)) + 1) + newset[W20].getPrecision() + 2;
433            if(val<0) tempwidth++;
434            for(int i=newset[W20].getWidth();i<tempwidth;i++) newset[W20].widen();
435          }
436
437          // w_Vel -- check width, title and units.
438          if(head.canUseThirdAxis()){
439            if(head.WCS().spec < 0) // if it's not a spectral axis
440              newset[WVEL].setName( std::string("w_") + head.WCS().ctype[2] );
441//          else if(head.WCS().restfrq == 0) // using frequency, not velocity
442            else if(head.getSpectralDescription()==duchamp::duchampSpectralDescription[FREQUENCY]) // using frequency, not velocity
443              newset[WVEL].setName("w_FREQ");
444            if(head.getSpectralUnits().size()>0)
445              newset[WVEL].setUnits("[" + head.getSpectralUnits() + "]");
446            tempwidth = newset[WVEL].getUnits().size() + 1;
447            for(int i=newset[WVEL].getWidth();i<tempwidth;i++)newset[WVEL].widen();
448            tempwidth = newset[WVEL].getName().size() + 1;
449            for(int i=newset[WVEL].getWidth();i<tempwidth;i++) newset[WVEL].widen();
450            val = objectList[obj].getVelWidth();
451            if((fabs(val) < 1.)&&(val>0.)){
452              minval = pow(10, -1. * (newset[WVEL].getPrecision()+1));
453              if(val < minval) newset[WVEL].upPrec();
454            }
455            tempwidth = int( log10(fabs(val)) + 1) + newset[WVEL].getPrecision() + 2;
456            if(val<0) tempwidth++;
457            for(int i=newset[WVEL].getWidth();i<tempwidth;i++) newset[WVEL].widen();
458          }
459
460          // F_int -- check width & units
461          if(head.getIntFluxUnits().size()>0)
462            newset[FINT].setUnits("[" + head.getIntFluxUnits() + "]");
463          tempwidth = newset[FINT].getUnits().size() + 1;
464          for(int i=newset[FINT].getWidth();i<tempwidth;i++) newset[FINT].widen();
465          val = objectList[obj].getIntegFlux();
466          if((fabs(val) < 1.)// &&(val>0.)
467             ){
468            int minprec = int(fabs(log10(fabs(val))))+2;
469            for(int i=newset[FINT].getPrecision();i<minprec;i++) newset[FINT].upPrec();
470          }
471          tempwidth = int( log10(fabs(val)) + 1) + newset[FINT].getPrecision() + 2;
472          if(val<0) tempwidth++;
473          for(int i=newset[FINT].getWidth();i<tempwidth;i++) newset[FINT].widen();
474     
475        }
476
477        // F_tot
478        newset[FTOT].setUnits("[" + head.getFluxUnits() + "]");
479        tempwidth = newset[FTOT].getUnits().size() + 1;
480        for(int i=newset[FTOT].getWidth();i<tempwidth;i++) newset[FTOT].widen();
481        val = objectList[obj].getTotalFlux();
482        //     std::cerr << val << "\n";
483        if((fabs(val) < 1.)// &&(val>0.)
484           ){
485          int minprec = int(fabs(log10(fabs(val))))+2;
486          for(int i=newset[FTOT].getPrecision();i<minprec;i++) newset[FTOT].upPrec();
487        }
488        tempwidth = int( log10(fabs(val)) + 1) + newset[FTOT].getPrecision() + 2;
489        if(val<0) tempwidth++;
490        for(int i=newset[FTOT].getWidth();i<tempwidth;i++) newset[FTOT].widen();
491
492        // F_peak
493        newset[FPEAK].setUnits("[" + head.getFluxUnits() + "]");
494        tempwidth = newset[FPEAK].getUnits().size() + 1;
495        for(int i=newset[FPEAK].getWidth();i<tempwidth;i++) newset[FPEAK].widen();
496        val = objectList[obj].getPeakFlux();
497        if((fabs(val) < 1.)// &&(val>0.)
498           ){
499          int minprec = int(fabs(log10(fabs(val))))+2;
500          for(int i=newset[FPEAK].getPrecision();i<minprec;i++) newset[FPEAK].upPrec();
501        }
502        tempwidth = int( log10(fabs(val)) + 1) + newset[FPEAK].getPrecision() + 2;
503        if(val<0) tempwidth++;
504        for(int i=newset[FPEAK].getWidth();i<tempwidth;i++) newset[FPEAK].widen();
505
506        // S/N_peak
507        val = objectList[obj].getPeakSNR();
508        if((fabs(val) < 1.)&&(val>0.)){
509          minval = pow(10, -1. * (newset[SNRPEAK].getPrecision()+1));
510          if(val < minval) newset[SNRPEAK].upPrec();
511        }
512        tempwidth = int( log10(fabs(val)) + 1) + newset[SNRPEAK].getPrecision() +2;
513        if(val<0) tempwidth++;
514        for(int i=newset[SNRPEAK].getWidth();i<tempwidth;i++) newset[SNRPEAK].widen();
515
516        // X1 position
517        val = objectList[obj].getXmin() + objectList[obj].getXOffset();
518        tempwidth = int( log10(val) + 1) + newset[X1].getPrecision() + 1;
519        for(int i=newset[X1].getWidth();i<tempwidth;i++) newset[X1].widen();
520        // X2 position
521        val = objectList[obj].getXmax() + objectList[obj].getXOffset();
522        tempwidth = int( log10(val) + 1) + newset[X2].getPrecision() + 1;
523        for(int i=newset[X2].getWidth();i<tempwidth;i++) newset[X2].widen();
524        // Y1 position
525        val = objectList[obj].getYmin() + objectList[obj].getYOffset();
526        tempwidth = int( log10(val) + 1) + newset[Y1].getPrecision() + 1;
527        for(int i=newset[Y1].getWidth();i<tempwidth;i++) newset[Y1].widen();
528        // Y2 position
529        val = objectList[obj].getYmax() + objectList[obj].getYOffset();
530        tempwidth = int( log10(val) + 1) + newset[Y2].getPrecision() + 1;
531        for(int i=newset[Y2].getWidth();i<tempwidth;i++) newset[Y2].widen();
532        // Z1 position
533        val = objectList[obj].getZmin() + objectList[obj].getZOffset();
534        tempwidth = int( log10(val) + 1) + newset[Z1].getPrecision() + 1;
535        for(int i=newset[Z1].getWidth();i<tempwidth;i++) newset[Z1].widen();
536        // Z2 position
537        val = objectList[obj].getZmax() + objectList[obj].getZOffset();
538        tempwidth = int( log10(val) + 1) + newset[Z2].getPrecision() + 1;
539        for(int i=newset[Z2].getWidth();i<tempwidth;i++) newset[Z2].widen();
540
541        // Npix
542        tempwidth = int( log10(objectList[obj].getSize()) + 1) +
543          newset[NPIX].getPrecision() + 1;
544        for(int i=newset[NPIX].getWidth();i<tempwidth;i++) newset[NPIX].widen();
545   
546        // average X position
547//      val = objectList[obj].getXAverage() + objectList[obj].getXOffset();
548        val = objectList[obj].getXaverage() + objectList[obj].getXOffset();
549        if((val<1.)&&(val>0.)){
550          minval = pow(10, -1. * (newset[XAV].getPrecision()+1));
551          if(val < minval) newset[XAV].upPrec();
552        }
553        tempwidth = int( log10(val) + 1) + newset[XAV].getPrecision() + 2;
554        for(int i=newset[XAV].getWidth();i<tempwidth;i++) newset[XAV].widen();
555        // average Y position
556//      val = objectList[obj].getYAverage() + objectList[obj].getYOffset();
557        val = objectList[obj].getYaverage() + objectList[obj].getYOffset();
558        if((val<1.)&&(val>0.)){
559          minval = pow(10, -1. * (newset[YAV].getPrecision()+1));
560          if(val < minval) newset[YAV].upPrec();
561        }
562        tempwidth = int( log10(val) + 1) + newset[YAV].getPrecision() + 2;
563        for(int i=newset[YAV].getWidth();i<tempwidth;i++) newset[YAV].widen();
564        // average Z position
565//      val = objectList[obj].getZAverage() + objectList[obj].getZOffset();
566        val = objectList[obj].getZaverage() + objectList[obj].getZOffset();
567        if((val<1.)&&(val>0.)){
568          minval = pow(10, -1. * (newset[ZAV].getPrecision()+1));
569          if((val>0.)&&(val < minval)) newset[ZAV].upPrec();
570        }
571        tempwidth = int( log10(val) + 1) + newset[ZAV].getPrecision() + 2;
572        for(int i=newset[ZAV].getWidth();i<tempwidth;i++) newset[ZAV].widen();
573   
574        // X position of centroid
575        val = objectList[obj].getXCentroid() + objectList[obj].getXOffset();
576        if((val<1.)&&(val>0.)){
577          minval = pow(10, -1. * (newset[XCENT].getPrecision()+1));
578          if(val < minval) newset[XCENT].upPrec();
579        }
580        tempwidth = int( log10(val) + 1) + newset[XCENT].getPrecision() + 2;
581        for(int i=newset[XCENT].getWidth();i<tempwidth;i++) newset[XCENT].widen();
582        // Y position of centroid
583        val = objectList[obj].getYCentroid() + objectList[obj].getYOffset();
584        if((val<1.)&&(val>0.)){
585          minval = pow(10, -1. * (newset[YCENT].getPrecision()+1));
586          if(val < minval) newset[YCENT].upPrec();
587        }
588        tempwidth = int( log10(val) + 1) + newset[YCENT].getPrecision() + 2;
589        for(int i=newset[YCENT].getWidth();i<tempwidth;i++) newset[YCENT].widen();
590        // Z position of centroid
591        val = objectList[obj].getZCentroid() + objectList[obj].getZOffset();
592        if((val<1.)&&(val>0.)){
593          minval = pow(10, -1. * (newset[ZCENT].getPrecision()+1));
594          if((val>0.)&&(val < minval)) newset[ZCENT].upPrec();
595        }
596        tempwidth = int( log10(val) + 1) + newset[ZCENT].getPrecision() + 2;
597        for(int i=newset[ZCENT].getWidth();i<tempwidth;i++) newset[ZCENT].widen();
598   
599        // X position of peak flux
600        val = objectList[obj].getXPeak() + objectList[obj].getXOffset();
601        if((val<1.)&&(val>0.)){
602          minval = pow(10, -1. * (newset[XPEAK].getPrecision()+1));
603          if(val < minval) newset[XPEAK].upPrec();
604        }
605        tempwidth = int( log10(val) + 1) + newset[XPEAK].getPrecision() + 2;
606        for(int i=newset[XPEAK].getWidth();i<tempwidth;i++) newset[XPEAK].widen();
607        // Y position of peak flux
608        val = objectList[obj].getYPeak() + objectList[obj].getYOffset();
609        if((val<1.)&&(val>0.)){
610          minval = pow(10, -1. * (newset[YPEAK].getPrecision()+1));
611          if(val < minval) newset[YPEAK].upPrec();
612        }
613        tempwidth = int( log10(val) + 1) + newset[YPEAK].getPrecision() + 2;
614        for(int i=newset[YPEAK].getWidth();i<tempwidth;i++) newset[YPEAK].widen();
615        // Z position of peak flux
616        val = objectList[obj].getZPeak() + objectList[obj].getZOffset();
617        if((val<1.)&&(val>0.)){
618          minval = pow(10, -1. * (newset[ZPEAK].getPrecision()+1));
619          if((val>0.)&&(val < minval)) newset[ZPEAK].upPrec();
620        }
621        tempwidth = int( log10(val) + 1) + newset[ZPEAK].getPrecision() + 2;
622        for(int i=newset[ZPEAK].getWidth();i<tempwidth;i++) newset[ZPEAK].widen();
623      }
624
625      return newset;
626
627    }
628
629    std::vector<Col> getLogColSet(std::vector<Detection> &objectList,
630                                  FitsHeader &head)
631    {
632      ///  @details A function that returns a std::vector of Col
633      ///    objects containing information on the columns necessary
634      ///    for logfile output:
635      ///    Obj#,X,Y,Z,F_tot,F_peak,X1,X2,Y1,Y2,Z1,Z2,Npix
636      ///
637      ///   Each object in the provided objectList is checked to see if
638      ///    it requires any column to be widened, or for that column to
639      ///    have its precision increased.
640      ///
641      /// \param objectList A std::vector list of Detection objects that the columns need to fit.
642      /// \param head The FitsHeader object defining the World Coordinate System.
643      /// \return A std::vector list of Col definitions.
644
645      std::vector<Col> newset,tempset;
646 
647      // set up the default columns:
648      //  get from FullColSet, and select only the ones we want.
649      tempset = getFullColSet(objectList,head);
650
651      newset.push_back( tempset[NUM] );
652      newset.push_back( tempset[X] );
653      newset.push_back( tempset[Y] );
654      newset.push_back( tempset[Z] );
655      newset.push_back( tempset[FTOT] );
656      newset.push_back( tempset[FPEAK] );
657      newset.push_back( tempset[SNRPEAK] );
658      newset.push_back( tempset[X1] );
659      newset.push_back( tempset[X2] );
660      newset.push_back( tempset[Y1] );
661      newset.push_back( tempset[Y2] );
662      newset.push_back( tempset[Z1] );
663      newset.push_back( tempset[Z2] );
664      newset.push_back( tempset[NPIX] );
665
666      return newset;
667
668    }
669
670  }
671
672}
Note: See TracBrowser for help on using the repository browser.