[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 | */ |
---|
| 23 | if((num>=0)&&(num<22)){ |
---|
| 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) ); |
---|
| 74 | newset.push_back( Col(X1) ); |
---|
| 75 | newset.push_back( Col(X2) ); |
---|
| 76 | newset.push_back( Col(Y1) ); |
---|
| 77 | newset.push_back( Col(Y2) ); |
---|
| 78 | newset.push_back( Col(Z1) ); |
---|
| 79 | newset.push_back( Col(Z2) ); |
---|
| 80 | newset.push_back( Col(NPIX) ); |
---|
| 81 | newset.push_back( Col(FLAG) ); |
---|
[93] | 82 | |
---|
[144] | 83 | // Now test each object against each new column |
---|
| 84 | for( int obj = 0; obj < objectList.size(); obj++){ |
---|
| 85 | string tempstr; |
---|
| 86 | int tempwidth; |
---|
| 87 | float val,minval; |
---|
[93] | 88 | |
---|
[144] | 89 | // Obj# |
---|
| 90 | tempwidth = int( log10(objectList[obj].getID()) + 1) + |
---|
| 91 | newset[NUM].getPrecision() + 1; |
---|
| 92 | for(int i=newset[NUM].getWidth();i<tempwidth;i++) newset[NUM].widen(); |
---|
[93] | 93 | |
---|
[144] | 94 | // Name |
---|
| 95 | tempwidth = objectList[obj].getName().size() + 1; |
---|
| 96 | for(int i=newset[NAME].getWidth();i<tempwidth;i++) newset[NAME].widen(); |
---|
[93] | 97 | |
---|
[144] | 98 | // X position |
---|
| 99 | val = objectList[obj].getXcentre(); |
---|
| 100 | tempwidth = int( log10(val) + 1) + newset[X].getPrecision() + 2; |
---|
| 101 | for(int i=newset[X].getWidth();i<tempwidth;i++) newset[X].widen(); |
---|
| 102 | if(val < 1.){ |
---|
| 103 | minval = pow(10, -1. * newset[X].getPrecision()+1); |
---|
| 104 | if(val < minval) newset[X].upPrec(); |
---|
| 105 | } |
---|
| 106 | // Y position |
---|
| 107 | val = objectList[obj].getYcentre(); |
---|
| 108 | tempwidth = int( log10(val) + 1) + newset[Y].getPrecision() + 2; |
---|
| 109 | for(int i=newset[Y].getWidth();i<tempwidth;i++) newset[Y].widen(); |
---|
| 110 | if(val < 1.){ |
---|
| 111 | minval = pow(10, -1. * newset[Y].getPrecision()+1); |
---|
| 112 | if(val < minval) newset[Y].upPrec(); |
---|
| 113 | } |
---|
| 114 | // Z position |
---|
| 115 | val = objectList[obj].getZcentre(); |
---|
| 116 | tempwidth = int( log10(val) + 1) + newset[Z].getPrecision() + 2; |
---|
| 117 | for(int i=newset[Z].getWidth();i<tempwidth;i++) newset[Z].widen(); |
---|
| 118 | if(val < 1.){ |
---|
| 119 | minval = pow(10, -1. * newset[Z].getPrecision()+1); |
---|
[155] | 120 | if((val>0.)&&(val < minval)) newset[Z].upPrec(); |
---|
[144] | 121 | } |
---|
[93] | 122 | |
---|
[144] | 123 | if(head.isWCS()){ |
---|
| 124 | // RA -- assign correct title. Check width but should be ok by definition |
---|
| 125 | tempstr = head.getWCS()->lngtyp; |
---|
| 126 | newset[RA].setName(tempstr); |
---|
| 127 | tempwidth = objectList[obj].getRAs().size() + 1; |
---|
| 128 | for(int i=newset[RA].getWidth();i<tempwidth;i++) newset[RA].widen(); |
---|
| 129 | |
---|
[146] | 130 | // Dec -- assign correct title. Check width, should be ok by definition |
---|
[144] | 131 | tempstr = head.getWCS()->lattyp; |
---|
| 132 | newset[DEC].setName(tempstr); |
---|
| 133 | tempwidth = objectList[obj].getDecs().size() + 1; |
---|
| 134 | for(int i=newset[DEC].getWidth();i<tempwidth;i++) newset[DEC].widen(); |
---|
[93] | 135 | |
---|
[144] | 136 | // Vel -- check width, title and units. |
---|
| 137 | if(head.getWCS()->restfrq == 0) // using frequency, not velocity |
---|
| 138 | newset[VEL].setName("FREQ"); |
---|
| 139 | newset[VEL].setUnits("[" + head.getSpectralUnits() + "]"); |
---|
| 140 | tempwidth = newset[VEL].getUnits().size() + 1; |
---|
[146] | 141 | for(int i=newset[VEL].getWidth();i<tempwidth;i++) newset[VEL].widen(); |
---|
| 142 | |
---|
[144] | 143 | val = objectList[obj].getVel(); |
---|
| 144 | tempwidth = int( log10(fabs(val)) + 1) + newset[VEL].getPrecision() + 2; |
---|
| 145 | if(val<0) tempwidth++; |
---|
| 146 | for(int i=newset[VEL].getWidth();i<tempwidth;i++) newset[VEL].widen(); |
---|
[146] | 147 | if(fabs(val) < 1.){ |
---|
[144] | 148 | minval = pow(10, -1. * newset[VEL].getPrecision()+1); |
---|
| 149 | if(val < minval) newset[VEL].upPrec(); |
---|
| 150 | } |
---|
[93] | 151 | |
---|
[144] | 152 | // w_RA -- check width & title. leave units for the moment. |
---|
| 153 | tempwidth = newset[RA].getUnits().size() + 1; |
---|
[146] | 154 | for(int i=newset[RA].getWidth();i<tempwidth;i++) newset[RA].widen(); |
---|
[144] | 155 | val = objectList[obj].getRAWidth(); |
---|
| 156 | tempwidth = int( log10(fabs(val)) + 1) + newset[WRA].getPrecision() + 2; |
---|
| 157 | if(val<0) tempwidth++; |
---|
| 158 | for(int i=newset[WRA].getWidth();i<tempwidth;i++) newset[WRA].widen(); |
---|
[146] | 159 | if(fabs(val) < 1.){ |
---|
[144] | 160 | minval = pow(10, -1. * newset[WRA].getPrecision()+1); |
---|
| 161 | if(val < minval) newset[WRA].upPrec(); |
---|
| 162 | } |
---|
[136] | 163 | |
---|
[144] | 164 | // w_DEC -- check width & title. leave units for the moment. |
---|
| 165 | tempwidth = newset[DEC].getUnits().size() + 1; |
---|
[146] | 166 | for(int i=newset[DEC].getWidth();i<tempwidth;i++) newset[DEC].widen(); |
---|
[144] | 167 | val = objectList[obj].getDecWidth(); |
---|
| 168 | tempwidth = int( log10(fabs(val)) + 1) + newset[WDEC].getPrecision() + 2; |
---|
| 169 | if(val<0) tempwidth++; |
---|
| 170 | for(int i=newset[WDEC].getWidth();i<tempwidth;i++) newset[WDEC].widen(); |
---|
[146] | 171 | if(fabs(val) < 1.){ |
---|
[144] | 172 | minval = pow(10, -1. * newset[WDEC].getPrecision()+1); |
---|
| 173 | if(val < minval) newset[WDEC].upPrec(); |
---|
| 174 | } |
---|
[136] | 175 | |
---|
[144] | 176 | // w_Vel -- check width, title and units. |
---|
| 177 | if(head.getWCS()->restfrq == 0) // using frequency, not velocity |
---|
| 178 | newset[WVEL].setName("w_FREQ"); |
---|
| 179 | newset[WVEL].setUnits("[" + head.getSpectralUnits() + "]"); |
---|
| 180 | tempwidth = newset[WVEL].getUnits().size() + 1; |
---|
[146] | 181 | for(int i=newset[WVEL].getWidth();i<tempwidth;i++) newset[WVEL].widen(); |
---|
[144] | 182 | val = objectList[obj].getVel(); |
---|
| 183 | tempwidth = int( log10(fabs(val)) + 1) + newset[WVEL].getPrecision() + 2; |
---|
| 184 | if(val<0) tempwidth++; |
---|
| 185 | for(int i=newset[WVEL].getWidth();i<tempwidth;i++) newset[WVEL].widen(); |
---|
[146] | 186 | if(fabs(val) < 1.){ |
---|
[144] | 187 | minval = pow(10, -1. * newset[WVEL].getPrecision()+1); |
---|
| 188 | if(val < minval) newset[WVEL].upPrec(); |
---|
| 189 | } |
---|
[136] | 190 | |
---|
[144] | 191 | // F_int -- check width & units |
---|
| 192 | newset[FINT].setUnits("[" + head.getIntFluxUnits() + "]"); |
---|
| 193 | tempwidth = newset[FINT].getUnits().size() + 1; |
---|
[146] | 194 | for(int i=newset[FINT].getWidth();i<tempwidth;i++) newset[FINT].widen(); |
---|
[144] | 195 | val = objectList[obj].getIntegFlux(); |
---|
| 196 | tempwidth = int( log10(fabs(val)) + 1) + newset[FINT].getPrecision() + 2; |
---|
| 197 | if(val<0) tempwidth++; |
---|
| 198 | for(int i=newset[FINT].getWidth();i<tempwidth;i++) newset[FINT].widen(); |
---|
[146] | 199 | if(fabs(val) < 1.){ |
---|
[144] | 200 | minval = pow(10, -1. * newset[FINT].getPrecision()+1); |
---|
| 201 | if(val < minval) newset[FINT].upPrec(); |
---|
| 202 | } |
---|
| 203 | } |
---|
[136] | 204 | |
---|
[144] | 205 | // F_tot |
---|
| 206 | newset[FTOT].setUnits("[" + head.getFluxUnits() + "]"); |
---|
| 207 | tempwidth = newset[FTOT].getUnits().size() + 1; |
---|
[146] | 208 | for(int i=newset[FTOT].getWidth();i<tempwidth;i++) newset[FTOT].widen(); |
---|
[144] | 209 | val = objectList[obj].getTotalFlux(); |
---|
| 210 | tempwidth = int( log10(fabs(val)) + 1) + newset[FTOT].getPrecision() + 2; |
---|
| 211 | if(val<0) tempwidth++; |
---|
| 212 | for(int i=newset[FTOT].getWidth();i<tempwidth;i++) newset[FTOT].widen(); |
---|
[146] | 213 | if(fabs(val) < 1.){ |
---|
[144] | 214 | minval = pow(10, -1. * newset[FTOT].getPrecision()+1); |
---|
| 215 | if(val < minval) newset[FTOT].upPrec(); |
---|
| 216 | } |
---|
[136] | 217 | |
---|
[144] | 218 | // F_peak |
---|
| 219 | newset[FPEAK].setUnits("[" + head.getFluxUnits() + "]"); |
---|
| 220 | tempwidth = newset[FPEAK].getUnits().size() + 1; |
---|
[146] | 221 | for(int i=newset[FPEAK].getWidth();i<tempwidth;i++) newset[FPEAK].widen(); |
---|
[144] | 222 | val = objectList[obj].getPeakFlux(); |
---|
| 223 | tempwidth = int( log10(fabs(val)) + 1) + newset[FPEAK].getPrecision() + 2; |
---|
| 224 | if(val<0) tempwidth++; |
---|
| 225 | for(int i=newset[FPEAK].getWidth();i<tempwidth;i++) newset[FPEAK].widen(); |
---|
[146] | 226 | if(fabs(val) < 1.){ |
---|
[144] | 227 | minval = pow(10, -1. * newset[FPEAK].getPrecision()+1); |
---|
| 228 | if(val < minval) newset[FPEAK].upPrec(); |
---|
| 229 | } |
---|
[136] | 230 | |
---|
[144] | 231 | // X1 position |
---|
| 232 | tempwidth = int( log10(objectList[obj].getXmin()) + 1) + |
---|
| 233 | newset[X1].getPrecision() + 1; |
---|
| 234 | for(int i=newset[X1].getWidth();i<tempwidth;i++) newset[X1].widen(); |
---|
| 235 | // X2 position |
---|
| 236 | tempwidth = int( log10(objectList[obj].getXmax()) + 1) + |
---|
| 237 | newset[X2].getPrecision() + 1; |
---|
| 238 | for(int i=newset[X2].getWidth();i<tempwidth;i++) newset[X2].widen(); |
---|
| 239 | // Y1 position |
---|
| 240 | tempwidth = int( log10(objectList[obj].getYmin()) + 1) + |
---|
| 241 | newset[Y1].getPrecision() + 1; |
---|
| 242 | for(int i=newset[Y1].getWidth();i<tempwidth;i++) newset[Y1].widen(); |
---|
| 243 | // Y2 position |
---|
| 244 | tempwidth = int( log10(objectList[obj].getYmax()) + 1) + |
---|
| 245 | newset[Y2].getPrecision() + 1; |
---|
| 246 | for(int i=newset[Y2].getWidth();i<tempwidth;i++) newset[Y2].widen(); |
---|
| 247 | // Z1 position |
---|
| 248 | tempwidth = int( log10(objectList[obj].getZmin()) + 1) + |
---|
| 249 | newset[Z1].getPrecision() + 1; |
---|
| 250 | for(int i=newset[Z1].getWidth();i<tempwidth;i++) newset[Z1].widen(); |
---|
| 251 | // Z2 position |
---|
| 252 | tempwidth = int( log10(objectList[obj].getZmax()) + 1) + |
---|
| 253 | newset[Z2].getPrecision() + 1; |
---|
| 254 | for(int i=newset[Z2].getWidth();i<tempwidth;i++) newset[Z2].widen(); |
---|
[136] | 255 | |
---|
[144] | 256 | // Npix |
---|
| 257 | tempwidth = int( log10(objectList[obj].getSize()) + 1) + |
---|
| 258 | newset[NPIX].getPrecision() + 1; |
---|
| 259 | for(int i=newset[NPIX].getWidth();i<tempwidth;i++) newset[NPIX].widen(); |
---|
| 260 | |
---|
[136] | 261 | } |
---|
| 262 | |
---|
[144] | 263 | return newset; |
---|
[136] | 264 | |
---|
[144] | 265 | } |
---|
[136] | 266 | |
---|
[144] | 267 | vector<Col> getLogColSet(vector<Detection> &objectList, FitsHeader &head) |
---|
| 268 | { |
---|
| 269 | /** |
---|
| 270 | * getLogColSet(objectlist) |
---|
| 271 | * A function that returns a vector of Col objects containing |
---|
| 272 | * information on the columns necessary for logfile output: |
---|
| 273 | * Obj#,X,Y,Z,F_tot,F_peak,X1,X2,Y1,Y2,Z1,Z2,Npix |
---|
| 274 | * Each object in the provided objectList is checked to see if |
---|
| 275 | * it requires any column to be widened, or for that column to |
---|
| 276 | * have its precision increased. |
---|
| 277 | */ |
---|
[136] | 278 | |
---|
[144] | 279 | vector<Col> newset,tempset; |
---|
[136] | 280 | |
---|
[144] | 281 | // set up the default columns: |
---|
| 282 | // get from FullColSet, and select only the ones we want. |
---|
| 283 | tempset = getFullColSet(objectList,head); |
---|
[136] | 284 | |
---|
[144] | 285 | newset.push_back( tempset[0] ); |
---|
| 286 | newset.push_back( tempset[2] ); |
---|
| 287 | newset.push_back( tempset[3] ); |
---|
| 288 | newset.push_back( tempset[4] ); |
---|
| 289 | newset.push_back( tempset[12] ); |
---|
| 290 | newset.push_back( tempset[13] ); |
---|
| 291 | newset.push_back( tempset[14] ); |
---|
| 292 | newset.push_back( tempset[15] ); |
---|
| 293 | newset.push_back( tempset[16] ); |
---|
| 294 | newset.push_back( tempset[17] ); |
---|
| 295 | newset.push_back( tempset[18] ); |
---|
| 296 | newset.push_back( tempset[19] ); |
---|
| 297 | newset.push_back( tempset[20] ); |
---|
[136] | 298 | |
---|
| 299 | return newset; |
---|
[93] | 300 | |
---|
| 301 | } |
---|