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