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