source: trunk/src/Outputs/VOTableCatalogueWriter.cc

Last change on this file was 1424, checked in by MatthewWhiting, 7 years ago

Applying patch from ASKAPsoft development, where we allow more
flexibility in specifying the RESOURCE and TABLE names for the VOTable
output.
ASKAPSDP revision r6758

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