source: tags/release-1.1.12/src/Detection/columns.cc

Last change on this file was 688, checked in by MatthewWhiting, 14 years ago

Adding number of channels and spatial size to the logfile output.

File size: 25.8 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 int>(std::ostream &stream, unsigned int value);
179    template void Col::printEntry<unsigned long>(std::ostream &stream, unsigned long value);
180    template void Col::printEntry<float>(std::ostream &stream, float value);
181    template void Col::printEntry<double>(std::ostream &stream, double value);
182    template void Col::printEntry<std::string>(std::ostream &stream, std::string value);
183
184 
185    bool Col::doCol(std::string tableType, bool flagFint)
186    {
187      ///  @details Uses the info in the isFile etc arrays to
188      ///  determine whether a given column, referenced by the
189      ///  enumeration COLNAME, is used for a given table type.
190      /// \param tableType The type of table: one of file, screen, log, votable.
191      /// \param flagFint Whether to use FINT (true) or FTOT
192      /// (false). This defaults to true, so need not be given. It only
193      /// applies to the screen and votable cases -- both are written for the
194      /// results file case.
195      /// \return True if column is used for given table type. False
196      /// otherwise. False if tableType not one of four listed.
197     
198      if(tableType == "file") return isFile[this->type];
199      else if(tableType == "screen"){
200        if(flagFint && this->type==FTOT) return false;
201        if(!flagFint && this->type==FINT) return false;
202        return isScreen[this->type];
203      }
204      else if(tableType == "log") return isLog[this->type];
205      else if(tableType == "votable"){
206        if(flagFint && this->type==FTOT) return false;
207        if(!flagFint && this->type==FINT) return false;
208        return isVOTable[this->type];
209      }
210      else return false;
211    }
212
213 
214
215    std::vector<Col> getFullColSet(std::vector<Detection> &objectList,
216                                   FitsHeader &head)
217    {
218      ///  @details A function that returns a std::vector of Col
219      ///  objects containing information on the columns necessary for
220      ///  output to the results file:
221      ///    Obj#,NAME,X,Y,Z,RA,DEC,VEL,w_RA,w_DEC,w_VEL,F_tot,F_int,F_peak,
222      ///                X1,X2,Y1,Y2,Z1,Z2,Npix,Flag,
223      ///                XAV,YAV,ZAV,XCENT,YCENT,ZCENT,XPEAK,YPEAK,ZPEAK
224      ///
225      ///   Each object in the provided objectList is checked to see if it
226      ///   requires any column to be widened, or for that column to have
227      ///   its precision increased.
228      ///
229      ///   Both Ftot and Fint are provided -- it is up to the calling
230      ///   function to determine which to use.
231      ///
232      /// \param objectList A std::vector list of Detection objects that the
233      /// columns need to fit.
234      /// \param head The FitsHeader object defining the World Coordinate
235      /// System.
236      /// \return A std::vector list of Col definitions.
237
238      std::vector<Col> newset;
239
240      // desired precisions for fluxes, velocities and SNR value
241      int precVel,precFlux,precSNR;
242      if(objectList.size()>0){
243        precVel=objectList[0].getVelPrec();
244        precFlux=objectList[0].getFpeakPrec(); // same as FintPrec at this point.
245        precSNR=objectList[0].getSNRPrec();
246      }
247      else {
248        precVel = prVEL;
249        precFlux = prFLUX;
250        precSNR = prSNR;
251      }
252
253      // set up the default columns
254      newset.push_back( Col(NUM) );
255      newset.push_back( Col(NAME) );
256      newset.push_back( Col(X) );
257      newset.push_back( Col(Y) );
258      newset.push_back( Col(Z) );
259      newset.push_back( Col(RA) );
260      newset.push_back( Col(DEC) );
261      newset.push_back( Col(RAJD) );
262      newset.push_back( Col(DECJD) );
263      newset.push_back( Col(VEL, precVel) );
264      newset.push_back( Col(WRA) );
265      newset.push_back( Col(WDEC) );
266      newset.push_back( Col(W50, precVel) );
267      newset.push_back( Col(W20, precVel) );
268      newset.push_back( Col(WVEL, precVel) );
269      newset.push_back( Col(FINT, precFlux) );
270      newset.push_back( Col(FTOT, precFlux) );
271      newset.push_back( Col(FPEAK, precFlux) );
272      newset.push_back( Col(SNRPEAK, precSNR) );
273      newset.push_back( Col(X1) );
274      newset.push_back( Col(X2) );
275      newset.push_back( Col(Y1) );
276      newset.push_back( Col(Y2) );
277      newset.push_back( Col(Z1) );
278      newset.push_back( Col(Z2) );
279      newset.push_back( Col(NPIX) );
280      newset.push_back( Col(FLAG) );
281      newset.push_back( Col(XAV) );
282      newset.push_back( Col(YAV) );
283      newset.push_back( Col(ZAV) );
284      newset.push_back( Col(XCENT) );
285      newset.push_back( Col(YCENT) );
286      newset.push_back( Col(ZCENT) );
287      newset.push_back( Col(XPEAK) );
288      newset.push_back( Col(YPEAK) );
289      newset.push_back( Col(ZPEAK) );
290      newset.push_back( Col(NUMCH) );
291      newset.push_back( Col(SPATSIZE) );
292
293
294      // Now test each object against each new column
295      std::vector<Detection>::iterator obj;
296      for(obj = objectList.begin(); obj < objectList.end(); obj++){
297        std::string tempstr;
298        int tempwidth;
299        float val,minval;
300
301        // Obj#
302        tempwidth = int( log10(obj->getID()) + 1) + 1;
303        for(int i=newset[NUM].getWidth();i<tempwidth;i++) newset[NUM].widen();
304
305        // Name
306        tempwidth = obj->getName().size() + 1;
307        for(int i=newset[NAME].getWidth();i<tempwidth;i++) newset[NAME].widen();
308
309        // X position
310        val = obj->getXcentre() + obj->getXOffset();
311        if((val<1.)&&(val>0.)){
312          minval = pow(10, -1. * (newset[X].getPrecision()+1));
313          if(val < minval) newset[X].upPrec();
314        }
315        tempwidth = int( log10(val) + 1) + newset[X].getPrecision() + 2;
316        for(int i=newset[X].getWidth();i<tempwidth;i++) newset[X].widen();
317        // Y position
318        val = obj->getYcentre() + obj->getYOffset();
319        if((val<1.)&&(val>0.)){
320          minval = pow(10, -1. * (newset[Y].getPrecision()+1));
321          if(val < minval) newset[Y].upPrec();
322        }
323        tempwidth = int( log10(val) + 1) + newset[Y].getPrecision() + 2;
324        for(int i=newset[Y].getWidth();i<tempwidth;i++) newset[Y].widen();
325        // Z position
326        val = obj->getZcentre() + obj->getZOffset();
327        if((val<1.)&&(val>0.)){
328          minval = pow(10, -1. * (newset[Z].getPrecision()+1));
329          if((val>0.)&&(val < minval)) newset[Z].upPrec();
330        }
331        tempwidth = int( log10(val) + 1) + newset[Z].getPrecision() + 2;
332        for(int i=newset[Z].getWidth();i<tempwidth;i++) newset[Z].widen();
333
334        if(head.isWCS()){ 
335          // RA -- assign correct title. Check width but should be ok by definition
336          tempstr = head.WCS().lngtyp;
337          newset[RA].setName(tempstr);
338          tempwidth = obj->getRAs().size() + 1;
339          for(int i=newset[RA].getWidth();i<tempwidth;i++) newset[RA].widen();
340     
341          // Dec -- assign correct title. Check width, should be ok by definition
342          tempstr = head.WCS().lattyp;
343          newset[DEC].setName(tempstr);
344          tempwidth = obj->getDecs().size() + 1;
345          for(int i=newset[DEC].getWidth();i<tempwidth;i++) newset[DEC].widen();
346
347          // RA decimal degrees -- assign correct title. Check width but should be OK
348          tempstr = head.WCS().lngtyp;
349          newset[RAJD].setName(tempstr);
350          val = obj->getRA();
351          tempwidth = int( log10(fabs(val)) + 1) + newset[RAJD].getPrecision() + 2;
352          for(int i=newset[RAJD].getWidth();i<tempwidth;i++) newset[RAJD].widen();
353     
354          // Dec decimal degrees -- assign correct title. Check width but should be OK
355          tempstr = head.WCS().lattyp;
356          newset[DECJD].setName(tempstr);
357          val = obj->getDec();
358          tempwidth = int( log10(fabs(val)) + 1) + newset[DECJD].getPrecision() + 2;
359          for(int i=newset[DECJD].getWidth();i<tempwidth;i++) newset[DECJD].widen();
360
361          // Vel -- check width, title and units.
362          //if(head.isSpecOK()){
363          if(head.canUseThirdAxis()){
364            if(head.WCS().spec < 0)  // if it's not a spectral axis
365              newset[VEL].setName( head.WCS().ctype[2] );
366//          else if(head.WCS().restfrq == 0) // using frequency, not velocity
367            else if(head.getSpectralDescription()==duchamp::duchampSpectralDescription[FREQUENCY]) // using frequency, not velocity
368              newset[VEL].setName("FREQ");
369            if(head.getSpectralUnits().size()>0)
370              newset[VEL].setUnits("[" + head.getSpectralUnits() + "]");
371            tempwidth = newset[VEL].getUnits().size() + 1;
372            for(int i=newset[VEL].getWidth();i<tempwidth;i++) newset[VEL].widen();
373       
374            val = obj->getVel();
375            if((fabs(val) < 1.)&&(val>0.)){
376              minval = pow(10, -1. * (newset[VEL].getPrecision()+1));
377              if(val < minval) newset[VEL].upPrec();
378            }
379            tempwidth = int(log10(fabs(val)) + 1) + newset[VEL].getPrecision() + 2;
380            if(val<0) tempwidth++;
381            for(int i=newset[VEL].getWidth();i<tempwidth;i++) newset[VEL].widen();
382          }
383
384          // w_RA -- check width & title. leave units for the moment.
385          tempwidth = newset[RA].getUnits().size() + 1;
386          for(int i=newset[RA].getWidth();i<tempwidth;i++) newset[RA].widen();
387          val = obj->getRAWidth();
388          if((fabs(val) < 1.)&&(val>0.)){
389            minval = pow(10, -1. * (newset[WRA].getPrecision()+1));
390            if(val < minval) newset[WRA].upPrec();
391          }
392          tempwidth = int( log10(fabs(val)) + 1) + newset[WRA].getPrecision() + 2;
393          if(val<0) tempwidth++;
394          for(int i=newset[WRA].getWidth();i<tempwidth;i++) newset[WRA].widen();
395
396          // w_DEC -- check width & title. leave units for the moment.
397          tempwidth = newset[DEC].getUnits().size() + 1;
398          for(int i=newset[DEC].getWidth();i<tempwidth;i++) newset[DEC].widen();
399          val = obj->getDecWidth();
400          if((fabs(val) < 1.)&&(val>0.)){
401            minval = pow(10, -1. * (newset[WDEC].getPrecision()+1));
402            if(val < minval) newset[WDEC].upPrec();
403          }
404          tempwidth = int( log10(fabs(val)) + 1) + newset[WDEC].getPrecision() + 2;
405          if(val<0) tempwidth++;
406          for(int i=newset[WDEC].getWidth();i<tempwidth;i++) newset[WDEC].widen();
407
408          // w_50 -- check width, title and units.
409          if(head.canUseThirdAxis()){
410            if(head.getSpectralUnits().size()>0)
411              newset[W50].setUnits("[" + head.getSpectralUnits() + "]");
412            tempwidth = newset[W50].getUnits().size() + 1;
413            for(int i=newset[W50].getWidth();i<tempwidth;i++) newset[W50].widen();
414            val = obj->getW50();
415            if((fabs(val) < 1.)&&(val>0.)){
416              minval = pow(10, -1. * (newset[W50].getPrecision()+1));
417              if(val < minval) newset[W50].upPrec();
418            }
419            tempwidth = int( log10(fabs(val)) + 1) + newset[W50].getPrecision() + 2;
420            if(val<0) tempwidth++;
421            for(int i=newset[W50].getWidth();i<tempwidth;i++) newset[W50].widen();
422          }
423
424          // w_20 -- check width, title and units.
425          if(head.canUseThirdAxis()){
426            if(head.getSpectralUnits().size()>0)
427              newset[W20].setUnits("[" + head.getSpectralUnits() + "]");
428            tempwidth = newset[W20].getUnits().size() + 1;
429            for(int i=newset[W20].getWidth();i<tempwidth;i++)newset[W20].widen();
430            val = obj->getW20();
431            if((fabs(val) < 1.)&&(val>0.)){
432              minval = pow(10, -1. * (newset[W20].getPrecision()+1));
433              if(val < minval) newset[W20].upPrec();
434            }
435            tempwidth = int( log10(fabs(val)) + 1) + newset[W20].getPrecision() + 2;
436            if(val<0) tempwidth++;
437            for(int i=newset[W20].getWidth();i<tempwidth;i++) newset[W20].widen();
438          }
439
440          // w_Vel -- check width, title and units.
441          if(head.canUseThirdAxis()){
442            if(head.WCS().spec < 0) // if it's not a spectral axis
443              newset[WVEL].setName( std::string("w_") + head.WCS().ctype[2] );
444//          else if(head.WCS().restfrq == 0) // using frequency, not velocity
445            else if(head.getSpectralDescription()==duchamp::duchampSpectralDescription[FREQUENCY]) // using frequency, not velocity
446              newset[WVEL].setName("w_FREQ");
447            if(head.getSpectralUnits().size()>0)
448              newset[WVEL].setUnits("[" + head.getSpectralUnits() + "]");
449            tempwidth = newset[WVEL].getUnits().size() + 1;
450            for(int i=newset[WVEL].getWidth();i<tempwidth;i++)newset[WVEL].widen();
451            tempwidth = newset[WVEL].getName().size() + 1;
452            for(int i=newset[WVEL].getWidth();i<tempwidth;i++) newset[WVEL].widen();
453            val = obj->getVelWidth();
454            if((fabs(val) < 1.)&&(val>0.)){
455              minval = pow(10, -1. * (newset[WVEL].getPrecision()+1));
456              if(val < minval) newset[WVEL].upPrec();
457            }
458            tempwidth = int( log10(fabs(val)) + 1) + newset[WVEL].getPrecision() + 2;
459            if(val<0) tempwidth++;
460            for(int i=newset[WVEL].getWidth();i<tempwidth;i++) newset[WVEL].widen();
461          }
462
463          // F_int -- check width & units
464          if(head.getIntFluxUnits().size()>0)
465            newset[FINT].setUnits("[" + head.getIntFluxUnits() + "]");
466          tempwidth = newset[FINT].getUnits().size() + 1;
467          for(int i=newset[FINT].getWidth();i<tempwidth;i++) newset[FINT].widen();
468          val = obj->getIntegFlux();
469          if((fabs(val) < 1.)// &&(val>0.)
470             ){
471            int minprec = int(fabs(log10(fabs(val))))+2;
472            for(int i=newset[FINT].getPrecision();i<minprec;i++) newset[FINT].upPrec();
473          }
474          tempwidth = int( log10(fabs(val)) + 1) + newset[FINT].getPrecision() + 2;
475          if(val<0) tempwidth++;
476          for(int i=newset[FINT].getWidth();i<tempwidth;i++) newset[FINT].widen();
477     
478        }
479
480        // F_tot
481        newset[FTOT].setUnits("[" + head.getFluxUnits() + "]");
482        tempwidth = newset[FTOT].getUnits().size() + 1;
483        for(int i=newset[FTOT].getWidth();i<tempwidth;i++) newset[FTOT].widen();
484        val = obj->getTotalFlux();
485        //     std::cerr << val << "\n";
486        if((fabs(val) < 1.)// &&(val>0.)
487           ){
488          int minprec = int(fabs(log10(fabs(val))))+2;
489          for(int i=newset[FTOT].getPrecision();i<minprec;i++) newset[FTOT].upPrec();
490        }
491        tempwidth = int( log10(fabs(val)) + 1) + newset[FTOT].getPrecision() + 2;
492        if(val<0) tempwidth++;
493        for(int i=newset[FTOT].getWidth();i<tempwidth;i++) newset[FTOT].widen();
494
495        // F_peak
496        newset[FPEAK].setUnits("[" + head.getFluxUnits() + "]");
497        tempwidth = newset[FPEAK].getUnits().size() + 1;
498        for(int i=newset[FPEAK].getWidth();i<tempwidth;i++) newset[FPEAK].widen();
499        val = obj->getPeakFlux();
500        if((fabs(val) < 1.)// &&(val>0.)
501           ){
502          int minprec = int(fabs(log10(fabs(val))))+2;
503          for(int i=newset[FPEAK].getPrecision();i<minprec;i++) newset[FPEAK].upPrec();
504        }
505        tempwidth = int( log10(fabs(val)) + 1) + newset[FPEAK].getPrecision() + 2;
506        if(val<0) tempwidth++;
507        for(int i=newset[FPEAK].getWidth();i<tempwidth;i++) newset[FPEAK].widen();
508
509        // S/N_peak
510        val = obj->getPeakSNR();
511        if((fabs(val) < 1.)&&(val>0.)){
512          minval = pow(10, -1. * (newset[SNRPEAK].getPrecision()+1));
513          if(val < minval) newset[SNRPEAK].upPrec();
514        }
515        tempwidth = int( log10(fabs(val)) + 1) + newset[SNRPEAK].getPrecision() +2;
516        if(val<0) tempwidth++;
517        for(int i=newset[SNRPEAK].getWidth();i<tempwidth;i++) newset[SNRPEAK].widen();
518
519        // X1 position
520        val = obj->getXmin() + obj->getXOffset();
521        tempwidth = int( log10(val) + 1) + newset[X1].getPrecision() + 1;
522        for(int i=newset[X1].getWidth();i<tempwidth;i++) newset[X1].widen();
523        // X2 position
524        val = obj->getXmax() + obj->getXOffset();
525        tempwidth = int( log10(val) + 1) + newset[X2].getPrecision() + 1;
526        for(int i=newset[X2].getWidth();i<tempwidth;i++) newset[X2].widen();
527        // Y1 position
528        val = obj->getYmin() + obj->getYOffset();
529        tempwidth = int( log10(val) + 1) + newset[Y1].getPrecision() + 1;
530        for(int i=newset[Y1].getWidth();i<tempwidth;i++) newset[Y1].widen();
531        // Y2 position
532        val = obj->getYmax() + obj->getYOffset();
533        tempwidth = int( log10(val) + 1) + newset[Y2].getPrecision() + 1;
534        for(int i=newset[Y2].getWidth();i<tempwidth;i++) newset[Y2].widen();
535        // Z1 position
536        val = obj->getZmin() + obj->getZOffset();
537        tempwidth = int( log10(val) + 1) + newset[Z1].getPrecision() + 1;
538        for(int i=newset[Z1].getWidth();i<tempwidth;i++) newset[Z1].widen();
539        // Z2 position
540        val = obj->getZmax() + obj->getZOffset();
541        tempwidth = int( log10(val) + 1) + newset[Z2].getPrecision() + 1;
542        for(int i=newset[Z2].getWidth();i<tempwidth;i++) newset[Z2].widen();
543
544        // Npix
545        tempwidth = int( log10(obj->getSize()) + 1) +
546          newset[NPIX].getPrecision() + 1;
547        for(int i=newset[NPIX].getWidth();i<tempwidth;i++) newset[NPIX].widen();
548   
549        // average X position
550//      val = obj->getXAverage() + obj->getXOffset();
551        val = obj->getXaverage() + obj->getXOffset();
552        if((val<1.)&&(val>0.)){
553          minval = pow(10, -1. * (newset[XAV].getPrecision()+1));
554          if(val < minval) newset[XAV].upPrec();
555        }
556        tempwidth = int( log10(val) + 1) + newset[XAV].getPrecision() + 2;
557        for(int i=newset[XAV].getWidth();i<tempwidth;i++) newset[XAV].widen();
558        // average Y position
559//      val = obj->getYAverage() + obj->getYOffset();
560        val = obj->getYaverage() + obj->getYOffset();
561        if((val<1.)&&(val>0.)){
562          minval = pow(10, -1. * (newset[YAV].getPrecision()+1));
563          if(val < minval) newset[YAV].upPrec();
564        }
565        tempwidth = int( log10(val) + 1) + newset[YAV].getPrecision() + 2;
566        for(int i=newset[YAV].getWidth();i<tempwidth;i++) newset[YAV].widen();
567        // average Z position
568//      val = obj->getZAverage() + obj->getZOffset();
569        val = obj->getZaverage() + obj->getZOffset();
570        if((val<1.)&&(val>0.)){
571          minval = pow(10, -1. * (newset[ZAV].getPrecision()+1));
572          if((val>0.)&&(val < minval)) newset[ZAV].upPrec();
573        }
574        tempwidth = int( log10(val) + 1) + newset[ZAV].getPrecision() + 2;
575        for(int i=newset[ZAV].getWidth();i<tempwidth;i++) newset[ZAV].widen();
576   
577        // X position of centroid
578        val = obj->getXCentroid() + obj->getXOffset();
579        if((val<1.)&&(val>0.)){
580          minval = pow(10, -1. * (newset[XCENT].getPrecision()+1));
581          if(val < minval) newset[XCENT].upPrec();
582        }
583        tempwidth = int( log10(val) + 1) + newset[XCENT].getPrecision() + 2;
584        for(int i=newset[XCENT].getWidth();i<tempwidth;i++) newset[XCENT].widen();
585        // Y position of centroid
586        val = obj->getYCentroid() + obj->getYOffset();
587        if((val<1.)&&(val>0.)){
588          minval = pow(10, -1. * (newset[YCENT].getPrecision()+1));
589          if(val < minval) newset[YCENT].upPrec();
590        }
591        tempwidth = int( log10(val) + 1) + newset[YCENT].getPrecision() + 2;
592        for(int i=newset[YCENT].getWidth();i<tempwidth;i++) newset[YCENT].widen();
593        // Z position of centroid
594        val = obj->getZCentroid() + obj->getZOffset();
595        if((val<1.)&&(val>0.)){
596          minval = pow(10, -1. * (newset[ZCENT].getPrecision()+1));
597          if((val>0.)&&(val < minval)) newset[ZCENT].upPrec();
598        }
599        tempwidth = int( log10(val) + 1) + newset[ZCENT].getPrecision() + 2;
600        for(int i=newset[ZCENT].getWidth();i<tempwidth;i++) newset[ZCENT].widen();
601   
602        // X position of peak flux
603        val = obj->getXPeak() + obj->getXOffset();
604        if((val<1.)&&(val>0.)){
605          minval = pow(10, -1. * (newset[XPEAK].getPrecision()+1));
606          if(val < minval) newset[XPEAK].upPrec();
607        }
608        tempwidth = int( log10(val) + 1) + newset[XPEAK].getPrecision() + 2;
609        for(int i=newset[XPEAK].getWidth();i<tempwidth;i++) newset[XPEAK].widen();
610        // Y position of peak flux
611        val = obj->getYPeak() + obj->getYOffset();
612        if((val<1.)&&(val>0.)){
613          minval = pow(10, -1. * (newset[YPEAK].getPrecision()+1));
614          if(val < minval) newset[YPEAK].upPrec();
615        }
616        tempwidth = int( log10(val) + 1) + newset[YPEAK].getPrecision() + 2;
617        for(int i=newset[YPEAK].getWidth();i<tempwidth;i++) newset[YPEAK].widen();
618        // Z position of peak flux
619        val = obj->getZPeak() + obj->getZOffset();
620        if((val<1.)&&(val>0.)){
621          minval = pow(10, -1. * (newset[ZPEAK].getPrecision()+1));
622          if((val>0.)&&(val < minval)) newset[ZPEAK].upPrec();
623        }
624        tempwidth = int( log10(val) + 1) + newset[ZPEAK].getPrecision() + 2;
625        for(int i=newset[ZPEAK].getWidth();i<tempwidth;i++) newset[ZPEAK].widen();
626
627        //Number of contiguous channels
628        tempwidth = int( log10(obj->getMaxAdjacentChannels()) + 1) +
629          newset[NUMCH].getPrecision() + 1;
630        for(int i=newset[NUMCH].getWidth();i<tempwidth;i++) newset[NUMCH].widen();
631        //Spatial size
632        tempwidth = int( log10(obj->getSpatialSize()) + 1) +
633          newset[SPATSIZE].getPrecision() + 1;
634        for(int i=newset[SPATSIZE].getWidth();i<tempwidth;i++) newset[SPATSIZE].widen();
635       
636      }
637     
638      return newset;
639
640    }
641
642    std::vector<Col> getLogColSet(std::vector<Detection> &objectList,
643                                  FitsHeader &head)
644    {
645      ///  @details A function that returns a std::vector of Col
646      ///    objects containing information on the columns necessary
647      ///    for logfile output:
648      ///    Obj#,X,Y,Z,F_tot,F_peak,X1,X2,Y1,Y2,Z1,Z2,Npix
649      ///
650      ///   Each object in the provided objectList is checked to see if
651      ///    it requires any column to be widened, or for that column to
652      ///    have its precision increased.
653      ///
654      /// \param objectList A std::vector list of Detection objects that the columns need to fit.
655      /// \param head The FitsHeader object defining the World Coordinate System.
656      /// \return A std::vector list of Col definitions.
657
658      std::vector<Col> newset,tempset;
659 
660      // set up the default columns:
661      //  get from FullColSet, and select only the ones we want.
662      tempset = getFullColSet(objectList,head);
663
664      newset.push_back( tempset[NUM] );
665      newset.push_back( tempset[X] );
666      newset.push_back( tempset[Y] );
667      newset.push_back( tempset[Z] );
668      newset.push_back( tempset[FTOT] );
669      newset.push_back( tempset[FPEAK] );
670      newset.push_back( tempset[SNRPEAK] );
671      newset.push_back( tempset[X1] );
672      newset.push_back( tempset[X2] );
673      newset.push_back( tempset[Y1] );
674      newset.push_back( tempset[Y2] );
675      newset.push_back( tempset[Z1] );
676      newset.push_back( tempset[Z2] );
677      newset.push_back( tempset[NPIX] );
678      newset.push_back( tempset[NUMCH] );
679      newset.push_back( tempset[SPATSIZE] );
680
681      return newset;
682
683    }
684
685  }
686
687}
Note: See TracBrowser for help on using the repository browser.