source: trunk/src/Outputs/VOTableCatalogueWriter.cc @ 1273

Last change on this file since 1273 was 1273, checked in by MatthewWhiting, 11 years ago

Expanding the VOTable output so that it includes almost all of what is in the results file (not the string RA/DEC nor the Ftot/eFtot). Also adding in Nchan & Nspatpix, and renaming Npix to Nvoxels (and removing the units string [pix] for Nvoxels).

File size: 8.6 KB
Line 
1// -----------------------------------------------------------------------
2// VOTableCatalogueWriter.cc: Writing output catalogues to VOTable files
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 <duchamp/Outputs/VOTableCatalogueWriter.hh>
29#include <duchamp/Outputs/CatalogueWriter.hh>
30#include <duchamp/Outputs/FileCatalogueWriter.hh>
31#include <duchamp/Outputs/columns.hh>
32#include <duchamp/Detection/detection.hh>
33#include <duchamp/Utils/utils.hh>
34#include <duchamp/Utils/VOField.hh>
35#include <duchamp/Utils/VOParam.hh>
36#include <ios>
37#include <iostream>
38#include <fstream>
39
40namespace duchamp {
41
42   VOTableCatalogueWriter::VOTableCatalogueWriter():
43    FileCatalogueWriter()
44  {
45    this->itsTableName="";
46    this->itsTableDescription="";
47  }
48
49  VOTableCatalogueWriter::VOTableCatalogueWriter(std::string name):
50    FileCatalogueWriter(name)
51  {
52    this->itsTableName="";
53    this->itsTableDescription="";
54  }
55
56  VOTableCatalogueWriter::VOTableCatalogueWriter(const VOTableCatalogueWriter& other)
57  {
58    this->operator=(other);
59  }
60
61  VOTableCatalogueWriter& VOTableCatalogueWriter::operator= (const VOTableCatalogueWriter& other)
62  {
63    if(this==&other) return *this;
64    ((FileCatalogueWriter &) *this) = other;
65    this->itsTableName=other.itsTableName;
66    this->itsTableDescription=other.itsTableDescription;
67    return *this;
68  }
69 
70  void VOTableCatalogueWriter::writeHeader()
71  {
72    if(this->itsOpenFlag){
73
74      this->itsFileStream<<"<?xml version=\"1.0\"?>\n";
75      this->itsFileStream<<"<VOTABLE version=\"1.1\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
76      this->itsFileStream<<" xsi:noNamespaceSchemaLocation=\"http://www.ivoa.net/xml/VOTable/VOTable/v1.1\">\n";
77     
78      std::string ID,equinox,system;
79      if(std::string(this->itsHead->WCS().lngtyp)=="RA") { //J2000 or B1950
80        if(this->itsHead->WCS().equinox==2000.){
81          ID=equinox= "J2000";
82          system="eq_FK5";
83        }
84        else{
85          ID=equinox="B1950";
86          system="eq_FK4";
87        }
88        this->itsFileStream <<"  <COOSYS ID=\""<<ID<<"\" equinox=\""<<equinox<<"\" system=\""<<system<<"\"/>\n";
89      }
90      else{
91        ID=system="galactic";
92        this->itsFileStream <<"  <COOSYS ID=\""<<ID<<"\" system=\""<<system<<"\"/>\n";
93      }
94      this->itsFileStream<<"  <RESOURCE name=\"Duchamp Output\">\n";
95      this->itsFileStream<<"    <TABLE name=\""<<this->itsTableName<<"\">\n";
96      this->itsFileStream<<"      <DESCRIPTION>"<<this->itsTableDescription<<"</DESCRIPTION>\n";
97
98     
99    }
100  }
101
102  void VOTableCatalogueWriter::writeParameters()
103  {
104    if(this->itsOpenFlag){
105      std::vector<VOParam> paramList = this->itsParam->getVOParams();
106      for(std::vector<VOParam>::iterator param=paramList.begin();param<paramList.end();param++){
107        this->itsFileStream << "      ";
108        param->printParam(this->itsFileStream);
109      }   
110    }
111  }
112
113  void VOTableCatalogueWriter::writeStats()
114  {
115    if(this->itsOpenFlag){
116     
117      VOParam threshParam("thresholdActual","","float",this->itsStats->getThreshold(),0,this->itsHead->getFluxUnits());
118      this->itsFileStream << "      ";
119      threshParam.printParam(this->itsFileStream);
120      if(!this->itsParam->getFlagUserThreshold()){
121        VOParam middleParam("noiseMeanActual","","float",this->itsStats->getMiddle(),0,this->itsHead->getFluxUnits());
122        this->itsFileStream << "      ";
123        middleParam.printParam(this->itsFileStream);
124        VOParam spreadParam("noiseSpreadActual","","float",this->itsStats->getSpread(),0,this->itsHead->getFluxUnits());
125        this->itsFileStream << "      ";
126        spreadParam.printParam(this->itsFileStream);
127      }
128    }
129  }
130
131  void VOTableCatalogueWriter::writeTableHeader()
132  {
133    std::map<std::string,std::string> posUCDmap;
134    posUCDmap.insert(std::pair<std::string,std::string>("ra","pos.eq.ra"));
135    posUCDmap.insert(std::pair<std::string,std::string>("dec","pos.eq.dec"));
136    posUCDmap.insert(std::pair<std::string,std::string>("glon","pos.galactic.lng"));
137    posUCDmap.insert(std::pair<std::string,std::string>("glat","pos.galactic.lat"));
138    Catalogues::Column &raCol=this->itsColumnSpecification->column("RAJD");
139    std::string lngUCDbase = posUCDmap[makelower(raCol.getName())];
140    Catalogues::Column &decCol=this->itsColumnSpecification->column("DECJD");
141    std::string latUCDbase = posUCDmap[makelower(decCol.getName())];
142
143    std::map<std::string,std::string> specUCDmap;
144    specUCDmap.insert(std::pair<std::string,std::string>("VELO","phys.veloc;spect.dopplerVeloc"));
145    specUCDmap.insert(std::pair<std::string,std::string>("VOPT","phys.veloc;spect.dopplerVeloc.opt"));
146    specUCDmap.insert(std::pair<std::string,std::string>("VRAD","phys.veloc;spect.dopplerVeloc.rad"));
147    specUCDmap.insert(std::pair<std::string,std::string>("FREQ","em.freq"));
148    specUCDmap.insert(std::pair<std::string,std::string>("ENER","em.energy"));
149    specUCDmap.insert(std::pair<std::string,std::string>("WAVN","em.wavenumber"));
150    specUCDmap.insert(std::pair<std::string,std::string>("WAVE","em.wl"));
151    specUCDmap.insert(std::pair<std::string,std::string>("AWAV","em.wl"));
152    specUCDmap.insert(std::pair<std::string,std::string>("ZOPT","src.redshift"));
153    specUCDmap.insert(std::pair<std::string,std::string>("BETA","src.redshift; spect.dopplerVeloc"));
154    std::string specUCDbase = specUCDmap[this->itsColumnSpecification->column("VEL").getName()];
155
156    for(size_t i=0;i<this->itsColumnSpecification->size();i++){
157     
158      Catalogues::Column *col = this->itsColumnSpecification->pCol(i);
159      bool useFint=this->itsHead->isSpecOK();
160      if(col->doCol(Catalogues::VOTABLE,useFint)){
161        VOField field(*col);
162        if(col->type()=="RA")    field.setUCD(lngUCDbase);
163        if(col->type()=="RAJD")  field.setUCD(lngUCDbase+";meta.main");
164        if(col->type()=="WRA")   field.setUCD("phys.angSize;"+lngUCDbase);
165        if(col->type()=="DEC")   field.setUCD(latUCDbase);
166        if(col->type()=="DECJD") field.setUCD(latUCDbase+";meta.main");
167        if(col->type()=="WDEC")  field.setUCD("phys.angSize;"+latUCDbase);     
168        if(col->type()=="VEL")   field.setUCD(specUCDbase+";meta.main");
169        if(col->type()=="W20")   field.setUCD("spect.line.width.20;"+specUCDbase);
170        if(col->type()=="W50")   field.setUCD("spect.line.width.50;"+specUCDbase);
171        if(col->type()=="WVEL")  field.setUCD("spect.line.width.full;"+specUCDbase);
172        if(!this->itsHead->is2D()){
173          if(col->type()=="FINT") field.setUCD(field.UCD()+"spect.line.intensity");
174          if(col->type()=="FTOT") field.setUCD(field.UCD()+"spect.line.intensity");
175          if(col->type()=="FPEAK") field.setUCD(field.UCD()+"spect.line.intensity");
176        }
177        this->itsFileStream << "      ";
178        field.printField(this->itsFileStream);
179      }
180
181    }
182
183    this->itsFileStream<<"      <DATA>\n"
184                        <<"        <TABLEDATA>\n";
185
186  }
187
188  void VOTableCatalogueWriter::writeEntry(Detection *object)
189  {
190    this->itsFileStream.setf(std::ios::fixed); 
191
192    this->itsFileStream<<"        <TR>\n";
193    this->itsFileStream<<"          ";
194    for(size_t i=0;i<this->itsColumnSpecification->size();i++){
195      Catalogues::Column *col = this->itsColumnSpecification->pCol(i);
196      if(col->doCol(Catalogues::VOTABLE,this->itsHead->isSpecOK())){
197        this->itsFileStream<<"<TD>";
198        object->printTableEntry(this->itsFileStream, *col);
199        this->itsFileStream<<"</TD>";
200      }
201    }
202    this->itsFileStream<<"\n";
203    this->itsFileStream<<"        </TR>\n";
204
205  }
206
207  void VOTableCatalogueWriter::writeFooter()
208  {
209    this->itsFileStream<<"        </TABLEDATA>\n";
210    this->itsFileStream<<"      </DATA>\n";
211    this->itsFileStream<<"    </TABLE>\n";
212    this->itsFileStream<<"  </RESOURCE>\n";
213    this->itsFileStream<<"</VOTABLE>\n";
214    resetiosflags(std::ios::fixed);
215  }
216
217
218
219
220}
Note: See TracBrowser for help on using the repository browser.