[3] | 1 | #include <iostream> |
---|
| 2 | #include <sstream> |
---|
| 3 | #include <fstream> |
---|
| 4 | #include <iomanip> |
---|
| 5 | #include <string> |
---|
[103] | 6 | #include <vector> |
---|
[137] | 7 | #include <duchamp.hh> |
---|
[103] | 8 | #include <param.hh> |
---|
| 9 | #include <Detection/detection.hh> |
---|
[3] | 10 | #include <Cubes/cubes.hh> |
---|
| 11 | #include <Utils/utils.hh> |
---|
[103] | 12 | #include <Detection/columns.hh> |
---|
[3] | 13 | |
---|
[103] | 14 | using namespace Column; |
---|
[3] | 15 | |
---|
[144] | 16 | void Detection::outputDetectionTextHeader(std::ostream &stream, vector<Col> columns) |
---|
[3] | 17 | { |
---|
| 18 | /** |
---|
[139] | 19 | * outputDetectionTextHeader |
---|
| 20 | * Prints to a stream the column headers to match the output |
---|
| 21 | * generated by outputDetectionText or outputDetectionTextWCS |
---|
[144] | 22 | * The exact columns depend on the vector<Col>. |
---|
[3] | 23 | */ |
---|
| 24 | |
---|
[144] | 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 | |
---|
[145] | 33 | stream << std::setfill(' '); |
---|
[144] | 34 | for(int i=0;i<local.size();i++) local[i].printDash(stream); |
---|
[145] | 35 | stream << std::endl; |
---|
[144] | 36 | for(int i=0;i<local.size();i++) local[i].printTitle(stream); |
---|
[145] | 37 | stream << std::endl; |
---|
[144] | 38 | for(int i=0;i<local.size();i++) local[i].printUnits(stream); |
---|
[145] | 39 | stream << std::endl; |
---|
[144] | 40 | for(int i=0;i<local.size();i++) local[i].printDash(stream); |
---|
[145] | 41 | stream << std::endl; |
---|
[3] | 42 | } |
---|
| 43 | |
---|
[144] | 44 | void Detection::outputDetectionTextWCS(std::ostream &stream, vector<Col> columns) |
---|
[3] | 45 | { |
---|
| 46 | /** |
---|
[103] | 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. |
---|
[3] | 52 | */ |
---|
| 53 | |
---|
[144] | 54 | if(columns.size()!=22){ |
---|
[139] | 55 | std::stringstream errmsg; |
---|
| 56 | errmsg << "columnSet used has wrong number of columns (" |
---|
[144] | 57 | << columns.size() << ")\nshould be 22.\n"; |
---|
[139] | 58 | duchampError("outputDetectionTextWCS",errmsg.str()); |
---|
[103] | 59 | } |
---|
[139] | 60 | else{ |
---|
| 61 | stream.setf(std::ios::fixed); |
---|
[144] | 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); |
---|
[139] | 67 | if(this->flagWCS){ |
---|
[144] | 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); |
---|
[139] | 74 | } |
---|
[144] | 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); |
---|
[145] | 87 | stream << std::endl; |
---|
[139] | 88 | } |
---|
[3] | 89 | } |
---|
| 90 | |
---|
[144] | 91 | void Detection::outputDetectionText(std::ostream &stream, vector<Col> columns, int idNumber) |
---|
[3] | 92 | { |
---|
| 93 | /** |
---|
| 94 | * outputDetectionText |
---|
[103] | 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. |
---|
[3] | 98 | * Also prints a counter, provided as an input. |
---|
| 99 | */ |
---|
| 100 | |
---|
[144] | 101 | if(columns.size()!=13){ |
---|
[137] | 102 | std::stringstream errmsg; |
---|
| 103 | errmsg << "columnSet used has wrong number of columns (" |
---|
[144] | 104 | << columns.size() << ")\nshould be 13.\n"; |
---|
[137] | 105 | duchampError("outputDetectionText",errmsg.str()); |
---|
| 106 | } |
---|
| 107 | else{ |
---|
[145] | 108 | stream << std::setfill(' '); |
---|
[144] | 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()); |
---|
[145] | 123 | stream<<std::endl; |
---|
[137] | 124 | } |
---|
[3] | 125 | } |
---|
| 126 | |
---|
| 127 | string Detection::outputLabelWCS() |
---|
| 128 | { |
---|
| 129 | |
---|
| 130 | std::stringstream ss; |
---|
[145] | 131 | ss << "#" << std::setfill('0') << std::setw(3) << this->id << ": "; |
---|
[87] | 132 | ss << this->name ; |
---|
| 133 | if(this->getFlagText()!="") |
---|
| 134 | ss << " [" << this->getFlagText() << "] "; |
---|
| 135 | else ss<< " "; |
---|
[145] | 136 | ss << std::setfill(' '); |
---|
[3] | 137 | ss << this->raS << ", "; |
---|
| 138 | ss << this->decS; |
---|
[145] | 139 | ss << std::setprecision(this->velPrec); |
---|
[3] | 140 | ss.setf(std::ios::fixed); |
---|
[103] | 141 | ss << ", " << this->vel << " " << this->specUnits; |
---|
[3] | 142 | |
---|
| 143 | return ss.str(); |
---|
| 144 | |
---|
| 145 | |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | |
---|
[103] | 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){ |
---|
[145] | 164 | ss << std::setprecision(this->posPrec); |
---|
[103] | 165 | ss << "w_" << this->lngtype <<"=" << this->raWidth; |
---|
| 166 | ss << ", w_" << this->lattype <<"=" << this->decWidth; |
---|
[145] | 167 | ss << std::setprecision(this->velPrec); |
---|
[103] | 168 | ss << ", w_Vel=" << this->velWidth << " " << this->specUnits; |
---|
[145] | 169 | ss << std::setprecision(this->fintPrec); |
---|
[103] | 170 | ss << ", F\\dint\\u=" << this->intFlux << " " << this->intFluxUnits; |
---|
[145] | 171 | ss << std::setprecision(this->fpeakPrec); |
---|
[103] | 172 | ss << ", F\\dpeak\\u=" << this->peakFlux << " " << this->fluxUnits; |
---|
| 173 | } |
---|
| 174 | else{ |
---|
[145] | 175 | ss << "#" << std::setfill('0') << std::setw(3) << this->id << ": "; |
---|
| 176 | ss << std::setprecision(this->fintPrec); |
---|
[103] | 177 | ss << "F\\dtot\\u=" << this->totalFlux << this->fluxUnits; |
---|
[145] | 178 | ss << std::setprecision(this->fpeakPrec); |
---|
[103] | 179 | ss << ", F\\dpeak\\u=" << this->peakFlux << this->fluxUnits; |
---|
| 180 | } |
---|
| 181 | string output = ss.str(); |
---|
| 182 | |
---|
| 183 | return output; |
---|
| 184 | } |
---|
| 185 | |
---|
| 186 | |
---|
[3] | 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); |
---|
[75] | 197 | ss << "Centre: "; |
---|
[145] | 198 | ss << std::setprecision(this->xyzPrec) << std::setfill(' '); |
---|
[88] | 199 | ss <<"(" << this->xcentre + this->xSubOffset; |
---|
[75] | 200 | ss <<", " << this->ycentre + this->ySubOffset; |
---|
| 201 | ss <<", " << this->zcentre + this->zSubOffset << ")"; |
---|
[88] | 202 | ss <<", Size: " << this->pix.size() << " voxels, "; |
---|
[144] | 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 << "]"; |
---|
[3] | 209 | |
---|
| 210 | return ss.str(); |
---|
| 211 | } |
---|
| 212 | |
---|
| 213 | |
---|