source: trunk/src/Outputs/columns.cc @ 1131

Last change on this file since 1131 was 1131, checked in by MatthewWhiting, 11 years ago

Ticket #132 - further improvements: getting the calculation and reporting of the position angle right (in particular so that kvis displays it properly - yet to do the same for casa/DS9), and putting the maj/min/pa values in the various output catalogues. Also changing the headers for the spectral plots - these now have the shape info rather that W_RA/W_DEC.

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