1 | #include <iostream> |
---|
2 | #include <sstream> |
---|
3 | #include <fstream> |
---|
4 | #include <iomanip> |
---|
5 | #include <string> |
---|
6 | #include <Cubes/cubes.hh> |
---|
7 | #include <Utils/utils.hh> |
---|
8 | |
---|
9 | //using std::ofstream; |
---|
10 | using std::endl; |
---|
11 | using std::setw; |
---|
12 | using std::setprecision; |
---|
13 | |
---|
14 | void Cube::outputDetectionsKarma(std::ostream &stream) |
---|
15 | { |
---|
16 | /** |
---|
17 | * outputDetectionsKarma |
---|
18 | * Prints to a stream (provided) the list of detected objects in the cube |
---|
19 | * in the format of an annotation file for the Karma suite of programs. |
---|
20 | * Annotation file draws a box enclosing the detection, and writes the ID number |
---|
21 | * of the detection to the right of the box. |
---|
22 | */ |
---|
23 | |
---|
24 | stream << "# Duchamp Source Finder results for cube " << this->par.getImageFile() << endl; |
---|
25 | stream << "COLOR RED" << endl; |
---|
26 | stream << "COORD W" << endl; |
---|
27 | for(int i=0;i<this->objectList.size();i++){ |
---|
28 | float radius = this->objectList[i].getRAWidth()/120.; |
---|
29 | if(this->objectList[i].getDecWidth()/120.>radius) |
---|
30 | radius = this->objectList[i].getDecWidth()/120.; |
---|
31 | stream << "CIRCLE " |
---|
32 | << this->objectList[i].getRA() << " " |
---|
33 | << this->objectList[i].getDec() << " " |
---|
34 | << radius << endl; |
---|
35 | stream << "TEXT " |
---|
36 | << this->objectList[i].getRA() << " " |
---|
37 | << this->objectList[i].getDec() << " " |
---|
38 | << this->objectList[i].getID() << endl; |
---|
39 | } |
---|
40 | |
---|
41 | } |
---|
42 | |
---|
43 | void Cube::outputDetectionsVOTable(std::ostream &stream) |
---|
44 | { |
---|
45 | /** |
---|
46 | * outputDetectionsVOTable |
---|
47 | * Prints to a stream (provided) the list of detected objects in the cube |
---|
48 | * in a VOTable format. |
---|
49 | * Uses WCS information and assumes WCS parameters have been calculated for each |
---|
50 | * detected object. |
---|
51 | * If they have not (given by the isWCS() function), then those objects are not written... |
---|
52 | */ |
---|
53 | |
---|
54 | stream<<"<?xml version=\"1.0\"?>"<<endl; |
---|
55 | stream<<"<VOTABLE version=\"1.1\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""<<endl; |
---|
56 | stream<<" xsi:noNamespaceSchemaLocation=\"http://www.ivoa.net/xml/VOTable/VOTable/v1.1\">"<<endl; |
---|
57 | |
---|
58 | stream<<" <COOSYS ID=\"J2000\" equinox=\"J2000.\" epoch=\"J2000.\" system=\"eq_FK5\"/>"<<endl; |
---|
59 | stream<<" <RESOURCE name=\"Duchamp Output\">"<<endl; |
---|
60 | stream<<" <TABLE name=\"Detections\">"<<endl; |
---|
61 | stream<<" <DESCRIPTION>Detected sources and parameters from running the Duchamp source finder.</DESCRIPTION>"<<endl; |
---|
62 | |
---|
63 | // PARAM section -- parts that are not entry-specific ie. apply to whole dataset |
---|
64 | stream<<" <PARAM name=\"FITS file\" datatype=\"char\" ucd=\"meta.file;meta.fits\" value=\"" << this->par.getImageFile() << "\"/>"<<endl; |
---|
65 | |
---|
66 | // FIELD section -- names, titles and info for each column. |
---|
67 | stream<<" <FIELD name=\"ID\" ID=\"col1\" ucd=\"meta.id\" datatype=\"int\" width=\"4\"/>"<<endl; |
---|
68 | stream<<" <FIELD name=\"Name\" ID=\"col2\" ucd=\"meta.id;meta.main\" datatype=\"char\" arraysize=\"14\"/>"<<endl; |
---|
69 | stream<<" <FIELD name=\"RA\" ID=\"col3\" ucd=\"pos.eq.ra;meta.main\" ref=\"J2000\" datatype=\"float\" width=\"10\" precision=\"6\" unit=\"deg\"/>"<<endl; |
---|
70 | stream<<" <FIELD name=\"Dec\" ID=\"col4\" ucd=\"pos.eq.dec;meta.main\" ref=\"J2000\" datatype=\"float\" width=\"10\" precision=\"6\" unit=\"deg\"/>"<<endl; |
---|
71 | stream<<" <FIELD name=\"w_RA\" ID=\"col3\" ucd=\"phys.angSize;pos.eq.ra\" ref=\"J2000\" datatype=\"float\" width=\"7\" precision=\"2\" unit=\"arcmin\"/>"<<endl; |
---|
72 | stream<<" <FIELD name=\"w_Dec\" ID=\"col4\" ucd=\"phys.angSize;pos.eq.dec\" ref=\"J2000\" datatype=\"float\" width=\"7\" precision=\"2\" unit=\"arcmin\"/>"<<endl; |
---|
73 | stream<<" <FIELD name=\"Vel\" ID=\"col4\" ucd=\"phys.veloc;src.dopplerVeloc\" datatype=\"float\" width=\"9\" precision=\"3\" unit=\"km/s\"/>"<<endl; |
---|
74 | stream<<" <FIELD name=\"w_Vel\" ID=\"col4\" ucd=\"phys.veloc;src.dopplerVeloc;spect.line.width\" datatype=\"float\" width=\"8\" precision=\"3\" unit=\"km/s\"/>"<<endl; |
---|
75 | stream<<" <FIELD name=\"Integrated_Flux\" ID=\"col4\" ucd=\"phys.flux;spect.line.intensity\" datatype=\"float\" width=\"10\" precision=\"4\" unit=\"km/s\"/>"<<endl; |
---|
76 | |
---|
77 | |
---|
78 | stream<<" <DATA>"<<endl |
---|
79 | <<" <TABLEDATA>"<<endl; |
---|
80 | |
---|
81 | stream.setf(std::ios::fixed); |
---|
82 | for(int i=0;i<this->objectList.size();i++){ |
---|
83 | if(this->objectList[i].isWCS()){ |
---|
84 | stream<<" <TR>"<<endl; |
---|
85 | stream<<" <TD>"<<setw(4)<<i+1<<"</TD>"; |
---|
86 | stream<<"<TD>" << setw(14) << this->objectList[i].getName() <<"</TD>"; |
---|
87 | stream<<setprecision(6); |
---|
88 | stream<<"<TD>" << setw(10) << this->objectList[i].getRA() <<"</TD>"; |
---|
89 | stream<<"<TD>" << setw(10) << this->objectList[i].getDec() <<"</TD>"; |
---|
90 | stream<<setprecision(2); |
---|
91 | stream<<"<TD>" << setw(7) << this->objectList[i].getRAWidth() <<"</TD>"; |
---|
92 | stream<<"<TD>" << setw(7) << this->objectList[i].getDecWidth() <<"</TD>"; |
---|
93 | stream<<setprecision(3); |
---|
94 | stream<<"<TD>" << setw(9) << this->objectList[i].getVel() <<"</TD>"; |
---|
95 | stream<<"<TD>" << setw(8) << this->objectList[i].getVelWidth() <<"</TD>"; |
---|
96 | stream<<setprecision(3); |
---|
97 | stream<<"<TD>" << setw(10) << this->objectList[i].getIntegFlux() <<"</TD>"; |
---|
98 | |
---|
99 | stream<<endl; |
---|
100 | stream<<" </TR>"<<endl; |
---|
101 | } |
---|
102 | } |
---|
103 | stream<<" </TABLEDATA>"<<endl; |
---|
104 | stream<<" </DATA>"<<endl; |
---|
105 | stream<<" </TABLE>"<<endl; |
---|
106 | stream<<" </RESOURCE>"<<endl; |
---|
107 | stream<<"</VOTABLE>"<<endl; |
---|
108 | resetiosflags(std::ios::fixed); |
---|
109 | |
---|
110 | } |
---|
111 | |
---|
112 | |
---|
113 | void Cube::outputDetectionList() |
---|
114 | { |
---|
115 | /** |
---|
116 | * outputDetectionList |
---|
117 | * A front-end to writing the full list of detected objects to a results file and to cout. |
---|
118 | * Uses outputDetectionTextWCS for each objects. |
---|
119 | * Leaves the testing of whether the WCS parameters for each object have been calculated |
---|
120 | * to outputDetectionTextWCS. |
---|
121 | */ |
---|
122 | |
---|
123 | int count=0; |
---|
124 | int flag; |
---|
125 | std::ofstream output(this->par.getOutFile().c_str()); |
---|
126 | output<<"Results of the Duchamp source finder: "; |
---|
127 | output.close(); |
---|
128 | string syscall = "date >> " + this->par.getOutFile(); |
---|
129 | system(syscall.c_str()); |
---|
130 | output.open(this->par.getOutFile().c_str(),std::ios::app); |
---|
131 | this->showParam(output); |
---|
132 | output<<"Total number of detections = "<<this->objectList.size()<<endl; |
---|
133 | output<<"--------------------"<<endl; |
---|
134 | if(flag=wcsset(wcs)){ |
---|
135 | std::cerr<<"outputDetectionList():: WCSSET failed! Code="<<flag <<": "<<wcs_errmsg[flag]<<endl; |
---|
136 | } |
---|
137 | outputDetectionTextWCSHeader(output,this->wcs); |
---|
138 | outputDetectionTextWCSHeader(std::cout,this->wcs); |
---|
139 | for(int i=0;i<this->objectList.size();i++){ |
---|
140 | this->objectList[i].outputDetectionTextWCS(output); |
---|
141 | this->objectList[i].outputDetectionTextWCS(std::cout); |
---|
142 | } |
---|
143 | } |
---|
144 | |
---|
145 | void Cube::logDetectionList() |
---|
146 | { |
---|
147 | /** |
---|
148 | * logDetectionList |
---|
149 | * A front-end to writing a list of detected objects to the log file. |
---|
150 | * Does not assume WCS, so uses outputDetectionText. |
---|
151 | * Designed to be used by searching routines before returning their final list. |
---|
152 | */ |
---|
153 | |
---|
154 | std::ofstream fout(this->par.getLogFile().c_str(),std::ios::app); |
---|
155 | outputDetectionTextHeader(fout); |
---|
156 | long pos; |
---|
157 | bool baselineFlag = this->par.getFlagBaseline(); |
---|
158 | for(int objCtr=0;objCtr<this->objectList.size();objCtr++){ |
---|
159 | Detection *obj = new Detection; |
---|
160 | *obj = objectList[objCtr]; |
---|
161 | if(this->par.getFlagCubeTrimmed()){ |
---|
162 | for(int pix=0;pix<obj->getSize();pix++){ |
---|
163 | // Need to correct the pixels first, as this hasn't been done yet. |
---|
164 | // Corrections needed for positions (to account for trimmed region) |
---|
165 | // and for the baseline removal, if it has happened. |
---|
166 | // Don't want to keep these changes, so just do it on a dummy variable. |
---|
167 | pos = obj->getX(pix) + obj->getY(pix)*this->axisDim[0] |
---|
168 | + obj->getZ(pix)*this->axisDim[0]*this->axisDim[1]; |
---|
169 | obj->setX(pix, obj->getX(pix) + this->par.getBorderLeft() ); |
---|
170 | obj->setY(pix, obj->getY(pix) + this->par.getBorderBottom() ); |
---|
171 | if(baselineFlag) obj->setF(pix, obj->getF(pix) + this->baseline[pos]); // add in baseline |
---|
172 | } |
---|
173 | obj->calcParams(); |
---|
174 | } |
---|
175 | obj->outputDetectionText(fout,objCtr); |
---|
176 | delete obj; |
---|
177 | } |
---|
178 | fout.close(); |
---|
179 | } |
---|
180 | |
---|
181 | void Cube::logDetection(Detection obj, int counter) |
---|
182 | { |
---|
183 | /** |
---|
184 | * logDetection |
---|
185 | * A front-end to writing a detected object to the log file. |
---|
186 | * Does not assume WCS, so uses outputDetectionText. |
---|
187 | * obj is passed by value, as we want to potentially change positions etc, but not for |
---|
188 | * object in the calling function. |
---|
189 | * Corrects for changes to positions of pixels and removal of baselines. |
---|
190 | * Designed to be used by searching routines before returning their final list. |
---|
191 | */ |
---|
192 | |
---|
193 | std::ofstream fout(this->par.getLogFile().c_str(),std::ios::app); |
---|
194 | bool baselineFlag = this->par.getFlagBaseline(); |
---|
195 | if(this->par.getFlagCubeTrimmed()){ |
---|
196 | for(int pix=0;pix<obj.getSize();pix++){ |
---|
197 | // Need to correct the pixels first, as this hasn't been done yet. |
---|
198 | // Corrections needed for positions (to account for trimmed region) |
---|
199 | // and for the baseline removal, if it has happened. |
---|
200 | // Don't want to keep these changes, so just do it on a dummy variable. |
---|
201 | long pos = obj.getX(pix) + obj.getY(pix)*this->axisDim[0] |
---|
202 | + obj.getZ(pix)*this->axisDim[0]*this->axisDim[1]; |
---|
203 | obj.setX(pix, obj.getX(pix) + this->par.getBorderLeft() ); |
---|
204 | obj.setY(pix, obj.getY(pix) + this->par.getBorderBottom() ); |
---|
205 | if(baselineFlag) obj.setF(pix, obj.getF(pix) + this->baseline[pos]); // add in baseline |
---|
206 | } |
---|
207 | obj.calcParams(); |
---|
208 | } |
---|
209 | obj.outputDetectionText(fout,counter); |
---|
210 | fout.close(); |
---|
211 | } |
---|