[3] | 1 | #include <iostream> |
---|
| 2 | #include <iomanip> |
---|
| 3 | #include <fstream> |
---|
| 4 | #include <sstream> |
---|
| 5 | #include <string> |
---|
| 6 | #include <math.h> |
---|
[91] | 7 | #include <wcs.h> |
---|
| 8 | #include <wcsunits.h> |
---|
[3] | 9 | #include <param.hh> |
---|
[91] | 10 | #include <Utils/utils.hh> |
---|
[3] | 11 | |
---|
| 12 | using std::setw; |
---|
| 13 | using std::endl; |
---|
| 14 | |
---|
| 15 | /****************************************************************/ |
---|
| 16 | /////////////////////////////////////////////////// |
---|
[90] | 17 | //// Functions for FitsHeader class: |
---|
| 18 | /////////////////////////////////////////////////// |
---|
| 19 | |
---|
[91] | 20 | FitsHeader::FitsHeader(){ |
---|
[90] | 21 | this->wcs = new wcsprm; |
---|
| 22 | this->wcs->flag=-1; |
---|
| 23 | wcsini(true,3,this->wcs); |
---|
| 24 | this->wcsIsGood = false; |
---|
| 25 | this->nwcs = 0; |
---|
[91] | 26 | this->scale=1.; |
---|
| 27 | this->offset=0.; |
---|
| 28 | this->power=1.; |
---|
[93] | 29 | this->fluxUnits="counts"; |
---|
[90] | 30 | } |
---|
| 31 | |
---|
[91] | 32 | FitsHeader::FitsHeader(const FitsHeader& h){ |
---|
[95] | 33 | this->wcs = new wcsprm; |
---|
| 34 | this->wcs->flag=-1; |
---|
| 35 | wcsini(true,h.wcs->naxis,this->wcs); |
---|
| 36 | wcscopy(true,h.wcs,this->wcs); |
---|
| 37 | wcsset(this->wcs); |
---|
[91] | 38 | nwcs = h.nwcs; |
---|
| 39 | wcsIsGood = h.wcsIsGood; |
---|
| 40 | spectralUnits = h.spectralUnits; |
---|
| 41 | fluxUnits = h.fluxUnits; |
---|
| 42 | intFluxUnits = h.intFluxUnits; |
---|
| 43 | beamSize = h.beamSize; |
---|
| 44 | bmajKeyword = h.bmajKeyword; |
---|
| 45 | bminKeyword = h.bminKeyword; |
---|
| 46 | blankKeyword = h.blankKeyword; |
---|
| 47 | bzeroKeyword = h.bzeroKeyword; |
---|
| 48 | bscaleKeyword = h.bscaleKeyword; |
---|
| 49 | scale = h.scale; |
---|
| 50 | offset = h.offset; |
---|
| 51 | power = h.power; |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | FitsHeader& FitsHeader::operator= (const FitsHeader& h){ |
---|
[95] | 55 | this->wcs = new wcsprm; |
---|
| 56 | this->wcs->flag=-1; |
---|
| 57 | wcsini(true,h.wcs->naxis,this->wcs); |
---|
| 58 | wcscopy(true,h.wcs,this->wcs); |
---|
| 59 | wcsset(this->wcs); |
---|
[91] | 60 | nwcs = h.nwcs; |
---|
| 61 | wcsIsGood = h.wcsIsGood; |
---|
| 62 | spectralUnits = h.spectralUnits; |
---|
| 63 | fluxUnits = h.fluxUnits; |
---|
| 64 | intFluxUnits = h.intFluxUnits; |
---|
| 65 | beamSize = h.beamSize; |
---|
| 66 | bmajKeyword = h.bmajKeyword; |
---|
| 67 | bminKeyword = h.bminKeyword; |
---|
| 68 | blankKeyword = h.blankKeyword; |
---|
| 69 | bzeroKeyword = h.bzeroKeyword; |
---|
| 70 | bscaleKeyword = h.bscaleKeyword; |
---|
| 71 | scale = h.scale; |
---|
| 72 | offset = h.offset; |
---|
| 73 | power = h.power; |
---|
| 74 | } |
---|
| 75 | |
---|
[90] | 76 | void FitsHeader::setWCS(wcsprm *w) |
---|
| 77 | { |
---|
| 78 | /** |
---|
| 79 | * FitsHeader::setWCS(wcsprm *) |
---|
| 80 | * A function that assigns the wcs parameters, and runs |
---|
| 81 | * wcsset to set it up correctly. |
---|
| 82 | * Performs a check to see if the WCS is good (by looking at |
---|
| 83 | * the lng and lat wcsprm parameters), and sets the wcsIsGood |
---|
| 84 | * flag accordingly. |
---|
| 85 | */ |
---|
| 86 | wcscopy(true,w,this->wcs); |
---|
| 87 | wcsset(this->wcs); |
---|
| 88 | if( (w->lng!=-1) && (w->lat!=-1) ) this->wcsIsGood = true; |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | wcsprm *FitsHeader::getWCS() |
---|
| 92 | { |
---|
| 93 | /** |
---|
| 94 | * FitsHeader::getWCS() |
---|
| 95 | * A function that returns a wcsprm object corresponding to the WCS. |
---|
| 96 | */ |
---|
| 97 | wcsprm *wNew = new wcsprm; |
---|
| 98 | wNew->flag=-1; |
---|
| 99 | wcsini(true,this->wcs->naxis,wNew); |
---|
| 100 | wcscopy(true,this->wcs,wNew); |
---|
| 101 | wcsset(wNew); |
---|
| 102 | return wNew; |
---|
| 103 | } |
---|
| 104 | |
---|
[91] | 105 | int FitsHeader::wcsToPix(const double *world, double *pix){ |
---|
| 106 | return wcsToPixSingle(this->wcs,world,pix);} |
---|
| 107 | int FitsHeader::wcsToPix(const double *world, double *pix, const int npts){ |
---|
| 108 | return wcsToPixMulti(this->wcs,world,pix,npts);} |
---|
| 109 | int FitsHeader::pixToWCS(const double *pix, double *world){ |
---|
| 110 | return pixToWCSSingle(this->wcs,pix,world);} |
---|
| 111 | int FitsHeader::pixToWCS(const double *pix, double *world, const int npts){ |
---|
| 112 | return pixToWCSMulti(this->wcs,pix,world,npts);} |
---|
[90] | 113 | |
---|
[91] | 114 | double FitsHeader::pixToVel(double &x, double &y, double &z) |
---|
| 115 | { |
---|
| 116 | // return pixelToVelocity(this->wcs,x,y,z,this->spectralUnits);}; |
---|
| 117 | double *pix = new double[3]; |
---|
| 118 | double *world = new double[3]; |
---|
| 119 | pix[0] = x; pix[1] = y; pix[2] = z; |
---|
| 120 | pixToWCSSingle(this->wcs,pix,world); |
---|
| 121 | double vel = this->specToVel(world[2]); |
---|
| 122 | delete [] pix; |
---|
| 123 | delete [] world; |
---|
| 124 | return vel; |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | double* FitsHeader::pixToVel(double &x, double &y, double *zarray, int size) |
---|
| 128 | { |
---|
| 129 | // return pixelToVelocity(this->wcs,x,y,z,this->spectralUnits);}; |
---|
| 130 | double *pix = new double[size*3]; |
---|
| 131 | for(int i=0;i<size;i++){ |
---|
| 132 | pix[3*i] = x; pix[3*i+1] = y; pix[3*i+2] = zarray[i]; |
---|
| 133 | } |
---|
| 134 | double *world = new double[size*3]; |
---|
| 135 | pixToWCSMulti(this->wcs,pix,world,size); |
---|
| 136 | delete [] pix; |
---|
[92] | 137 | double *newzarray = new double[size]; |
---|
| 138 | for(int i=0;i<size;i++) newzarray[i] = this->specToVel(world[3*i+2]); |
---|
| 139 | delete [] world; |
---|
| 140 | return newzarray; |
---|
[91] | 141 | } |
---|
| 142 | |
---|
| 143 | double FitsHeader::specToVel(const double &coord) |
---|
| 144 | { |
---|
| 145 | // return coordToVel(this->wcs,coord,this->spectralUnits);}; |
---|
| 146 | double vel; |
---|
| 147 | if(power==1.0){ |
---|
| 148 | // std::cerr << coord << " --> " << coord*this->scale + this->offset << std::endl; |
---|
| 149 | vel = coord*this->scale + this->offset; |
---|
| 150 | } |
---|
| 151 | else vel = pow( (coord*this->scale + this->offset), this->power); |
---|
| 152 | |
---|
| 153 | return vel; |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | double FitsHeader::velToSpec(const float &velocity) |
---|
| 157 | { |
---|
| 158 | // return velToCoord(this->wcs,velocity,this->spectralUnits);}; |
---|
| 159 | return (pow(velocity, 1./this->power) - this->offset) / this->scale;} |
---|
| 160 | |
---|
| 161 | string FitsHeader::getIAUName(double ra, double dec) |
---|
| 162 | { |
---|
| 163 | if(strcmp(this->wcs->lngtyp,"RA")==0) return getIAUNameEQ(ra, dec, this->wcs->equinox); |
---|
| 164 | else return getIAUNameGAL(ra, dec); |
---|
| 165 | } |
---|
| 166 | |
---|
| 167 | void FitsHeader::fixUnits(Param &par) |
---|
| 168 | { |
---|
| 169 | // define spectral units from the param set |
---|
| 170 | this->spectralUnits = par.getSpectralUnits(); |
---|
| 171 | |
---|
[93] | 172 | double sc=1.; |
---|
| 173 | double of=0.; |
---|
| 174 | double po=1.;; |
---|
| 175 | if(this->wcsIsGood){ |
---|
| 176 | int flag = wcsunits( this->wcs->cunit[2], this->spectralUnits.c_str(), &sc, &of, &po); |
---|
| 177 | if(flag>0){ |
---|
[95] | 178 | std::cerr << "ERROR <fixUnits> : WCSUNITS Error Code = " << flag << ": " |
---|
[93] | 179 | << wcsunits_errmsg[flag] << std::endl; |
---|
[95] | 180 | if(flag==10) |
---|
| 181 | std::cerr<<" Tried to get conversion from '" << wcs->cunit[2] |
---|
| 182 | << "' to '" << this->spectralUnits.c_str() << "'\n"; |
---|
| 183 | // std::cerr << " Using coordinate value instead\n"; |
---|
| 184 | this->spectralUnits = this->wcs->cunit[2]; |
---|
| 185 | if(this->spectralUnits==""){ |
---|
| 186 | std::cerr << " Setting coordinates to 'XX' for clarity.\n"; |
---|
| 187 | this->spectralUnits = "XX"; |
---|
| 188 | } |
---|
[93] | 189 | } |
---|
[91] | 190 | } |
---|
| 191 | this->scale = sc; |
---|
| 192 | this->offset= of; |
---|
| 193 | this->power = po; |
---|
[95] | 194 | |
---|
| 195 | // work out the integrated flux units, based on the spectral units |
---|
| 196 | // if flux is per beam, trim the /beam from the flux units and multiply by the spectral units. |
---|
| 197 | // otherwise, just muliply by the spectral units. |
---|
| 198 | if(this->fluxUnits.size()>0){ |
---|
| 199 | if(this->fluxUnits.substr(this->fluxUnits.size()-5,this->fluxUnits.size())=="/beam"){ |
---|
| 200 | this->intFluxUnits = this->fluxUnits.substr(0,this->fluxUnits.size()-5) |
---|
| 201 | +" " +this->spectralUnits; |
---|
| 202 | } |
---|
| 203 | else this->intFluxUnits = fluxUnits + " " + this->spectralUnits; |
---|
| 204 | } |
---|
| 205 | |
---|
[91] | 206 | } |
---|
| 207 | |
---|
[90] | 208 | /****************************************************************/ |
---|
| 209 | /////////////////////////////////////////////////// |
---|
[3] | 210 | //// Accessor Functions for Parameter class: |
---|
| 211 | /////////////////////////////////////////////////// |
---|
| 212 | Param::Param(){ |
---|
| 213 | /** |
---|
| 214 | * Param() |
---|
| 215 | * Default intial values for the parameters. |
---|
| 216 | * imageFile has no default value! |
---|
| 217 | */ |
---|
| 218 | // Input files |
---|
| 219 | this->imageFile = ""; |
---|
| 220 | this->flagSubsection = false; |
---|
| 221 | this->subsection = "[*,*,*]"; |
---|
[71] | 222 | this->flagReconExists = false; |
---|
| 223 | this->reconFile = ""; |
---|
[3] | 224 | // Output files |
---|
| 225 | this->flagLog = true; |
---|
[80] | 226 | this->logFile = "duchamp-Logfile.txt"; |
---|
| 227 | this->outFile = "duchamp-Results.txt"; |
---|
| 228 | this->spectraFile = "duchamp-Spectra.ps"; |
---|
[3] | 229 | this->flagOutputRecon = false; |
---|
| 230 | this->flagOutputResid = false; |
---|
| 231 | this->flagVOT = false; |
---|
[80] | 232 | this->votFile = "duchamp-Results.xml"; |
---|
[20] | 233 | this->flagKarma = false; |
---|
[80] | 234 | this->karmaFile = "duchamp-Results.ann"; |
---|
[3] | 235 | this->flagMaps = true; |
---|
[80] | 236 | this->detectionMap = "duchamp-DetectionMap.ps"; |
---|
| 237 | this->momentMap = "duchamp-MomentMap.ps"; |
---|
[3] | 238 | // Cube related parameters |
---|
| 239 | this->flagBlankPix = true; |
---|
| 240 | this->blankPixValue = -8.00061; |
---|
| 241 | this->blankKeyword = 1; |
---|
| 242 | this->bscaleKeyword = -8.00061; |
---|
| 243 | this->bzeroKeyword = 0.; |
---|
[96] | 244 | this->flagUsingBlank = false; |
---|
[3] | 245 | this->nanAsBlank = false; |
---|
[55] | 246 | this->flagMW = false; |
---|
[3] | 247 | this->maxMW = 112; |
---|
| 248 | this->minMW = 75; |
---|
| 249 | this->numPixBeam = 0.; |
---|
| 250 | // Trim-related |
---|
| 251 | this->flagTrimmed = false; |
---|
| 252 | this->borderLeft = 0; |
---|
| 253 | this->borderRight = 0; |
---|
| 254 | this->borderBottom = 0; |
---|
| 255 | this->borderTop = 0; |
---|
| 256 | // Subsection offsets |
---|
| 257 | this->xSubOffset = 0; |
---|
| 258 | this->ySubOffset = 0; |
---|
| 259 | this->zSubOffset = 0; |
---|
| 260 | // Baseline related |
---|
| 261 | this->flagBaseline = false; |
---|
| 262 | // Detection-related |
---|
[71] | 263 | this->flagNegative = false; |
---|
[3] | 264 | // Object growth |
---|
[69] | 265 | this->flagGrowth = false; |
---|
[80] | 266 | this->growthCut = 2.; |
---|
[3] | 267 | // FDR analysis |
---|
| 268 | this->flagFDR = false; |
---|
| 269 | this->alphaFDR = 0.01; |
---|
| 270 | // Other detection |
---|
| 271 | this->snrCut = 3.; |
---|
| 272 | // A trous reconstruction parameters |
---|
| 273 | this->flagATrous = true; |
---|
[96] | 274 | this->reconDim = 3; |
---|
[3] | 275 | this->scaleMin = 1; |
---|
| 276 | this->snrRecon = 4.; |
---|
| 277 | this->filterCode = 2; |
---|
| 278 | // Volume-merging parameters |
---|
| 279 | this->flagAdjacent = true; |
---|
| 280 | this->threshSpatial = 3.; |
---|
| 281 | this->threshVelocity = 7.; |
---|
| 282 | this->minChannels = 3; |
---|
[71] | 283 | this->minPix = 2; |
---|
[3] | 284 | // Input-Output related |
---|
[45] | 285 | this->spectralMethod = "peak"; |
---|
[3] | 286 | this->borders = true; |
---|
| 287 | this->verbose = true; |
---|
[90] | 288 | this->spectralUnits = "km/s"; |
---|
[3] | 289 | }; |
---|
| 290 | |
---|
| 291 | /****************************************************************/ |
---|
| 292 | /////////////////////////////////////////////////// |
---|
| 293 | //// Other Functions using the Parameter class: |
---|
| 294 | /////////////////////////////////////////////////// |
---|
| 295 | |
---|
| 296 | string makelower( string s ) |
---|
| 297 | { |
---|
| 298 | // "borrowed" from Matt Howlett's 'fred' |
---|
| 299 | string out = ""; |
---|
| 300 | for( int i=0; i<s.size(); ++i ) { |
---|
| 301 | out += tolower(s[i]); |
---|
| 302 | } |
---|
| 303 | return out; |
---|
| 304 | } |
---|
| 305 | |
---|
| 306 | void Param::readParams(string ¶mfile) |
---|
| 307 | { |
---|
| 308 | |
---|
| 309 | std::ifstream fin(paramfile.c_str()); |
---|
| 310 | string line; |
---|
| 311 | string sval; |
---|
| 312 | float fval; |
---|
| 313 | int ival; |
---|
| 314 | bool bval; |
---|
| 315 | while( !std::getline(fin,line,'\n').eof()){ |
---|
| 316 | |
---|
| 317 | if(line[0]!='#'){ |
---|
| 318 | std::stringstream ss; |
---|
| 319 | ss.str(line); |
---|
| 320 | string arg; |
---|
| 321 | ss >> arg; |
---|
[69] | 322 | if(makelower(arg)=="imagefile"){ ss >> sval; this->imageFile = sval;} |
---|
[71] | 323 | if(makelower(arg)=="flagsubsection"){ ss >> bval; this->flagSubsection = bval; } |
---|
| 324 | if(makelower(arg)=="subsection"){ ss >> sval; this->subsection = sval; } |
---|
| 325 | if(makelower(arg)=="flagreconexists"){ ss >> bval; this->flagReconExists = bval; } |
---|
| 326 | if(makelower(arg)=="reconfile"){ ss >> sval; this->reconFile = sval; } |
---|
| 327 | |
---|
[3] | 328 | if(makelower(arg)=="flaglog"){ ss >> bval; this->flagLog = bval; } |
---|
| 329 | if(makelower(arg)=="logfile"){ ss >> sval; this->logFile = sval; } |
---|
| 330 | if(makelower(arg)=="outfile"){ ss >> sval; this->outFile = sval; } |
---|
| 331 | if(makelower(arg)=="spectrafile"){ ss >> sval; this->spectraFile = sval; } |
---|
| 332 | if(makelower(arg)=="flagoutputrecon"){ ss >> bval; this->flagOutputRecon = bval; } |
---|
| 333 | if(makelower(arg)=="flagoutputresid"){ ss >> bval; this->flagOutputResid = bval; } |
---|
| 334 | if(makelower(arg)=="flagvot"){ ss >> bval; this->flagVOT = bval; } |
---|
| 335 | if(makelower(arg)=="votfile"){ ss >> sval; this->votFile = sval; } |
---|
[20] | 336 | if(makelower(arg)=="flagkarma"){ ss >> bval; this->flagKarma = bval; } |
---|
| 337 | if(makelower(arg)=="karmafile"){ ss >> sval; this->karmaFile = sval; } |
---|
[3] | 338 | if(makelower(arg)=="flagmaps"){ ss >> bval; this->flagMaps = bval; } |
---|
| 339 | if(makelower(arg)=="detectionmap"){ ss >> sval; this->detectionMap = sval; } |
---|
| 340 | if(makelower(arg)=="momentmap"){ ss >> sval; this->momentMap = sval; } |
---|
| 341 | |
---|
[60] | 342 | if(makelower(arg)=="flagnegative"){ ss >> bval; this->flagNegative = bval;} |
---|
[3] | 343 | if(makelower(arg)=="flagblankpix"){ ss >> bval; this->flagBlankPix = bval; } |
---|
| 344 | if(makelower(arg)=="blankpixvalue"){ ss >> fval; this->blankPixValue = fval; } |
---|
| 345 | if(makelower(arg)=="flagmw"){ ss >> bval; this->flagMW = bval; } |
---|
| 346 | if(makelower(arg)=="maxmw"){ ss >> ival; this->maxMW = ival; } |
---|
| 347 | if(makelower(arg)=="minmw"){ ss >> ival; this->minMW = ival; } |
---|
[71] | 348 | |
---|
| 349 | if(makelower(arg)=="flagbaseline"){ ss >> bval; this->flagBaseline = bval; } |
---|
[3] | 350 | if(makelower(arg)=="minpix"){ ss >> ival; this->minPix = ival; } |
---|
[71] | 351 | if(makelower(arg)=="flaggrowth"){ ss >> bval; this->flagGrowth = bval; } |
---|
| 352 | if(makelower(arg)=="growthcut"){ ss >> fval; this->growthCut = fval; } |
---|
| 353 | |
---|
[3] | 354 | if(makelower(arg)=="flagfdr"){ ss >> bval; this->flagFDR = bval; } |
---|
| 355 | if(makelower(arg)=="alphafdr"){ ss >> fval; this->alphaFDR = fval; } |
---|
[96] | 356 | |
---|
[3] | 357 | if(makelower(arg)=="snrcut"){ ss >> fval; this->snrCut = fval; } |
---|
[96] | 358 | |
---|
[3] | 359 | if(makelower(arg)=="flagatrous"){ ss >> bval; this->flagATrous = bval; } |
---|
[96] | 360 | if(makelower(arg)=="recondim"){ ss >> ival; this->reconDim = ival; } |
---|
[3] | 361 | if(makelower(arg)=="scalemin"){ ss >> ival; this->scaleMin = ival; } |
---|
| 362 | if(makelower(arg)=="snrrecon"){ ss >> fval; this->snrRecon = fval; } |
---|
| 363 | if(makelower(arg)=="filtercode"){ ss >> ival; this->filterCode = ival; } |
---|
[71] | 364 | |
---|
[3] | 365 | if(makelower(arg)=="flagadjacent"){ ss >> bval; this->flagAdjacent = bval; } |
---|
| 366 | if(makelower(arg)=="threshspatial"){ ss >> fval; this->threshSpatial = fval; } |
---|
| 367 | if(makelower(arg)=="threshvelocity"){ ss >> fval; this->threshVelocity = fval; } |
---|
| 368 | if(makelower(arg)=="minchannels"){ ss >> ival; this->minChannels = ival; } |
---|
[71] | 369 | |
---|
[90] | 370 | if(makelower(arg)=="spectralmethod"){ ss >> sval; this->spectralMethod = makelower(sval); } |
---|
| 371 | if(makelower(arg)=="spectralunits"){ ss >> sval; this->spectralUnits = makelower(sval); } |
---|
[3] | 372 | if(makelower(arg)=="drawborders"){ ss >> bval; this->borders = bval; } |
---|
| 373 | if(makelower(arg)=="verbose"){ ss >> bval; this->verbose = bval; } |
---|
| 374 | } |
---|
| 375 | } |
---|
| 376 | } |
---|
| 377 | |
---|
| 378 | |
---|
| 379 | std::ostream& operator<< ( std::ostream& theStream, Param& par) |
---|
| 380 | { |
---|
[96] | 381 | // Only show the [blankPixValue] bit if we are using the parameter |
---|
| 382 | // otherwise we have read it from the FITS header. |
---|
| 383 | string blankParam = ""; |
---|
| 384 | if(par.getFlagUsingBlank()) blankParam = "[blankPixValue]"; |
---|
| 385 | |
---|
| 386 | // WARNING -- sometimes get error: `boolalpha' is not a member of type `ios' -- old compilers? |
---|
[3] | 387 | theStream.setf(std::ios::boolalpha); |
---|
| 388 | theStream.setf(std::ios::left); |
---|
| 389 | theStream <<"---- Parameters ----"<<endl; |
---|
[93] | 390 | theStream << std::setfill('.'); |
---|
[3] | 391 | if(par.getFlagSubsection()) |
---|
[93] | 392 | theStream<<setw(38)<<"Image to be analysed" |
---|
| 393 | <<setw(18)<<setiosflags(std::ios::right) <<"[imageFile]" |
---|
| 394 | <<" = " <<resetiosflags(std::ios::right) |
---|
| 395 | <<(par.getImageFile()+par.getSubsection()) <<endl; |
---|
[3] | 396 | else |
---|
[93] | 397 | theStream<<setw(38)<<"Image to be analysed" |
---|
| 398 | <<setw(18)<<setiosflags(std::ios::right) <<"[imageFile]" |
---|
| 399 | <<" = " <<resetiosflags(std::ios::right)<<par.getImageFile() <<endl; |
---|
[81] | 400 | if(par.getFlagReconExists() && par.getFlagATrous()){ |
---|
[93] | 401 | theStream<<setw(38)<<"Reconstructed array exists?" |
---|
| 402 | <<setw(18)<<setiosflags(std::ios::right) <<"[reconExists]" |
---|
| 403 | <<" = " <<resetiosflags(std::ios::right)<<par.getFlagReconExists()<<endl; |
---|
| 404 | theStream<<setw(38)<<"FITS file containing reconstruction" |
---|
| 405 | <<setw(18)<<setiosflags(std::ios::right) <<"[reconFile]" |
---|
| 406 | <<" = " <<resetiosflags(std::ios::right)<<par.getReconFile() <<endl; |
---|
[71] | 407 | } |
---|
[93] | 408 | theStream <<setw(38)<<"Intermediate Logfile" |
---|
| 409 | <<setw(18)<<setiosflags(std::ios::right) <<"[logFile]" |
---|
| 410 | <<" = " <<resetiosflags(std::ios::right)<<par.getLogFile() <<endl; |
---|
| 411 | theStream <<setw(38)<<"Final Results file" |
---|
| 412 | <<setw(18)<<setiosflags(std::ios::right) <<"[outFile]" |
---|
| 413 | <<" = " <<resetiosflags(std::ios::right)<<par.getOutFile() <<endl; |
---|
| 414 | theStream <<setw(38)<<"Spectrum file" |
---|
| 415 | <<setw(18)<<setiosflags(std::ios::right) <<"[spectraFile]" |
---|
| 416 | <<" = " <<resetiosflags(std::ios::right)<<par.getSpectraFile() <<endl; |
---|
[3] | 417 | if(par.getFlagVOT()){ |
---|
[93] | 418 | theStream<<setw(38)<<"VOTable file" |
---|
| 419 | <<setw(18)<<setiosflags(std::ios::right) <<"[votFile]" |
---|
| 420 | <<" = " <<resetiosflags(std::ios::right)<<par.getVOTFile() <<endl; |
---|
[3] | 421 | } |
---|
[20] | 422 | if(par.getFlagKarma()){ |
---|
[93] | 423 | theStream<<setw(38)<<"Karma annotation file" |
---|
| 424 | <<setw(18)<<setiosflags(std::ios::right) <<"[karmaFile]" |
---|
| 425 | <<" = " <<resetiosflags(std::ios::right)<<par.getKarmaFile() <<endl; |
---|
[20] | 426 | } |
---|
[3] | 427 | if(par.getFlagMaps()){ |
---|
[93] | 428 | theStream<<setw(38)<<"0th Moment Map" |
---|
| 429 | <<setw(18)<<setiosflags(std::ios::right) <<"[momentMap]" |
---|
| 430 | <<" = " <<resetiosflags(std::ios::right)<<par.getMomentMap() <<endl; |
---|
| 431 | theStream<<setw(38)<<"Detection Map" |
---|
| 432 | <<setw(18)<<setiosflags(std::ios::right) <<"[detectionMap]" |
---|
| 433 | <<" = " <<resetiosflags(std::ios::right)<<par.getDetectionMap() <<endl; |
---|
[3] | 434 | } |
---|
| 435 | if(par.getFlagATrous()){ |
---|
[93] | 436 | theStream<<setw(38)<<"Saving reconstructed cube?" |
---|
| 437 | <<setw(18)<<setiosflags(std::ios::right) <<"[flagoutputrecon]" |
---|
| 438 | <<" = " <<resetiosflags(std::ios::right)<<par.getFlagOutputRecon()<<endl; |
---|
| 439 | theStream<<setw(38)<<"Saving residuals from reconstruction?" |
---|
| 440 | <<setw(18)<<setiosflags(std::ios::right) <<"[flagoutputresid]" |
---|
| 441 | <<" = " <<resetiosflags(std::ios::right)<<par.getFlagOutputResid()<<endl; |
---|
[3] | 442 | } |
---|
[60] | 443 | theStream <<"------"<<endl; |
---|
[93] | 444 | theStream <<setw(38)<<"Searching for Negative features?" |
---|
| 445 | <<setw(18)<<setiosflags(std::ios::right) <<"[flagNegative]" |
---|
| 446 | <<" = " <<resetiosflags(std::ios::right)<<par.getFlagNegative() <<endl; |
---|
| 447 | theStream <<setw(38)<<"Fixing Blank Pixels?" |
---|
| 448 | <<setw(18)<<setiosflags(std::ios::right) <<"[flagBlankPix]" |
---|
| 449 | <<" = " <<resetiosflags(std::ios::right)<<par.getFlagBlankPix() <<endl; |
---|
[3] | 450 | if(par.getFlagBlankPix()){ |
---|
[93] | 451 | theStream<<setw(38)<<"Blank Pixel Value" |
---|
[96] | 452 | <<setw(18)<<setiosflags(std::ios::right) << blankParam |
---|
[93] | 453 | <<" = " <<resetiosflags(std::ios::right)<<par.getBlankPixVal() <<endl; |
---|
[3] | 454 | } |
---|
[93] | 455 | theStream <<setw(38)<<"Removing Milky Way channels?" |
---|
| 456 | <<setw(18)<<setiosflags(std::ios::right) <<"[flagMW]" |
---|
| 457 | <<" = " <<resetiosflags(std::ios::right)<<par.getFlagMW() <<endl; |
---|
[3] | 458 | if(par.getFlagMW()){ |
---|
[93] | 459 | theStream<<setw(38)<<"Milky Way Channels" |
---|
[95] | 460 | <<setw(18)<<setiosflags(std::ios::right) <<"[minMW - maxMW]" |
---|
[93] | 461 | <<" = " <<resetiosflags(std::ios::right)<<par.getMinMW() |
---|
[92] | 462 | <<"-" <<par.getMaxMW() <<endl; |
---|
[3] | 463 | } |
---|
[93] | 464 | theStream <<setw(38)<<"Beam Size (pixels)" |
---|
| 465 | <<setw(18)<<setiosflags(std::ios::right) <<"" |
---|
| 466 | <<" = " <<resetiosflags(std::ios::right)<<par.getBeamSize() <<endl; |
---|
| 467 | theStream <<setw(38)<<"Removing baselines before search?" |
---|
| 468 | <<setw(18)<<setiosflags(std::ios::right) <<"[flagBaseline]" |
---|
| 469 | <<" = " <<resetiosflags(std::ios::right)<<par.getFlagBaseline() <<endl; |
---|
| 470 | theStream <<setw(38)<<"Minimum # Pixels in a detection" |
---|
| 471 | <<setw(18)<<setiosflags(std::ios::right) <<"[minPix]" |
---|
| 472 | <<" = " <<resetiosflags(std::ios::right)<<par.getMinPix() <<endl; |
---|
| 473 | theStream <<setw(38)<<"Minimum # Channels in a detection" |
---|
| 474 | <<setw(18)<<setiosflags(std::ios::right) <<"[minChannels]" |
---|
| 475 | <<" = " <<resetiosflags(std::ios::right)<<par.getMinChannels() <<endl; |
---|
| 476 | theStream <<setw(38)<<"Growing objects after detection?" |
---|
| 477 | <<setw(18)<<setiosflags(std::ios::right) <<"[flagGrowth]" |
---|
| 478 | <<" = " <<resetiosflags(std::ios::right)<<par.getFlagGrowth() <<endl; |
---|
[3] | 479 | if(par.getFlagGrowth()) { |
---|
[93] | 480 | theStream<<setw(38)<<"SNR Threshold for growth" |
---|
| 481 | <<setw(18)<<setiosflags(std::ios::right) <<"[growthCut]" |
---|
| 482 | <<" = " <<resetiosflags(std::ios::right)<<par.getGrowthCut() <<endl; |
---|
[3] | 483 | } |
---|
[93] | 484 | theStream <<setw(38)<<"Using A Trous reconstruction?" |
---|
| 485 | <<setw(18)<<setiosflags(std::ios::right) <<"[flagATrous]" |
---|
| 486 | <<" = " <<resetiosflags(std::ios::right)<<par.getFlagATrous() <<endl; |
---|
[3] | 487 | if(par.getFlagATrous()){ |
---|
[96] | 488 | theStream<<setw(38)<<"Number of dimensions in reconstruction" |
---|
| 489 | <<setw(18)<<setiosflags(std::ios::right) <<"[reconDim]" |
---|
| 490 | <<" = " <<resetiosflags(std::ios::right)<<par.getReconDim() <<endl; |
---|
[93] | 491 | theStream<<setw(38)<<"Minimum scale in reconstruction" |
---|
| 492 | <<setw(18)<<setiosflags(std::ios::right) <<"[scaleMin]" |
---|
| 493 | <<" = " <<resetiosflags(std::ios::right)<<par.getMinScale() <<endl; |
---|
| 494 | theStream<<setw(38)<<"SNR Threshold within reconstruction" |
---|
| 495 | <<setw(18)<<setiosflags(std::ios::right) <<"[snrRecon]" |
---|
| 496 | <<" = " <<resetiosflags(std::ios::right)<<par.getAtrousCut() <<endl; |
---|
| 497 | theStream<<setw(38)<<"Filter being used for reconstruction" |
---|
| 498 | <<setw(18)<<setiosflags(std::ios::right) <<"[filterCode]" |
---|
| 499 | <<" = " <<resetiosflags(std::ios::right)<<par.getFilterCode() |
---|
| 500 | << " (" << par.getFilterName() << ")" <<endl; |
---|
[3] | 501 | } |
---|
[93] | 502 | theStream <<setw(38)<<"Using FDR analysis?" |
---|
| 503 | <<setw(18)<<setiosflags(std::ios::right) <<"[flagFDR]" |
---|
| 504 | <<" = " <<resetiosflags(std::ios::right)<<par.getFlagFDR() <<endl; |
---|
[3] | 505 | if(par.getFlagFDR()){ |
---|
[93] | 506 | theStream<<setw(38)<<"Alpha value for FDR analysis" |
---|
| 507 | <<setw(18)<<setiosflags(std::ios::right) <<"[alphaFDR]" |
---|
| 508 | <<" = " <<resetiosflags(std::ios::right)<<par.getAlpha() <<endl; |
---|
[3] | 509 | } |
---|
| 510 | else { |
---|
[93] | 511 | theStream<<setw(38)<<"SNR Threshold" |
---|
| 512 | <<setw(18)<<setiosflags(std::ios::right) <<"[snrCut]" |
---|
| 513 | <<" = " <<resetiosflags(std::ios::right)<<par.getCut() <<endl; |
---|
[3] | 514 | } |
---|
[93] | 515 | theStream <<setw(38)<<"Using Adjacent-pixel criterion?" |
---|
| 516 | <<setw(18)<<setiosflags(std::ios::right) <<"[flagAdjacent]" |
---|
| 517 | <<" = " <<resetiosflags(std::ios::right)<<par.getFlagAdjacent() <<endl; |
---|
[3] | 518 | if(!par.getFlagAdjacent()){ |
---|
[93] | 519 | theStream<<setw(38)<<"Max. spatial separation for merging" |
---|
| 520 | <<setw(18)<<setiosflags(std::ios::right) <<"[threshSpatial]" |
---|
| 521 | <<" = " <<resetiosflags(std::ios::right)<<par.getThreshS() <<endl; |
---|
[3] | 522 | } |
---|
[93] | 523 | theStream <<setw(38)<<"Max. velocity separation for merging" |
---|
| 524 | <<setw(18)<<setiosflags(std::ios::right) <<"[threshVelocity]" |
---|
| 525 | <<" = " <<resetiosflags(std::ios::right)<<par.getThreshV() <<endl; |
---|
| 526 | theStream <<setw(38)<<"Method of spectral plotting" |
---|
| 527 | <<setw(18)<<setiosflags(std::ios::right) <<"[spectralMethod]" |
---|
| 528 | <<" = " <<resetiosflags(std::ios::right)<<par.getSpectralMethod() <<endl; |
---|
[3] | 529 | theStream <<"--------------------"<<endl; |
---|
[93] | 530 | theStream << std::setfill(' '); |
---|
[3] | 531 | theStream.unsetf(std::ios::left); |
---|
| 532 | theStream.unsetf(std::ios::boolalpha); |
---|
| 533 | } |
---|
| 534 | |
---|
| 535 | void Param::parseSubsection() |
---|
| 536 | { |
---|
| 537 | std::stringstream ss; |
---|
| 538 | ss.str(this->subsection); |
---|
| 539 | bool removeStep = false; |
---|
| 540 | string x,y,z; |
---|
| 541 | getline(ss,x,'['); |
---|
| 542 | getline(ss,x,','); |
---|
| 543 | getline(ss,y,','); |
---|
| 544 | getline(ss,z,']'); |
---|
| 545 | char *end; |
---|
| 546 | if(x!="*") { |
---|
| 547 | int x1,x2,dx; |
---|
| 548 | int a = x.find(':'); // first occurence of ':' in x-subsection string |
---|
| 549 | int b = x.find(':',a+1); // location of second ':' -- will be -1 if there is no second occurence. |
---|
| 550 | x1 = atoi( x.substr(0,a).c_str() ); // minimum x in subsection |
---|
| 551 | this->xSubOffset = x1 - 1; |
---|
| 552 | if(b>0){ // there is a dx component |
---|
| 553 | x2 = atoi( x.substr(a+1,b-a-1).c_str() ); // maximum x in subsection |
---|
| 554 | dx = atoi( x.substr(b+1,x.size()).c_str() ); // delta x in subsection |
---|
| 555 | x = x.substr(0,b); // rewrite x without the delta-x part. |
---|
| 556 | removeStep = true; |
---|
| 557 | } |
---|
| 558 | } |
---|
| 559 | if(y!="*") { |
---|
| 560 | int y1,y2,dy; |
---|
| 561 | int a = y.find(':'); // first occurence of ':' in y-subsection string |
---|
| 562 | int b = y.find(':',a+1); // location of second ':' -- will be -1 if there is no second occurence. |
---|
| 563 | y1 = atoi( y.substr(0,a).c_str() ); // minimum y in subsection |
---|
| 564 | this->ySubOffset = y1 - 1; |
---|
| 565 | if(b>0){ // there is a dy component |
---|
| 566 | y2 = atoi( y.substr(a+1,b-a-1).c_str() ); // maximum y in subsection |
---|
| 567 | dy = atoi( y.substr(b+1,y.size()).c_str() ); // delta y in subsection |
---|
| 568 | y = y.substr(0,b); // rewrite y without the delta-y part. |
---|
| 569 | removeStep = true; |
---|
| 570 | } |
---|
| 571 | } |
---|
| 572 | if(z!="*") { |
---|
| 573 | int z1,z2,dz; |
---|
| 574 | int a = z.find(':'); // first occurence of ':' in z-subsection string |
---|
| 575 | int b = z.find(':',a+1); // location of second ':' -- will be -1 if there is no second occurence. |
---|
| 576 | z1 = atoi( z.substr(0,a).c_str() ); // minimum z in subsection |
---|
| 577 | this->zSubOffset = z1 - 1; |
---|
| 578 | if(b>0){ // there is a dz component |
---|
| 579 | z2 = atoi( z.substr(a+1,b-a-1).c_str() ); // maximum z in subsection |
---|
| 580 | dz = atoi( z.substr(b+1,z.size()).c_str() ); // delta z in subsection |
---|
| 581 | z = z.substr(0,b); // rewrite z without the delta-z part. |
---|
| 582 | removeStep = true; |
---|
| 583 | } |
---|
| 584 | } |
---|
| 585 | |
---|
| 586 | if(removeStep){ |
---|
| 587 | std::cerr << "\a\tThe subsection given is " << this->subsection <<".\n"; |
---|
| 588 | std::cerr << "\tDuchamp is currently unable to deal with pixel steps in the subsection.\n"; |
---|
| 589 | std::cerr << "\tThese have been ignored, and so the subection used is "; |
---|
| 590 | this->subsection = "[" + x + "," + y + "," + z + "]"; // rewrite subsection without any step sizes. |
---|
| 591 | std::cerr << this->subsection << std::endl; |
---|
| 592 | } |
---|
| 593 | |
---|
| 594 | // if(x!="*") this->xSubOffset = strtol(x.c_str(),&end,10) - 1; |
---|
| 595 | // if(y!="*") this->ySubOffset = strtol(y.c_str(),&end,10) - 1; |
---|
| 596 | // if(z!="*") this->zSubOffset = strtol(z.c_str(),&end,10) - 1; |
---|
| 597 | } |
---|
| 598 | |
---|
| 599 | bool Param::isBlank(float &val) |
---|
| 600 | { |
---|
| 601 | // std::cerr << "val = " << val << " " << int((val-this->bzeroKeyword)/this->bscaleKeyword) |
---|
| 602 | // <<" " <<this->blankKeyword << std::endl; |
---|
| 603 | if(this->flagBlankPix){ |
---|
| 604 | if(this->nanAsBlank) return bool(isnan(val)); |
---|
| 605 | else// return (val == this->blankPixValue); |
---|
| 606 | return ( this->blankKeyword == int((val-this->bzeroKeyword)/this->bscaleKeyword) ); |
---|
| 607 | } |
---|
| 608 | else return false; |
---|
| 609 | } |
---|
[100] | 610 | |
---|
| 611 | string Param::outputReconFile() |
---|
| 612 | { |
---|
| 613 | /** |
---|
| 614 | * outputReconFile() |
---|
| 615 | * |
---|
| 616 | * This function produces the required filename in which to save |
---|
| 617 | * the reconstructed array. If the input image is image.fits, then |
---|
| 618 | * the output will be eg. image.RECON-3-2-4-1.fits, where the numbers are |
---|
| 619 | * 3=reconDim, 2=filterCode, 4=snrRecon, 1=minScale |
---|
| 620 | */ |
---|
| 621 | string inputName = this->imageFile; |
---|
| 622 | std::stringstream ss; |
---|
| 623 | ss << inputName.substr(0,inputName.size()-5); // remove the ".fits" on the end. |
---|
| 624 | ss << ".RECON-" << this->reconDim |
---|
| 625 | << "-" << this->filterCode |
---|
| 626 | << "-" << this->snrRecon |
---|
| 627 | << "-" << this->scaleMin |
---|
| 628 | << ".fits"; |
---|
| 629 | return ss.str(); |
---|
| 630 | } |
---|
| 631 | |
---|
| 632 | string Param::outputResidFile() |
---|
| 633 | { |
---|
| 634 | /** |
---|
| 635 | * outputResidFile() |
---|
| 636 | * |
---|
| 637 | * This function produces the required filename in which to save |
---|
| 638 | * the reconstructed array. If the input image is image.fits, then |
---|
| 639 | * the output will be eg. image.RESID-3-2-4-1.fits, where the numbers are |
---|
| 640 | * 3=reconDim, 2=filterCode, 4=snrRecon, 1=scaleMin |
---|
| 641 | */ |
---|
| 642 | string inputName = this->imageFile; |
---|
| 643 | std::stringstream ss; |
---|
| 644 | ss << inputName.substr(0,inputName.size()-5); // remove the ".fits" on the end. |
---|
| 645 | ss << ".RESID-" << this->reconDim |
---|
| 646 | << "-" << this->filterCode |
---|
| 647 | << "-" << this->snrRecon |
---|
| 648 | << "-" << this->scaleMin |
---|
| 649 | << ".fits"; |
---|
| 650 | return ss.str(); |
---|
| 651 | } |
---|