1 | #include <iostream> |
---|
2 | #include <sstream> |
---|
3 | #include <fstream> |
---|
4 | #include <iomanip> |
---|
5 | #include <string> |
---|
6 | #include <time.h> |
---|
7 | #include <Cubes/cubes.hh> |
---|
8 | #include <Detection/columns.hh> |
---|
9 | #include <Utils/utils.hh> |
---|
10 | |
---|
11 | using std::endl; |
---|
12 | using std::setw; |
---|
13 | using std::setprecision; |
---|
14 | |
---|
15 | void Cube::outputDetectionsKarma(std::ostream &stream) |
---|
16 | { |
---|
17 | /** |
---|
18 | * outputDetectionsKarma |
---|
19 | * Prints to a stream (provided) the list of detected objects in the cube |
---|
20 | * in the format of an annotation file for the Karma suite of programs. |
---|
21 | * Annotation file draws a box enclosing the detection, and writes the ID number |
---|
22 | * of the detection to the right of the box. |
---|
23 | */ |
---|
24 | |
---|
25 | stream << "# Duchamp Source Finder results for cube " << this->par.getImageFile() << endl; |
---|
26 | stream << "COLOR RED" << endl; |
---|
27 | stream << "COORD W" << endl; |
---|
28 | for(int i=0;i<this->objectList.size();i++){ |
---|
29 | float radius = this->objectList[i].getRAWidth()/120.; |
---|
30 | if(this->objectList[i].getDecWidth()/120.>radius) |
---|
31 | radius = this->objectList[i].getDecWidth()/120.; |
---|
32 | stream << "CIRCLE " |
---|
33 | << this->objectList[i].getRA() << " " |
---|
34 | << this->objectList[i].getDec() << " " |
---|
35 | << radius << endl; |
---|
36 | stream << "TEXT " |
---|
37 | << this->objectList[i].getRA() << " " |
---|
38 | << this->objectList[i].getDec() << " " |
---|
39 | << this->objectList[i].getID() << endl; |
---|
40 | } |
---|
41 | |
---|
42 | } |
---|
43 | |
---|
44 | void Cube::outputDetectionsVOTable(std::ostream &stream) |
---|
45 | { |
---|
46 | /** |
---|
47 | * outputDetectionsVOTable |
---|
48 | * Prints to a stream (provided) the list of detected objects in the cube |
---|
49 | * in a VOTable format. |
---|
50 | * Uses WCS information and assumes WCS parameters have been calculated for each |
---|
51 | * detected object. |
---|
52 | * If they have not (given by the isWCS() function), then those objects are not written... |
---|
53 | */ |
---|
54 | |
---|
55 | // Set up Column definitions here |
---|
56 | vector<Column::Col> localCol; |
---|
57 | string posUCD[4]; |
---|
58 | localCol.push_back(this->fullColSet.vec[0]); // objID |
---|
59 | localCol.push_back(this->fullColSet.vec[1]); // name |
---|
60 | localCol.push_back(this->fullColSet.vec[5]); // ra |
---|
61 | if(makelower(localCol[2].getName())=="ra"){ |
---|
62 | posUCD[0] = "pos.eq.ra;meta.main"; |
---|
63 | posUCD[2] = "phys.angSize;pos.eq.ra"; |
---|
64 | } |
---|
65 | else{ |
---|
66 | posUCD[0] = "pos.galactic.lat;meta.main"; |
---|
67 | posUCD[2] = "phys.angSize;pos.galactic.lat"; |
---|
68 | } |
---|
69 | localCol.push_back(this->fullColSet.vec[6]); // dec |
---|
70 | if(makelower(localCol[2].getName())=="dec"){ |
---|
71 | posUCD[1] = "pos.eq.dec;meta.main"; |
---|
72 | posUCD[3] = "phys.angSize;pos.eq.dec"; |
---|
73 | } |
---|
74 | else{ |
---|
75 | posUCD[1] = "pos.galactic.lon;meta.main"; |
---|
76 | posUCD[3] = "phys.angSize;pos.galactic.lon"; |
---|
77 | } |
---|
78 | localCol.push_back(this->fullColSet.vec[8]); // w_ra |
---|
79 | localCol.push_back(this->fullColSet.vec[9]); // w_dec |
---|
80 | localCol.push_back(this->fullColSet.vec[7]); // vel |
---|
81 | localCol.push_back(this->fullColSet.vec[10]); // w_vel |
---|
82 | localCol.push_back(this->fullColSet.vec[11]); // f_int |
---|
83 | localCol.push_back(this->fullColSet.vec[12]); // f_peak |
---|
84 | localCol.push_back(this->fullColSet.vec[20]); // flag |
---|
85 | |
---|
86 | stream<<"<?xml version=\"1.0\"?>"<<endl; |
---|
87 | stream<<"<VOTABLE version=\"1.1\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""<<endl; |
---|
88 | stream<<" xsi:noNamespaceSchemaLocation=\"http://www.ivoa.net/xml/VOTable/VOTable/v1.1\">"<<endl; |
---|
89 | |
---|
90 | stream<<" <COOSYS ID=\"J2000\" equinox=\"J2000.\" epoch=\"J2000.\" system=\"eq_FK5\"/>"<<endl; |
---|
91 | stream<<" <RESOURCE name=\"Duchamp Output\">"<<endl; |
---|
92 | stream<<" <TABLE name=\"Detections\">"<<endl; |
---|
93 | stream<<" <DESCRIPTION>Detected sources and parameters from running the Duchamp source finder.</DESCRIPTION>"<<endl; |
---|
94 | |
---|
95 | // PARAM section -- parts that are not entry-specific ie. apply to whole dataset |
---|
96 | string fname = this->pars().getImageFile(); |
---|
97 | if(this->pars().getFlagSubsection()) fname+=this->pars().getSubsection(); |
---|
98 | stream<<" <PARAM name=\"FITS file\" datatype=\"char\" ucd=\"meta.file;meta.fits\" value=\"" << fname << "\"/>"<<endl; |
---|
99 | if(this->pars().getFlagFDR()) |
---|
100 | stream<<" <PARAM name=\"FDR Significance\" datatype=\"float\" ucd=\"stat.param\" value=\"" << this->pars().getAlpha() << "\">" << endl; |
---|
101 | else |
---|
102 | stream<<" <PARAM name=\"Threshold\" datatype=\"float\" ucd=\"stat.snr\" value=\"" << this->pars().getCut() << "\">" << endl; |
---|
103 | if(this->pars().getFlagATrous()){ |
---|
104 | stream<<" <PARAM name=\"ATrous note\" datatype=\"char\" ucd=\"meta.note\" value=\"The a trous reconstruction method was used, with the following parameters.\">" << endl; |
---|
105 | stream<<" <PARAM name=\"ATrous Cut\" datatype=\"float\" ucd=\"stat.snr\" value=\"" << this->pars().getAtrousCut() << "\">" << endl; |
---|
106 | stream<<" <PARAM name=\"ATrous Minimum Scale\" datatype=\"int\" ucd=\"stat.param\" value=\"" << this->pars().getMinScale() << "\">" << endl; |
---|
107 | stream<<" <PARAM name=\"ATrous Filter\" datatype=\"char\" ucd=\"meta.code;stat\" value=\"" << this->pars().getFilterName() << "\">" << endl; |
---|
108 | } |
---|
109 | // FIELD section -- names, titles and info for each column. |
---|
110 | stream<<" <FIELD name=\"ID\" ID=\"col01\" ucd=\"meta.id\" datatype=\"int\" width=\""<<localCol[0].getWidth()<<"\"/>"<<endl; |
---|
111 | stream<<" <FIELD name=\"Name\" ID=\"col02\" ucd=\"meta.id;meta.main\" datatype=\"char\" arraysize=\""<<localCol[1].getWidth()<<"\"/>"<<endl; |
---|
112 | stream<<" <FIELD name=\""<<localCol[2].getName()<<"\" ID=\"col03\" ucd=\""<<posUCD[0]<<"\" ref=\"J2000\" datatype=\"float\" width=\""<<localCol[2].getWidth()<<"\" precision=\""<<Column::posPrec<<"\" unit=\"[deg]\"/>"<<endl; |
---|
113 | stream<<" <FIELD name=\""<<localCol[3].getName()<<"\" ID=\"col04\" ucd=\""<<posUCD[1]<<"\" ref=\"J2000\" datatype=\"float\" width=\""<<localCol[3].getWidth()<<"\" precision=\""<<Column::posPrec<<"\" unit=\"[deg]\"/>"<<endl; |
---|
114 | stream<<" <FIELD name=\""<<localCol[4].getName()<<"\" ID=\"col05\" ucd=\""<<posUCD[2]<<"\" ref=\"J2000\" datatype=\"float\" width=\""<<localCol[4].getWidth()<<"\" precision=\""<<Column::wposPrec<<"\" unit=\""<<localCol[4].getUnit()<<"\"/>"<<endl; |
---|
115 | stream<<" <FIELD name=\""<<localCol[5].getName()<<"\" ID=\"col06\" ucd=\""<<posUCD[2]<<"\" ref=\"J2000\" datatype=\"float\" width=\""<<localCol[5].getWidth()<<"\" precision=\""<<Column::wposPrec<<"\" unit=\""<<localCol[5].getUnit()<<"\"/>"<<endl; |
---|
116 | stream<<" <FIELD name=\"Vel\" ID=\"col07\" ucd=\"phys.veloc;src.dopplerVeloc\" datatype=\"float\" width=\""<<localCol[6].getWidth()<<"\" precision=\""<<Column::velPrec<<"\" unit=\""<<localCol[6].getUnit()<<"\"/>"<<endl; |
---|
117 | stream<<" <FIELD name=\"w_Vel\" ID=\"col08\" ucd=\"phys.veloc;src.dopplerVeloc;spect.line.width\" datatype=\"float\" width=\""<<localCol[7].getWidth()<<"\" precision=\""<<Column::velPrec<<"\" unit=\""<<localCol[7].getUnit()<<"\"/>"<<endl; |
---|
118 | stream<<" <FIELD name=\"Integrated_Flux\" ID=\"col09\" ucd=\"phot.flux;spect.line.intensity\" datatype=\"float\" width=\""<<localCol[8].getWidth()<<"\" precision=\""<<Column::fluxPrec<<"\" unit=\""<<localCol[8].getUnit()<<"\"/>"<<endl; |
---|
119 | stream<<" <FIELD name=\"Peak_Flux\" ID=\"col10\" ucd=\"phot.flux;spect.line.intensity\" datatype=\"float\" width=\""<<localCol[9].getWidth()<<"\" precision=\""<<Column::fluxPrec<<"\" unit=\""<<localCol[9].getUnit()<<"\"/>"<<endl; |
---|
120 | stream<<" <FIELD name=\"Flag\" ID=\"col11\" ucd=\"meta.code.qual\" datatype=\"char\" arraysize=\"3\"/>"<<endl; |
---|
121 | |
---|
122 | |
---|
123 | stream<<" <DATA>"<<endl |
---|
124 | <<" <TABLEDATA>"<<endl; |
---|
125 | |
---|
126 | stream.setf(std::ios::fixed); |
---|
127 | for(int i=0;i<this->objectList.size();i++){ |
---|
128 | if(this->objectList[i].isWCS()){ |
---|
129 | stream<<" <TR>"<<endl; |
---|
130 | stream<<" <TD>"<<setw(localCol[0].getWidth())<<i+1<<"</TD>"; |
---|
131 | stream<<"<TD>" << setw(localCol[1].getWidth()) << this->objectList[i].getName() <<"</TD>"; |
---|
132 | stream<<setprecision(Column::posPrec); |
---|
133 | stream<<"<TD>" << setw(localCol[2].getWidth()) << this->objectList[i].getRA() <<"</TD>"; |
---|
134 | stream<<"<TD>" << setw(localCol[3].getWidth()) << this->objectList[i].getDec() <<"</TD>"; |
---|
135 | stream<<setprecision(Column::wposPrec); |
---|
136 | stream<<"<TD>" << setw(localCol[4].getWidth()) << this->objectList[i].getRAWidth() <<"</TD>"; |
---|
137 | stream<<"<TD>" << setw(localCol[5].getWidth()) << this->objectList[i].getDecWidth() <<"</TD>"; |
---|
138 | stream<<setprecision(Column::velPrec); |
---|
139 | stream<<"<TD>" << setw(localCol[6].getWidth()) << this->objectList[i].getVel() <<"</TD>"; |
---|
140 | stream<<"<TD>" << setw(localCol[7].getWidth()) << this->objectList[i].getVelWidth() <<"</TD>"; |
---|
141 | stream<<setprecision(Column::fluxPrec); |
---|
142 | stream<<"<TD>" << setw(localCol[8].getWidth()) << this->objectList[i].getIntegFlux() <<"</TD>"; |
---|
143 | stream<<"<TD>" << setw(localCol[9].getWidth()) << this->objectList[i].getPeakFlux() <<"</TD>"; |
---|
144 | stream<<"<TD>" << setw(localCol[10].getWidth())<< this->objectList[i].getFlagText() <<"</TD>"; |
---|
145 | |
---|
146 | stream<<endl; |
---|
147 | stream<<" </TR>"<<endl; |
---|
148 | } |
---|
149 | } |
---|
150 | stream<<" </TABLEDATA>"<<endl; |
---|
151 | stream<<" </DATA>"<<endl; |
---|
152 | stream<<" </TABLE>"<<endl; |
---|
153 | stream<<" </RESOURCE>"<<endl; |
---|
154 | stream<<"</VOTABLE>"<<endl; |
---|
155 | resetiosflags(std::ios::fixed); |
---|
156 | |
---|
157 | } |
---|
158 | |
---|
159 | |
---|
160 | void Cube::outputDetectionList() |
---|
161 | { |
---|
162 | /** |
---|
163 | * outputDetectionList |
---|
164 | * A front-end to writing the full list of detected objects to a results |
---|
165 | * file and to cout. |
---|
166 | * Uses outputDetectionTextWCS for each objects. |
---|
167 | * Leaves the testing of whether the WCS parameters for each object |
---|
168 | * have been calculated to outputDetectionTextWCS. |
---|
169 | */ |
---|
170 | |
---|
171 | int count=0; |
---|
172 | int flag; |
---|
173 | std::ofstream output(this->par.getOutFile().c_str()); |
---|
174 | output<<"Results of the Duchamp source finder: "; |
---|
175 | time_t now = time(NULL); |
---|
176 | output << asctime( localtime(&now) ); |
---|
177 | this->showParam(output); |
---|
178 | output<<"Total number of detections = "<<this->objectList.size()<<endl; |
---|
179 | output<<"--------------------"<<endl; |
---|
180 | this->setupColumns(); |
---|
181 | outputDetectionTextWCSHeader(output,this->fullColSet); |
---|
182 | outputDetectionTextWCSHeader(std::cout,this->fullColSet); |
---|
183 | for(int i=0;i<this->objectList.size();i++){ |
---|
184 | this->objectList[i].outputDetectionTextWCS(output,this->fullColSet); |
---|
185 | this->objectList[i].outputDetectionTextWCS(std::cout,this->fullColSet); |
---|
186 | } |
---|
187 | } |
---|
188 | |
---|
189 | void Cube::logDetectionList() |
---|
190 | { |
---|
191 | /** |
---|
192 | * logDetectionList |
---|
193 | * A front-end to writing a list of detected objects to the log file. |
---|
194 | * Does not assume WCS, so uses outputDetectionText. |
---|
195 | * Designed to be used by searching routines before returning their final list. |
---|
196 | */ |
---|
197 | |
---|
198 | std::ofstream fout(this->par.getLogFile().c_str(),std::ios::app); |
---|
199 | this->setupColumns(); |
---|
200 | outputDetectionTextHeader(fout,this->logColSet); |
---|
201 | long pos; |
---|
202 | bool baselineFlag = this->par.getFlagBaseline(); |
---|
203 | for(int objCtr=0;objCtr<this->objectList.size();objCtr++){ |
---|
204 | Detection *obj = new Detection; |
---|
205 | *obj = objectList[objCtr]; |
---|
206 | if(this->par.getFlagCubeTrimmed()){ |
---|
207 | for(int pix=0;pix<obj->getSize();pix++){ |
---|
208 | // Need to correct the pixels first, as this hasn't been done yet. |
---|
209 | // Corrections needed for positions (to account for trimmed region) |
---|
210 | // and for the baseline removal, if it has happened. |
---|
211 | // Don't want to keep these changes, so just do it on a dummy variable. |
---|
212 | pos = obj->getX(pix) + obj->getY(pix)*this->axisDim[0] |
---|
213 | + obj->getZ(pix)*this->axisDim[0]*this->axisDim[1]; |
---|
214 | obj->setX(pix, obj->getX(pix) + this->par.getBorderLeft() ); |
---|
215 | obj->setY(pix, obj->getY(pix) + this->par.getBorderBottom() ); |
---|
216 | if(baselineFlag) obj->setF(pix, obj->getF(pix) + this->baseline[pos]); // add in baseline |
---|
217 | } |
---|
218 | obj->calcParams(); |
---|
219 | } |
---|
220 | obj->outputDetectionText(fout,logColSet,objCtr+1); |
---|
221 | delete obj; |
---|
222 | } |
---|
223 | fout.close(); |
---|
224 | } |
---|
225 | |
---|
226 | void Cube::logDetection(Detection obj, int counter) |
---|
227 | { |
---|
228 | /** |
---|
229 | * logDetection |
---|
230 | * A front-end to writing a detected object to the log file. |
---|
231 | * Does not assume WCS, so uses outputDetectionText. |
---|
232 | * obj is passed by value, as we want to potentially change positions etc, but not for |
---|
233 | * object in the calling function. |
---|
234 | * Corrects for changes to positions of pixels and removal of baselines. |
---|
235 | * Designed to be used by searching routines before returning their final list. |
---|
236 | */ |
---|
237 | |
---|
238 | std::ofstream fout(this->par.getLogFile().c_str(),std::ios::app); |
---|
239 | bool baselineFlag = this->par.getFlagBaseline(); |
---|
240 | if(this->par.getFlagCubeTrimmed()){ |
---|
241 | for(int pix=0;pix<obj.getSize();pix++){ |
---|
242 | // Need to correct the pixels first, as this hasn't been done yet. |
---|
243 | // Corrections needed for positions (to account for trimmed region) |
---|
244 | // and for the baseline removal, if it has happened. |
---|
245 | // Don't want to keep these changes, so just do it on a dummy variable. |
---|
246 | long pos = obj.getX(pix) + obj.getY(pix)*this->axisDim[0] |
---|
247 | + obj.getZ(pix)*this->axisDim[0]*this->axisDim[1]; |
---|
248 | obj.setX(pix, obj.getX(pix) + this->par.getBorderLeft() ); |
---|
249 | obj.setY(pix, obj.getY(pix) + this->par.getBorderBottom() ); |
---|
250 | if(baselineFlag) obj.setF(pix, obj.getF(pix) + this->baseline[pos]); // add in baseline |
---|
251 | } |
---|
252 | obj.calcParams(); |
---|
253 | } |
---|
254 | obj.outputDetectionText(fout,this->logColSet,counter); |
---|
255 | fout.close(); |
---|
256 | } |
---|