[144] | 1 | #include <iostream> |
---|
| 2 | #include <sstream> |
---|
| 3 | |
---|
[155] | 4 | #include <math.h> |
---|
[120] | 5 | #include <duchamp.hh> |
---|
[93] | 6 | #include <param.hh> |
---|
| 7 | #include <vector> |
---|
| 8 | #include <string> |
---|
[144] | 9 | #include <Detection/detection.hh> |
---|
| 10 | #include <Detection/columns.hh> |
---|
[93] | 11 | |
---|
| 12 | using std::string; |
---|
| 13 | using std::vector; |
---|
| 14 | using namespace Column; |
---|
| 15 | |
---|
[144] | 16 | Col::Col(int num) |
---|
| 17 | { |
---|
| 18 | /** |
---|
| 19 | * Col::Col(int num) |
---|
| 20 | * A specialised constructor that defines one of the default |
---|
| 21 | * columns, as defined in the Column namespace |
---|
| 22 | */ |
---|
[191] | 23 | if((num>=0)&&(num<numColumns)){ |
---|
[144] | 24 | this->width = defaultWidth[num]; |
---|
| 25 | this->precision = defaultPrec[num]; |
---|
| 26 | this->name = defaultName[num]; |
---|
| 27 | this->units = defaultUnits[num]; |
---|
| 28 | } |
---|
| 29 | else{ |
---|
[120] | 30 | std::stringstream errmsg; |
---|
[144] | 31 | errmsg << "Incorrect value for Col(num) --> num="<<num |
---|
| 32 | << ", should be between 0 and 21.\n"; |
---|
| 33 | duchampError("Col constructor", errmsg.str()); |
---|
| 34 | this->width = 1; |
---|
| 35 | this->precision = 0; |
---|
| 36 | this->name = " "; |
---|
| 37 | this->units = " "; |
---|
[93] | 38 | } |
---|
[144] | 39 | } |
---|
[93] | 40 | |
---|
[144] | 41 | vector<Col> getFullColSet(vector<Detection> &objectList, FitsHeader &head) |
---|
[136] | 42 | { |
---|
[144] | 43 | /** |
---|
| 44 | * getFullColSet(objectlist, head) |
---|
| 45 | * A function that returns a vector of Col objects containing |
---|
| 46 | * information on the columns necessary for output to the results file: |
---|
| 47 | * Obj#,NAME,X,Y,Z,RA,DEC,VEL,w_RA,w_DEC,w_VEL,F_tot,F_int,F_peak, |
---|
| 48 | * X1,X2,Y1,Y2,Z1,Z2,Npix,Flag |
---|
| 49 | * Each object in the provided objectList is checked to see if |
---|
| 50 | * it requires any column to be widened, or for that column to |
---|
| 51 | * have its precision increased. |
---|
| 52 | * Both Ftot and Fint are provided -- it is up to the calling function to |
---|
| 53 | * determine which to use. |
---|
| 54 | */ |
---|
[93] | 55 | |
---|
[144] | 56 | vector<Col> newset; |
---|
[93] | 57 | |
---|
[144] | 58 | // set up the default columns |
---|
[93] | 59 | |
---|
[144] | 60 | newset.push_back( Col(NUM) ); |
---|
| 61 | newset.push_back( Col(NAME) ); |
---|
| 62 | newset.push_back( Col(X) ); |
---|
| 63 | newset.push_back( Col(Y) ); |
---|
| 64 | newset.push_back( Col(Z) ); |
---|
| 65 | newset.push_back( Col(RA) ); |
---|
| 66 | newset.push_back( Col(DEC) ); |
---|
| 67 | newset.push_back( Col(VEL) ); |
---|
| 68 | newset.push_back( Col(WRA) ); |
---|
| 69 | newset.push_back( Col(WDEC) ); |
---|
| 70 | newset.push_back( Col(WVEL) ); |
---|
| 71 | newset.push_back( Col(FINT) ); |
---|
| 72 | newset.push_back( Col(FTOT) ); |
---|
| 73 | newset.push_back( Col(FPEAK) ); |
---|
[191] | 74 | newset.push_back( Col(SNRPEAK) ); |
---|
[144] | 75 | newset.push_back( Col(X1) ); |
---|
| 76 | newset.push_back( Col(X2) ); |
---|
| 77 | newset.push_back( Col(Y1) ); |
---|
| 78 | newset.push_back( Col(Y2) ); |
---|
| 79 | newset.push_back( Col(Z1) ); |
---|
| 80 | newset.push_back( Col(Z2) ); |
---|
| 81 | newset.push_back( Col(NPIX) ); |
---|
| 82 | newset.push_back( Col(FLAG) ); |
---|
[93] | 83 | |
---|
[144] | 84 | // Now test each object against each new column |
---|
| 85 | for( int obj = 0; obj < objectList.size(); obj++){ |
---|
| 86 | string tempstr; |
---|
| 87 | int tempwidth; |
---|
| 88 | float val,minval; |
---|
[93] | 89 | |
---|
[144] | 90 | // Obj# |
---|
| 91 | tempwidth = int( log10(objectList[obj].getID()) + 1) + |
---|
| 92 | newset[NUM].getPrecision() + 1; |
---|
| 93 | for(int i=newset[NUM].getWidth();i<tempwidth;i++) newset[NUM].widen(); |
---|
[93] | 94 | |
---|
[144] | 95 | // Name |
---|
| 96 | tempwidth = objectList[obj].getName().size() + 1; |
---|
| 97 | for(int i=newset[NAME].getWidth();i<tempwidth;i++) newset[NAME].widen(); |
---|
[93] | 98 | |
---|
[144] | 99 | // X position |
---|
| 100 | val = objectList[obj].getXcentre(); |
---|
| 101 | tempwidth = int( log10(val) + 1) + newset[X].getPrecision() + 2; |
---|
| 102 | for(int i=newset[X].getWidth();i<tempwidth;i++) newset[X].widen(); |
---|
| 103 | if(val < 1.){ |
---|
| 104 | minval = pow(10, -1. * newset[X].getPrecision()+1); |
---|
| 105 | if(val < minval) newset[X].upPrec(); |
---|
| 106 | } |
---|
| 107 | // Y position |
---|
| 108 | val = objectList[obj].getYcentre(); |
---|
| 109 | tempwidth = int( log10(val) + 1) + newset[Y].getPrecision() + 2; |
---|
| 110 | for(int i=newset[Y].getWidth();i<tempwidth;i++) newset[Y].widen(); |
---|
| 111 | if(val < 1.){ |
---|
| 112 | minval = pow(10, -1. * newset[Y].getPrecision()+1); |
---|
| 113 | if(val < minval) newset[Y].upPrec(); |
---|
| 114 | } |
---|
| 115 | // Z position |
---|
| 116 | val = objectList[obj].getZcentre(); |
---|
| 117 | tempwidth = int( log10(val) + 1) + newset[Z].getPrecision() + 2; |
---|
| 118 | for(int i=newset[Z].getWidth();i<tempwidth;i++) newset[Z].widen(); |
---|
| 119 | if(val < 1.){ |
---|
| 120 | minval = pow(10, -1. * newset[Z].getPrecision()+1); |
---|
[155] | 121 | if((val>0.)&&(val < minval)) newset[Z].upPrec(); |
---|
[144] | 122 | } |
---|
[93] | 123 | |
---|
[144] | 124 | if(head.isWCS()){ |
---|
| 125 | // RA -- assign correct title. Check width but should be ok by definition |
---|
| 126 | tempstr = head.getWCS()->lngtyp; |
---|
| 127 | newset[RA].setName(tempstr); |
---|
| 128 | tempwidth = objectList[obj].getRAs().size() + 1; |
---|
| 129 | for(int i=newset[RA].getWidth();i<tempwidth;i++) newset[RA].widen(); |
---|
| 130 | |
---|
[146] | 131 | // Dec -- assign correct title. Check width, should be ok by definition |
---|
[144] | 132 | tempstr = head.getWCS()->lattyp; |
---|
| 133 | newset[DEC].setName(tempstr); |
---|
| 134 | tempwidth = objectList[obj].getDecs().size() + 1; |
---|
| 135 | for(int i=newset[DEC].getWidth();i<tempwidth;i++) newset[DEC].widen(); |
---|
[93] | 136 | |
---|
[144] | 137 | // Vel -- check width, title and units. |
---|
| 138 | if(head.getWCS()->restfrq == 0) // using frequency, not velocity |
---|
| 139 | newset[VEL].setName("FREQ"); |
---|
| 140 | newset[VEL].setUnits("[" + head.getSpectralUnits() + "]"); |
---|
| 141 | tempwidth = newset[VEL].getUnits().size() + 1; |
---|
[146] | 142 | for(int i=newset[VEL].getWidth();i<tempwidth;i++) newset[VEL].widen(); |
---|
| 143 | |
---|
[144] | 144 | val = objectList[obj].getVel(); |
---|
| 145 | tempwidth = int( log10(fabs(val)) + 1) + newset[VEL].getPrecision() + 2; |
---|
| 146 | if(val<0) tempwidth++; |
---|
| 147 | for(int i=newset[VEL].getWidth();i<tempwidth;i++) newset[VEL].widen(); |
---|
[146] | 148 | if(fabs(val) < 1.){ |
---|
[144] | 149 | minval = pow(10, -1. * newset[VEL].getPrecision()+1); |
---|
| 150 | if(val < minval) newset[VEL].upPrec(); |
---|
| 151 | } |
---|
[93] | 152 | |
---|
[144] | 153 | // w_RA -- check width & title. leave units for the moment. |
---|
| 154 | tempwidth = newset[RA].getUnits().size() + 1; |
---|
[146] | 155 | for(int i=newset[RA].getWidth();i<tempwidth;i++) newset[RA].widen(); |
---|
[144] | 156 | val = objectList[obj].getRAWidth(); |
---|
| 157 | tempwidth = int( log10(fabs(val)) + 1) + newset[WRA].getPrecision() + 2; |
---|
| 158 | if(val<0) tempwidth++; |
---|
| 159 | for(int i=newset[WRA].getWidth();i<tempwidth;i++) newset[WRA].widen(); |
---|
[146] | 160 | if(fabs(val) < 1.){ |
---|
[144] | 161 | minval = pow(10, -1. * newset[WRA].getPrecision()+1); |
---|
| 162 | if(val < minval) newset[WRA].upPrec(); |
---|
| 163 | } |
---|
[136] | 164 | |
---|
[144] | 165 | // w_DEC -- check width & title. leave units for the moment. |
---|
| 166 | tempwidth = newset[DEC].getUnits().size() + 1; |
---|
[146] | 167 | for(int i=newset[DEC].getWidth();i<tempwidth;i++) newset[DEC].widen(); |
---|
[144] | 168 | val = objectList[obj].getDecWidth(); |
---|
| 169 | tempwidth = int( log10(fabs(val)) + 1) + newset[WDEC].getPrecision() + 2; |
---|
| 170 | if(val<0) tempwidth++; |
---|
| 171 | for(int i=newset[WDEC].getWidth();i<tempwidth;i++) newset[WDEC].widen(); |
---|
[146] | 172 | if(fabs(val) < 1.){ |
---|
[144] | 173 | minval = pow(10, -1. * newset[WDEC].getPrecision()+1); |
---|
| 174 | if(val < minval) newset[WDEC].upPrec(); |
---|
| 175 | } |
---|
[136] | 176 | |
---|
[144] | 177 | // w_Vel -- check width, title and units. |
---|
| 178 | if(head.getWCS()->restfrq == 0) // using frequency, not velocity |
---|
| 179 | newset[WVEL].setName("w_FREQ"); |
---|
| 180 | newset[WVEL].setUnits("[" + head.getSpectralUnits() + "]"); |
---|
| 181 | tempwidth = newset[WVEL].getUnits().size() + 1; |
---|
[146] | 182 | for(int i=newset[WVEL].getWidth();i<tempwidth;i++) newset[WVEL].widen(); |
---|
[144] | 183 | val = objectList[obj].getVel(); |
---|
| 184 | tempwidth = int( log10(fabs(val)) + 1) + newset[WVEL].getPrecision() + 2; |
---|
| 185 | if(val<0) tempwidth++; |
---|
| 186 | for(int i=newset[WVEL].getWidth();i<tempwidth;i++) newset[WVEL].widen(); |
---|
[146] | 187 | if(fabs(val) < 1.){ |
---|
[144] | 188 | minval = pow(10, -1. * newset[WVEL].getPrecision()+1); |
---|
| 189 | if(val < minval) newset[WVEL].upPrec(); |
---|
| 190 | } |
---|
[136] | 191 | |
---|
[144] | 192 | // F_int -- check width & units |
---|
| 193 | newset[FINT].setUnits("[" + head.getIntFluxUnits() + "]"); |
---|
| 194 | tempwidth = newset[FINT].getUnits().size() + 1; |
---|
[146] | 195 | for(int i=newset[FINT].getWidth();i<tempwidth;i++) newset[FINT].widen(); |
---|
[144] | 196 | val = objectList[obj].getIntegFlux(); |
---|
| 197 | tempwidth = int( log10(fabs(val)) + 1) + newset[FINT].getPrecision() + 2; |
---|
| 198 | if(val<0) tempwidth++; |
---|
| 199 | for(int i=newset[FINT].getWidth();i<tempwidth;i++) newset[FINT].widen(); |
---|
[146] | 200 | if(fabs(val) < 1.){ |
---|
[144] | 201 | minval = pow(10, -1. * newset[FINT].getPrecision()+1); |
---|
| 202 | if(val < minval) newset[FINT].upPrec(); |
---|
| 203 | } |
---|
| 204 | } |
---|
[136] | 205 | |
---|
[144] | 206 | // F_tot |
---|
| 207 | newset[FTOT].setUnits("[" + head.getFluxUnits() + "]"); |
---|
| 208 | tempwidth = newset[FTOT].getUnits().size() + 1; |
---|
[146] | 209 | for(int i=newset[FTOT].getWidth();i<tempwidth;i++) newset[FTOT].widen(); |
---|
[144] | 210 | val = objectList[obj].getTotalFlux(); |
---|
| 211 | tempwidth = int( log10(fabs(val)) + 1) + newset[FTOT].getPrecision() + 2; |
---|
| 212 | if(val<0) tempwidth++; |
---|
| 213 | for(int i=newset[FTOT].getWidth();i<tempwidth;i++) newset[FTOT].widen(); |
---|
[146] | 214 | if(fabs(val) < 1.){ |
---|
[144] | 215 | minval = pow(10, -1. * newset[FTOT].getPrecision()+1); |
---|
| 216 | if(val < minval) newset[FTOT].upPrec(); |
---|
| 217 | } |
---|
[136] | 218 | |
---|
[144] | 219 | // F_peak |
---|
| 220 | newset[FPEAK].setUnits("[" + head.getFluxUnits() + "]"); |
---|
| 221 | tempwidth = newset[FPEAK].getUnits().size() + 1; |
---|
[146] | 222 | for(int i=newset[FPEAK].getWidth();i<tempwidth;i++) newset[FPEAK].widen(); |
---|
[144] | 223 | val = objectList[obj].getPeakFlux(); |
---|
| 224 | tempwidth = int( log10(fabs(val)) + 1) + newset[FPEAK].getPrecision() + 2; |
---|
| 225 | if(val<0) tempwidth++; |
---|
| 226 | for(int i=newset[FPEAK].getWidth();i<tempwidth;i++) newset[FPEAK].widen(); |
---|
[146] | 227 | if(fabs(val) < 1.){ |
---|
[144] | 228 | minval = pow(10, -1. * newset[FPEAK].getPrecision()+1); |
---|
| 229 | if(val < minval) newset[FPEAK].upPrec(); |
---|
| 230 | } |
---|
[136] | 231 | |
---|
[191] | 232 | // S/N_peak |
---|
| 233 | val = objectList[obj].getPeakSNR(); |
---|
| 234 | tempwidth = int( log10(fabs(val)) + 1) + newset[SNRPEAK].getPrecision() +1; |
---|
| 235 | if(val<0) tempwidth++; |
---|
| 236 | for(int i=newset[SNRPEAK].getWidth();i<tempwidth;i++) |
---|
| 237 | newset[SNRPEAK].widen(); |
---|
| 238 | if(fabs(val) < 1.){ |
---|
| 239 | minval = pow(10, -1. * newset[SNRPEAK].getPrecision()+1); |
---|
| 240 | if(val < minval) newset[SNRPEAK].upPrec(); |
---|
| 241 | } |
---|
| 242 | |
---|
[144] | 243 | // X1 position |
---|
| 244 | tempwidth = int( log10(objectList[obj].getXmin()) + 1) + |
---|
| 245 | newset[X1].getPrecision() + 1; |
---|
| 246 | for(int i=newset[X1].getWidth();i<tempwidth;i++) newset[X1].widen(); |
---|
| 247 | // X2 position |
---|
| 248 | tempwidth = int( log10(objectList[obj].getXmax()) + 1) + |
---|
| 249 | newset[X2].getPrecision() + 1; |
---|
| 250 | for(int i=newset[X2].getWidth();i<tempwidth;i++) newset[X2].widen(); |
---|
| 251 | // Y1 position |
---|
| 252 | tempwidth = int( log10(objectList[obj].getYmin()) + 1) + |
---|
| 253 | newset[Y1].getPrecision() + 1; |
---|
| 254 | for(int i=newset[Y1].getWidth();i<tempwidth;i++) newset[Y1].widen(); |
---|
| 255 | // Y2 position |
---|
| 256 | tempwidth = int( log10(objectList[obj].getYmax()) + 1) + |
---|
| 257 | newset[Y2].getPrecision() + 1; |
---|
| 258 | for(int i=newset[Y2].getWidth();i<tempwidth;i++) newset[Y2].widen(); |
---|
| 259 | // Z1 position |
---|
| 260 | tempwidth = int( log10(objectList[obj].getZmin()) + 1) + |
---|
| 261 | newset[Z1].getPrecision() + 1; |
---|
| 262 | for(int i=newset[Z1].getWidth();i<tempwidth;i++) newset[Z1].widen(); |
---|
| 263 | // Z2 position |
---|
| 264 | tempwidth = int( log10(objectList[obj].getZmax()) + 1) + |
---|
| 265 | newset[Z2].getPrecision() + 1; |
---|
| 266 | for(int i=newset[Z2].getWidth();i<tempwidth;i++) newset[Z2].widen(); |
---|
[136] | 267 | |
---|
[144] | 268 | // Npix |
---|
| 269 | tempwidth = int( log10(objectList[obj].getSize()) + 1) + |
---|
| 270 | newset[NPIX].getPrecision() + 1; |
---|
| 271 | for(int i=newset[NPIX].getWidth();i<tempwidth;i++) newset[NPIX].widen(); |
---|
| 272 | |
---|
[136] | 273 | } |
---|
| 274 | |
---|
[144] | 275 | return newset; |
---|
[136] | 276 | |
---|
[144] | 277 | } |
---|
[136] | 278 | |
---|
[144] | 279 | vector<Col> getLogColSet(vector<Detection> &objectList, FitsHeader &head) |
---|
| 280 | { |
---|
| 281 | /** |
---|
| 282 | * getLogColSet(objectlist) |
---|
| 283 | * A function that returns a vector of Col objects containing |
---|
| 284 | * information on the columns necessary for logfile output: |
---|
| 285 | * Obj#,X,Y,Z,F_tot,F_peak,X1,X2,Y1,Y2,Z1,Z2,Npix |
---|
| 286 | * Each object in the provided objectList is checked to see if |
---|
| 287 | * it requires any column to be widened, or for that column to |
---|
| 288 | * have its precision increased. |
---|
| 289 | */ |
---|
[136] | 290 | |
---|
[144] | 291 | vector<Col> newset,tempset; |
---|
[136] | 292 | |
---|
[144] | 293 | // set up the default columns: |
---|
| 294 | // get from FullColSet, and select only the ones we want. |
---|
| 295 | tempset = getFullColSet(objectList,head); |
---|
[136] | 296 | |
---|
[191] | 297 | newset.push_back( tempset[NUM] ); |
---|
| 298 | newset.push_back( tempset[X] ); |
---|
| 299 | newset.push_back( tempset[Y] ); |
---|
| 300 | newset.push_back( tempset[Z] ); |
---|
| 301 | newset.push_back( tempset[FTOT] ); |
---|
| 302 | newset.push_back( tempset[FPEAK] ); |
---|
| 303 | newset.push_back( tempset[SNRPEAK] ); |
---|
| 304 | newset.push_back( tempset[X1] ); |
---|
| 305 | newset.push_back( tempset[X2] ); |
---|
| 306 | newset.push_back( tempset[Y1] ); |
---|
| 307 | newset.push_back( tempset[Y2] ); |
---|
| 308 | newset.push_back( tempset[Z1] ); |
---|
| 309 | newset.push_back( tempset[Z2] ); |
---|
| 310 | newset.push_back( tempset[NPIX] ); |
---|
[136] | 311 | |
---|
| 312 | return newset; |
---|
[93] | 313 | |
---|
| 314 | } |
---|