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