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

Last change on this file since 1044 was 1044, checked in by MatthewWhiting, 12 years ago

Incorporating the UCD, datatype, ref (as "extraInfo") and colID into the Column::Col structure. This allows the definition of a VOField directly from the Col, streamlining the code somewhat. Use default arrays to define most of these things - some UCDs are set in Cubes/VOTable.cc for now.

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