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 | std::string ID,equinox,system; |
---|
62 | if(std::string(this->head.WCS().lngtyp)=="RA") { //J2000 or B1950 |
---|
63 | if(this->head.WCS().equinox==2000.){ |
---|
64 | ID=equinox= "J2000"; |
---|
65 | system="eq_FK5"; |
---|
66 | } |
---|
67 | else{ |
---|
68 | ID=equinox="B1950"; |
---|
69 | system="eq_FK4"; |
---|
70 | } |
---|
71 | stream <<" <COOSYS ID=\""<<ID<<"\" equinox=\""<<equinox<<"\" system=\""<<system<<"\"/>\n"; |
---|
72 | } |
---|
73 | else{ |
---|
74 | ID=system="galactic"; |
---|
75 | stream <<" <COOSYS ID=\""<<ID<<"\" system=\""<<system<<"\"/>\n"; |
---|
76 | } |
---|
77 | stream<<" <RESOURCE name=\"Duchamp Output\">\n"; |
---|
78 | stream<<" <TABLE name=\"Detections\">\n"; |
---|
79 | stream<<" <DESCRIPTION>Detected sources and parameters from running the Duchamp source finder.</DESCRIPTION>\n"; |
---|
80 | |
---|
81 | // PARAM section -- parts that are not entry-specific ie. apply to whole dataset |
---|
82 | std::vector<VOParam> paramList = this->par.getVOParams(); |
---|
83 | for(std::vector<VOParam>::iterator param=paramList.begin();param<paramList.end();param++){ |
---|
84 | stream << " "; |
---|
85 | param->printParam(stream); |
---|
86 | } |
---|
87 | |
---|
88 | |
---|
89 | if(this->fullCols.size()==0) this->setupColumns(); |
---|
90 | // in case cols haven't been set -- need the column names |
---|
91 | |
---|
92 | std::string posUCD[4]; |
---|
93 | if(makelower(this->fullCols[Column::RAJD].getName())=="ra"){ |
---|
94 | posUCD[0] = "pos.eq.ra;meta.main"; |
---|
95 | posUCD[2] = "phys.angSize;pos.eq.ra"; |
---|
96 | } |
---|
97 | else{ |
---|
98 | posUCD[0] = "pos.galactic.lat;meta.main"; |
---|
99 | posUCD[2] = "phys.angSize;pos.galactic.lat"; |
---|
100 | } |
---|
101 | if(makelower(this->fullCols[Column::DECJD].getName())=="dec"){ |
---|
102 | posUCD[1] = "pos.eq.dec;meta.main"; |
---|
103 | posUCD[3] = "phys.angSize;pos.eq.dec"; |
---|
104 | } |
---|
105 | else{ |
---|
106 | posUCD[1] = "pos.galactic.lon;meta.main"; |
---|
107 | posUCD[3] = "phys.angSize;pos.galactic.lon"; |
---|
108 | } |
---|
109 | |
---|
110 | std::vector<Column::Col>::iterator col; |
---|
111 | for(col=this->fullCols.begin();col<this->fullCols.end();col++){ |
---|
112 | |
---|
113 | if(col->doCol("votable",this->head.isSpecOK())){ |
---|
114 | // VOField field; |
---|
115 | // field.define(*col); |
---|
116 | VOField field(*col); |
---|
117 | if(col->getType()==Column::RAJD) field.setUCD(posUCD[0]); |
---|
118 | if(col->getType()==Column::WRA) field.setUCD(posUCD[1]); |
---|
119 | if(col->getType()==Column::DECJD) field.setUCD(posUCD[2]); |
---|
120 | if(col->getType()==Column::WDEC) field.setUCD(posUCD[3]); |
---|
121 | stream << " "; |
---|
122 | field.printField(stream); |
---|
123 | } |
---|
124 | |
---|
125 | } |
---|
126 | |
---|
127 | stream<<" <DATA>\n" |
---|
128 | <<" <TABLEDATA>\n"; |
---|
129 | |
---|
130 | stream.setf(std::ios::fixed); |
---|
131 | |
---|
132 | std::vector<Detection>::iterator obj; |
---|
133 | for(obj=this->objectList->begin();obj<this->objectList->end();obj++){ |
---|
134 | |
---|
135 | stream<<" <TR>\n"; |
---|
136 | stream<<" "; |
---|
137 | std::vector<Column::Col>::iterator col; |
---|
138 | for(col=this->fullCols.begin();col<this->fullCols.end();col++){ |
---|
139 | if(col->doCol("votable",this->head.isSpecOK())){ |
---|
140 | stream<<"<TD>"; |
---|
141 | obj->printTableEntry(stream, *col); |
---|
142 | stream<<"</TD>"; |
---|
143 | } |
---|
144 | } |
---|
145 | stream<<"\n"; |
---|
146 | stream<<" </TR>\n"; |
---|
147 | |
---|
148 | } |
---|
149 | |
---|
150 | stream<<" </TABLEDATA>\n"; |
---|
151 | stream<<" </DATA>\n"; |
---|
152 | stream<<" </TABLE>\n"; |
---|
153 | stream<<" </RESOURCE>\n"; |
---|
154 | stream<<"</VOTABLE>\n"; |
---|
155 | resetiosflags(std::ios::fixed); |
---|
156 | |
---|
157 | } |
---|
158 | |
---|
159 | |
---|
160 | |
---|
161 | |
---|
162 | } |
---|