source: trunk/src/Outputs/AnnotationWriter.cc @ 1075

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

Improved parameter output for the annotation files. Tidying up the VOParam & VOField classes, and adding some documentation comments.

File size: 6.2 KB
Line 
1// -----------------------------------------------------------------------
2// AnnotationWriter.cc: Writing output catalogues to VOTable files
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 <duchamp/Outputs/AnnotationWriter.hh>
29#include <duchamp/Outputs/CatalogueWriter.hh>
30#include <duchamp/Outputs/FileCatalogueWriter.hh>
31#include <duchamp/fitsHeader.hh>
32#include <duchamp/param.hh>
33#include <duchamp/Detection/detection.hh>
34#include <ios>
35#include <iostream>
36#include <fstream>
37#include <sstream>
38#include <string>
39
40
41namespace duchamp {
42
43  AnnotationWriter::AnnotationWriter():
44    FileCatalogueWriter()
45  {
46    /// @details Sets the comment string to the default of '#'.
47    this->itsComment = "#";
48  }
49
50  AnnotationWriter::AnnotationWriter(std::string name):
51    FileCatalogueWriter(name)
52  {
53    /// @details Sets the comment string to the default of '#'.
54    this->itsComment = "#";
55  }
56
57  AnnotationWriter::AnnotationWriter(const AnnotationWriter& other)
58  {
59    this->operator=(other);
60  }
61
62  AnnotationWriter& AnnotationWriter::operator= (const AnnotationWriter& other)
63  {
64    if(this==&other) return *this;
65    ((FileCatalogueWriter &) *this) = other;
66    this->itsComment = other.itsComment;
67    return *this;
68  }
69 
70
71  void AnnotationWriter::writeHeader()
72  {
73    /// @details Writes, as comments, two lines indicating the file
74    /// comes from Duchamp (giving the version number) and the name of
75    /// the FITS file (with subsection if used).
76
77    if(this->itsOpenFlag){
78      this->itsFileStream << this->itsComment << " Duchamp Source Finder v."<< VERSION <<"\n";
79      this->itsFileStream << this->itsComment << " Results for FITS file: " << this->itsParam->getFullImageFile() << "\n";
80    }
81  }
82
83  void AnnotationWriter::writeParameters()
84  {
85    /// @details Writes, as comments, a summary of the parameters used
86    /// in running Duchamp. Uses the VOParam interface (as for
87    /// VOTableCatalogeWriter), taking just the name and the value -
88    /// this provides the effective parameter set that generated the
89    /// detection list
90
91    if(this->itsOpenFlag){
92     
93      std::vector<VOParam> paramList = this->itsParam->getVOParams();
94      size_t width=0;
95      for(std::vector<VOParam>::iterator param=paramList.begin();param<paramList.end();param++) width=std::max(width,param->name().size()+2);
96      for(std::vector<VOParam>::iterator param=paramList.begin();param<paramList.end();param++){
97        this->itsFileStream.setf(std::ios::left);
98        this->itsFileStream << this->itsComment << " "<< std::setw(width) << param->name() << param->value() <<"\n";
99      }
100
101    }
102  }
103
104  void AnnotationWriter::writeStats()
105  {
106    /// @details Writes, as comments, the detection threshold, plus
107    /// the mean and std.deviation (or their robust estimates) of the
108    /// noise. If robust methods are used, a note is added to that
109    /// effect.
110
111    if(this->itsOpenFlag){
112      this->itsFileStream << this->itsComment << " Detection threshold used = " << this->itsStats->getThreshold() <<"\n";
113      this->itsFileStream << this->itsComment << " Mean of noise background = " << this->itsStats->getMiddle() << "\n";
114      this->itsFileStream << this->itsComment << " Std. Deviation of noise background = " << this->itsStats->getSpread() << "\n";
115      if(this->itsParam->getFlagRobustStats())
116        this->itsFileStream << this->itsComment << "  [Using robust methods]\n";
117    }
118  }
119
120  void AnnotationWriter::writeEntry(Detection *object)
121  {
122    /// @details The given object is written as an annotation. If the
123    /// parameter annotationType = "borders", then vertical &
124    /// horizontal lines are drawn around the spatial extent of the
125    /// detection, otherwise (annotationType = "circles") a circle is
126    /// drawn with radius of (half) the maximum spatial width. A text
127    /// string is also written showing the object ID. In all cases,
128    /// the derived class must define the actual methods for writing
129    /// lines, circles, text.
130
131    if(this->itsOpenFlag){
132
133      if(this->itsParam->getAnnotationType() == "borders"){
134        double *pix = new double[3];
135        double *wld = new double[3];
136        double x1,x2,y1,y2;
137        std::vector<int> vertexSet = object->getVertexSet();
138        for(size_t i=0;i<vertexSet.size()/4;i++){
139          pix[0] = vertexSet[i*4]-0.5;
140          pix[1] = vertexSet[i*4+1]-0.5;
141          pix[2] = object->getZcentre();
142          if(this->itsHead->isWCS()){
143            this->itsHead->pixToWCS(pix,wld);
144            x1=wld[0];
145            y1=wld[1];
146          }
147          else{
148            x1=pix[0];
149            y1=pix[1];
150          }
151          pix[0] = vertexSet[i*4+2]-0.5;
152          pix[1] = vertexSet[i*4+3]-0.5;
153          if(this->itsHead->isWCS()){
154            this->itsHead->pixToWCS(pix,wld);
155            x2=wld[0];
156            y2=wld[1];
157          }
158          else{
159            x2=wld[0];
160            y2=wld[1];
161          }
162          this->line(x1,x2,y1,y2);
163        }
164      }
165      else if(this->itsParam->getAnnotationType()=="circles"){
166        float radius = std::max(object->getRAWidth(),object->getDecWidth())/120.;
167        this->circle(object->getRA(),object->getDec(),radius);
168      }
169
170      std::stringstream ss;
171      ss << object->getID();
172      this->text(object->getRA(),object->getDec(),ss.str());
173      this->itsFileStream << "\n";
174
175    }
176  }
177
178
179}
Note: See TracBrowser for help on using the repository browser.