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 | // ----------------------------------------------------------------------- |
---|
28 | #include <iostream> |
---|
29 | #include <sstream> |
---|
30 | |
---|
31 | #include <math.h> |
---|
32 | #include <duchamp/duchamp.hh> |
---|
33 | #include <duchamp/fitsHeader.hh> |
---|
34 | #include <vector> |
---|
35 | #include <string> |
---|
36 | #include <duchamp/Detection/detection.hh> |
---|
37 | #include <duchamp/Detection/columns.hh> |
---|
38 | |
---|
39 | namespace duchamp |
---|
40 | { |
---|
41 | |
---|
42 | namespace Column |
---|
43 | { |
---|
44 | |
---|
45 | |
---|
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=" "; |
---|
53 | this->type=UNKNOWN; |
---|
54 | } |
---|
55 | |
---|
56 | Col::~Col(){} |
---|
57 | |
---|
58 | Col::Col(const Col& c) |
---|
59 | { |
---|
60 | operator=(c); |
---|
61 | } |
---|
62 | |
---|
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; |
---|
70 | this->type = c.type; |
---|
71 | return *this; |
---|
72 | } |
---|
73 | |
---|
74 | Col::Col(int num, int prec) |
---|
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. |
---|
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. |
---|
84 | */ |
---|
85 | if((num>=0)&&(num<numColumns)){ |
---|
86 | this->width = defaultWidth[num]; |
---|
87 | if(prec<0) this->precision = defaultPrec[num]; |
---|
88 | else this->precision = prec; |
---|
89 | this->name = defaultName[num]; |
---|
90 | this->units = defaultUnits[num]; |
---|
91 | this->type = COLNAME(num); |
---|
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 = " "; |
---|
102 | this->type=UNKNOWN; |
---|
103 | } |
---|
104 | } |
---|
105 | |
---|
106 | //------------------------------------------------------------ |
---|
107 | void Col::printTitle(std::ostream &stream) |
---|
108 | { |
---|
109 | stream << std::setw(this->width) |
---|
110 | << std::setfill(' ') |
---|
111 | << this->name; |
---|
112 | } |
---|
113 | |
---|
114 | void Col::printUnits(std::ostream &stream) |
---|
115 | { |
---|
116 | stream << std::setw(this->width) |
---|
117 | << std::setfill(' ') |
---|
118 | << this->units; |
---|
119 | } |
---|
120 | |
---|
121 | void Col::printDash (std::ostream &stream) |
---|
122 | { |
---|
123 | stream << std::setw(this->width) |
---|
124 | << std::setfill('-') |
---|
125 | << "" |
---|
126 | << std::setfill(' '); |
---|
127 | } |
---|
128 | |
---|
129 | void Col::printBlank(std::ostream &stream) |
---|
130 | { |
---|
131 | stream << std::setw(this->width) |
---|
132 | << std::setfill(' ') |
---|
133 | << ""; |
---|
134 | } |
---|
135 | |
---|
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); |
---|
153 | |
---|
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 | |
---|
185 | |
---|
186 | |
---|
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, |
---|
195 | * X1,X2,Y1,Y2,Z1,Z2,Npix,Flag, |
---|
196 | * XAV,YAV,ZAV,XCENT,YCENT,ZCENT,XPEAK,YPEAK,ZPEAK |
---|
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 | */ |
---|
211 | |
---|
212 | std::vector<Col> newset; |
---|
213 | |
---|
214 | // desired precisions for fluxes, velocities and SNR value |
---|
215 | int precVel=objectList[0].getVelPrec(), |
---|
216 | precFlux=objectList[0].getFpeakPrec(), // same as FintPrec at this point. |
---|
217 | precSNR=objectList[0].getSNRPrec(); |
---|
218 | |
---|
219 | // set up the default columns |
---|
220 | newset.push_back( Col(NUM) ); |
---|
221 | newset.push_back( Col(NAME) ); |
---|
222 | newset.push_back( Col(X) ); |
---|
223 | newset.push_back( Col(Y) ); |
---|
224 | newset.push_back( Col(Z) ); |
---|
225 | newset.push_back( Col(RA) ); |
---|
226 | newset.push_back( Col(DEC) ); |
---|
227 | newset.push_back( Col(RAJD) ); |
---|
228 | newset.push_back( Col(DECJD) ); |
---|
229 | newset.push_back( Col(VEL, precVel) ); |
---|
230 | newset.push_back( Col(WRA) ); |
---|
231 | newset.push_back( Col(WDEC) ); |
---|
232 | newset.push_back( Col(WVEL, precVel) ); |
---|
233 | newset.push_back( Col(FINT, precFlux) ); |
---|
234 | newset.push_back( Col(FTOT, precFlux) ); |
---|
235 | newset.push_back( Col(FPEAK, precFlux) ); |
---|
236 | newset.push_back( Col(SNRPEAK, precSNR) ); |
---|
237 | newset.push_back( Col(X1) ); |
---|
238 | newset.push_back( Col(X2) ); |
---|
239 | newset.push_back( Col(Y1) ); |
---|
240 | newset.push_back( Col(Y2) ); |
---|
241 | newset.push_back( Col(Z1) ); |
---|
242 | newset.push_back( Col(Z2) ); |
---|
243 | newset.push_back( Col(NPIX) ); |
---|
244 | newset.push_back( Col(FLAG) ); |
---|
245 | newset.push_back( Col(XAV) ); |
---|
246 | newset.push_back( Col(YAV) ); |
---|
247 | newset.push_back( Col(ZAV) ); |
---|
248 | newset.push_back( Col(XCENT) ); |
---|
249 | newset.push_back( Col(YCENT) ); |
---|
250 | newset.push_back( Col(ZCENT) ); |
---|
251 | newset.push_back( Col(XPEAK) ); |
---|
252 | newset.push_back( Col(YPEAK) ); |
---|
253 | newset.push_back( Col(ZPEAK) ); |
---|
254 | |
---|
255 | |
---|
256 | // Now test each object against each new column |
---|
257 | for( int obj = 0; obj < objectList.size(); obj++){ |
---|
258 | std::string tempstr; |
---|
259 | int tempwidth; |
---|
260 | float val,minval; |
---|
261 | |
---|
262 | // Obj# |
---|
263 | tempwidth = int( log10(objectList[obj].getID()) + 1) + |
---|
264 | newset[NUM].getPrecision() + 1; |
---|
265 | for(int i=newset[NUM].getWidth();i<tempwidth;i++) newset[NUM].widen(); |
---|
266 | |
---|
267 | // Name |
---|
268 | tempwidth = objectList[obj].getName().size() + 1; |
---|
269 | for(int i=newset[NAME].getWidth();i<tempwidth;i++) newset[NAME].widen(); |
---|
270 | |
---|
271 | // X position |
---|
272 | val = objectList[obj].getXcentre() + objectList[obj].getXOffset(); |
---|
273 | if((val<1.)&&(val>0.)){ |
---|
274 | minval = pow(10, -1. * (newset[X].getPrecision()+1)); |
---|
275 | if(val < minval) newset[X].upPrec(); |
---|
276 | } |
---|
277 | tempwidth = int( log10(val) + 1) + newset[X].getPrecision() + 2; |
---|
278 | for(int i=newset[X].getWidth();i<tempwidth;i++) newset[X].widen(); |
---|
279 | // Y position |
---|
280 | val = objectList[obj].getYcentre() + objectList[obj].getYOffset(); |
---|
281 | if((val<1.)&&(val>0.)){ |
---|
282 | minval = pow(10, -1. * (newset[Y].getPrecision()+1)); |
---|
283 | if(val < minval) newset[Y].upPrec(); |
---|
284 | } |
---|
285 | tempwidth = int( log10(val) + 1) + newset[Y].getPrecision() + 2; |
---|
286 | for(int i=newset[Y].getWidth();i<tempwidth;i++) newset[Y].widen(); |
---|
287 | // Z position |
---|
288 | val = objectList[obj].getZcentre() + objectList[obj].getZOffset(); |
---|
289 | if((val<1.)&&(val>0.)){ |
---|
290 | minval = pow(10, -1. * (newset[Z].getPrecision()+1)); |
---|
291 | if((val>0.)&&(val < minval)) newset[Z].upPrec(); |
---|
292 | } |
---|
293 | tempwidth = int( log10(val) + 1) + newset[Z].getPrecision() + 2; |
---|
294 | for(int i=newset[Z].getWidth();i<tempwidth;i++) newset[Z].widen(); |
---|
295 | |
---|
296 | if(head.isWCS()){ |
---|
297 | // RA -- assign correct title. Check width but should be ok by definition |
---|
298 | tempstr = head.WCS().lngtyp; |
---|
299 | newset[RA].setName(tempstr); |
---|
300 | tempwidth = objectList[obj].getRAs().size() + 1; |
---|
301 | for(int i=newset[RA].getWidth();i<tempwidth;i++) newset[RA].widen(); |
---|
302 | |
---|
303 | // Dec -- assign correct title. Check width, should be ok by definition |
---|
304 | tempstr = head.WCS().lattyp; |
---|
305 | newset[DEC].setName(tempstr); |
---|
306 | tempwidth = objectList[obj].getDecs().size() + 1; |
---|
307 | for(int i=newset[DEC].getWidth();i<tempwidth;i++) newset[DEC].widen(); |
---|
308 | |
---|
309 | // RA decimal degrees -- assign correct title. Check width but should be OK |
---|
310 | tempstr = head.WCS().lngtyp; |
---|
311 | newset[RAJD].setName(tempstr); |
---|
312 | val = objectList[obj].getRA(); |
---|
313 | tempwidth = int( log10(fabs(val)) + 1) + newset[RAJD].getPrecision() + 2; |
---|
314 | for(int i=newset[RAJD].getWidth();i<tempwidth;i++) newset[RAJD].widen(); |
---|
315 | |
---|
316 | // Dec decimal degrees -- assign correct title. Check width but should be OK |
---|
317 | tempstr = head.WCS().lattyp; |
---|
318 | newset[DECJD].setName(tempstr); |
---|
319 | val = objectList[obj].getDec(); |
---|
320 | tempwidth = int( log10(fabs(val)) + 1) + newset[DECJD].getPrecision() + 2; |
---|
321 | for(int i=newset[DECJD].getWidth();i<tempwidth;i++) newset[DECJD].widen(); |
---|
322 | |
---|
323 | // Vel -- check width, title and units. |
---|
324 | //if(head.isSpecOK()){ |
---|
325 | if(head.canUseThirdAxis()){ |
---|
326 | if(head.WCS().restfrq == 0) // using frequency, not velocity |
---|
327 | newset[VEL].setName("FREQ"); |
---|
328 | if(head.getSpectralUnits().size()>0) |
---|
329 | newset[VEL].setUnits("[" + head.getSpectralUnits() + "]"); |
---|
330 | tempwidth = newset[VEL].getUnits().size() + 1; |
---|
331 | for(int i=newset[VEL].getWidth();i<tempwidth;i++) newset[VEL].widen(); |
---|
332 | |
---|
333 | val = objectList[obj].getVel(); |
---|
334 | if((fabs(val) < 1.)&&(val>0.)){ |
---|
335 | minval = pow(10, -1. * (newset[VEL].getPrecision()+1)); |
---|
336 | if(val < minval) newset[VEL].upPrec(); |
---|
337 | } |
---|
338 | tempwidth = int(log10(fabs(val)) + 1) + newset[VEL].getPrecision() + 2; |
---|
339 | if(val<0) tempwidth++; |
---|
340 | for(int i=newset[VEL].getWidth();i<tempwidth;i++) newset[VEL].widen(); |
---|
341 | } |
---|
342 | |
---|
343 | // w_RA -- check width & title. leave units for the moment. |
---|
344 | tempwidth = newset[RA].getUnits().size() + 1; |
---|
345 | for(int i=newset[RA].getWidth();i<tempwidth;i++) newset[RA].widen(); |
---|
346 | val = objectList[obj].getRAWidth(); |
---|
347 | if((fabs(val) < 1.)&&(val>0.)){ |
---|
348 | minval = pow(10, -1. * (newset[WRA].getPrecision()+1)); |
---|
349 | if(val < minval) newset[WRA].upPrec(); |
---|
350 | } |
---|
351 | tempwidth = int( log10(fabs(val)) + 1) + newset[WRA].getPrecision() + 2; |
---|
352 | if(val<0) tempwidth++; |
---|
353 | for(int i=newset[WRA].getWidth();i<tempwidth;i++) newset[WRA].widen(); |
---|
354 | |
---|
355 | // w_DEC -- check width & title. leave units for the moment. |
---|
356 | tempwidth = newset[DEC].getUnits().size() + 1; |
---|
357 | for(int i=newset[DEC].getWidth();i<tempwidth;i++) newset[DEC].widen(); |
---|
358 | val = objectList[obj].getDecWidth(); |
---|
359 | if((fabs(val) < 1.)&&(val>0.)){ |
---|
360 | minval = pow(10, -1. * (newset[WDEC].getPrecision()+1)); |
---|
361 | if(val < minval) newset[WDEC].upPrec(); |
---|
362 | } |
---|
363 | tempwidth = int( log10(fabs(val)) + 1) + newset[WDEC].getPrecision() + 2; |
---|
364 | if(val<0) tempwidth++; |
---|
365 | for(int i=newset[WDEC].getWidth();i<tempwidth;i++) newset[WDEC].widen(); |
---|
366 | |
---|
367 | // w_Vel -- check width, title and units. |
---|
368 | //if(head.isSpecOK()){ |
---|
369 | if(head.canUseThirdAxis()){ |
---|
370 | if(head.WCS().restfrq == 0) // using frequency, not velocity |
---|
371 | newset[WVEL].setName("w_FREQ"); |
---|
372 | if(head.getSpectralUnits().size()>0) |
---|
373 | newset[WVEL].setUnits("[" + head.getSpectralUnits() + "]"); |
---|
374 | tempwidth = newset[WVEL].getUnits().size() + 1; |
---|
375 | for(int i=newset[WVEL].getWidth();i<tempwidth;i++)newset[WVEL].widen(); |
---|
376 | val = objectList[obj].getVel(); |
---|
377 | if((fabs(val) < 1.)&&(val>0.)){ |
---|
378 | minval = pow(10, -1. * (newset[WVEL].getPrecision()+1)); |
---|
379 | if(val < minval) newset[WVEL].upPrec(); |
---|
380 | } |
---|
381 | tempwidth = int( log10(fabs(val)) + 1) + newset[WVEL].getPrecision() + 2; |
---|
382 | if(val<0) tempwidth++; |
---|
383 | for(int i=newset[WVEL].getWidth();i<tempwidth;i++) newset[WVEL].widen(); |
---|
384 | } |
---|
385 | |
---|
386 | // F_int -- check width & units |
---|
387 | if(head.getIntFluxUnits().size()>0) |
---|
388 | newset[FINT].setUnits("[" + head.getIntFluxUnits() + "]"); |
---|
389 | tempwidth = newset[FINT].getUnits().size() + 1; |
---|
390 | for(int i=newset[FINT].getWidth();i<tempwidth;i++) newset[FINT].widen(); |
---|
391 | val = objectList[obj].getIntegFlux(); |
---|
392 | if((fabs(val) < 1.)// &&(val>0.) |
---|
393 | ){ |
---|
394 | int minprec = int(fabs(log10(fabs(val))))+2; |
---|
395 | for(int i=newset[FINT].getPrecision();i<minprec;i++) newset[FINT].upPrec(); |
---|
396 | } |
---|
397 | tempwidth = int( log10(fabs(val)) + 1) + newset[FINT].getPrecision() + 2; |
---|
398 | if(val<0) tempwidth++; |
---|
399 | for(int i=newset[FINT].getWidth();i<tempwidth;i++) newset[FINT].widen(); |
---|
400 | |
---|
401 | } |
---|
402 | |
---|
403 | // F_tot |
---|
404 | newset[FTOT].setUnits("[" + head.getFluxUnits() + "]"); |
---|
405 | tempwidth = newset[FTOT].getUnits().size() + 1; |
---|
406 | for(int i=newset[FTOT].getWidth();i<tempwidth;i++) newset[FTOT].widen(); |
---|
407 | val = objectList[obj].getTotalFlux(); |
---|
408 | // std::cerr << val << "\n"; |
---|
409 | if((fabs(val) < 1.)// &&(val>0.) |
---|
410 | ){ |
---|
411 | int minprec = int(fabs(log10(fabs(val))))+2; |
---|
412 | for(int i=newset[FTOT].getPrecision();i<minprec;i++) newset[FTOT].upPrec(); |
---|
413 | } |
---|
414 | tempwidth = int( log10(fabs(val)) + 1) + newset[FTOT].getPrecision() + 2; |
---|
415 | if(val<0) tempwidth++; |
---|
416 | for(int i=newset[FTOT].getWidth();i<tempwidth;i++) newset[FTOT].widen(); |
---|
417 | |
---|
418 | // F_peak |
---|
419 | newset[FPEAK].setUnits("[" + head.getFluxUnits() + "]"); |
---|
420 | tempwidth = newset[FPEAK].getUnits().size() + 1; |
---|
421 | for(int i=newset[FPEAK].getWidth();i<tempwidth;i++) newset[FPEAK].widen(); |
---|
422 | val = objectList[obj].getPeakFlux(); |
---|
423 | if((fabs(val) < 1.)// &&(val>0.) |
---|
424 | ){ |
---|
425 | int minprec = int(fabs(log10(fabs(val))))+2; |
---|
426 | for(int i=newset[FPEAK].getPrecision();i<minprec;i++) newset[FPEAK].upPrec(); |
---|
427 | } |
---|
428 | tempwidth = int( log10(fabs(val)) + 1) + newset[FPEAK].getPrecision() + 2; |
---|
429 | if(val<0) tempwidth++; |
---|
430 | for(int i=newset[FPEAK].getWidth();i<tempwidth;i++) newset[FPEAK].widen(); |
---|
431 | |
---|
432 | // S/N_peak |
---|
433 | val = objectList[obj].getPeakSNR(); |
---|
434 | if((fabs(val) < 1.)&&(val>0.)){ |
---|
435 | minval = pow(10, -1. * (newset[SNRPEAK].getPrecision()+1)); |
---|
436 | if(val < minval) newset[SNRPEAK].upPrec(); |
---|
437 | } |
---|
438 | tempwidth = int( log10(fabs(val)) + 1) + newset[SNRPEAK].getPrecision() +2; |
---|
439 | if(val<0) tempwidth++; |
---|
440 | for(int i=newset[SNRPEAK].getWidth();i<tempwidth;i++) newset[SNRPEAK].widen(); |
---|
441 | |
---|
442 | // X1 position |
---|
443 | val = objectList[obj].getXmin() + objectList[obj].getXOffset(); |
---|
444 | tempwidth = int( log10(val) + 1) + newset[X1].getPrecision() + 1; |
---|
445 | for(int i=newset[X1].getWidth();i<tempwidth;i++) newset[X1].widen(); |
---|
446 | // X2 position |
---|
447 | val = objectList[obj].getXmax() + objectList[obj].getXOffset(); |
---|
448 | tempwidth = int( log10(val) + 1) + newset[X2].getPrecision() + 1; |
---|
449 | for(int i=newset[X2].getWidth();i<tempwidth;i++) newset[X2].widen(); |
---|
450 | // Y1 position |
---|
451 | val = objectList[obj].getYmin() + objectList[obj].getYOffset(); |
---|
452 | tempwidth = int( log10(val) + 1) + newset[Y1].getPrecision() + 1; |
---|
453 | for(int i=newset[Y1].getWidth();i<tempwidth;i++) newset[Y1].widen(); |
---|
454 | // Y2 position |
---|
455 | val = objectList[obj].getYmax() + objectList[obj].getYOffset(); |
---|
456 | tempwidth = int( log10(val) + 1) + newset[Y2].getPrecision() + 1; |
---|
457 | for(int i=newset[Y2].getWidth();i<tempwidth;i++) newset[Y2].widen(); |
---|
458 | // Z1 position |
---|
459 | val = objectList[obj].getZmin() + objectList[obj].getZOffset(); |
---|
460 | tempwidth = int( log10(val) + 1) + newset[Z1].getPrecision() + 1; |
---|
461 | for(int i=newset[Z1].getWidth();i<tempwidth;i++) newset[Z1].widen(); |
---|
462 | // Z2 position |
---|
463 | val = objectList[obj].getZmax() + objectList[obj].getZOffset(); |
---|
464 | tempwidth = int( log10(val) + 1) + newset[Z2].getPrecision() + 1; |
---|
465 | for(int i=newset[Z2].getWidth();i<tempwidth;i++) newset[Z2].widen(); |
---|
466 | |
---|
467 | // Npix |
---|
468 | tempwidth = int( log10(objectList[obj].getSize()) + 1) + |
---|
469 | newset[NPIX].getPrecision() + 1; |
---|
470 | for(int i=newset[NPIX].getWidth();i<tempwidth;i++) newset[NPIX].widen(); |
---|
471 | |
---|
472 | // average X position |
---|
473 | val = objectList[obj].getXAverage() + objectList[obj].getXOffset(); |
---|
474 | if((val<1.)&&(val>0.)){ |
---|
475 | minval = pow(10, -1. * (newset[XAV].getPrecision()+1)); |
---|
476 | if(val < minval) newset[XAV].upPrec(); |
---|
477 | } |
---|
478 | tempwidth = int( log10(val) + 1) + newset[XAV].getPrecision() + 2; |
---|
479 | for(int i=newset[XAV].getWidth();i<tempwidth;i++) newset[XAV].widen(); |
---|
480 | // average Y position |
---|
481 | val = objectList[obj].getYAverage() + objectList[obj].getYOffset(); |
---|
482 | if((val<1.)&&(val>0.)){ |
---|
483 | minval = pow(10, -1. * (newset[YAV].getPrecision()+1)); |
---|
484 | if(val < minval) newset[YAV].upPrec(); |
---|
485 | } |
---|
486 | tempwidth = int( log10(val) + 1) + newset[YAV].getPrecision() + 2; |
---|
487 | for(int i=newset[YAV].getWidth();i<tempwidth;i++) newset[YAV].widen(); |
---|
488 | // average Z position |
---|
489 | val = objectList[obj].getZAverage() + objectList[obj].getZOffset(); |
---|
490 | if((val<1.)&&(val>0.)){ |
---|
491 | minval = pow(10, -1. * (newset[ZAV].getPrecision()+1)); |
---|
492 | if((val>0.)&&(val < minval)) newset[ZAV].upPrec(); |
---|
493 | } |
---|
494 | tempwidth = int( log10(val) + 1) + newset[ZAV].getPrecision() + 2; |
---|
495 | for(int i=newset[ZAV].getWidth();i<tempwidth;i++) newset[ZAV].widen(); |
---|
496 | |
---|
497 | // X position of centroid |
---|
498 | val = objectList[obj].getXCentroid() + objectList[obj].getXOffset(); |
---|
499 | if((val<1.)&&(val>0.)){ |
---|
500 | minval = pow(10, -1. * (newset[XCENT].getPrecision()+1)); |
---|
501 | if(val < minval) newset[XCENT].upPrec(); |
---|
502 | } |
---|
503 | tempwidth = int( log10(val) + 1) + newset[XCENT].getPrecision() + 2; |
---|
504 | for(int i=newset[XCENT].getWidth();i<tempwidth;i++) newset[XCENT].widen(); |
---|
505 | // Y position of centroid |
---|
506 | val = objectList[obj].getYCentroid() + objectList[obj].getYOffset(); |
---|
507 | if((val<1.)&&(val>0.)){ |
---|
508 | minval = pow(10, -1. * (newset[YCENT].getPrecision()+1)); |
---|
509 | if(val < minval) newset[YCENT].upPrec(); |
---|
510 | } |
---|
511 | tempwidth = int( log10(val) + 1) + newset[YCENT].getPrecision() + 2; |
---|
512 | for(int i=newset[YCENT].getWidth();i<tempwidth;i++) newset[YCENT].widen(); |
---|
513 | // Z position of centroid |
---|
514 | val = objectList[obj].getZCentroid() + objectList[obj].getZOffset(); |
---|
515 | if((val<1.)&&(val>0.)){ |
---|
516 | minval = pow(10, -1. * (newset[ZCENT].getPrecision()+1)); |
---|
517 | if((val>0.)&&(val < minval)) newset[ZCENT].upPrec(); |
---|
518 | } |
---|
519 | tempwidth = int( log10(val) + 1) + newset[ZCENT].getPrecision() + 2; |
---|
520 | for(int i=newset[ZCENT].getWidth();i<tempwidth;i++) newset[ZCENT].widen(); |
---|
521 | |
---|
522 | // X position of peak flux |
---|
523 | val = objectList[obj].getXPeak() + objectList[obj].getXOffset(); |
---|
524 | if((val<1.)&&(val>0.)){ |
---|
525 | minval = pow(10, -1. * (newset[XPEAK].getPrecision()+1)); |
---|
526 | if(val < minval) newset[XPEAK].upPrec(); |
---|
527 | } |
---|
528 | tempwidth = int( log10(val) + 1) + newset[XPEAK].getPrecision() + 2; |
---|
529 | for(int i=newset[XPEAK].getWidth();i<tempwidth;i++) newset[XPEAK].widen(); |
---|
530 | // Y position of peak flux |
---|
531 | val = objectList[obj].getYPeak() + objectList[obj].getYOffset(); |
---|
532 | if((val<1.)&&(val>0.)){ |
---|
533 | minval = pow(10, -1. * (newset[YPEAK].getPrecision()+1)); |
---|
534 | if(val < minval) newset[YPEAK].upPrec(); |
---|
535 | } |
---|
536 | tempwidth = int( log10(val) + 1) + newset[YPEAK].getPrecision() + 2; |
---|
537 | for(int i=newset[YPEAK].getWidth();i<tempwidth;i++) newset[YPEAK].widen(); |
---|
538 | // Z position of peak flux |
---|
539 | val = objectList[obj].getZPeak() + objectList[obj].getZOffset(); |
---|
540 | if((val<1.)&&(val>0.)){ |
---|
541 | minval = pow(10, -1. * (newset[ZPEAK].getPrecision()+1)); |
---|
542 | if((val>0.)&&(val < minval)) newset[ZPEAK].upPrec(); |
---|
543 | } |
---|
544 | tempwidth = int( log10(val) + 1) + newset[ZPEAK].getPrecision() + 2; |
---|
545 | for(int i=newset[ZPEAK].getWidth();i<tempwidth;i++) newset[ZPEAK].widen(); |
---|
546 | } |
---|
547 | |
---|
548 | return newset; |
---|
549 | |
---|
550 | } |
---|
551 | |
---|
552 | std::vector<Col> getLogColSet(std::vector<Detection> &objectList, |
---|
553 | FitsHeader &head) |
---|
554 | { |
---|
555 | /** |
---|
556 | * A function that returns a std::vector of Col objects containing |
---|
557 | * information on the columns necessary for logfile output: |
---|
558 | * Obj#,X,Y,Z,F_tot,F_peak,X1,X2,Y1,Y2,Z1,Z2,Npix |
---|
559 | * |
---|
560 | * Each object in the provided objectList is checked to see if |
---|
561 | * it requires any column to be widened, or for that column to |
---|
562 | * have its precision increased. |
---|
563 | * |
---|
564 | * \param objectList A std::vector list of Detection objects that the columns need to fit. |
---|
565 | * \param head The FitsHeader object defining the World Coordinate System. |
---|
566 | * \return A std::vector list of Col definitions. |
---|
567 | */ |
---|
568 | |
---|
569 | std::vector<Col> newset,tempset; |
---|
570 | |
---|
571 | // set up the default columns: |
---|
572 | // get from FullColSet, and select only the ones we want. |
---|
573 | tempset = getFullColSet(objectList,head); |
---|
574 | |
---|
575 | newset.push_back( tempset[NUM] ); |
---|
576 | newset.push_back( tempset[X] ); |
---|
577 | newset.push_back( tempset[Y] ); |
---|
578 | newset.push_back( tempset[Z] ); |
---|
579 | newset.push_back( tempset[FTOT] ); |
---|
580 | newset.push_back( tempset[FPEAK] ); |
---|
581 | newset.push_back( tempset[SNRPEAK] ); |
---|
582 | newset.push_back( tempset[X1] ); |
---|
583 | newset.push_back( tempset[X2] ); |
---|
584 | newset.push_back( tempset[Y1] ); |
---|
585 | newset.push_back( tempset[Y2] ); |
---|
586 | newset.push_back( tempset[Z1] ); |
---|
587 | newset.push_back( tempset[Z2] ); |
---|
588 | newset.push_back( tempset[NPIX] ); |
---|
589 | |
---|
590 | return newset; |
---|
591 | |
---|
592 | } |
---|
593 | |
---|
594 | } |
---|
595 | |
---|
596 | } |
---|