source: trunk/src/Detection/outputDetection.cc @ 367

Last change on this file since 367 was 367, checked in by MatthewWhiting, 17 years ago

Added a new function to plot moment map cutouts + summary information for each source in the case of there not being a spectral axis. This way you get a closeup look at each object when there aren't spectra to plot.

File size: 16.0 KB
Line 
1// -----------------------------------------------------------------------
2// outputDetection.cc: Different ways of printing inforamtion about
3//                     the Detections.
4// -----------------------------------------------------------------------
5// Copyright (C) 2006, Matthew Whiting, ATNF
6//
7// This program is free software; you can redistribute it and/or modify it
8// under the terms of the GNU General Public License as published by the
9// Free Software Foundation; either version 2 of the License, or (at your
10// option) any later version.
11//
12// Duchamp is distributed in the hope that it will be useful, but WITHOUT
13// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15// for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with Duchamp; if not, write to the Free Software Foundation,
19// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
20//
21// Correspondence concerning Duchamp may be directed to:
22//    Internet email: Matthew.Whiting [at] atnf.csiro.au
23//    Postal address: Dr. Matthew Whiting
24//                    Australia Telescope National Facility, CSIRO
25//                    PO Box 76
26//                    Epping NSW 1710
27//                    AUSTRALIA
28// -----------------------------------------------------------------------
29#include <iostream>
30#include <sstream>
31#include <fstream>
32#include <iomanip>
33#include <string>
34#include <vector>
35#include <duchamp.hh>
36#include <Detection/detection.hh>
37#include <Cubes/cubes.hh>
38#include <Utils/utils.hh>
39#include <Detection/columns.hh>
40#include <Utils/feedback.hh>
41
42using namespace Column;
43
44void Detection::outputDetectionTextHeader(std::ostream &stream,
45                                          std::vector<Column::Col> columns)
46{
47  /**
48   *  Prints to a stream the column headers to match the output
49   *  generated by outputDetectionText or outputDetectionTextWCS
50   *  The exact columns depend on the std::vector<Col>.
51   *
52   *  If the WCS is good, it will print the FINT column, otherwise the
53   *  FTOT column.
54   *
55   *  NOTE: It does not print out the 9 columns containing the three
56   *  different pixel centre options -- it stops after the FLAG
57   *  column.
58   *
59   * \param stream Where to print.
60   * \param columns The set of Columns::Col objects that define the
61   *                columns to be printed.
62   */
63
64  std::vector<Col> local = columns;
65  if(local.size()==Column::numColumns){
66    std::vector <Col>::iterator iter;
67    if(this->flagWCS)
68      iter = local.begin() + FTOT;
69    else
70      iter = local.begin() + FINT;
71    local.erase(iter);
72  }
73 
74  int size = local.size();
75  if(int(FLAG)<size) size = int(FLAG);
76
77  stream << std::setfill(' ');
78  for(int i=0;i<size;i++) local[i].printDash(stream);
79  stream << std::endl;
80  for(int i=0;i<size;i++) local[i].printTitle(stream);
81  stream << std::endl;
82  for(int i=0;i<size;i++) local[i].printUnits(stream);
83  stream << std::endl;
84  for(int i=0;i<size;i++) local[i].printDash(stream);
85  stream << std::endl;
86}
87//--------------------------------------------------------------------
88
89void Detection::outputDetectionTextWCS(std::ostream &stream,
90                                       std::vector<Column::Col> columns)
91{
92  /**
93   *  Prints to a stream the relevant details of a detected object,
94   *  including the WCS parameters, which need to have been
95   *  calculated.  If they have not (given by the isWCS() function),
96   *  then the WCS-related outputs are left blank.
97   *
98   *  Also, if the WCS is good, we print the FINT column, else the
99   *  FTOT column.
100   *
101   * \param stream Where to print.
102   * \param columns The set of Columns::Col objects that define the
103   *                columns to be printed.
104   */
105
106  if(columns.size()!=Column::numColumns){
107    std::stringstream errmsg;
108    errmsg << "columnSet used has wrong number of columns ("
109           << columns.size() << ")\nshould be "
110           << Column::numColumns << ".\n";
111    duchampError("outputDetectionTextWCS",errmsg.str());
112  }
113  else{
114    stream.setf(std::ios::fixed); 
115    columns[NUM].printEntry(stream,this->id);
116    columns[NAME].printEntry(stream,this->name);
117    columns[X].printEntry(stream,this->getXcentre() + this->xSubOffset);
118    columns[Y].printEntry(stream,this->getYcentre() + this->ySubOffset);
119    columns[Z].printEntry(stream,this->getZcentre() + this->zSubOffset);
120    if(this->flagWCS){
121      columns[RA].printEntry(stream,this->raS);
122      columns[DEC].printEntry(stream,this->decS);
123      if(this->specOK) columns[VEL].printEntry(stream,this->vel);
124      else columns[VEL].printEntry(stream,0.);
125      columns[WRA].printEntry(stream,this->raWidth);
126      columns[WDEC].printEntry(stream,this->decWidth);
127      if(this->specOK) columns[WVEL].printEntry(stream,this->velWidth);
128      else columns[WVEL].printEntry(stream,0.);
129    }
130    else for(int i=RA;i<=WVEL;i++) columns[i].printBlank(stream);
131    if(this->flagWCS)
132      columns[FINT].printEntry(stream,this->intFlux);
133    else
134      columns[FTOT].printEntry(stream,this->totalFlux);
135    columns[FPEAK].printEntry(stream,this->peakFlux);
136    columns[SNRPEAK].printEntry(stream,this->peakSNR);
137    columns[X1].printEntry(stream,this->getXmin() + this->xSubOffset);
138    columns[X2].printEntry(stream,this->getXmax() + this->xSubOffset);
139    columns[Y1].printEntry(stream,this->getYmin() + this->ySubOffset);
140    columns[Y2].printEntry(stream,this->getYmax() + this->ySubOffset);
141    columns[Z1].printEntry(stream,this->getZmin() + this->zSubOffset);
142    columns[Z2].printEntry(stream,this->getZmax() + this->zSubOffset);
143    columns[NPIX].printEntry(stream,int(this->pixelArray.getSize()));
144    columns[FLAG].printEntry(stream,this->flagText);
145    stream << std::endl;
146  }
147}
148//--------------------------------------------------------------------
149
150void Detection::outputDetectionText(std::ostream &stream,
151                                    std::vector<Column::Col> columns,
152                                    int idNumber)
153{
154  /**
155   *  Print to a stream the relevant details of a detected object.
156   *  This does not include any WCS parameters, only pixel positions & extent,
157   *    and flux info (FTOT, FPEAK, SNRPEAK).
158   *  Also prints a counter, provided as an input.
159   *
160   * \param stream Where to print.
161   * \param columns The set of Columns::Col objects that define the
162   *    columns to be printed.
163   * \param idNumber The number that acts as a counter in the first column.
164   */
165
166  if(columns.size()!=Column::numColumnsLog){
167    std::stringstream errmsg;
168    errmsg << "columnSet used has wrong number of columns ("
169           << columns.size() << ")\nshould be "
170           << Column::numColumnsLog <<".\n";
171    duchampError("outputDetectionText",errmsg.str());
172  }
173  else{
174   stream << std::setfill(' ');
175   stream.setf(std::ios::fixed); 
176   columns[lNUM].printEntry(stream,idNumber);
177   columns[lX].printEntry(stream,this->getXcentre() + this->xSubOffset);
178   columns[lY].printEntry(stream,this->getYcentre() + this->ySubOffset);
179   columns[lZ].printEntry(stream,this->getZcentre() + this->zSubOffset);
180   columns[lFTOT].printEntry(stream,this->totalFlux);
181   columns[lFPEAK].printEntry(stream,this->peakFlux);
182   columns[lSNRPEAK].printEntry(stream,this->peakSNR);
183   columns[lX1].printEntry(stream,this->getXmin() + this->xSubOffset);
184   columns[lX2].printEntry(stream,this->getXmax() + this->xSubOffset);
185   columns[lY1].printEntry(stream,this->getYmin() + this->ySubOffset);
186   columns[lY2].printEntry(stream,this->getYmax() + this->ySubOffset);
187   columns[lZ1].printEntry(stream,this->getZmin() + this->zSubOffset);
188   columns[lZ2].printEntry(stream,this->getZmax() + this->zSubOffset);
189   columns[lNPIX].printEntry(stream,this->pixelArray.getSize());
190   stream<<std::endl;
191  }
192}
193//--------------------------------------------------------------------
194
195void Detection::outputDetectionTextHeaderFull(std::ostream &stream,
196                                              std::vector<Column::Col> columns)
197{
198  /**
199   *  Prints to a stream the column headers to match the output
200   *  generated by outputDetectionText or outputDetectionTextWCS
201   *  The exact columns depend on the std::vector<Col>.
202   *
203   *  NOTE: It prints all columns, including all the different pixel
204   *  centre options and all FLUX columns.
205   *
206   * \param stream Where to print.
207   * \param columns The set of Columns::Col objects that define the
208   * columns to be printed.
209   */
210
211  stream << std::setfill(' ');
212  for(int i=0;i<columns.size();i++) columns[i].printDash(stream);
213  stream << std::endl;
214  for(int i=0;i<columns.size();i++) columns[i].printTitle(stream);
215  stream << std::endl;
216  for(int i=0;i<columns.size();i++) columns[i].printUnits(stream);
217  stream << std::endl;
218  for(int i=0;i<columns.size();i++) columns[i].printDash(stream);
219  stream << std::endl;
220}
221//--------------------------------------------------------------------
222
223void Detection::outputDetectionTextWCSFull(std::ostream &stream,
224                                           std::vector<Column::Col> columns)
225{
226  /**
227   *  Prints to a stream the relevant details of a detected object,
228   *  including the WCS parameters, which need to have been calculated.
229   *  If they have not (given by the isWCS() function), then the
230   *  WCS-related outputs are left blank.
231   *  This function prints all the different versions of the centre
232   *  pixel values, and all different flux quantities.
233   * \param stream Where to print.
234   * \param columns The set of Columns::Col objects that define the
235   * columns to be printed.
236   */
237
238  if(columns.size()!=Column::numColumns){
239    std::stringstream errmsg;
240    errmsg << "columnSet used has wrong number of columns ("
241           << columns.size() << ")\nshould be "
242           << Column::numColumns << ".\n";
243    duchampError("outputDetectionTextWCS",errmsg.str());
244  }
245  else{
246    stream.setf(std::ios::fixed); 
247    columns[NUM].printEntry(stream,this->id);
248    columns[NAME].printEntry(stream,this->name);
249    columns[X].printEntry(stream,this->getXcentre() + this->xSubOffset);
250    columns[Y].printEntry(stream,this->getYcentre() + this->ySubOffset);
251    columns[Z].printEntry(stream,this->getZcentre() + this->zSubOffset);
252    if(this->flagWCS){
253      columns[RA].printEntry(stream,this->raS);
254      columns[DEC].printEntry(stream,this->decS);
255      if(this->specOK) columns[VEL].printEntry(stream,this->vel);
256//       else printSpace(stream,columns[VEL].getWidth());
257      else columns[VEL].printEntry(stream,0.);
258      columns[WRA].printEntry(stream,this->raWidth);
259      columns[WDEC].printEntry(stream,this->decWidth);
260      if(this->specOK) columns[WVEL].printEntry(stream,this->velWidth);
261      else columns[WVEL].printEntry(stream,0.);
262    }
263    else for(int i=RA;i<=WVEL;i++) columns[i].printBlank(stream);
264    columns[FINT].printEntry(stream,this->intFlux);
265    columns[FTOT].printEntry(stream,this->totalFlux);
266    columns[FPEAK].printEntry(stream,this->peakFlux);
267    columns[SNRPEAK].printEntry(stream,this->peakSNR);
268    columns[X1].printEntry(stream,this->getXmin() + this->xSubOffset);
269    columns[X2].printEntry(stream,this->getXmax() + this->xSubOffset);
270    columns[Y1].printEntry(stream,this->getYmin() + this->ySubOffset);
271    columns[Y2].printEntry(stream,this->getYmax() + this->ySubOffset);
272    columns[Z1].printEntry(stream,this->getZmin() + this->zSubOffset);
273    columns[Z2].printEntry(stream,this->getZmax() + this->zSubOffset);
274    columns[NPIX].printEntry(stream,int(this->pixelArray.getSize()));
275    columns[FLAG].printEntry(stream,this->flagText);
276    columns[XAV].printEntry(stream,this->getXAverage() + this->xSubOffset);
277    columns[YAV].printEntry(stream,this->getYAverage() + this->ySubOffset);
278    columns[ZAV].printEntry(stream,this->getZAverage() + this->zSubOffset);
279    columns[XCENT].printEntry(stream,this->getXCentroid() + this->xSubOffset);
280    columns[YCENT].printEntry(stream,this->getYCentroid() + this->ySubOffset);
281    columns[ZCENT].printEntry(stream,this->getZCentroid() + this->zSubOffset);
282    columns[XPEAK].printEntry(stream,this->getXPeak() + this->xSubOffset);
283    columns[YPEAK].printEntry(stream,this->getYPeak() + this->ySubOffset);
284    columns[ZPEAK].printEntry(stream,this->getZPeak() + this->zSubOffset);
285    stream << std::endl;
286  }
287}
288//--------------------------------------------------------------------
289
290std::string Detection::outputLabelWCS()
291{
292  /**
293   *  Prints to a std::string the WCS position and velocity
294   *  information of the Detection, as well as the ID number and any
295   *  flags.
296   *  Assumes the WCS parameters of the object have been calculated.
297   *  If they have not (given by the isWCS() function), then the
298   *  WCS-related outputs are left blank.
299   *  Returns the string.
300   */
301  std::stringstream ss;
302  ss << "#" << std::setfill('0') << std::setw(3) << this->id << ": ";
303  ss << this->name ;
304  if(this->getFlagText()!="")
305    ss << " [" << this->getFlagText() << "]   ";
306  else ss<< "   ";
307  ss << std::setfill(' ');
308  ss << this->raS << ", ";
309  ss << this->decS;
310  if(this->specOK){
311    ss << std::setprecision(this->velPrec);
312    ss.setf(std::ios::fixed);
313    ss << ", " << this->vel << " " << this->specUnits;
314  }
315
316  return ss.str();
317
318}
319//--------------------------------------------------------------------
320
321std::string Detection::outputLabelFluxes()
322{
323  /**
324   *  Prints to a std::string the fluxes of the object, both
325   *  integrated/total and peak, as well as the peak S/N value.
326   *  Assumes the WCS parameters of the object have been calculated.
327   *  If they have not (given by the isWCS() function), then the ID
328   *  number and the total/peak/SNR values are returned.
329   *  /return The string.
330   */
331
332  std::stringstream ss;
333  ss.setf(std::ios::fixed);
334  if(this->flagWCS){
335    ss << std::setprecision(this->fintPrec);
336    ss << "F\\dint\\u=" << this->intFlux << " " << this->intFluxUnits;
337    ss << std::setprecision(this->fpeakPrec);
338    ss << ", F\\dpeak\\u=" << this->peakFlux << " " << this->fluxUnits;
339    ss << std::setprecision(this->snrPrec);
340    ss << ", S/N\\dmax\\u=" << this->peakSNR;
341  }
342  else{
343    ss << "#" << std::setfill('0') << std::setw(3) << this->id << ": ";
344    ss << std::setprecision(this->fintPrec);
345    ss << "F\\dtot\\u=" << this->totalFlux << this->fluxUnits;
346    ss << std::setprecision(this->fpeakPrec);
347    ss << ", F\\dpeak\\u=" << this->peakFlux << this->fluxUnits;
348    ss << std::setprecision(this->snrPrec);
349    ss << ", S/N\\dmax\\u=" << this->peakSNR;
350  }
351  std::string output = ss.str();
352
353  return output;
354}
355//--------------------------------------------------------------------
356
357std::string Detection::outputLabelWidths()
358{
359  /**
360   *  Prints to a std::string the widths of the object in position
361   *  and velocity.
362   *  Assumes the WCS parameters of the object have been calculated.
363   *  If they have not (given by the isWCS() function), then a string of
364   *   length 0 is returned.
365   *  \returns The string.
366   */
367
368  std::string output;
369  if(this->flagWCS){
370    std::stringstream ss;
371    ss.setf(std::ios::fixed);
372    ss << std::setprecision(this->posPrec);
373    ss << "w_"          << this->lngtype  <<"="    << this->raWidth;
374    ss << ", w_"        << this->lattype  <<"="    << this->decWidth;
375    if(this->specOK){
376      ss << std::setprecision(this->velPrec);
377      ss << ", w_Vel="    << this->velWidth << " " << this->specUnits;
378    }
379    output = ss.str();
380  }
381  else output = this->outputLabelFluxes();
382
383  return output;
384}
385//--------------------------------------------------------------------
386
387std::string Detection::outputLabelPix()
388{
389  /**
390   *  Prints to a std::string the pixel centres and extents of a
391   *  detected object.  Returns the string.
392   */
393
394  std::stringstream ss;
395  ss.setf(std::ios::fixed);
396  ss << "Centre: ";
397  ss << std::setprecision(this->xyzPrec) << std::setfill(' ');
398  ss <<"("       << this->getXcentre() + this->xSubOffset;
399  ss <<", "      << this->getYcentre() + this->ySubOffset;
400  ss <<", "      << this->getZcentre() + this->zSubOffset << ")";
401  ss <<", Size: "<< this->pixelArray.getSize() << " voxels,  ";
402  ss <<"Range: [";
403  ss <<             this->getXmin() + this->xSubOffset
404     <<":"       << this->getXmax() + this->xSubOffset;
405  ss <<", "      << this->getYmin() + this->ySubOffset
406     <<":"       << this->getYmax() + this->ySubOffset;
407  if(this->specOK){
408    ss <<", "      << this->getZmin() + this->zSubOffset
409       <<":"       << this->getZmax() + this->zSubOffset;
410  }
411  ss<< "]";
412 
413  return ss.str();
414}
415
416
Note: See TracBrowser for help on using the repository browser.