1 | #include <iostream> |
---|
2 | #include <sstream> |
---|
3 | #include <fstream> |
---|
4 | #include <iomanip> |
---|
5 | #include <string> |
---|
6 | #include <vector> |
---|
7 | #include <duchamp.hh> |
---|
8 | #include <param.hh> |
---|
9 | #include <Detection/detection.hh> |
---|
10 | #include <Cubes/cubes.hh> |
---|
11 | #include <Utils/utils.hh> |
---|
12 | #include <Detection/columns.hh> |
---|
13 | |
---|
14 | using namespace Column; |
---|
15 | using std::vector; |
---|
16 | |
---|
17 | void Detection::outputDetectionTextHeader(std::ostream &stream, |
---|
18 | vector<Col> columns) |
---|
19 | { |
---|
20 | /** |
---|
21 | * Prints to a stream the column headers to match the output |
---|
22 | * generated by outputDetectionText or outputDetectionTextWCS |
---|
23 | * The exact columns depend on the vector<Col>. |
---|
24 | * \param stream Where to print. |
---|
25 | * \param columns The set of Columns::Col objects that define the columns to be printed. |
---|
26 | */ |
---|
27 | |
---|
28 | vector<Col> local = columns; |
---|
29 | if(local.size()==Column::numColumns){ |
---|
30 | vector <Col>::iterator iter; |
---|
31 | if(this->flagWCS) iter = local.begin() + FTOT; |
---|
32 | else iter = local.begin() + FINT; |
---|
33 | local.erase(iter); |
---|
34 | } |
---|
35 | |
---|
36 | stream << std::setfill(' '); |
---|
37 | for(int i=0;i<local.size();i++) local[i].printDash(stream); |
---|
38 | stream << std::endl; |
---|
39 | for(int i=0;i<local.size();i++) local[i].printTitle(stream); |
---|
40 | stream << std::endl; |
---|
41 | for(int i=0;i<local.size();i++) local[i].printUnits(stream); |
---|
42 | stream << std::endl; |
---|
43 | for(int i=0;i<local.size();i++) local[i].printDash(stream); |
---|
44 | stream << std::endl; |
---|
45 | } |
---|
46 | //-------------------------------------------------------------------- |
---|
47 | |
---|
48 | void Detection::outputDetectionTextWCS(std::ostream &stream, |
---|
49 | vector<Col> columns) |
---|
50 | { |
---|
51 | /** |
---|
52 | * outputDetectionTextWCS |
---|
53 | * Prints to a stream the relevant details of a detected object, |
---|
54 | * including the WCS parameters, which need to have been calculated. |
---|
55 | * If they have not (given by the isWCS() function), then the |
---|
56 | * WCS-related outputs are left blank. |
---|
57 | * \param stream Where to print. |
---|
58 | * \param columns The set of Columns::Col objects that define the columns to be printed. |
---|
59 | */ |
---|
60 | |
---|
61 | if(columns.size()!=Column::numColumns){ |
---|
62 | std::stringstream errmsg; |
---|
63 | errmsg << "columnSet used has wrong number of columns (" |
---|
64 | << columns.size() << ")\nshould be " |
---|
65 | << Column::numColumns << ".\n"; |
---|
66 | duchampError("outputDetectionTextWCS",errmsg.str()); |
---|
67 | } |
---|
68 | else{ |
---|
69 | stream.setf(std::ios::fixed); |
---|
70 | columns[NUM].printEntry(stream,this->id); |
---|
71 | columns[NAME].printEntry(stream,this->name); |
---|
72 | columns[X].printEntry(stream,this->getXcentre() + this->xSubOffset); |
---|
73 | columns[Y].printEntry(stream,this->getYcentre() + this->ySubOffset); |
---|
74 | columns[Z].printEntry(stream,this->getZcentre() + this->zSubOffset); |
---|
75 | if(this->flagWCS){ |
---|
76 | columns[RA].printEntry(stream,this->raS); |
---|
77 | columns[DEC].printEntry(stream,this->decS); |
---|
78 | columns[VEL].printEntry(stream,this->vel); |
---|
79 | columns[WRA].printEntry(stream,this->raWidth); |
---|
80 | columns[WDEC].printEntry(stream,this->decWidth); |
---|
81 | columns[WVEL].printEntry(stream,this->velWidth); |
---|
82 | } |
---|
83 | else for(int i=RA;i<=WVEL;i++) columns[i].printBlank(stream); |
---|
84 | if(this->flagWCS) columns[FINT].printEntry(stream,this->intFlux); |
---|
85 | else columns[FTOT].printEntry(stream,this->totalFlux); |
---|
86 | columns[FPEAK].printEntry(stream,this->peakFlux); |
---|
87 | columns[SNRPEAK].printEntry(stream,this->peakSNR); |
---|
88 | columns[X1].printEntry(stream,this->getXmin() + this->xSubOffset); |
---|
89 | columns[X2].printEntry(stream,this->getXmax() + this->xSubOffset); |
---|
90 | columns[Y1].printEntry(stream,this->getYmin() + this->ySubOffset); |
---|
91 | columns[Y2].printEntry(stream,this->getYmax() + this->ySubOffset); |
---|
92 | columns[Z1].printEntry(stream,this->getZmin() + this->zSubOffset); |
---|
93 | columns[Z2].printEntry(stream,this->getZmax() + this->zSubOffset); |
---|
94 | columns[NPIX].printEntry(stream,int(this->pixelArray.getSize())); |
---|
95 | columns[FLAG].printEntry(stream,this->flagText); |
---|
96 | stream << std::endl; |
---|
97 | } |
---|
98 | } |
---|
99 | //-------------------------------------------------------------------- |
---|
100 | |
---|
101 | void Detection::outputDetectionText(std::ostream &stream, |
---|
102 | vector<Col> columns, int idNumber) |
---|
103 | { |
---|
104 | /** |
---|
105 | * outputDetectionText |
---|
106 | * Print to a stream the relevant details of a detected object. |
---|
107 | * This does not include any WCS parameters, only pixel positions & extent, |
---|
108 | * and flux info (including peak SNR). |
---|
109 | * Also prints a counter, provided as an input. |
---|
110 | * |
---|
111 | * \param stream Where to print. |
---|
112 | * \param columns The set of Columns::Col objects that define the |
---|
113 | * columns to be printed. |
---|
114 | * \param idNumber The number that acts as a counter in the first column. |
---|
115 | */ |
---|
116 | |
---|
117 | if(columns.size()!=Column::numColumnsLog){ |
---|
118 | std::stringstream errmsg; |
---|
119 | errmsg << "columnSet used has wrong number of columns (" |
---|
120 | << columns.size() << ")\nshould be " |
---|
121 | << Column::numColumnsLog <<".\n"; |
---|
122 | duchampError("outputDetectionText",errmsg.str()); |
---|
123 | } |
---|
124 | else{ |
---|
125 | stream << std::setfill(' '); |
---|
126 | stream.setf(std::ios::fixed); |
---|
127 | columns[lNUM].printEntry(stream,idNumber); |
---|
128 | columns[lX].printEntry(stream,this->getXcentre() + this->xSubOffset); |
---|
129 | columns[lY].printEntry(stream,this->getYcentre() + this->ySubOffset); |
---|
130 | columns[lZ].printEntry(stream,this->getZcentre() + this->zSubOffset); |
---|
131 | columns[lFTOT].printEntry(stream,this->totalFlux); |
---|
132 | columns[lFPEAK].printEntry(stream,this->peakFlux); |
---|
133 | columns[lSNRPEAK].printEntry(stream,this->peakSNR); |
---|
134 | columns[lX1].printEntry(stream,this->getXmin() + this->xSubOffset); |
---|
135 | columns[lX2].printEntry(stream,this->getXmax() + this->xSubOffset); |
---|
136 | columns[lY1].printEntry(stream,this->getYmin() + this->ySubOffset); |
---|
137 | columns[lY2].printEntry(stream,this->getYmax() + this->ySubOffset); |
---|
138 | columns[lZ1].printEntry(stream,this->getZmin() + this->zSubOffset); |
---|
139 | columns[lZ2].printEntry(stream,this->getZmax() + this->zSubOffset); |
---|
140 | columns[lNPIX].printEntry(stream,this->pixelArray.getSize()); |
---|
141 | stream<<std::endl; |
---|
142 | } |
---|
143 | } |
---|
144 | //-------------------------------------------------------------------- |
---|
145 | |
---|
146 | std::string Detection::outputLabelWCS() |
---|
147 | { |
---|
148 | /** |
---|
149 | * Prints to a std::string the WCS position and velocity |
---|
150 | * information of the Detection, as well as the ID number and any |
---|
151 | * flags. |
---|
152 | * Assumes the WCS parameters of the object have been calculated. |
---|
153 | * If they have not (given by the isWCS() function), then the |
---|
154 | * WCS-related outputs are left blank. |
---|
155 | * Returns the string. |
---|
156 | */ |
---|
157 | std::stringstream ss; |
---|
158 | ss << "#" << std::setfill('0') << std::setw(3) << this->id << ": "; |
---|
159 | ss << this->name ; |
---|
160 | if(this->getFlagText()!="") |
---|
161 | ss << " [" << this->getFlagText() << "] "; |
---|
162 | else ss<< " "; |
---|
163 | ss << std::setfill(' '); |
---|
164 | ss << this->raS << ", "; |
---|
165 | ss << this->decS; |
---|
166 | ss << std::setprecision(this->velPrec); |
---|
167 | ss.setf(std::ios::fixed); |
---|
168 | ss << ", " << this->vel << " " << this->specUnits; |
---|
169 | |
---|
170 | return ss.str(); |
---|
171 | |
---|
172 | } |
---|
173 | //-------------------------------------------------------------------- |
---|
174 | |
---|
175 | std::string Detection::outputLabelInfo() |
---|
176 | { |
---|
177 | /** |
---|
178 | * Prints to a std::string the widths of the object (in position |
---|
179 | * and velocity), as well as the flux information. |
---|
180 | * Assumes the WCS parameters of the object have been calculated. |
---|
181 | * If they have not (given by the isWCS() function), then the WCS-related |
---|
182 | * outputs are left blank. |
---|
183 | * Returns the string. |
---|
184 | */ |
---|
185 | |
---|
186 | std::stringstream ss; |
---|
187 | ss.setf(std::ios::fixed); |
---|
188 | if(this->flagWCS){ |
---|
189 | ss << std::setprecision(this->posPrec); |
---|
190 | ss << "w_" << this->lngtype <<"=" << this->raWidth; |
---|
191 | ss << ", w_" << this->lattype <<"=" << this->decWidth; |
---|
192 | ss << std::setprecision(this->velPrec); |
---|
193 | ss << ", w_Vel=" << this->velWidth << " " << this->specUnits; |
---|
194 | ss << std::setprecision(this->fintPrec); |
---|
195 | ss << ", F\\dint\\u=" << this->intFlux << " " << this->intFluxUnits; |
---|
196 | ss << std::setprecision(this->fpeakPrec); |
---|
197 | ss << ", F\\dpeak\\u=" << this->peakFlux << " " << this->fluxUnits; |
---|
198 | ss << std::setprecision(this->snrPrec); |
---|
199 | ss << ", S/N\\dmax\\u=" << this->peakSNR; |
---|
200 | } |
---|
201 | else{ |
---|
202 | ss << "#" << std::setfill('0') << std::setw(3) << this->id << ": "; |
---|
203 | ss << std::setprecision(this->fintPrec); |
---|
204 | ss << "F\\dtot\\u=" << this->totalFlux << this->fluxUnits; |
---|
205 | ss << std::setprecision(this->fpeakPrec); |
---|
206 | ss << ", F\\dpeak\\u=" << this->peakFlux << this->fluxUnits; |
---|
207 | ss << std::setprecision(this->snrPrec); |
---|
208 | ss << ", S/N\\dmax\\u=" << this->peakSNR; |
---|
209 | } |
---|
210 | std::string output = ss.str(); |
---|
211 | |
---|
212 | return output; |
---|
213 | } |
---|
214 | //-------------------------------------------------------------------- |
---|
215 | |
---|
216 | std::string Detection::outputLabelPix() |
---|
217 | { |
---|
218 | /** |
---|
219 | * Prints to a std::string the pixel centres and extents of a |
---|
220 | * detected object. Returns the string. |
---|
221 | */ |
---|
222 | |
---|
223 | std::stringstream ss; |
---|
224 | ss.setf(std::ios::fixed); |
---|
225 | ss << "Centre: "; |
---|
226 | ss << std::setprecision(this->xyzPrec) << std::setfill(' '); |
---|
227 | ss <<"(" << this->getXcentre() + this->xSubOffset; |
---|
228 | ss <<", " << this->getYcentre() + this->ySubOffset; |
---|
229 | ss <<", " << this->getZcentre() + this->zSubOffset << ")"; |
---|
230 | ss <<", Size: "<< this->pixelArray.getSize() << " voxels, "; |
---|
231 | ss <<"Range: ["<< this->getXmin() + this->xSubOffset |
---|
232 | <<":" << this->getXmax() + this->xSubOffset; |
---|
233 | ss <<", " << this->getYmin() + this->ySubOffset |
---|
234 | <<":" << this->getYmax() + this->ySubOffset; |
---|
235 | ss <<", " << this->getZmin() + this->zSubOffset |
---|
236 | <<":" << this->getZmax() + this->zSubOffset << "]"; |
---|
237 | |
---|
238 | return ss.str(); |
---|
239 | } |
---|
240 | |
---|
241 | |
---|