source: trunk/src/Cubes/VOTable.cc @ 1062

Last change on this file since 1062 was 1061, checked in by MatthewWhiting, 12 years ago

Ticket #162 - A large refactoring of the Column-related code. Columns have moved to Outputs, and in a new namespace Catalogues. The interface has changed, using strings to record the type rather
than the enum. Also included is a new class CatalogueSpecification?, that is designed to hold a collection of Columns. This is not yet implemented - everything still uses the full & log column
vectors, and the code still passes the verification script.

File size: 7.2 KB
Line 
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/Outputs/columns.hh>
41#include <duchamp/Utils/utils.hh>
42#include <duchamp/Utils/VOParam.hh>
43#include <duchamp/Utils/VOField.hh>
44#include <duchamp/Outputs/VOTableCatalogueWriter.hh>
45
46namespace duchamp
47{
48 
49  void Cube::outputDetectionsVOTable()
50  {
51    VOTableCatalogueWriter writer(this->pars().getVOTFile());
52    writer.setup(this);
53    writer.setTableName("Detections");
54    writer.setTableDescription("Detected sources and parameters from running the Duchamp source finder.");
55    writer.openCatalogue();
56    writer.writeHeader();
57    writer.writeParameters();
58    writer.writeStats();
59    writer.writeTableHeader();
60    writer.writeEntries();
61    writer.writeFooter();
62    writer.closeCatalogue();
63
64  }
65
66  void Cube::outputDetectionsVOTable(std::ostream &stream)
67  {
68    /// @details
69    ///  Prints to a stream (provided) the list of detected objects in the cube
70    ///   in a VOTable format.
71    ///  Uses WCS information and assumes WCS parameters have been calculated for each
72    ///   detected object.
73    /// \param stream The output stream to send the text to.
74   
75    stream<<"<?xml version=\"1.0\"?>\n";
76    stream<<"<VOTABLE version=\"1.1\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
77    stream<<" xsi:noNamespaceSchemaLocation=\"http://www.ivoa.net/xml/VOTable/VOTable/v1.1\">\n";
78
79    std::string ID,equinox,system;
80    if(std::string(this->head.WCS().lngtyp)=="RA") { //J2000 or B1950
81      if(this->head.WCS().equinox==2000.){
82        ID=equinox= "J2000";
83        system="eq_FK5";
84      }
85      else{
86        ID=equinox="B1950";
87        system="eq_FK4";
88      }
89      stream <<"  <COOSYS ID=\""<<ID<<"\" equinox=\""<<equinox<<"\" system=\""<<system<<"\"/>\n";
90    }
91    else{
92      ID=system="galactic";
93      stream <<"  <COOSYS ID=\""<<ID<<"\" system=\""<<system<<"\"/>\n";
94    }
95    stream<<"  <RESOURCE name=\"Duchamp Output\">\n";
96    stream<<"    <TABLE name=\"Detections\">\n";
97    stream<<"      <DESCRIPTION>Detected sources and parameters from running the Duchamp source finder.</DESCRIPTION>\n";
98
99    // PARAM section -- parts that are not entry-specific ie. apply to whole dataset
100    std::vector<VOParam> paramList = this->par.getVOParams();
101    for(std::vector<VOParam>::iterator param=paramList.begin();param<paramList.end();param++){
102      stream << "      ";
103      param->printParam(stream);
104    }   
105
106
107    if(this->fullCols.size()==0) this->setupColumns();
108    // in case cols haven't been set -- need the column names
109
110    std::map<std::string,std::string> posUCDmap;
111    posUCDmap.insert(std::pair<std::string,std::string>("ra","pos.eq.ra"));
112    posUCDmap.insert(std::pair<std::string,std::string>("dec","pos.eq.dec"));
113    posUCDmap.insert(std::pair<std::string,std::string>("glon","pos.galactic.lng"));
114    posUCDmap.insert(std::pair<std::string,std::string>("glat","pos.galactic.lat"));
115    std::string lngUCDbase = posUCDmap[makelower(this->fullCols[Catalogues::RAJD].getName())];
116    std::string latUCDbase = posUCDmap[makelower(this->fullCols[Catalogues::DECJD].getName())];
117
118    std::map<std::string,std::string> specUCDmap;
119    specUCDmap.insert(std::pair<std::string,std::string>("VELO","phys.veloc;spect.dopplerVeloc"));
120    specUCDmap.insert(std::pair<std::string,std::string>("VOPT","phys.veloc;spect.dopplerVeloc.opt"));
121    specUCDmap.insert(std::pair<std::string,std::string>("VRAD","phys.veloc;spect.dopplerVeloc.rad"));
122    specUCDmap.insert(std::pair<std::string,std::string>("FREQ","em.freq"));
123    specUCDmap.insert(std::pair<std::string,std::string>("ENER","em.energy"));
124    specUCDmap.insert(std::pair<std::string,std::string>("WAVN","em.wavenumber"));
125    specUCDmap.insert(std::pair<std::string,std::string>("WAVE","em.wl"));
126    specUCDmap.insert(std::pair<std::string,std::string>("AWAV","em.wl"));
127    specUCDmap.insert(std::pair<std::string,std::string>("ZOPT","src.redshift"));
128    specUCDmap.insert(std::pair<std::string,std::string>("BETA","src.redshift; spect.dopplerVeloc"));
129    std::string specUCDbase = specUCDmap[this->fullCols[Catalogues::VEL].getName()];
130
131    std::vector<Catalogues::Column>::iterator col;
132    for(col=this->fullCols.begin();col<this->fullCols.end();col++){
133
134      if(col->doCol(Catalogues::VOTABLE,this->head.isSpecOK())){
135        // VOField field;
136        // field.define(*col);
137        VOField field(*col);
138        if(col->type()=="RAJD")  field.setUCD(lngUCDbase+";meta.main");
139        if(col->type()=="WRA")   field.setUCD("phys.angSize;"+lngUCDbase);
140        if(col->type()=="DECJD") field.setUCD(latUCDbase+";meta.main");
141        if(col->type()=="WDEC")  field.setUCD("phys.angSize;"+latUCDbase);     
142        if(col->type()=="VEL")   field.setUCD(specUCDbase+";meta.main");
143        if(col->type()=="W20")   field.setUCD("spect.line.width;"+specUCDbase);
144        if(col->type()=="W50")   field.setUCD("spect.line.width;"+specUCDbase);
145        if(col->type()=="WVEL")  field.setUCD("spect.line.width;"+specUCDbase);
146        stream << "      ";
147        field.printField(stream);
148      }
149
150    }
151
152    stream<<"      <DATA>\n"
153          <<"        <TABLEDATA>\n";
154
155    stream.setf(std::ios::fixed); 
156
157    std::vector<Detection>::iterator obj;
158    for(obj=this->objectList->begin();obj<this->objectList->end();obj++){
159
160      stream<<"        <TR>\n";
161      stream<<"          ";
162      std::vector<Catalogues::Column>::iterator col;
163      for(col=this->fullCols.begin();col<this->fullCols.end();col++){
164        if(col->doCol(Catalogues::VOTABLE,this->head.isSpecOK())){
165          stream<<"<TD>";
166          obj->printTableEntry(stream, *col);
167          stream<<"</TD>";
168        }
169      }
170      stream<<"\n";
171      stream<<"        </TR>\n";
172
173    }
174
175    stream<<"        </TABLEDATA>\n";
176    stream<<"      </DATA>\n";
177    stream<<"    </TABLE>\n";
178    stream<<"  </RESOURCE>\n";
179    stream<<"</VOTABLE>\n";
180    resetiosflags(std::ios::fixed);
181 
182  }
183
184
185
186
187}
Note: See TracBrowser for help on using the repository browser.