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