[1061] | 1 | // ----------------------------------------------------------------------- |
---|
| 2 | // CatalogueSpecification.cc: Define the specification of a catalogue, |
---|
| 3 | // being a set of Columns |
---|
| 4 | // ----------------------------------------------------------------------- |
---|
| 5 | // Copyright (C) 2006, Matthew Whiting, ATNF |
---|
| 6 | // |
---|
| 7 | // This program is free software; you can redistribute it and/or modify it |
---|
| 8 | // under the terms of the GNU General Public License as published by the |
---|
| 9 | // Free Software Foundation; either version 2 of the License, or (at your |
---|
| 10 | // option) any later version. |
---|
| 11 | // |
---|
| 12 | // Duchamp is distributed in the hope that it will be useful, but WITHOUT |
---|
| 13 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
---|
| 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
---|
| 15 | // for more details. |
---|
| 16 | // |
---|
| 17 | // You should have received a copy of the GNU General Public License |
---|
| 18 | // along with Duchamp; if not, write to the Free Software Foundation, |
---|
| 19 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA |
---|
| 20 | // |
---|
| 21 | // Correspondence concerning Duchamp may be directed to: |
---|
| 22 | // Internet email: Matthew.Whiting [at] atnf.csiro.au |
---|
| 23 | // Postal address: Dr. Matthew Whiting |
---|
| 24 | // Australia Telescope National Facility, CSIRO |
---|
| 25 | // PO Box 76 |
---|
| 26 | // Epping NSW 1710 |
---|
| 27 | // AUSTRALIA |
---|
| 28 | // ----------------------------------------------------------------------- |
---|
| 29 | #include <duchamp/Outputs/CatalogueSpecification.hh> |
---|
| 30 | #include <duchamp/duchamp.hh> |
---|
| 31 | #include <duchamp/Outputs/columns.hh> |
---|
[1422] | 32 | #include <duchamp/Detection/detection.hh> |
---|
| 33 | #include <duchamp/fitsHeader.hh> |
---|
[1061] | 34 | #include <vector> |
---|
| 35 | #include <map> |
---|
| 36 | #include <string> |
---|
| 37 | |
---|
| 38 | namespace duchamp { |
---|
| 39 | |
---|
| 40 | namespace Catalogues { |
---|
| 41 | |
---|
| 42 | CatalogueSpecification::CatalogueSpecification(const CatalogueSpecification& other) |
---|
| 43 | { |
---|
| 44 | operator=(other); |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | CatalogueSpecification& CatalogueSpecification::operator= (const CatalogueSpecification& other) |
---|
| 48 | { |
---|
| 49 | if(this == &other) return *this; |
---|
| 50 | this->itsColumnList = other.itsColumnList; |
---|
| 51 | this->itsTypeMap = other.itsTypeMap; |
---|
[1137] | 52 | this->itsCommentString = other.itsCommentString; |
---|
[1061] | 53 | return *this; |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | void CatalogueSpecification::addColumn(Column col) |
---|
| 57 | { |
---|
[1064] | 58 | this->removeColumn(col.type()); |
---|
[1061] | 59 | this->itsColumnList.push_back(col); |
---|
[1153] | 60 | // this->itsTypeMap[col.type()] = this->itsColumnList.size() - 1; |
---|
| 61 | this->setMap(); |
---|
[1061] | 62 | } |
---|
| 63 | |
---|
[1422] | 64 | void CatalogueSpecification::addColumn(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) |
---|
| 65 | { |
---|
| 66 | Column col(type,name,units,width,prec,ucd,datatype,colID,extraInfo); |
---|
| 67 | this->addColumn(col); |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | |
---|
[1153] | 71 | void CatalogueSpecification::setMap() |
---|
| 72 | { |
---|
| 73 | for(size_t i=0;i<this->itsColumnList.size();i++) |
---|
| 74 | this->itsTypeMap[this->itsColumnList[i].type()] = i; |
---|
| 75 | } |
---|
| 76 | |
---|
[1064] | 77 | void CatalogueSpecification::removeColumn(std::string type) |
---|
| 78 | { |
---|
[1153] | 79 | if( this->itsTypeMap.find(type) != this->itsTypeMap.end() ) // already in list |
---|
| 80 | this->itsColumnList.erase( this->itsColumnList.begin()+this->itsTypeMap[type] ); |
---|
| 81 | this->setMap(); |
---|
[1064] | 82 | } |
---|
| 83 | |
---|
[1152] | 84 | bool CatalogueSpecification::hasColumn(std::string type) |
---|
| 85 | { |
---|
| 86 | return this->itsTypeMap.find(type) != this->itsTypeMap.end(); |
---|
| 87 | } |
---|
[1137] | 88 | |
---|
| 89 | void CatalogueSpecification::outputTableHeader(std::ostream &stream, Catalogues::DESTINATION tableType, bool flagWCS) |
---|
| 90 | { |
---|
| 91 | /// @details |
---|
| 92 | /// Prints the header row for a table of detections. The columns |
---|
| 93 | /// that are included depend on the value of tableType, according |
---|
| 94 | /// to the Column::doCol() function. The format is a row of |
---|
| 95 | /// dashes, a row with column names, a row with column units, and |
---|
| 96 | /// another row of dashes. |
---|
| 97 | /// \param stream Where the output is written |
---|
| 98 | /// \param columns The vector list of Column objects |
---|
| 99 | /// \param tableType A string saying what format to use: one of |
---|
| 100 | /// "file", "log", "screen" or "votable" (although the latter |
---|
| 101 | /// shouldn't be used with this function). |
---|
| 102 | /// \param flagWCS A flag for use with Column::doCol(), specifying |
---|
| 103 | /// whether to use FINT or FTOT. |
---|
| 104 | |
---|
| 105 | stream << this->itsCommentString; |
---|
| 106 | for(size_t i=0;i<this->itsColumnList.size();i++) |
---|
| 107 | if(this->itsColumnList[i].doCol(tableType,flagWCS)) this->itsColumnList[i].printDash(stream); |
---|
| 108 | stream << "\n"<<this->itsCommentString; |
---|
| 109 | for(size_t i=0;i<this->itsColumnList.size();i++) |
---|
| 110 | if(this->itsColumnList[i].doCol(tableType,flagWCS)) this->itsColumnList[i].printTitle(stream); |
---|
| 111 | stream << "\n"<<this->itsCommentString; |
---|
| 112 | for(size_t i=0;i<this->itsColumnList.size();i++) |
---|
| 113 | if(this->itsColumnList[i].doCol(tableType,flagWCS)) this->itsColumnList[i].printUnits(stream); |
---|
| 114 | stream << "\n"<<this->itsCommentString; |
---|
| 115 | for(size_t i=0;i<this->itsColumnList.size();i++) |
---|
| 116 | if(this->itsColumnList[i].doCol(tableType,flagWCS)) this->itsColumnList[i].printDash(stream); |
---|
| 117 | stream << "\n"; |
---|
| 118 | |
---|
| 119 | for(size_t i=0;i<this->itsCommentString.size();i++) this->itsColumnList[0].widen(); |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | |
---|
[1422] | 123 | template <class T> void CatalogueSpecification::check(std::string type, T value) |
---|
| 124 | { |
---|
| 125 | if(hasColumn(type)){ |
---|
| 126 | itsColumnList[itsTypeMap[type]].check(value); |
---|
| 127 | } |
---|
| 128 | } |
---|
| 129 | template void CatalogueSpecification::check<int>(std::string type, int value); |
---|
| 130 | template void CatalogueSpecification::check<long>(std::string type, long value); |
---|
| 131 | template void CatalogueSpecification::check<unsigned int>(std::string type, unsigned int value); |
---|
| 132 | template void CatalogueSpecification::check<unsigned long>(std::string type, unsigned long value); |
---|
| 133 | template void CatalogueSpecification::check<std::string>(std::string type, std::string value); |
---|
| 134 | template void CatalogueSpecification::check<float>(std::string type, float value); |
---|
| 135 | template void CatalogueSpecification::check<double>(std::string type, double value); |
---|
| 136 | |
---|
| 137 | template <class T> void CatalogueSpecification::check(std::string type, T value, bool doPrec) |
---|
| 138 | { |
---|
| 139 | if(hasColumn(type)){ |
---|
| 140 | itsColumnList[itsTypeMap[type]].check(value,doPrec); |
---|
| 141 | } |
---|
| 142 | } |
---|
| 143 | template void CatalogueSpecification::check<float>(std::string type, float value, bool doPrec); |
---|
| 144 | template void CatalogueSpecification::check<double>(std::string type, double value, bool doPrec); |
---|
| 145 | |
---|
| 146 | void CatalogueSpecification::checkAll(std::vector<Detection> &objectList, FitsHeader &head) |
---|
| 147 | { |
---|
| 148 | // Now test each object against each new column, ensuring each |
---|
| 149 | // column has sufficient width and (in most cases) precision to |
---|
| 150 | // accomodate the data. |
---|
| 151 | std::vector<Detection>::iterator obj; |
---|
| 152 | for(obj = objectList.begin(); obj < objectList.end(); obj++){ |
---|
| 153 | |
---|
| 154 | this->check("NUM",obj->getID()); |
---|
| 155 | this->check("NAME",obj->getName()); |
---|
| 156 | this->check("X",obj->getXcentre()+obj->getXOffset()); |
---|
| 157 | this->check("Y",obj->getYcentre()+obj->getYOffset()); |
---|
| 158 | this->check("Z",obj->getZcentre()+obj->getZOffset()); |
---|
| 159 | if(head.isWCS()){ |
---|
| 160 | this->check("RA",obj->getRAs()); |
---|
| 161 | this->check("DEC",obj->getDecs()); |
---|
| 162 | this->check("RAJD",obj->getRA()); |
---|
| 163 | this->check("DECJD",obj->getDec()); |
---|
| 164 | if(head.canUseThirdAxis()){ |
---|
| 165 | this->check("VEL",obj->getVel()); |
---|
| 166 | } |
---|
| 167 | this->check("MAJ",obj->getMajorAxis()); |
---|
| 168 | this->check("MIN",obj->getMinorAxis()); |
---|
| 169 | // For the PA column, we don't increase the precision. If |
---|
| 170 | // something is very close to zero position angle, then |
---|
| 171 | // we're happy to call it zero. |
---|
| 172 | this->check("PA",obj->getPositionAngle(),false); |
---|
| 173 | this->check("WRA",obj->getRAWidth()); |
---|
| 174 | this->check("WDEC",obj->getDecWidth()); |
---|
| 175 | if(head.canUseThirdAxis()){ |
---|
| 176 | this->check("W50",obj->getW50()); |
---|
| 177 | this->check("W20",obj->getW20()); |
---|
| 178 | this->check("WVEL",obj->getVelWidth()); |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | this->check("FINT",obj->getIntegFlux()); |
---|
| 182 | if(obj->getIntegFluxError()>0.) |
---|
| 183 | this->check("FINTERR",obj->getIntegFluxError()); |
---|
| 184 | } |
---|
| 185 | this->check("FTOT",obj->getTotalFlux()); |
---|
| 186 | if(obj->getTotalFluxError()>0.) |
---|
| 187 | this->check("FTOTERR",obj->getTotalFluxError()); |
---|
| 188 | this->check("FPEAK",obj->getPeakFlux()); |
---|
| 189 | if(obj->getPeakSNR()>0.) |
---|
| 190 | this->check("SNRPEAK",obj->getPeakSNR()); |
---|
| 191 | this->check("X1",obj->getXmin()+obj->getXOffset()); |
---|
| 192 | this->check("X2",obj->getXmax()+obj->getXOffset()); |
---|
| 193 | this->check("Y1",obj->getYmin()+obj->getYOffset()); |
---|
| 194 | this->check("Y2",obj->getYmax()+obj->getYOffset()); |
---|
| 195 | this->check("Z1",obj->getZmin()+obj->getZOffset()); |
---|
| 196 | this->check("Z2",obj->getZmax()+obj->getZOffset()); |
---|
| 197 | this->check("NVOX",obj->getSize()); |
---|
| 198 | this->check("XAV",obj->getXaverage()+obj->getXOffset()); |
---|
| 199 | this->check("YAV",obj->getYaverage()+obj->getYOffset()); |
---|
| 200 | this->check("ZAV",obj->getZaverage()+obj->getZOffset()); |
---|
| 201 | this->check("XCENTROID",obj->getXCentroid()+obj->getXOffset()); |
---|
| 202 | this->check("YCENTROID",obj->getYCentroid()+obj->getYOffset()); |
---|
| 203 | this->check("ZCENTROID",obj->getZCentroid()+obj->getZOffset()); |
---|
| 204 | this->check("XPEAK",obj->getXPeak()+obj->getXOffset()); |
---|
| 205 | this->check("YPEAK",obj->getYPeak()+obj->getYOffset()); |
---|
| 206 | this->check("ZPEAK",obj->getZPeak()+obj->getZOffset()); |
---|
| 207 | this->check("NUMCH",obj->getNumChannels()); |
---|
| 208 | this->check("SPATSIZE",obj->getSpatialSize()); |
---|
| 209 | |
---|
| 210 | } |
---|
| 211 | |
---|
| 212 | |
---|
| 213 | } |
---|
| 214 | |
---|
| 215 | |
---|
[1061] | 216 | } |
---|
| 217 | |
---|
| 218 | } |
---|