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