1 | // ----------------------------------------------------------------------- |
---|
2 | // VOTable.cc: Output of the detected objects to a VOTable |
---|
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 | |
---|
29 | #include <iostream> |
---|
30 | #include <sstream> |
---|
31 | #include <fstream> |
---|
32 | #include <iomanip> |
---|
33 | #include <string> |
---|
34 | #include <vector> |
---|
35 | #include <time.h> |
---|
36 | #include <duchamp/param.hh> |
---|
37 | #include <duchamp/fitsHeader.hh> |
---|
38 | #include <duchamp/Cubes/cubes.hh> |
---|
39 | #include <duchamp/Detection/detection.hh> |
---|
40 | #include <duchamp/Detection/columns.hh> |
---|
41 | #include <duchamp/Utils/utils.hh> |
---|
42 | #include <duchamp/Utils/VOParam.hh> |
---|
43 | #include <duchamp/Utils/VOField.hh> |
---|
44 | |
---|
45 | namespace duchamp |
---|
46 | { |
---|
47 | |
---|
48 | void Cube::outputDetectionsVOTable(std::ostream &stream) |
---|
49 | { |
---|
50 | /// @details |
---|
51 | /// Prints to a stream (provided) the list of detected objects in the cube |
---|
52 | /// in a VOTable format. |
---|
53 | /// Uses WCS information and assumes WCS parameters have been calculated for each |
---|
54 | /// detected object. |
---|
55 | /// \param stream The output stream to send the text to. |
---|
56 | |
---|
57 | stream<<"<?xml version=\"1.0\"?>\n"; |
---|
58 | stream<<"<VOTABLE version=\"1.1\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"; |
---|
59 | stream<<" xsi:noNamespaceSchemaLocation=\"http://www.ivoa.net/xml/VOTable/VOTable/v1.1\">\n"; |
---|
60 | |
---|
61 | stream<<" <COOSYS ID=\"J2000\" equinox=\"J2000.\" epoch=\"J2000.\" system=\"eq_FK5\"/>\n"; |
---|
62 | stream<<" <RESOURCE name=\"Duchamp Output\">\n"; |
---|
63 | stream<<" <TABLE name=\"Detections\">\n"; |
---|
64 | stream<<" <DESCRIPTION>Detected sources and parameters from running the Duchamp source finder.</DESCRIPTION>\n"; |
---|
65 | |
---|
66 | // PARAM section -- parts that are not entry-specific ie. apply to whole dataset |
---|
67 | std::vector<VOParam> paramList = this->par.getVOParams(); |
---|
68 | for(std::vector<VOParam>::iterator param=paramList.begin();param<paramList.end();param++){ |
---|
69 | stream << " "; |
---|
70 | param->printParam(stream); |
---|
71 | } |
---|
72 | |
---|
73 | |
---|
74 | if(this->fullCols.size()==0) this->setupColumns(); |
---|
75 | // in case cols haven't been set -- need the column names |
---|
76 | |
---|
77 | std::string posUCD[4]; |
---|
78 | if(makelower(this->fullCols[Column::RAJD].getName())=="ra"){ |
---|
79 | posUCD[0] = "pos.eq.ra;meta.main"; |
---|
80 | posUCD[2] = "phys.angSize;pos.eq.ra"; |
---|
81 | } |
---|
82 | else{ |
---|
83 | posUCD[0] = "pos.galactic.lat;meta.main"; |
---|
84 | posUCD[2] = "phys.angSize;pos.galactic.lat"; |
---|
85 | } |
---|
86 | if(makelower(this->fullCols[Column::DECJD].getName())=="dec"){ |
---|
87 | posUCD[1] = "pos.eq.dec;meta.main"; |
---|
88 | posUCD[3] = "phys.angSize;pos.eq.dec"; |
---|
89 | } |
---|
90 | else{ |
---|
91 | posUCD[1] = "pos.galactic.lon;meta.main"; |
---|
92 | posUCD[3] = "phys.angSize;pos.galactic.lon"; |
---|
93 | } |
---|
94 | |
---|
95 | std::vector<Column::Col>::iterator col; |
---|
96 | for(col=this->fullCols.begin();col<this->fullCols.end();col++){ |
---|
97 | |
---|
98 | if(col->doCol("votable",this->head.isSpecOK())){ |
---|
99 | // VOField field; |
---|
100 | // field.define(*col); |
---|
101 | VOField field(*col); |
---|
102 | if(col->getType()==Column::RAJD) field.setUCD(posUCD[0]); |
---|
103 | if(col->getType()==Column::WRA) field.setUCD(posUCD[1]); |
---|
104 | if(col->getType()==Column::DECJD) field.setUCD(posUCD[2]); |
---|
105 | if(col->getType()==Column::WDEC) field.setUCD(posUCD[3]); |
---|
106 | stream << " "; |
---|
107 | field.printField(stream); |
---|
108 | } |
---|
109 | |
---|
110 | } |
---|
111 | |
---|
112 | stream<<" <DATA>\n" |
---|
113 | <<" <TABLEDATA>\n"; |
---|
114 | |
---|
115 | stream.setf(std::ios::fixed); |
---|
116 | |
---|
117 | std::vector<Detection>::iterator obj; |
---|
118 | for(obj=this->objectList->begin();obj<this->objectList->end();obj++){ |
---|
119 | |
---|
120 | stream<<" <TR>\n"; |
---|
121 | stream<<" "; |
---|
122 | std::vector<Column::Col>::iterator col; |
---|
123 | for(col=this->fullCols.begin();col<this->fullCols.end();col++){ |
---|
124 | if(col->doCol("votable",this->head.isSpecOK())){ |
---|
125 | stream<<"<TD>"; |
---|
126 | obj->printTableEntry(stream, *col); |
---|
127 | stream<<"</TD>"; |
---|
128 | } |
---|
129 | } |
---|
130 | stream<<"\n"; |
---|
131 | stream<<" </TR>\n"; |
---|
132 | |
---|
133 | } |
---|
134 | |
---|
135 | stream<<" </TABLEDATA>\n"; |
---|
136 | stream<<" </DATA>\n"; |
---|
137 | stream<<" </TABLE>\n"; |
---|
138 | stream<<" </RESOURCE>\n"; |
---|
139 | stream<<"</VOTABLE>\n"; |
---|
140 | resetiosflags(std::ios::fixed); |
---|
141 | |
---|
142 | } |
---|
143 | |
---|
144 | |
---|
145 | |
---|
146 | |
---|
147 | } |
---|