[299] | 1 | // ----------------------------------------------------------------------- |
---|
| 2 | // param.cc: Dealing with the set of parameters for Duchamp. |
---|
| 3 | // ----------------------------------------------------------------------- |
---|
| 4 | // Copyright (C) 2006, Matthew Whiting, ATNF |
---|
| 5 | // |
---|
| 6 | // This program is free software; you can redistribute it and/or modify it |
---|
| 7 | // under the terms of the GNU General Public License as published by the |
---|
| 8 | // Free Software Foundation; either version 2 of the License, or (at your |
---|
| 9 | // option) any later version. |
---|
| 10 | // |
---|
| 11 | // Duchamp is distributed in the hope that it will be useful, but WITHOUT |
---|
| 12 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
---|
| 13 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
---|
| 14 | // for more details. |
---|
| 15 | // |
---|
| 16 | // You should have received a copy of the GNU General Public License |
---|
| 17 | // along with Duchamp; if not, write to the Free Software Foundation, |
---|
| 18 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA |
---|
| 19 | // |
---|
| 20 | // Correspondence concerning Duchamp may be directed to: |
---|
| 21 | // Internet email: Matthew.Whiting [at] atnf.csiro.au |
---|
| 22 | // Postal address: Dr. Matthew Whiting |
---|
| 23 | // Australia Telescope National Facility, CSIRO |
---|
| 24 | // PO Box 76 |
---|
| 25 | // Epping NSW 1710 |
---|
| 26 | // AUSTRALIA |
---|
| 27 | // ----------------------------------------------------------------------- |
---|
[3] | 28 | #include <iostream> |
---|
| 29 | #include <iomanip> |
---|
| 30 | #include <fstream> |
---|
| 31 | #include <sstream> |
---|
| 32 | #include <string> |
---|
[534] | 33 | #include <algorithm> |
---|
[205] | 34 | #include <stdlib.h> |
---|
[269] | 35 | #include <ctype.h> |
---|
[3] | 36 | #include <math.h> |
---|
[410] | 37 | #include <unistd.h> |
---|
[393] | 38 | #include <duchamp/param.hh> |
---|
| 39 | #include <duchamp/fitsHeader.hh> |
---|
| 40 | #include <duchamp/duchamp.hh> |
---|
[420] | 41 | #include <duchamp/pgheader.hh> |
---|
[393] | 42 | #include <duchamp/ATrous/filter.hh> |
---|
| 43 | #include <duchamp/Utils/utils.hh> |
---|
| 44 | #include <duchamp/Utils/Section.hh> |
---|
[916] | 45 | #include <duchamp/Utils/VOParam.hh> |
---|
[1061] | 46 | #include <duchamp/Outputs/columns.hh> |
---|
[3] | 47 | |
---|
[378] | 48 | namespace duchamp |
---|
[309] | 49 | { |
---|
[882] | 50 | const std::string defaultSection = "[*,*,*]"; |
---|
[309] | 51 | |
---|
[378] | 52 | /****************************************************************/ |
---|
| 53 | /////////////////////////////////////////////////// |
---|
| 54 | //// Accessor Functions for Parameter class: |
---|
| 55 | /////////////////////////////////////////////////// |
---|
| 56 | Param::~Param() |
---|
| 57 | { |
---|
[528] | 58 | /// Deletes the offsets array if the sizeOffsets parameter is |
---|
| 59 | /// positive. |
---|
[378] | 60 | if(this->sizeOffsets>0) delete [] this->offsets; |
---|
| 61 | } |
---|
[309] | 62 | |
---|
[378] | 63 | Param::Param() |
---|
| 64 | { |
---|
| 65 | this->defaultValues(); |
---|
| 66 | } |
---|
[3] | 67 | |
---|
[378] | 68 | void Param::defaultValues() |
---|
| 69 | { |
---|
[528] | 70 | /// Provides default intial values for the parameters. Note that |
---|
| 71 | /// imageFile has no default value! |
---|
| 72 | |
---|
[378] | 73 | // Input files |
---|
| 74 | this->imageFile = ""; |
---|
| 75 | this->flagSubsection = false; |
---|
[882] | 76 | this->pixelSec.setSection(defaultSection); |
---|
[378] | 77 | this->flagReconExists = false; |
---|
| 78 | this->reconFile = ""; |
---|
| 79 | this->flagSmoothExists = false; |
---|
| 80 | this->smoothFile = ""; |
---|
[475] | 81 | this->usePrevious = false; |
---|
| 82 | this->objectList = ""; |
---|
[378] | 83 | // Output files |
---|
| 84 | this->flagLog = false; |
---|
| 85 | this->logFile = "duchamp-Logfile.txt"; |
---|
| 86 | this->outFile = "duchamp-Results.txt"; |
---|
| 87 | this->flagSeparateHeader= false; |
---|
| 88 | this->headerFile = "duchamp-Results.hdr"; |
---|
[1146] | 89 | this->flagWriteBinaryCatalogue = true; |
---|
| 90 | this->binaryCatalogue = "duchamp-Catalogue.dpc"; |
---|
[831] | 91 | this->flagPlotSpectra = true; |
---|
[378] | 92 | this->spectraFile = "duchamp-Spectra.ps"; |
---|
[1148] | 93 | this->flagPlotIndividualSpectra = false; |
---|
[424] | 94 | this->flagTextSpectra = false; |
---|
| 95 | this->spectraTextFile = "duchamp-Spectra.txt"; |
---|
[1120] | 96 | this->flagOutputBaseline = false; |
---|
| 97 | this->fileOutputBaseline = ""; |
---|
[670] | 98 | this->flagOutputMomentMap = false; |
---|
| 99 | this->fileOutputMomentMap = ""; |
---|
[1142] | 100 | this->flagOutputMomentMask = false; |
---|
| 101 | this->fileOutputMomentMask = ""; |
---|
[379] | 102 | this->flagOutputMask = false; |
---|
[525] | 103 | this->fileOutputMask = ""; |
---|
[521] | 104 | this->flagMaskWithObjectNum = false; |
---|
[378] | 105 | this->flagOutputSmooth = false; |
---|
[525] | 106 | this->fileOutputSmooth = ""; |
---|
[378] | 107 | this->flagOutputRecon = false; |
---|
[525] | 108 | this->fileOutputRecon = ""; |
---|
[378] | 109 | this->flagOutputResid = false; |
---|
[525] | 110 | this->fileOutputResid = ""; |
---|
[378] | 111 | this->flagVOT = false; |
---|
| 112 | this->votFile = "duchamp-Results.xml"; |
---|
| 113 | this->flagKarma = false; |
---|
| 114 | this->karmaFile = "duchamp-Results.ann"; |
---|
[1077] | 115 | this->flagDS9 = false; |
---|
| 116 | this->ds9File = "duchamp-Results.reg"; |
---|
[1126] | 117 | this->flagCasa = false; |
---|
| 118 | this->casaFile = "duchamp-Results.crf"; |
---|
[446] | 119 | this->annotationType = "borders"; |
---|
[378] | 120 | this->flagMaps = true; |
---|
| 121 | this->detectionMap = "duchamp-DetectionMap.ps"; |
---|
| 122 | this->momentMap = "duchamp-MomentMap.ps"; |
---|
| 123 | this->flagXOutput = true; |
---|
[1061] | 124 | this->precFlux = Catalogues::prFLUX; |
---|
| 125 | this->precVel = Catalogues::prVEL; |
---|
| 126 | this->precSNR = Catalogues::prSNR; |
---|
[378] | 127 | // Cube related parameters |
---|
[845] | 128 | this->flagBlankPix = false; |
---|
[378] | 129 | this->blankPixValue = -8.00061; |
---|
| 130 | this->blankKeyword = 1; |
---|
| 131 | this->bscaleKeyword = -8.00061; |
---|
| 132 | this->bzeroKeyword = 0.; |
---|
[434] | 133 | this->newFluxUnits = ""; |
---|
[378] | 134 | // Milky-Way parameters |
---|
| 135 | this->flagMW = false; |
---|
| 136 | this->maxMW = 112; |
---|
| 137 | this->minMW = 75; |
---|
[788] | 138 | this->areaBeam = 0.; |
---|
| 139 | this->fwhmBeam = 0.; |
---|
[791] | 140 | this->beamAsUsed.empty(); |
---|
[686] | 141 | this->searchType = "spatial"; |
---|
[378] | 142 | // Trim-related |
---|
| 143 | this->flagTrim = false; |
---|
| 144 | this->hasBeenTrimmed = false; |
---|
| 145 | this->borderLeft = 0; |
---|
| 146 | this->borderRight = 0; |
---|
| 147 | this->borderBottom = 0; |
---|
| 148 | this->borderTop = 0; |
---|
| 149 | // Subsection offsets |
---|
| 150 | this->sizeOffsets = 0; |
---|
| 151 | this->xSubOffset = 0; |
---|
| 152 | this->ySubOffset = 0; |
---|
| 153 | this->zSubOffset = 0; |
---|
| 154 | // Baseline related |
---|
| 155 | this->flagBaseline = false; |
---|
| 156 | // Detection-related |
---|
| 157 | this->flagNegative = false; |
---|
| 158 | // Object growth |
---|
| 159 | this->flagGrowth = false; |
---|
[458] | 160 | this->growthCut = 3.; |
---|
[461] | 161 | this->flagUserGrowthThreshold = false; |
---|
| 162 | this->growthThreshold = 0.; |
---|
[378] | 163 | // FDR analysis |
---|
| 164 | this->flagFDR = false; |
---|
| 165 | this->alphaFDR = 0.01; |
---|
[543] | 166 | this->FDRnumCorChan = 2; |
---|
[378] | 167 | // Other detection |
---|
| 168 | this->flagStatSec = false; |
---|
[882] | 169 | this->statSec.setSection(defaultSection); |
---|
[385] | 170 | this->flagRobustStats = true; |
---|
[1025] | 171 | this->snrCut = 5.; |
---|
[378] | 172 | this->threshold = 0.; |
---|
| 173 | this->flagUserThreshold = false; |
---|
| 174 | // Smoothing |
---|
| 175 | this->flagSmooth = false; |
---|
| 176 | this->smoothType = "spectral"; |
---|
| 177 | this->hanningWidth = 5; |
---|
| 178 | this->kernMaj = 3.; |
---|
| 179 | this->kernMin = -1.; |
---|
| 180 | this->kernPA = 0.; |
---|
| 181 | // A trous reconstruction parameters |
---|
| 182 | this->flagATrous = false; |
---|
| 183 | this->reconDim = 1; |
---|
| 184 | this->scaleMin = 1; |
---|
| 185 | this->scaleMax = 0; |
---|
| 186 | this->snrRecon = 4.; |
---|
[1026] | 187 | this->reconConvergence = 0.005; |
---|
[378] | 188 | this->filterCode = 1; |
---|
| 189 | this->reconFilter.define(this->filterCode); |
---|
| 190 | // Volume-merging parameters |
---|
| 191 | this->flagAdjacent = true; |
---|
| 192 | this->threshSpatial = 3.; |
---|
| 193 | this->threshVelocity = 7.; |
---|
| 194 | this->minChannels = 3; |
---|
| 195 | this->minPix = 2; |
---|
[720] | 196 | this->minVoxels = 4; |
---|
[672] | 197 | this->flagRejectBeforeMerge = false; |
---|
[691] | 198 | this->flagTwoStageMerging = true; |
---|
[378] | 199 | // Input-Output related |
---|
| 200 | this->spectralMethod = "peak"; |
---|
[948] | 201 | this->spectralType = ""; |
---|
| 202 | this->restFrequency = -1.; |
---|
| 203 | this->restFrequencyUsed = false; |
---|
[949] | 204 | this->spectralUnits = ""; |
---|
[378] | 205 | this->pixelCentre = "centroid"; |
---|
[571] | 206 | this->sortingParam = "vel"; |
---|
[378] | 207 | this->borders = true; |
---|
| 208 | this->blankEdge = true; |
---|
| 209 | this->verbose = true; |
---|
[1140] | 210 | this->commentStr = ""; |
---|
[419] | 211 | } |
---|
[204] | 212 | |
---|
[378] | 213 | Param::Param (const Param& p) |
---|
| 214 | { |
---|
| 215 | operator=(p); |
---|
[309] | 216 | } |
---|
[137] | 217 | |
---|
[378] | 218 | Param& Param::operator= (const Param& p) |
---|
| 219 | { |
---|
| 220 | if(this == &p) return *this; |
---|
| 221 | this->imageFile = p.imageFile; |
---|
| 222 | this->flagSubsection = p.flagSubsection; |
---|
| 223 | this->pixelSec = p.pixelSec; |
---|
| 224 | this->flagReconExists = p.flagReconExists; |
---|
| 225 | this->reconFile = p.reconFile; |
---|
| 226 | this->flagSmoothExists = p.flagSmoothExists; |
---|
[475] | 227 | this->smoothFile = p.smoothFile; |
---|
| 228 | this->usePrevious = p.usePrevious; |
---|
| 229 | this->objectList = p.objectList; |
---|
[378] | 230 | this->flagLog = p.flagLog; |
---|
| 231 | this->logFile = p.logFile; |
---|
| 232 | this->outFile = p.outFile; |
---|
| 233 | this->flagSeparateHeader= p.flagSeparateHeader; |
---|
| 234 | this->headerFile = p.headerFile; |
---|
[1146] | 235 | this->flagWriteBinaryCatalogue = p.flagWriteBinaryCatalogue; |
---|
| 236 | this->binaryCatalogue = p.binaryCatalogue; |
---|
[882] | 237 | this->flagPlotSpectra = p.flagPlotSpectra; |
---|
[378] | 238 | this->spectraFile = p.spectraFile; |
---|
[1148] | 239 | this->flagPlotIndividualSpectra = p.flagPlotIndividualSpectra; |
---|
[424] | 240 | this->flagTextSpectra = p.flagTextSpectra; |
---|
| 241 | this->spectraTextFile = p.spectraTextFile; |
---|
[1120] | 242 | this->flagOutputBaseline = p.flagOutputBaseline; |
---|
| 243 | this->fileOutputBaseline = p.fileOutputBaseline; |
---|
[670] | 244 | this->flagOutputMomentMap = p.flagOutputMomentMap; |
---|
| 245 | this->fileOutputMomentMap = p.fileOutputMomentMap; |
---|
[1142] | 246 | this->flagOutputMomentMask = p.flagOutputMomentMask; |
---|
| 247 | this->fileOutputMomentMask = p.fileOutputMomentMask; |
---|
[379] | 248 | this->flagOutputMask = p.flagOutputMask; |
---|
[525] | 249 | this->fileOutputMask = p.fileOutputMask; |
---|
[521] | 250 | this->flagMaskWithObjectNum = p.flagMaskWithObjectNum; |
---|
[378] | 251 | this->flagOutputSmooth = p.flagOutputSmooth; |
---|
[525] | 252 | this->fileOutputSmooth = p.fileOutputSmooth; |
---|
[378] | 253 | this->flagOutputRecon = p.flagOutputRecon; |
---|
[525] | 254 | this->fileOutputRecon = p.fileOutputRecon; |
---|
[378] | 255 | this->flagOutputResid = p.flagOutputResid; |
---|
[525] | 256 | this->fileOutputResid = p.fileOutputResid; |
---|
[378] | 257 | this->flagVOT = p.flagVOT; |
---|
| 258 | this->votFile = p.votFile; |
---|
| 259 | this->flagKarma = p.flagKarma; |
---|
| 260 | this->karmaFile = p.karmaFile; |
---|
[1077] | 261 | this->flagDS9 = p.flagDS9; |
---|
| 262 | this->ds9File = p.ds9File; |
---|
[1126] | 263 | this->flagCasa = p.flagCasa; |
---|
| 264 | this->casaFile = p.casaFile; |
---|
[446] | 265 | this->annotationType = p.annotationType; |
---|
[378] | 266 | this->flagMaps = p.flagMaps; |
---|
| 267 | this->detectionMap = p.detectionMap; |
---|
| 268 | this->momentMap = p.momentMap; |
---|
| 269 | this->flagXOutput = p.flagXOutput; |
---|
[438] | 270 | this->precFlux = p.precFlux; |
---|
| 271 | this->precVel = p.precVel; |
---|
| 272 | this->precSNR = p.precSNR; |
---|
[882] | 273 | this->flagNegative = p.flagNegative; |
---|
[378] | 274 | this->flagBlankPix = p.flagBlankPix; |
---|
| 275 | this->blankPixValue = p.blankPixValue; |
---|
| 276 | this->blankKeyword = p.blankKeyword; |
---|
| 277 | this->bscaleKeyword = p.bscaleKeyword; |
---|
| 278 | this->bzeroKeyword = p.bzeroKeyword; |
---|
[434] | 279 | this->newFluxUnits = p.newFluxUnits; |
---|
[378] | 280 | this->flagMW = p.flagMW; |
---|
| 281 | this->maxMW = p.maxMW; |
---|
| 282 | this->minMW = p.minMW; |
---|
[662] | 283 | this->areaBeam = p.areaBeam; |
---|
| 284 | this->fwhmBeam = p.fwhmBeam; |
---|
[791] | 285 | this->beamAsUsed = p.beamAsUsed; |
---|
[686] | 286 | this->searchType = p.searchType; |
---|
[378] | 287 | this->flagTrim = p.flagTrim; |
---|
| 288 | this->hasBeenTrimmed = p.hasBeenTrimmed; |
---|
| 289 | this->borderLeft = p.borderLeft; |
---|
| 290 | this->borderRight = p.borderRight; |
---|
| 291 | this->borderBottom = p.borderBottom; |
---|
| 292 | this->borderTop = p.borderTop; |
---|
| 293 | if(this->sizeOffsets>0) delete [] this->offsets; |
---|
| 294 | this->sizeOffsets = p.sizeOffsets; |
---|
| 295 | if(this->sizeOffsets>0){ |
---|
| 296 | this->offsets = new long[this->sizeOffsets]; |
---|
| 297 | for(int i=0;i<this->sizeOffsets;i++) this->offsets[i] = p.offsets[i]; |
---|
| 298 | } |
---|
| 299 | this->xSubOffset = p.xSubOffset; |
---|
| 300 | this->ySubOffset = p.ySubOffset; |
---|
| 301 | this->zSubOffset = p.zSubOffset; |
---|
| 302 | this->flagBaseline = p.flagBaseline; |
---|
| 303 | this->flagGrowth = p.flagGrowth; |
---|
| 304 | this->growthCut = p.growthCut; |
---|
[503] | 305 | this->growthThreshold = p.growthThreshold; |
---|
| 306 | this->flagUserGrowthThreshold = p.flagUserGrowthThreshold; |
---|
[378] | 307 | this->flagFDR = p.flagFDR; |
---|
| 308 | this->alphaFDR = p.alphaFDR; |
---|
[543] | 309 | this->FDRnumCorChan = p.FDRnumCorChan; |
---|
[378] | 310 | this->flagStatSec = p.flagStatSec; |
---|
[385] | 311 | this->statSec = p.statSec; |
---|
| 312 | this->flagRobustStats = p.flagRobustStats; |
---|
[378] | 313 | this->snrCut = p.snrCut; |
---|
| 314 | this->threshold = p.threshold; |
---|
| 315 | this->flagUserThreshold = p.flagUserThreshold; |
---|
| 316 | this->flagSmooth = p.flagSmooth; |
---|
| 317 | this->smoothType = p.smoothType; |
---|
| 318 | this->hanningWidth = p.hanningWidth; |
---|
| 319 | this->kernMaj = p.kernMaj; |
---|
| 320 | this->kernMin = p.kernMin; |
---|
| 321 | this->kernPA = p.kernPA; |
---|
| 322 | this->flagATrous = p.flagATrous; |
---|
| 323 | this->reconDim = p.reconDim; |
---|
| 324 | this->scaleMin = p.scaleMin; |
---|
| 325 | this->scaleMax = p.scaleMax; |
---|
| 326 | this->snrRecon = p.snrRecon; |
---|
[1026] | 327 | this->reconConvergence = p.reconConvergence; |
---|
[378] | 328 | this->filterCode = p.filterCode; |
---|
| 329 | this->reconFilter = p.reconFilter; |
---|
| 330 | this->flagAdjacent = p.flagAdjacent; |
---|
| 331 | this->threshSpatial = p.threshSpatial; |
---|
| 332 | this->threshVelocity = p.threshVelocity; |
---|
| 333 | this->minChannels = p.minChannels; |
---|
| 334 | this->minPix = p.minPix; |
---|
[720] | 335 | this->minVoxels = p.minVoxels; |
---|
[691] | 336 | this->flagRejectBeforeMerge = p.flagRejectBeforeMerge; |
---|
| 337 | this->flagTwoStageMerging = p.flagTwoStageMerging; |
---|
[378] | 338 | this->spectralMethod = p.spectralMethod; |
---|
[948] | 339 | this->spectralType = p.spectralType; |
---|
| 340 | this->restFrequency = p.restFrequency; |
---|
| 341 | this->restFrequencyUsed = p.restFrequencyUsed; |
---|
[378] | 342 | this->spectralUnits = p.spectralUnits; |
---|
| 343 | this->pixelCentre = p.pixelCentre; |
---|
[571] | 344 | this->sortingParam = p.sortingParam; |
---|
[378] | 345 | this->borders = p.borders; |
---|
[571] | 346 | this->blankEdge = p.blankEdge; |
---|
[378] | 347 | this->verbose = p.verbose; |
---|
[1140] | 348 | this->commentStr = p.commentStr; |
---|
[378] | 349 | return *this; |
---|
| 350 | } |
---|
| 351 | //-------------------------------------------------------------------- |
---|
[266] | 352 | |
---|
[698] | 353 | OUTCOME Param::getopts(int argc, char ** argv, std::string progname) |
---|
[378] | 354 | { |
---|
[528] | 355 | /// A function that reads in the command-line options, in a manner |
---|
| 356 | /// tailored for use with the main Duchamp program. |
---|
| 357 | /// |
---|
| 358 | /// \param argc The number of command line arguments. |
---|
| 359 | /// \param argv The array of command line arguments. |
---|
[378] | 360 | |
---|
[698] | 361 | OUTCOME returnValue = FAILURE; |
---|
[378] | 362 | if(argc==1){ |
---|
[1149] | 363 | std::cout << ERR_USAGE_MSG; |
---|
[378] | 364 | returnValue = FAILURE; |
---|
| 365 | } |
---|
| 366 | else { |
---|
| 367 | std::string file; |
---|
[1149] | 368 | float thresh; |
---|
| 369 | bool changeX = false, changeThresh=false; |
---|
[378] | 370 | this->defaultValues(); |
---|
| 371 | char c; |
---|
[1149] | 372 | while( ( c = getopt(argc,argv,"p:f:t:hvx") )!=-1){ |
---|
[378] | 373 | switch(c) { |
---|
| 374 | case 'p': |
---|
| 375 | file = optarg; |
---|
| 376 | if(this->readParams(file)==FAILURE){ |
---|
[913] | 377 | DUCHAMPERROR(progname,"Could not open parameter file " << file); |
---|
[378] | 378 | } |
---|
| 379 | else returnValue = SUCCESS; |
---|
| 380 | break; |
---|
| 381 | case 'f': |
---|
| 382 | file = optarg; |
---|
| 383 | this->imageFile = file; |
---|
| 384 | returnValue = SUCCESS; |
---|
| 385 | break; |
---|
| 386 | case 'v': |
---|
| 387 | std::cout << PROGNAME << " version " << VERSION << std::endl; |
---|
| 388 | break; |
---|
| 389 | case 'x': |
---|
| 390 | changeX = true; |
---|
| 391 | break; |
---|
[1149] | 392 | case 't': |
---|
| 393 | thresh = atof(optarg); |
---|
| 394 | changeThresh = true; |
---|
| 395 | break; |
---|
[378] | 396 | case 'h': |
---|
| 397 | default : |
---|
[1149] | 398 | std::cout << ERR_USAGE_MSG; |
---|
[378] | 399 | break; |
---|
[266] | 400 | } |
---|
| 401 | } |
---|
[378] | 402 | if(changeX){ |
---|
| 403 | if(returnValue == SUCCESS) this->setFlagXOutput(false); |
---|
| 404 | else { |
---|
[913] | 405 | DUCHAMPERROR(progname, "You need to specify either a parameter file or FITS image.\n"); |
---|
[378] | 406 | std::cout << "\n" << ERR_USAGE_MSG; |
---|
| 407 | } |
---|
[294] | 408 | } |
---|
[1149] | 409 | if(changeThresh){ |
---|
| 410 | this->threshold = thresh; |
---|
| 411 | this->flagUserThreshold = true; |
---|
| 412 | this->checkPars(); |
---|
| 413 | } |
---|
[294] | 414 | } |
---|
[378] | 415 | return returnValue; |
---|
[266] | 416 | } |
---|
[378] | 417 | //-------------------------------------------------------------------- |
---|
[266] | 418 | |
---|
[378] | 419 | bool Param::isBlank(float &value) |
---|
| 420 | { |
---|
[528] | 421 | /// Tests whether the value passed as the argument is BLANK or not. |
---|
| 422 | /// \param value Pixel value to be tested. |
---|
| 423 | /// \return False if flagBlankPix is false. Else, compare to the |
---|
| 424 | /// relevant FITS keywords, using integer comparison. |
---|
| 425 | |
---|
[378] | 426 | return this->flagBlankPix && |
---|
| 427 | (this->blankKeyword == int((value-this->bzeroKeyword)/this->bscaleKeyword)); |
---|
[419] | 428 | } |
---|
[266] | 429 | |
---|
[1000] | 430 | bool *Param::makeBlankMask(float *array, size_t size) |
---|
[378] | 431 | { |
---|
[528] | 432 | /// This returns an array of bools, saying whether each pixel in the |
---|
| 433 | /// given array is BLANK or not. If the pixel is BLANK, set mask to |
---|
| 434 | /// false, else set to true. The array is allocated by the function. |
---|
| 435 | |
---|
[378] | 436 | bool *mask = new bool[size]; |
---|
[1000] | 437 | for(size_t i=0;i<size;i++) mask[i] = !this->isBlank(array[i]); |
---|
[378] | 438 | return mask; |
---|
| 439 | } |
---|
[275] | 440 | |
---|
| 441 | |
---|
[1000] | 442 | bool *Param::makeStatMask(float *array, size_t *dim) |
---|
[506] | 443 | { |
---|
[528] | 444 | /// This returns an array of bools, saying whether each pixel in |
---|
| 445 | /// the given array is suitable for a stats calculation. It needs |
---|
| 446 | /// to be in the StatSec (if defined), not blank and not a MW |
---|
| 447 | /// channel. The array is allocated by the function with a 'new' call. |
---|
| 448 | |
---|
[506] | 449 | bool *mask = new bool[dim[0]*dim[1]*dim[2]]; |
---|
[1000] | 450 | for(size_t x=0;x<dim[0];x++) { |
---|
| 451 | for(size_t y=0;y<dim[1];y++) { |
---|
| 452 | for(size_t z=0;z<dim[2];z++) { |
---|
| 453 | size_t i = x+y*dim[0]+z*dim[0]*dim[1]; |
---|
[506] | 454 | mask[i] = !this->isBlank(array[i]) && !this->isInMW(z) && this->isStatOK(x,y,z); |
---|
| 455 | } |
---|
| 456 | } |
---|
| 457 | } |
---|
| 458 | return mask; |
---|
| 459 | } |
---|
| 460 | |
---|
| 461 | |
---|
[378] | 462 | bool Param::isInMW(int z) |
---|
| 463 | { |
---|
[528] | 464 | /// Tests whether we are flagging Milky Way channels, and if so |
---|
| 465 | /// whether the given channel number is in the Milky Way range. The |
---|
| 466 | /// channels are assumed to start at number 0. |
---|
| 467 | /// \param z The channel number |
---|
| 468 | /// \return True if we are flagging Milky Way channels and z is in |
---|
| 469 | /// the range. |
---|
| 470 | |
---|
[673] | 471 | return ( this->flagMW && (z>=this->getMinMW()) && (z<=this->getMaxMW()) ); |
---|
[378] | 472 | } |
---|
[266] | 473 | |
---|
[378] | 474 | bool Param::isStatOK(int x, int y, int z) |
---|
| 475 | { |
---|
[913] | 476 | /// Test whether a given pixel position lies within the subsection |
---|
| 477 | /// given by the statSec parameter. Only tested if the flagSubsection |
---|
| 478 | /// parameter is true -- if it isn't, we just return true since all |
---|
| 479 | /// pixels are therefore available for statstical calculations. |
---|
| 480 | /// \param x X-value of pixel being tested. |
---|
| 481 | /// \param y Y-value of pixel being tested. |
---|
| 482 | /// \param z Z-value of pixel being tested. |
---|
| 483 | /// \return True if pixel is able to be used for statistical |
---|
| 484 | /// calculations. False otherwise. |
---|
[528] | 485 | |
---|
[272] | 486 | int xval=x,yval=y,zval=z; |
---|
| 487 | if(flagSubsection){ |
---|
| 488 | xval += pixelSec.getStart(0); |
---|
| 489 | yval += pixelSec.getStart(1); |
---|
| 490 | zval += pixelSec.getStart(2); |
---|
| 491 | } |
---|
| 492 | return !flagStatSec || statSec.isInside(xval,yval,zval); |
---|
[419] | 493 | } |
---|
[266] | 494 | |
---|
[475] | 495 | std::vector<int> Param::getObjectRequest() |
---|
| 496 | { |
---|
[528] | 497 | /// Returns a list of the object numbers requested via the objectList parameter. |
---|
| 498 | /// \return a vector of integers, one for each number in the objectList set. |
---|
| 499 | |
---|
[475] | 500 | std::stringstream ss1; |
---|
| 501 | std::string tmp; |
---|
| 502 | std::vector<int> tmplist; |
---|
| 503 | ss1.str(this->objectList); |
---|
| 504 | while(!ss1.eof()){ |
---|
| 505 | getline(ss1,tmp,','); |
---|
[623] | 506 | for(size_t i=0;i<tmp.size();i++) if(tmp[i]=='-') tmp[i]=' '; |
---|
[475] | 507 | int a,b; |
---|
| 508 | std::stringstream ss2; |
---|
| 509 | ss2.str(tmp); |
---|
| 510 | ss2 >>a; |
---|
| 511 | if(!ss2.eof()) ss2 >> b; |
---|
| 512 | else b=a; |
---|
| 513 | for(int n=a;n<=b;n++){ |
---|
| 514 | tmplist.push_back(n); |
---|
| 515 | } |
---|
| 516 | } |
---|
| 517 | return tmplist; |
---|
| 518 | } |
---|
| 519 | |
---|
| 520 | std::vector<bool> Param::getObjectChoices() |
---|
| 521 | { |
---|
[528] | 522 | /// Returns a list of bool values, indicating whether a given |
---|
| 523 | /// object was requested or not. The size of the vector is |
---|
| 524 | /// determined by the maximum value in objectList. For instance, |
---|
| 525 | /// if objectList="2,3,5-8", then the returned vector will be |
---|
| 526 | /// [0,1,1,0,1,1,1,1]. |
---|
| 527 | /// \return Vector of bool values. |
---|
| 528 | |
---|
[475] | 529 | std::vector<int> objectChoices = this->getObjectRequest(); |
---|
| 530 | int maxNum = *std::max_element(objectChoices.begin(), objectChoices.end()); |
---|
| 531 | std::vector<bool> choices(maxNum,false); |
---|
[623] | 532 | for(std::vector<int>::iterator obj = objectChoices.begin();obj!=objectChoices.end();obj++) |
---|
| 533 | choices[*obj-1] = true; |
---|
[475] | 534 | return choices; |
---|
| 535 | } |
---|
| 536 | |
---|
| 537 | std::vector<bool> Param::getObjectChoices(int numObjects) |
---|
| 538 | { |
---|
[528] | 539 | /// Returns a list of bool values, indicating whether a given |
---|
| 540 | /// object was requested or not. The size of the vector is given |
---|
| 541 | /// by the numObjects parameter. So, if objectList="2,3,5-8", then |
---|
| 542 | /// the returned vector from a getObjectChoices(10) call will be |
---|
| 543 | /// [0,1,1,0,1,1,1,1,0,0]. |
---|
| 544 | /// \param numObjects How many objects there are in total. |
---|
| 545 | /// \return Vector of bool values. |
---|
| 546 | |
---|
[475] | 547 | if(this->objectList==""){ |
---|
| 548 | std::vector<bool> choices(numObjects,true); |
---|
| 549 | return choices; |
---|
| 550 | } |
---|
| 551 | else{ |
---|
| 552 | std::vector<int> objectChoices = this->getObjectRequest(); |
---|
| 553 | std::vector<bool> choices(numObjects,false); |
---|
[623] | 554 | for(std::vector<int>::iterator obj = objectChoices.begin();obj!=objectChoices.end();obj++) |
---|
| 555 | if(*obj<=numObjects) choices[*obj-1] = true; |
---|
[475] | 556 | return choices; |
---|
| 557 | } |
---|
| 558 | } |
---|
| 559 | |
---|
[378] | 560 | /****************************************************************/ |
---|
[528] | 561 | /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// |
---|
| 562 | /// / Other Functions using the Parameter class: |
---|
| 563 | /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// |
---|
[3] | 564 | |
---|
[698] | 565 | OUTCOME Param::readParams(std::string paramfile) |
---|
[378] | 566 | { |
---|
[528] | 567 | /// The parameters are read in from a disk file, on the assumption that each |
---|
| 568 | /// line of the file has the format "parameter value" (eg. alphafdr 0.1) |
---|
| 569 | /// |
---|
| 570 | /// The case of the parameter name does not matter, nor does the |
---|
| 571 | /// formatting of the spaces (it can be any amount of whitespace or |
---|
| 572 | /// tabs). |
---|
| 573 | /// |
---|
| 574 | /// \param paramfile A std::string containing the parameter filename. |
---|
| 575 | /// |
---|
| 576 | /// \return FAILURE if the parameter file does not exist. SUCCESS if |
---|
| 577 | /// it is able to read it. |
---|
| 578 | |
---|
[839] | 579 | if(!USE_PGPLOT){ |
---|
| 580 | // Change default values for these parameters when we don't use PGPlot |
---|
| 581 | this->flagXOutput = false; |
---|
| 582 | this->flagMaps = false; |
---|
| 583 | this->flagPlotSpectra = false; |
---|
| 584 | } |
---|
| 585 | |
---|
[378] | 586 | std::ifstream fin(paramfile.c_str()); |
---|
| 587 | if(!fin.is_open()) return FAILURE; |
---|
| 588 | std::string line; |
---|
| 589 | while( !std::getline(fin,line,'\n').eof()){ |
---|
[3] | 590 | |
---|
[378] | 591 | if(line[0]!='#'){ |
---|
| 592 | std::stringstream ss; |
---|
| 593 | ss.str(line); |
---|
| 594 | std::string arg; |
---|
| 595 | ss >> arg; |
---|
| 596 | arg = makelower(arg); |
---|
[733] | 597 | if(arg=="imagefile") this->imageFile = readFilename(ss); |
---|
[378] | 598 | if(arg=="flagsubsection") this->flagSubsection = readFlag(ss); |
---|
| 599 | if(arg=="subsection") this->pixelSec.setSection(readSval(ss)); |
---|
| 600 | if(arg=="flagreconexists") this->flagReconExists = readFlag(ss); |
---|
| 601 | if(arg=="reconfile") this->reconFile = readSval(ss); |
---|
| 602 | if(arg=="flagsmoothexists")this->flagSmoothExists = readFlag(ss); |
---|
| 603 | if(arg=="smoothfile") this->smoothFile = readSval(ss); |
---|
[839] | 604 | if(arg=="beamarea") this->areaBeam = readFval(ss); |
---|
| 605 | if(arg=="beamfwhm") this->fwhmBeam = readFval(ss); |
---|
[475] | 606 | if(arg=="useprevious") this->usePrevious = readFlag(ss); |
---|
| 607 | if(arg=="objectlist") this->objectList = readSval(ss); |
---|
[71] | 608 | |
---|
[378] | 609 | if(arg=="flaglog") this->flagLog = readFlag(ss); |
---|
| 610 | if(arg=="logfile") this->logFile = readSval(ss); |
---|
| 611 | if(arg=="outfile") this->outFile = readSval(ss); |
---|
| 612 | if(arg=="flagseparateheader") this->flagSeparateHeader = readFlag(ss); |
---|
[733] | 613 | if(arg=="headerfile") this->headerFile = readFilename(ss); |
---|
[1146] | 614 | if(arg=="flagwritebinarycatalogue") this->flagWriteBinaryCatalogue = readFlag(ss); |
---|
| 615 | if(arg=="binarycatalogue") this->binaryCatalogue = readFilename(ss); |
---|
[831] | 616 | if(arg=="flagplotspectra") this->flagPlotSpectra = readFlag(ss); |
---|
[733] | 617 | if(arg=="spectrafile") this->spectraFile = readFilename(ss); |
---|
[1148] | 618 | if(arg=="flagplotindividualspectra") this->flagPlotIndividualSpectra = readFlag(ss); |
---|
[424] | 619 | if(arg=="flagtextspectra") this->flagTextSpectra = readFlag(ss); |
---|
[733] | 620 | if(arg=="spectratextfile") this->spectraTextFile = readFilename(ss); |
---|
[1120] | 621 | if(arg=="flagoutputbaseline") this->flagOutputBaseline = readFlag(ss); |
---|
| 622 | if(arg=="fileoutputbaseline") this->fileOutputBaseline = readFilename(ss); |
---|
[670] | 623 | if(arg=="flagoutputmomentmap") this->flagOutputMomentMap = readFlag(ss); |
---|
[733] | 624 | if(arg=="fileoutputmomentmap") this->fileOutputMomentMap = readFilename(ss); |
---|
[1142] | 625 | if(arg=="flagoutputmomentmask") this->flagOutputMomentMask = readFlag(ss); |
---|
| 626 | if(arg=="fileoutputmomentmask") this->fileOutputMomentMask = readFilename(ss); |
---|
[379] | 627 | if(arg=="flagoutputmask") this->flagOutputMask = readFlag(ss); |
---|
[733] | 628 | if(arg=="fileoutputmask") this->fileOutputMask = readFilename(ss); |
---|
[521] | 629 | if(arg=="flagmaskwithobjectnum") this->flagMaskWithObjectNum = readFlag(ss); |
---|
[378] | 630 | if(arg=="flagoutputsmooth")this->flagOutputSmooth = readFlag(ss); |
---|
[733] | 631 | if(arg=="fileoutputsmooth")this->fileOutputSmooth = readFilename(ss); |
---|
[378] | 632 | if(arg=="flagoutputrecon") this->flagOutputRecon = readFlag(ss); |
---|
[733] | 633 | if(arg=="fileoutputrecon") this->fileOutputRecon = readFilename(ss); |
---|
[378] | 634 | if(arg=="flagoutputresid") this->flagOutputResid = readFlag(ss); |
---|
[733] | 635 | if(arg=="fileoutputresid") this->fileOutputResid = readFilename(ss); |
---|
[378] | 636 | if(arg=="flagvot") this->flagVOT = readFlag(ss); |
---|
[733] | 637 | if(arg=="votfile") this->votFile = readFilename(ss); |
---|
[378] | 638 | if(arg=="flagkarma") this->flagKarma = readFlag(ss); |
---|
[733] | 639 | if(arg=="karmafile") this->karmaFile = readFilename(ss); |
---|
[1077] | 640 | if(arg=="flagds9") this->flagDS9 = readFlag(ss); |
---|
| 641 | if(arg=="ds9file") this->ds9File = readFilename(ss); |
---|
[1126] | 642 | if(arg=="flagcasa") this->flagCasa = readFlag(ss); |
---|
| 643 | if(arg=="casafile") this->casaFile = readFilename(ss); |
---|
[446] | 644 | if(arg=="annotationtype") this->annotationType = readSval(ss); |
---|
[378] | 645 | if(arg=="flagmaps") this->flagMaps = readFlag(ss); |
---|
[733] | 646 | if(arg=="detectionmap") this->detectionMap = readFilename(ss); |
---|
| 647 | if(arg=="momentmap") this->momentMap = readFilename(ss); |
---|
[378] | 648 | if(arg=="flagxoutput") this->flagXOutput = readFlag(ss); |
---|
[434] | 649 | if(arg=="newfluxunits") this->newFluxUnits = readSval(ss); |
---|
[438] | 650 | if(arg=="precflux") this->precFlux = readIval(ss); |
---|
| 651 | if(arg=="precvel") this->precVel = readIval(ss); |
---|
| 652 | if(arg=="precsnr") this->precSNR = readIval(ss); |
---|
[3] | 653 | |
---|
[378] | 654 | if(arg=="flagtrim") this->flagTrim = readFlag(ss); |
---|
| 655 | if(arg=="flagmw") this->flagMW = readFlag(ss); |
---|
| 656 | if(arg=="maxmw") this->maxMW = readIval(ss); |
---|
| 657 | if(arg=="minmw") this->minMW = readIval(ss); |
---|
[442] | 658 | if(arg=="flagbaseline") this->flagBaseline = readFlag(ss); |
---|
[691] | 659 | if(arg=="searchtype") this->searchType = readSval(ss); |
---|
[71] | 660 | |
---|
[442] | 661 | if(arg=="flagnegative") this->flagNegative = readFlag(ss); |
---|
[378] | 662 | if(arg=="minpix") this->minPix = readIval(ss); |
---|
| 663 | if(arg=="flaggrowth") this->flagGrowth = readFlag(ss); |
---|
| 664 | if(arg=="growthcut") this->growthCut = readFval(ss); |
---|
[461] | 665 | if(arg=="growththreshold"){ |
---|
| 666 | this->growthThreshold = readFval(ss); |
---|
| 667 | this->flagUserGrowthThreshold = true; |
---|
| 668 | } |
---|
[71] | 669 | |
---|
[378] | 670 | if(arg=="flagfdr") this->flagFDR = readFlag(ss); |
---|
| 671 | if(arg=="alphafdr") this->alphaFDR = readFval(ss); |
---|
[543] | 672 | if(arg=="fdrnumcorchan") this->FDRnumCorChan = readIval(ss); |
---|
[378] | 673 | if(arg=="flagstatsec") this->flagStatSec = readFlag(ss); |
---|
| 674 | if(arg=="statsec") this->statSec.setSection(readSval(ss)); |
---|
[385] | 675 | if(arg=="flagrobuststats") this->flagRobustStats = readFlag(ss); |
---|
[378] | 676 | if(arg=="snrcut") this->snrCut = readFval(ss); |
---|
| 677 | if(arg=="threshold"){ |
---|
| 678 | this->threshold = readFval(ss); |
---|
| 679 | this->flagUserThreshold = true; |
---|
| 680 | } |
---|
[201] | 681 | |
---|
[378] | 682 | if(arg=="flagsmooth") this->flagSmooth = readFlag(ss); |
---|
| 683 | if(arg=="smoothtype") this->smoothType = readSval(ss); |
---|
| 684 | if(arg=="hanningwidth") this->hanningWidth = readIval(ss); |
---|
| 685 | if(arg=="kernmaj") this->kernMaj = readFval(ss); |
---|
| 686 | if(arg=="kernmin") this->kernMin = readFval(ss); |
---|
| 687 | if(arg=="kernpa") this->kernPA = readFval(ss); |
---|
[103] | 688 | |
---|
[378] | 689 | if(arg=="flagatrous") this->flagATrous = readFlag(ss); |
---|
| 690 | if(arg=="recondim") this->reconDim = readIval(ss); |
---|
| 691 | if(arg=="scalemin") this->scaleMin = readIval(ss); |
---|
| 692 | if(arg=="scalemax") this->scaleMax = readIval(ss); |
---|
| 693 | if(arg=="snrrecon") this->snrRecon = readFval(ss); |
---|
[1026] | 694 | if(arg=="reconconvergence") this->reconConvergence = readFval(ss); |
---|
| 695 | if(arg=="filtercode") this->filterCode = readIval(ss); |
---|
[71] | 696 | |
---|
[378] | 697 | if(arg=="flagadjacent") this->flagAdjacent = readFlag(ss); |
---|
| 698 | if(arg=="threshspatial") this->threshSpatial = readFval(ss); |
---|
| 699 | if(arg=="threshvelocity") this->threshVelocity = readFval(ss); |
---|
| 700 | if(arg=="minchannels") this->minChannels = readIval(ss); |
---|
[720] | 701 | if(arg=="minvoxels") this->minVoxels = readIval(ss); |
---|
[691] | 702 | if(arg=="flagrejectbeforemerge") this->flagRejectBeforeMerge = readFlag(ss); |
---|
| 703 | if(arg=="flagtwostagemerging") this->flagTwoStageMerging = readFlag(ss); |
---|
[71] | 704 | |
---|
[378] | 705 | if(arg=="spectralmethod") this->spectralMethod=makelower(readSval(ss)); |
---|
[948] | 706 | if(arg=="spectraltype") this->spectralType = readSval(ss); |
---|
| 707 | if(arg=="restfrequency") this->restFrequency = readFval(ss); |
---|
[949] | 708 | if(arg=="spectralunits") this->spectralUnits = readSval(ss); |
---|
[378] | 709 | if(arg=="pixelcentre") this->pixelCentre = makelower(readSval(ss)); |
---|
[571] | 710 | if(arg=="sortingparam") this->sortingParam = makelower(readSval(ss)); |
---|
[378] | 711 | if(arg=="drawborders") this->borders = readFlag(ss); |
---|
| 712 | if(arg=="drawblankedges") this->blankEdge = readFlag(ss); |
---|
| 713 | if(arg=="verbose") this->verbose = readFlag(ss); |
---|
[295] | 714 | |
---|
[378] | 715 | // Dealing with deprecated parameters. |
---|
| 716 | if(arg=="flagblankpix"){ |
---|
| 717 | this->flagTrim = readFlag(ss); |
---|
[913] | 718 | DUCHAMPWARN("Reading parameters","The parameter flagBlankPix is deprecated. Please use the flagTrim parameter in future."); |
---|
| 719 | DUCHAMPWARN("Reading parameters","Setting flagTrim = " << stringize(this->flagTrim)); |
---|
[378] | 720 | } |
---|
| 721 | if(arg=="blankpixvalue"){ |
---|
[913] | 722 | DUCHAMPWARN("Reading parameters","The parameter blankPixValue is deprecated. This value is only taken from the FITS header."); |
---|
[378] | 723 | } |
---|
[662] | 724 | if(arg=="beamsize"){ |
---|
[675] | 725 | this->areaBeam = readFval(ss); |
---|
[913] | 726 | DUCHAMPWARN("Reading parameters","The parameter beamSize is deprecated. You can specify the beam size by beamArea or beamFWHM."); |
---|
| 727 | DUCHAMPWARN("Reading parameters","Setting beamArea = " << this->areaBeam); |
---|
[662] | 728 | } |
---|
[378] | 729 | |
---|
[295] | 730 | } |
---|
[378] | 731 | } |
---|
[295] | 732 | |
---|
[506] | 733 | this->checkPars(); |
---|
| 734 | |
---|
| 735 | return SUCCESS; |
---|
| 736 | |
---|
| 737 | } |
---|
| 738 | |
---|
| 739 | void Param::checkPars() |
---|
| 740 | { |
---|
| 741 | |
---|
[882] | 742 | // If flagSubsection is false, but the parset had a subsection string in it, we want to set this back to the default. |
---|
| 743 | if(!this->flagSubsection){ |
---|
| 744 | this->pixelSec.setSection(defaultSection); |
---|
| 745 | } |
---|
| 746 | if(!this->flagStatSec){ |
---|
| 747 | this->statSec.setSection(defaultSection); |
---|
| 748 | } |
---|
| 749 | |
---|
[475] | 750 | // If we have usePrevious=false, set the objectlist to blank so that we use all of them |
---|
| 751 | if(!this->usePrevious) this->objectList = ""; |
---|
| 752 | |
---|
[420] | 753 | // If pgplot was not included in the compilation, need to set flagXOutput to false |
---|
[831] | 754 | if(!USE_PGPLOT){ |
---|
[1148] | 755 | if(this->flagXOutput || this->flagMaps || this->flagPlotSpectra || this->flagPlotIndividualSpectra) |
---|
| 756 | DUCHAMPWARN("Reading parameters","PGPlot has not been enabled, so setting flagXOutput, flagMaps, flagPlotSpectra and flagPlotIndividualSpectra to false."); |
---|
[831] | 757 | this->flagXOutput = false; |
---|
| 758 | this->flagMaps = false; |
---|
| 759 | this->flagPlotSpectra = false; |
---|
[1148] | 760 | this->flagPlotIndividualSpectra = false; |
---|
[831] | 761 | } |
---|
[420] | 762 | |
---|
[1148] | 763 | if(!this->flagPlotSpectra && this->flagPlotIndividualSpectra){ |
---|
| 764 | DUCHAMPWARN("Reading parameters","flagPlotSpectra is false, so setting flagPlotIndividualSpectra to false as well."); |
---|
| 765 | this->flagPlotIndividualSpectra = false; |
---|
| 766 | } |
---|
| 767 | |
---|
[438] | 768 | // Correcting bad precision values -- if negative, set to 0 |
---|
| 769 | if(this->precFlux<0) this->precFlux = 0; |
---|
| 770 | if(this->precVel<0) this->precVel = 0; |
---|
| 771 | if(this->precSNR<0) this->precSNR = 0; |
---|
| 772 | |
---|
[686] | 773 | // Can only have "spatial" or "spectral" as search types |
---|
| 774 | if(this->searchType != "spatial" && this->searchType != "spectral"){ |
---|
[913] | 775 | DUCHAMPWARN("Reading parameters","You have requested a search type of \""<<this->searchType<<"\" -- Only \"spectral\" and \"spatial\" are accepted, so setting to \"spatial\"."); |
---|
[686] | 776 | this->searchType = "spatial"; |
---|
| 777 | } |
---|
| 778 | |
---|
[378] | 779 | // The wavelet reconstruction takes precendence over the smoothing. |
---|
| 780 | if(this->flagATrous) this->flagSmooth = false; |
---|
| 781 | |
---|
[1026] | 782 | // Check validity of recon parameters |
---|
| 783 | if(this->flagATrous){ |
---|
| 784 | if(this->reconConvergence < 0.){ |
---|
| 785 | DUCHAMPWARN("Reading Parameters","Your reconConvergence value is negative ("<<this->reconConvergence<<") - setting to " << -this->reconConvergence <<"."); |
---|
| 786 | this->reconConvergence *= -1.; |
---|
| 787 | } |
---|
| 788 | |
---|
| 789 | this->reconFilter.define(this->filterCode); |
---|
| 790 | |
---|
| 791 | if((this->scaleMax) > 0 && (this->scaleMax < this->scaleMin)){ |
---|
| 792 | DUCHAMPWARN("Reading Parameters","Reconstruction scaleMax ("<<this->scaleMax<<") is less than scaleMin ("<<this->scaleMin<<"): setting both to "<<this->scaleMin); |
---|
| 793 | this->scaleMax = this->scaleMin; |
---|
| 794 | } |
---|
| 795 | |
---|
| 796 | if( (this->reconDim < 1) || (this->reconDim > 3) ){ |
---|
| 797 | DUCHAMPWARN("Reading Parameters", "You requested a " << this->reconDim << " dimensional reconstruction. Setting reconDim to 1"); |
---|
| 798 | this->reconDim = 1; |
---|
| 799 | } |
---|
| 800 | |
---|
| 801 | if( this->snrRecon < 0.){ |
---|
| 802 | DUCHAMPWARN("Reading Parameters", "Your snrRecon value is negative (" << this->snrRecon<<"). Turning reconstruction off -- fix your parameter file!"); |
---|
| 803 | this->flagATrous = false; |
---|
| 804 | } |
---|
| 805 | |
---|
| 806 | } |
---|
| 807 | |
---|
[461] | 808 | if(this->flagUserThreshold){ |
---|
| 809 | |
---|
| 810 | // If we specify a manual threshold, need to also specify a manual growth threshold |
---|
| 811 | // If we haven't done so, turn growing off |
---|
| 812 | if(this->flagGrowth && !this->flagUserGrowthThreshold){ |
---|
[913] | 813 | DUCHAMPWARN("Reading parameters","You have specified a manual search threshold, but not a manual growth threshold. You need to do so using the \"growthThreshold\" parameter."); |
---|
| 814 | DUCHAMPWARN("Reading parameters","The growth function is being turned off."); |
---|
[461] | 815 | this->flagGrowth = false; |
---|
| 816 | } |
---|
| 817 | |
---|
| 818 | // If we specify a manual threshold, we don't need the FDR method, so turn it off if requested. |
---|
| 819 | if(this->flagFDR){ |
---|
[913] | 820 | DUCHAMPWARN("Reading parameters","You have specified a manual search threshold, so we don't need to use the FDR method. Setting \"flagFDR=false\"."); |
---|
[461] | 821 | this->flagFDR = false; |
---|
| 822 | } |
---|
| 823 | |
---|
| 824 | } |
---|
| 825 | |
---|
[537] | 826 | // Make sure the growth level is less than the detection level. Else turn off growing. |
---|
| 827 | if(this->flagGrowth){ |
---|
| 828 | std::stringstream errmsg; |
---|
| 829 | bool doWarn = false; |
---|
| 830 | if(this->flagUserThreshold && |
---|
| 831 | ( (this->threshold < this->growthThreshold) |
---|
| 832 | || (this->snrCut < this->growthCut) ) ){ |
---|
[913] | 833 | errmsg << "Your \"growthThreshold\" parameter" << this->growthThreshold <<" is larger than your \"threshold\"" << this->threshold; |
---|
[537] | 834 | doWarn = true; |
---|
| 835 | } |
---|
| 836 | |
---|
| 837 | if(!this->flagUserThreshold && |
---|
| 838 | (this->snrCut < this->growthCut)) { |
---|
[913] | 839 | errmsg << "Your \"growthCut\" parameter " << this->growthCut << " is larger than your \"snrCut\"" << this->snrCut; |
---|
[537] | 840 | doWarn = true; |
---|
| 841 | } |
---|
| 842 | |
---|
[913] | 843 | if(doWarn){ |
---|
| 844 | DUCHAMPWARN("Reading parameters",errmsg); |
---|
| 845 | DUCHAMPWARN("Reading parameters","The growth function is being turned off."); |
---|
[537] | 846 | |
---|
[913] | 847 | } |
---|
[537] | 848 | } |
---|
| 849 | |
---|
[446] | 850 | // Make sure the annnotationType is an acceptable option -- default is "borders" |
---|
[1130] | 851 | if((this->annotationType != "borders") && (this->annotationType!="circles") && (this->annotationType!="ellipses")){ |
---|
[913] | 852 | DUCHAMPWARN("Reading parameters","The requested value of the parameter annotationType, \"" << this->annotationType << "\", is invalid -- changing to \"borders\"."); |
---|
[446] | 853 | this->annotationType = "borders"; |
---|
| 854 | } |
---|
| 855 | |
---|
[378] | 856 | // Make sure smoothType is an acceptable type -- default is "spectral" |
---|
| 857 | if((this->smoothType!="spectral")&& |
---|
| 858 | (this->smoothType!="spatial")){ |
---|
[913] | 859 | DUCHAMPWARN("Reading parameters","The requested value of the parameter smoothType, \"" << this->smoothType << "\", is invalid -- changing to \"spectral\"."); |
---|
[378] | 860 | this->smoothType = "spectral"; |
---|
[3] | 861 | } |
---|
[378] | 862 | // If kernMin has not been given, or is negative, make it equal to kernMaj |
---|
| 863 | if(this->kernMin < 0) this->kernMin = this->kernMaj; |
---|
[272] | 864 | |
---|
[378] | 865 | // Make sure spectralMethod is an acceptable type -- default is "peak" |
---|
| 866 | if((this->spectralMethod!="peak")&& |
---|
| 867 | (this->spectralMethod!="sum")){ |
---|
[913] | 868 | DUCHAMPWARN("Reading parameters","The requested value of the parameter spectralMethod, \"" << this->spectralMethod << "\", is invalid -- changing to \"peak\"."); |
---|
[378] | 869 | this->spectralMethod = "peak"; |
---|
| 870 | } |
---|
[232] | 871 | |
---|
[913] | 872 | // make sure pixelCentre is an acceptable type -- default is "peak" |
---|
[378] | 873 | if((this->pixelCentre!="centroid")&& |
---|
| 874 | (this->pixelCentre!="average") && |
---|
| 875 | (this->pixelCentre!="peak") ){ |
---|
[913] | 876 | DUCHAMPWARN("Reading parameters","The requested value of the parameter pixelCentre, \"" << this->pixelCentre << "\", is invalid -- changing to \"centroid\"."); |
---|
[378] | 877 | this->pixelCentre = "centroid"; |
---|
| 878 | } |
---|
[275] | 879 | |
---|
[571] | 880 | // Make sure sortingParam is an acceptable type -- default is "vel" |
---|
| 881 | bool OK = false; |
---|
[955] | 882 | int loc=(this->sortingParam[0]=='-') ? 1 : 0; |
---|
[571] | 883 | for(int i=0;i<numSortingParamOptions;i++) |
---|
[955] | 884 | OK = OK || this->sortingParam.substr(loc)==sortingParamOptions[i]; |
---|
[571] | 885 | if(!OK){ |
---|
[913] | 886 | DUCHAMPWARN("Reading parameters","The requested value of the parameter sortingParam, \"" << this->sortingParam << "\", is invalid. -- changing to \"vel\"."); |
---|
[571] | 887 | this->sortingParam = "vel"; |
---|
| 888 | } |
---|
[942] | 889 | |
---|
| 890 | // Make sure minVoxels is appropriate given minChannels & minPixels |
---|
| 891 | if(this->minVoxels < (this->minPix + this->minChannels - 1) ){ |
---|
| 892 | DUCHAMPWARN("Reading parameters","Changing minVoxels to " << this->minPix + this->minChannels - 1 << " given minPix="<<this->minPix << " and minChannels="<<this->minChannels); |
---|
| 893 | this->minVoxels = this->minPix + this->minChannels - 1; |
---|
| 894 | } |
---|
[1146] | 895 | |
---|
| 896 | // check that baselines are being calculated if we want to save them to a FITS file |
---|
| 897 | if(this->flagOutputBaseline && !this->flagBaseline){ |
---|
| 898 | DUCHAMPWARN("Reading parameters","Saving of baseline values to a FITS file has been requested, but baselines are not being calculated. Turning off saving of baseline values."); |
---|
| 899 | this->flagOutputBaseline = false; |
---|
| 900 | } |
---|
[571] | 901 | |
---|
[265] | 902 | } |
---|
| 903 | |
---|
[910] | 904 | OUTCOME Param::checkImageExists() |
---|
| 905 | { |
---|
| 906 | /// A simple check to see whether the image actually exists or not, using the cfitsio interface. |
---|
| 907 | /// If it does, we return SUCCESS, otherwise we throw an exception. |
---|
| 908 | |
---|
| 909 | int exists,status = 0; /* MUST initialize status */ |
---|
| 910 | fits_file_exists(this->imageFile.c_str(),&exists,&status); |
---|
| 911 | if(exists<=0){ |
---|
| 912 | fits_report_error(stderr, status); |
---|
| 913 | DUCHAMPTHROW("Cube Reader","Requested image " << this->imageFile << " does not exist!"); |
---|
| 914 | return FAILURE; |
---|
| 915 | } |
---|
| 916 | return SUCCESS; |
---|
| 917 | } |
---|
| 918 | |
---|
| 919 | |
---|
[1137] | 920 | void recordParameters(std::ostream& theStream, Param &par, std::string paramName, std::string paramDesc, std::string paramValue) |
---|
[664] | 921 | { |
---|
| 922 | |
---|
[1142] | 923 | const int width = 60; |
---|
[716] | 924 | int widthText = width - paramName.size(); |
---|
[265] | 925 | |
---|
[1137] | 926 | theStream << par.commentString() |
---|
| 927 | << std::setw(widthText) << paramDesc |
---|
[716] | 928 | << setiosflags(std::ios::right) << paramName |
---|
[664] | 929 | << " = " << resetiosflags(std::ios::right) << paramValue |
---|
| 930 | <<std::endl; |
---|
| 931 | } |
---|
| 932 | |
---|
| 933 | std::string fileOption(bool flag, std::string file) |
---|
| 934 | { |
---|
| 935 | std::ostringstream ss; |
---|
| 936 | ss << stringize(flag); |
---|
| 937 | if(flag) ss << " --> " << file; |
---|
| 938 | return ss.str(); |
---|
| 939 | |
---|
| 940 | } |
---|
| 941 | |
---|
[378] | 942 | std::ostream& operator<< ( std::ostream& theStream, Param& par) |
---|
| 943 | { |
---|
[528] | 944 | /// Print out the parameter set in a formatted, easy to read style. |
---|
| 945 | /// Lists the parameters, a description of them, and their value. |
---|
[3] | 946 | |
---|
[378] | 947 | // BUG -- can get error: `boolalpha' is not a member of type `ios' -- old compilers: gcc 2.95.3? |
---|
| 948 | // theStream.setf(std::ios::boolalpha); |
---|
| 949 | theStream.setf(std::ios::left); |
---|
[1137] | 950 | theStream <<par.commentString()<<"\n"<<par.commentString()<<"---- Parameters ----"<<std::endl; |
---|
[378] | 951 | theStream << std::setfill('.'); |
---|
| 952 | if(par.getFlagSubsection()) |
---|
[1137] | 953 | recordParam(theStream, par, "[imageFile]", "Image to be analysed", par.getImageFile()<<par.getSubsection()); |
---|
[378] | 954 | else |
---|
[1137] | 955 | recordParam(theStream, par, "[imageFile]", "Image to be analysed", par.getImageFile()); |
---|
[948] | 956 | if(par.getFlagRestFrequencyUsed()){ |
---|
[1137] | 957 | recordParam(theStream, par, "[restFrequency]","Rest frequency as used", par.getRestFrequency()); |
---|
[948] | 958 | } |
---|
[378] | 959 | if(par.getFlagReconExists() && par.getFlagATrous()){ |
---|
[1137] | 960 | recordParam(theStream, par, "[reconExists]", "Reconstructed array exists?", stringize(par.getFlagReconExists())); |
---|
| 961 | recordParam(theStream, par, "[reconFile]", "FITS file containing reconstruction", par.getReconFile()); |
---|
[378] | 962 | } |
---|
| 963 | if(par.getFlagSmoothExists() && par.getFlagSmooth()){ |
---|
[1137] | 964 | recordParam(theStream, par, "[smoothExists]", "Smoothed array exists?", stringize(par.getFlagSmoothExists())); |
---|
| 965 | recordParam(theStream, par, "[smoothFile]", "FITS file containing smoothed array", par.getSmoothFile()); |
---|
[378] | 966 | } |
---|
[1137] | 967 | recordParam(theStream, par, "[logFile]", "Intermediate Logfile", par.logFile); |
---|
| 968 | recordParam(theStream, par, "[outFile]", "Final Results file", par.getOutFile()); |
---|
[664] | 969 | if(par.getFlagSeparateHeader()){ |
---|
[1137] | 970 | recordParam(theStream, par, "[headerFile]", "Header for results file", par.getHeaderFile()); |
---|
[664] | 971 | } |
---|
[831] | 972 | if(USE_PGPLOT && par.getFlagPlotSpectra()){ |
---|
[1148] | 973 | std::string label=par.getSpectraFile(); |
---|
| 974 | if(par.getFlagPlotIndividualSpectra()) label += ", with individual spectra too"; |
---|
| 975 | recordParam(theStream, par, "[spectraFile]", "Spectrum file", label); |
---|
[831] | 976 | } |
---|
[424] | 977 | if(par.getFlagTextSpectra()){ |
---|
[1137] | 978 | recordParam(theStream, par, "[spectraTextFile]", "Text file with ascii spectral data", par.getSpectraTextFile()); |
---|
[424] | 979 | } |
---|
[378] | 980 | if(par.getFlagVOT()){ |
---|
[1137] | 981 | recordParam(theStream, par, "[votFile]", "VOTable file", par.getVOTFile()); |
---|
[378] | 982 | } |
---|
| 983 | if(par.getFlagKarma()){ |
---|
[1137] | 984 | recordParam(theStream, par, "[karmaFile]", "Karma annotation file" , par.getKarmaFile()); |
---|
[378] | 985 | } |
---|
[1077] | 986 | if(par.getFlagDS9()){ |
---|
[1137] | 987 | recordParam(theStream, par, "[ds9File]", "DS9 annotation file" , par.getDS9File()); |
---|
[1077] | 988 | } |
---|
[1126] | 989 | if(par.getFlagCasa()){ |
---|
[1137] | 990 | recordParam(theStream, par, "[casaFile]", "CASA annotation file" , par.getCasaFile()); |
---|
[1126] | 991 | } |
---|
[831] | 992 | if(USE_PGPLOT && par.getFlagMaps()){ |
---|
[1137] | 993 | recordParam(theStream, par, "[momentMap]", "0th Moment Map", par.getMomentMap()); |
---|
| 994 | recordParam(theStream, par, "[detectionMap]", "Detection Map", par.getDetectionMap()); |
---|
[378] | 995 | } |
---|
[831] | 996 | if(USE_PGPLOT){ |
---|
[1137] | 997 | recordParam(theStream, par, "[flagXOutput]", "Display a map in a pgplot xwindow?", stringize(par.getFlagXOutput())); |
---|
[831] | 998 | } |
---|
[664] | 999 | if(par.getFlagATrous()){ |
---|
[1137] | 1000 | recordParam(theStream, par, "[flagOutputRecon]", "Saving reconstructed cube?", fileOption(par.getFlagOutputRecon(),par.outputReconFile())); |
---|
| 1001 | recordParam(theStream, par, "[flagOutputResid]", "Saving residuals from reconstruction?", fileOption(par.getFlagOutputResid(),par.outputResidFile())); |
---|
[378] | 1002 | } |
---|
[664] | 1003 | if(par.getFlagSmooth()){ |
---|
[1137] | 1004 | recordParam(theStream, par, "[flagOutputSmooth]", "Saving smoothed cube?", fileOption(par.getFlagOutputSmooth(),par.outputSmoothFile())); |
---|
[378] | 1005 | } |
---|
[1137] | 1006 | recordParam(theStream, par, "[flagOutputMask]", "Saving mask cube?", fileOption(par.getFlagOutputMask(),par.outputMaskFile())); |
---|
| 1007 | recordParam(theStream, par, "[flagOutputMomentMap]", "Saving 0th moment to FITS file?", fileOption(par.getFlagOutputMomentMap(),par.outputMomentMapFile())); |
---|
[1142] | 1008 | recordParam(theStream, par, "[flagOutputMomentMask]", "Saving 0th moment mask to FITS file?", fileOption(par.getFlagOutputMomentMask(),par.outputMomentMaskFile())); |
---|
[1137] | 1009 | recordParam(theStream, par, "[flagOutputBaseline]", "Saving baseline values to FITS file?", fileOption(par.getFlagOutputBaseline(),par.outputBaselineFile())); |
---|
[664] | 1010 | |
---|
[1137] | 1011 | theStream << par.commentString() <<"------"<<std::endl; |
---|
[664] | 1012 | |
---|
[1137] | 1013 | recordParam(theStream, par, "[searchType]", "Type of searching performed", par.getSearchType()); |
---|
[378] | 1014 | if(par.getFlagBlankPix()){ |
---|
[1137] | 1015 | recordParam(theStream, par, "", "Blank Pixel Value", par.getBlankPixVal()); |
---|
[275] | 1016 | } |
---|
[1137] | 1017 | recordParam(theStream, par, "[flagTrim]", "Trimming Blank Pixels?", stringize(par.getFlagTrim())); |
---|
| 1018 | recordParam(theStream, par, "[flagNegative]", "Searching for Negative features?", stringize(par.getFlagNegative())); |
---|
| 1019 | recordParam(theStream, par, "[flagMW]", "Removing Milky Way channels?", stringize(par.getFlagMW())); |
---|
[378] | 1020 | if(par.getFlagMW()){ |
---|
[673] | 1021 | // need to remove the offset correction, as we want to report the parameters actually entered |
---|
[1137] | 1022 | recordParam(theStream, par, "[minMW - maxMW]", "Milky Way Channels", par.getMinMW()+par.getZOffset()<<"-"<<par.getMaxMW()+par.getZOffset()); |
---|
[348] | 1023 | } |
---|
[791] | 1024 | if(par.beamAsUsed.origin()==EMPTY){ // No beam in FITS file and no information provided |
---|
[1137] | 1025 | recordParam(theStream, par, "", "Area of Beam", "No beam"); |
---|
[675] | 1026 | } |
---|
[791] | 1027 | else if(par.beamAsUsed.origin()==HEADER){ // Report beam size from FITS file |
---|
[1137] | 1028 | recordParam(theStream, par, "", "Area of Beam (pixels)", par.beamAsUsed.area() << " (beam: " << par.beamAsUsed.maj() << " x " << par.beamAsUsed.min() <<" pixels)"); |
---|
[675] | 1029 | } |
---|
[791] | 1030 | else if(par.beamAsUsed.origin()==PARAM){ // Report beam size requested in parameter set input |
---|
[1137] | 1031 | if(par.fwhmBeam>0.) recordParam(theStream, par, "[beamFWHM]", "FWHM of Beam (pixels)", par.beamAsUsed.maj() << " (beam area = " << par.beamAsUsed.area() <<" pixels)"); |
---|
| 1032 | else recordParam(theStream, par, "[beamArea]", "Area of Beam (pixels)", par.beamAsUsed.area()); |
---|
[788] | 1033 | } |
---|
| 1034 | else{ |
---|
[1137] | 1035 | recordParam(theStream, par, "[beam info]", "Size & shape of beam", "No information available!"); |
---|
[788] | 1036 | } |
---|
[1137] | 1037 | recordParam(theStream, par, "[flagBaseline]", "Removing baselines before search?", stringize(par.getFlagBaseline())); |
---|
| 1038 | recordParam(theStream, par, "[flagSmooth]", "Smoothing data prior to searching?", stringize(par.getFlagSmooth())); |
---|
[378] | 1039 | if(par.getFlagSmooth()){ |
---|
[1137] | 1040 | recordParam(theStream, par, "[smoothType]", "Type of smoothing", par.getSmoothType()); |
---|
[378] | 1041 | if(par.getSmoothType()=="spectral") |
---|
[1137] | 1042 | recordParam(theStream, par, "[hanningWidth]", "Width of hanning filter", par.getHanningWidth()); |
---|
[378] | 1043 | else{ |
---|
[1137] | 1044 | recordParam(theStream, par, "[kernMaj]", "Gaussian kernel semi-major axis [pix]", par.getKernMaj()); |
---|
| 1045 | recordParam(theStream, par, "[kernMin]", "Gaussian kernel semi-minor axis [pix]", par.getKernMin()); |
---|
| 1046 | recordParam(theStream, par, "[kernPA]", "Gaussian kernel position angle [deg]", par.getKernPA()); |
---|
[378] | 1047 | } |
---|
[348] | 1048 | } |
---|
[1137] | 1049 | recordParam(theStream, par, "[flagATrous]", "Using A Trous reconstruction?", stringize(par.getFlagATrous())); |
---|
[378] | 1050 | if(par.getFlagATrous()){ |
---|
[1137] | 1051 | recordParam(theStream, par, "[reconDim]", "Number of dimensions in reconstruction", par.getReconDim()); |
---|
[378] | 1052 | if(par.getMaxScale()>0){ |
---|
[1137] | 1053 | recordParam(theStream, par, "[scaleMin-scaleMax]", "Scales used in reconstruction", par.getMinScale()<<"-"<<par.getMaxScale()); |
---|
[378] | 1054 | } |
---|
| 1055 | else{ |
---|
[1137] | 1056 | recordParam(theStream, par, "[scaleMin]", "Minimum scale in reconstruction", par.getMinScale()); |
---|
[378] | 1057 | } |
---|
[1137] | 1058 | recordParam(theStream, par, "[snrRecon]", "SNR Threshold within reconstruction", par.getAtrousCut()); |
---|
| 1059 | recordParam(theStream, par, "[reconConvergence]", "Residual convergence criterion", par.getReconConvergence()); |
---|
| 1060 | recordParam(theStream, par, "[filterCode]", "Filter being used for reconstruction", par.getFilterCode()<<" ("<<par.getFilterName()<<")"); |
---|
[378] | 1061 | } |
---|
[1137] | 1062 | recordParam(theStream, par, "[flagRobustStats]", "Using Robust statistics?", stringize(par.getFlagRobustStats())); |
---|
[378] | 1063 | if(par.getFlagStatSec()){ |
---|
[1137] | 1064 | recordParam(theStream, par, "[statSec]", "Section used by statistics calculation", par.statSec.getSection()); |
---|
[189] | 1065 | } |
---|
[1137] | 1066 | recordParam(theStream, par, "[flagFDR]", "Using FDR analysis?", stringize(par.getFlagFDR())); |
---|
[378] | 1067 | if(par.getFlagFDR()){ |
---|
[1137] | 1068 | recordParam(theStream, par, "[alphaFDR]", "Alpha value for FDR analysis", par.getAlpha()); |
---|
| 1069 | recordParam(theStream, par, "[FDRnumCorChan]", "Number of correlated channels for FDR", par.getFDRnumCorChan()); |
---|
[378] | 1070 | } |
---|
| 1071 | else { |
---|
| 1072 | if(par.getFlagUserThreshold()){ |
---|
[1137] | 1073 | recordParam(theStream, par, "[threshold]", "Detection Threshold", par.getThreshold()); |
---|
[378] | 1074 | } |
---|
| 1075 | else{ |
---|
[1137] | 1076 | recordParam(theStream, par, "[snrCut]", "SNR Threshold (in sigma)", par.getCut()); |
---|
[378] | 1077 | } |
---|
[189] | 1078 | } |
---|
[1137] | 1079 | recordParam(theStream, par, "[minPix]", "Minimum # Pixels in a detection", par.getMinPix()); |
---|
| 1080 | recordParam(theStream, par, "[minChannels]", "Minimum # Channels in a detection", par.getMinChannels()); |
---|
| 1081 | recordParam(theStream, par, "[minVoxels]", "Minimum # Voxels in a detection", par.getMinVoxels()); |
---|
| 1082 | recordParam(theStream, par, "[flagGrowth]", "Growing objects after detection?", stringize(par.getFlagGrowth())); |
---|
[378] | 1083 | if(par.getFlagGrowth()) { |
---|
[503] | 1084 | if(par.getFlagUserGrowthThreshold()){ |
---|
[1137] | 1085 | recordParam(theStream, par, "[growthThreshold]", "Threshold for growth", par.getGrowthThreshold()); |
---|
[503] | 1086 | } |
---|
| 1087 | else{ |
---|
[1137] | 1088 | recordParam(theStream, par, "[growthCut]", "SNR Threshold for growth", par.getGrowthCut()); |
---|
[503] | 1089 | } |
---|
[378] | 1090 | } |
---|
[1137] | 1091 | recordParam(theStream, par, "[flagAdjacent]", "Using Adjacent-pixel criterion?", stringize(par.getFlagAdjacent())); |
---|
[378] | 1092 | if(!par.getFlagAdjacent()){ |
---|
[1137] | 1093 | recordParam(theStream, par, "[threshSpatial]", "Max. spatial separation for merging", par.getThreshS()); |
---|
[378] | 1094 | } |
---|
[1137] | 1095 | recordParam(theStream, par, "[threshVelocity]", "Max. velocity separation for merging", par.getThreshV()); |
---|
| 1096 | recordParam(theStream, par, "[flagRejectBeforeMerge]", "Reject objects before merging?", stringize(par.getFlagRejectBeforeMerge())); |
---|
| 1097 | recordParam(theStream, par, "[flagTwoStageMerging]", "Merge objects in two stages?", stringize(par.getFlagTwoStageMerging())); |
---|
| 1098 | recordParam(theStream, par, "[spectralMethod]", "Method of spectral plotting", par.getSpectralMethod()); |
---|
| 1099 | recordParam(theStream, par, "[pixelCentre]", "Type of object centre used in results", par.getPixelCentre()); |
---|
[664] | 1100 | |
---|
[1137] | 1101 | theStream << par.commentString() <<"--------------------\n"; |
---|
[378] | 1102 | theStream << std::setfill(' '); |
---|
| 1103 | theStream.unsetf(std::ios::left); |
---|
| 1104 | // theStream.unsetf(std::ios::boolalpha); |
---|
| 1105 | return theStream; |
---|
[3] | 1106 | } |
---|
| 1107 | |
---|
[916] | 1108 | std::vector<VOParam> Param::getVOParams() |
---|
| 1109 | { |
---|
| 1110 | std::vector<VOParam> vopars; |
---|
| 1111 | vopars.push_back(VOParam("imageFile","meta.file;meta.fits","char",this->imageFile,this->imageFile.size(),"")); |
---|
[958] | 1112 | vopars.push_back(VOParam("flagSubsection","meta.code","boolean",this->flagSubsection,0,"")); |
---|
[916] | 1113 | if(this->flagSubsection) |
---|
| 1114 | vopars.push_back(VOParam("subsection","","char",this->pixelSec.getSection(),this->pixelSec.getSection().size(),"")); |
---|
[958] | 1115 | vopars.push_back(VOParam("flagStatSec","meta.code","boolean",this->flagStatSec,0,"")); |
---|
[916] | 1116 | if(this->flagSubsection) |
---|
| 1117 | vopars.push_back(VOParam("StatSec","","char",this->statSec.getSection(),this->statSec.getSection().size(),"")); |
---|
| 1118 | if(this->flagReconExists) |
---|
| 1119 | vopars.push_back(VOParam("reconfile","meta.file;meta.fits","char",this->reconFile, this->reconFile.size(),"")); |
---|
| 1120 | if(this->flagSmoothExists) |
---|
| 1121 | vopars.push_back(VOParam("smoothfile","meta.file;meta.fits","char",this->smoothFile, this->smoothFile.size(),"")); |
---|
| 1122 | if(this->usePrevious) |
---|
| 1123 | vopars.push_back(VOParam("objectlist","","char",this->objectList,this->objectList.size(),"")); |
---|
[120] | 1124 | |
---|
[916] | 1125 | vopars.push_back(VOParam("searchType","meta.note","char",this->searchType,this->searchType.size(),"")); |
---|
[958] | 1126 | vopars.push_back(VOParam("flagNegative","meta.code","boolean",this->flagNegative,0,"")); |
---|
| 1127 | vopars.push_back(VOParam("flagBaseline","meta.code","boolean",this->flagBaseline,0,"")); |
---|
| 1128 | vopars.push_back(VOParam("flagRobustStats","meta.code","boolean",this->flagRobustStats,0,"")); |
---|
| 1129 | vopars.push_back(VOParam("flagFDR","meta.code","boolean",this->flagFDR,0,"")); |
---|
[916] | 1130 | if(this->flagFDR){ |
---|
| 1131 | vopars.push_back(VOParam("alphaFDR","stat.param","float",this->alphaFDR,0,"")); |
---|
| 1132 | vopars.push_back(VOParam("FDRnumCorChan","stat.param","int",this->FDRnumCorChan,0,"")); |
---|
| 1133 | } |
---|
| 1134 | else{ |
---|
| 1135 | if(this->flagUserThreshold) |
---|
| 1136 | vopars.push_back(VOParam("threshold","phot.flux;stat.min","float",this->threshold,0,"")); |
---|
| 1137 | else |
---|
| 1138 | vopars.push_back(VOParam("snrCut","stat.snr;phot;stat.min","float",this->snrCut,0,"")); |
---|
| 1139 | } |
---|
[958] | 1140 | vopars.push_back(VOParam("flagGrowth","meta.code","boolean",this->flagGrowth,0,"")); |
---|
[916] | 1141 | if(this->flagGrowth){ |
---|
| 1142 | if(this->flagUserGrowthThreshold) |
---|
| 1143 | vopars.push_back(VOParam("growthThreshold","phot.flux;stat.min","float",this->growthThreshold,0,"")); |
---|
| 1144 | else |
---|
| 1145 | vopars.push_back(VOParam("growthCut","stat.snr;phot;stat.min","float",this->growthCut,0,"")); |
---|
| 1146 | } |
---|
| 1147 | vopars.push_back(VOParam("minVoxels","","int",minVoxels,0,"")); |
---|
| 1148 | vopars.push_back(VOParam("minPix","","int",minPix,0,"")); |
---|
| 1149 | vopars.push_back(VOParam("minChannels","","int",minChannels,0,"")); |
---|
[958] | 1150 | vopars.push_back(VOParam("flagAdjacent","meta.code","boolean",this->flagAdjacent,0,"")); |
---|
[916] | 1151 | if(!this->flagAdjacent) |
---|
| 1152 | vopars.push_back(VOParam("threshSpatial","","float",this->threshSpatial,0,"")); |
---|
[1145] | 1153 | vopars.push_back(VOParam("threshVelocity","","float",this->threshVelocity,0,"")); |
---|
[958] | 1154 | vopars.push_back(VOParam("flagRejectBeforeMerge","","boolean",this->flagRejectBeforeMerge,0,"")); |
---|
| 1155 | vopars.push_back(VOParam("flagTwoStageMerging","","boolean",this->flagTwoStageMerging,0,"")); |
---|
[916] | 1156 | vopars.push_back(VOParam("pixelCentre","","char",this->pixelCentre,this->pixelCentre.size(),"")); |
---|
[958] | 1157 | vopars.push_back(VOParam("flagSmooth","meta.code","boolean",this->flagSmooth,0,"")); |
---|
[916] | 1158 | if(this->flagSmooth){ |
---|
| 1159 | vopars.push_back(VOParam("smoothType","","char",this->smoothType,this->smoothType.size(),"")); |
---|
| 1160 | if(this->smoothType=="spectral") |
---|
| 1161 | vopars.push_back(VOParam("hanningWidth","","int",this->hanningWidth,0,"")); |
---|
| 1162 | else{ |
---|
| 1163 | vopars.push_back(VOParam("kernMaj","","float",this->kernMaj,0,"")); |
---|
| 1164 | vopars.push_back(VOParam("kernMin","","float",this->kernMin,0,"")); |
---|
| 1165 | vopars.push_back(VOParam("kernPA","","float",this->kernPA,0,"")); |
---|
| 1166 | } |
---|
| 1167 | } |
---|
[958] | 1168 | vopars.push_back(VOParam("flagATrous","meta.code","boolean",this->flagATrous,0,"")); |
---|
[916] | 1169 | if(this->flagATrous){ |
---|
| 1170 | vopars.push_back(VOParam("reconDim","","int",this->reconDim,0,"")); |
---|
| 1171 | vopars.push_back(VOParam("scaleMin","","int",this->scaleMin,0,"")); |
---|
| 1172 | if(this->scaleMax>0) |
---|
| 1173 | vopars.push_back(VOParam("scaleMax","","int",this->scaleMax,0,"")); |
---|
| 1174 | vopars.push_back(VOParam("snrRecon","","float",this->snrRecon,0,"")); |
---|
[1026] | 1175 | vopars.push_back(VOParam("reconConvergence","","float",this->reconConvergence,0,"")); |
---|
[916] | 1176 | vopars.push_back(VOParam("filterCode","","int",this->filterCode,0,"")); |
---|
| 1177 | } |
---|
| 1178 | if(this->beamAsUsed.origin()==PARAM){ |
---|
| 1179 | if(this->fwhmBeam>0) |
---|
| 1180 | vopars.push_back(VOParam("beamFWHM","","float",this->fwhmBeam,0,"")); |
---|
| 1181 | else |
---|
| 1182 | vopars.push_back(VOParam("beamArea","","float",this->areaBeam,0,"")); |
---|
| 1183 | } |
---|
[948] | 1184 | if(this->restFrequencyUsed){ |
---|
| 1185 | vopars.push_back(VOParam("restFrequency","em.freq","float",this->restFrequency,0,"Hz")); |
---|
| 1186 | } |
---|
[916] | 1187 | |
---|
| 1188 | return vopars; |
---|
| 1189 | |
---|
| 1190 | } |
---|
| 1191 | |
---|
[1145] | 1192 | void Param::writeToBinaryFile(std::string &filename) |
---|
| 1193 | { |
---|
| 1194 | std::ofstream outfile(filename.c_str(), std::ios::out | std::ios::binary | std::ios::app); |
---|
| 1195 | writeStringToBinaryFile(outfile,this->imageFile); |
---|
| 1196 | outfile.write(reinterpret_cast<const char*>(&this->flagSubsection), sizeof this->flagSubsection); |
---|
| 1197 | if(this->flagSubsection) writeStringToBinaryFile(outfile,this->pixelSec.getSection()); |
---|
| 1198 | outfile.write(reinterpret_cast<const char*>(&this->flagStatSec), sizeof this->flagStatSec); |
---|
| 1199 | if(this->flagStatSec) writeStringToBinaryFile(outfile,this->statSec.getSection()); |
---|
| 1200 | outfile.write(reinterpret_cast<const char*>(&this->flagReconExists), sizeof this->flagReconExists); |
---|
| 1201 | if(this->flagReconExists) writeStringToBinaryFile(outfile,this->reconFile); |
---|
| 1202 | outfile.write(reinterpret_cast<const char*>(&this->flagSmoothExists), sizeof this->flagSmoothExists); |
---|
| 1203 | if(this->flagSmoothExists) writeStringToBinaryFile(outfile,this->smoothFile); |
---|
| 1204 | // |
---|
| 1205 | writeStringToBinaryFile(outfile,this->searchType); |
---|
| 1206 | outfile.write(reinterpret_cast<const char*>(&this->flagNegative), sizeof this->flagNegative); |
---|
| 1207 | outfile.write(reinterpret_cast<const char*>(&this->flagBaseline), sizeof this->flagBaseline); |
---|
| 1208 | outfile.write(reinterpret_cast<const char*>(&this->flagRobustStats), sizeof this->flagRobustStats); |
---|
| 1209 | outfile.write(reinterpret_cast<const char*>(&this->flagFDR), sizeof this->flagFDR); |
---|
| 1210 | if(this->flagFDR){ |
---|
| 1211 | outfile.write(reinterpret_cast<const char*>(&this->alphaFDR), sizeof this->alphaFDR); |
---|
| 1212 | outfile.write(reinterpret_cast<const char*>(&this->FDRnumCorChan), sizeof this->FDRnumCorChan); |
---|
| 1213 | if(this->beamAsUsed.origin()==PARAM){ |
---|
| 1214 | outfile.write(reinterpret_cast<const char*>(&this->fwhmBeam), sizeof this->fwhmBeam); |
---|
| 1215 | outfile.write(reinterpret_cast<const char*>(&this->areaBeam), sizeof this->areaBeam); |
---|
| 1216 | } |
---|
| 1217 | } |
---|
| 1218 | else{ |
---|
| 1219 | outfile.write(reinterpret_cast<const char*>(&this->flagUserThreshold), sizeof this->flagUserThreshold); |
---|
| 1220 | if(this->flagUserThreshold) |
---|
| 1221 | outfile.write(reinterpret_cast<const char*>(&this->threshold), sizeof this->threshold); |
---|
| 1222 | else |
---|
| 1223 | outfile.write(reinterpret_cast<const char*>(&this->snrCut), sizeof this->snrCut); |
---|
| 1224 | } |
---|
| 1225 | outfile.write(reinterpret_cast<const char*>(&this->flagGrowth), sizeof this->flagGrowth); |
---|
| 1226 | if(this->flagGrowth){ |
---|
| 1227 | if(this->flagUserGrowthThreshold) |
---|
| 1228 | outfile.write(reinterpret_cast<const char*>(&this->growthThreshold), sizeof this->growthThreshold); |
---|
| 1229 | else |
---|
| 1230 | outfile.write(reinterpret_cast<const char*>(&this->growthCut), sizeof this->growthCut); |
---|
| 1231 | } |
---|
| 1232 | outfile.write(reinterpret_cast<const char*>(&this->minVoxels), sizeof this->minVoxels); |
---|
| 1233 | outfile.write(reinterpret_cast<const char*>(&this->minPix), sizeof this->minPix); |
---|
| 1234 | outfile.write(reinterpret_cast<const char*>(&this->minChannels), sizeof this->minChannels); |
---|
| 1235 | outfile.write(reinterpret_cast<const char*>(&this->flagAdjacent), sizeof this->flagAdjacent); |
---|
| 1236 | if(!this->flagAdjacent) |
---|
| 1237 | outfile.write(reinterpret_cast<const char*>(&this->threshSpatial), sizeof this->threshSpatial); |
---|
| 1238 | outfile.write(reinterpret_cast<const char*>(&this->threshVelocity), sizeof this->threshVelocity); |
---|
| 1239 | outfile.write(reinterpret_cast<const char*>(&this->flagRejectBeforeMerge), sizeof this->flagRejectBeforeMerge); |
---|
| 1240 | outfile.write(reinterpret_cast<const char*>(&this->flagTwoStageMerging), sizeof this->flagTwoStageMerging); |
---|
| 1241 | outfile.write(reinterpret_cast<const char*>(&this->flagSmooth), sizeof this->flagSmooth); |
---|
| 1242 | if(this->flagSmooth){ |
---|
| 1243 | bool type=(this->smoothType=="spectral"); |
---|
| 1244 | outfile.write(reinterpret_cast<const char*>(&type), sizeof type); |
---|
| 1245 | if(type) |
---|
| 1246 | outfile.write(reinterpret_cast<const char*>(&this->hanningWidth), sizeof this->hanningWidth); |
---|
| 1247 | else{ |
---|
| 1248 | outfile.write(reinterpret_cast<const char*>(&this->kernMaj), sizeof this->kernMaj); |
---|
| 1249 | outfile.write(reinterpret_cast<const char*>(&this->kernMin), sizeof this->kernMin); |
---|
| 1250 | outfile.write(reinterpret_cast<const char*>(&this->kernPA), sizeof this->kernPA); |
---|
| 1251 | } |
---|
| 1252 | } |
---|
| 1253 | outfile.write(reinterpret_cast<const char*>(&this->flagATrous), sizeof this->flagATrous); |
---|
| 1254 | if(this->flagATrous){ |
---|
| 1255 | outfile.write(reinterpret_cast<const char*>(&this->reconDim), sizeof this->reconDim); |
---|
| 1256 | outfile.write(reinterpret_cast<const char*>(&this->scaleMin), sizeof this->scaleMin); |
---|
| 1257 | outfile.write(reinterpret_cast<const char*>(&this->scaleMax), sizeof this->scaleMax); |
---|
| 1258 | outfile.write(reinterpret_cast<const char*>(&this->snrRecon), sizeof this->snrRecon); |
---|
| 1259 | outfile.write(reinterpret_cast<const char*>(&this->reconConvergence), sizeof this->reconConvergence); |
---|
| 1260 | outfile.write(reinterpret_cast<const char*>(&this->filterCode), sizeof this->filterCode); |
---|
| 1261 | } |
---|
| 1262 | outfile.write(reinterpret_cast<const char*>(&this->flagMW), sizeof this->flagMW); |
---|
| 1263 | if(this->flagMW){ |
---|
| 1264 | outfile.write(reinterpret_cast<const char*>(&this->minMW), sizeof this->minMW); |
---|
| 1265 | outfile.write(reinterpret_cast<const char*>(&this->maxMW), sizeof this->maxMW); |
---|
| 1266 | } |
---|
| 1267 | |
---|
| 1268 | outfile.close(); |
---|
| 1269 | } |
---|
| 1270 | |
---|
[1146] | 1271 | std::streampos Param::readFromBinaryFile(std::string &filename, std::streampos loc) |
---|
[1145] | 1272 | { |
---|
[1146] | 1273 | std::ifstream infile(filename.c_str(), std::ios::in | std::ios::binary); |
---|
| 1274 | if(!infile.is_open()){ |
---|
| 1275 | DUCHAMPERROR("read binary parameters","Could not open binary catalogue \""<<filename <<"\""); |
---|
| 1276 | return -1; |
---|
| 1277 | } |
---|
| 1278 | infile.seekg(loc); |
---|
[1145] | 1279 | this->imageFile = readStringFromBinaryFile(infile); |
---|
| 1280 | infile.read(reinterpret_cast<char*>(&this->flagSubsection), sizeof this->flagSubsection); |
---|
| 1281 | if(this->flagSubsection){ |
---|
| 1282 | std::string sec=readStringFromBinaryFile(infile); |
---|
| 1283 | this->pixelSec.setSection(sec); |
---|
| 1284 | } |
---|
| 1285 | infile.read(reinterpret_cast<char*>(&this->flagStatSec), sizeof this->flagStatSec); |
---|
| 1286 | if(this->flagStatSec){ |
---|
| 1287 | std::string sec=readStringFromBinaryFile(infile); |
---|
| 1288 | this->statSec.setSection(sec); |
---|
| 1289 | } |
---|
| 1290 | infile.read(reinterpret_cast<char*>(&this->flagReconExists), sizeof this->flagReconExists); |
---|
| 1291 | if(this->flagReconExists) this->reconFile=readStringFromBinaryFile(infile); |
---|
| 1292 | infile.read(reinterpret_cast<char*>(&this->flagSmoothExists), sizeof this->flagSmoothExists); |
---|
| 1293 | if(this->flagSmoothExists) this->smoothFile=readStringFromBinaryFile(infile); |
---|
| 1294 | // |
---|
| 1295 | this->searchType=readStringFromBinaryFile(infile); |
---|
| 1296 | infile.read(reinterpret_cast<char*>(&this->flagNegative), sizeof this->flagNegative); |
---|
| 1297 | infile.read(reinterpret_cast<char*>(&this->flagBaseline), sizeof this->flagBaseline); |
---|
| 1298 | infile.read(reinterpret_cast<char*>(&this->flagRobustStats), sizeof this->flagRobustStats); |
---|
| 1299 | infile.read(reinterpret_cast<char*>(&this->flagFDR), sizeof this->flagFDR); |
---|
| 1300 | if(this->flagFDR){ |
---|
| 1301 | infile.read(reinterpret_cast<char*>(&this->alphaFDR), sizeof this->alphaFDR); |
---|
| 1302 | infile.read(reinterpret_cast<char*>(&this->FDRnumCorChan), sizeof this->FDRnumCorChan); |
---|
| 1303 | if(this->beamAsUsed.origin()==PARAM){ |
---|
| 1304 | infile.read(reinterpret_cast<char*>(&this->fwhmBeam), sizeof this->fwhmBeam); |
---|
| 1305 | infile.read(reinterpret_cast<char*>(&this->areaBeam), sizeof this->areaBeam); |
---|
| 1306 | } |
---|
| 1307 | } |
---|
| 1308 | else{ |
---|
| 1309 | infile.read(reinterpret_cast<char*>(&this->flagUserThreshold), sizeof this->flagUserThreshold); |
---|
| 1310 | if(this->flagUserThreshold) |
---|
| 1311 | infile.read(reinterpret_cast<char*>(&this->threshold), sizeof this->threshold); |
---|
| 1312 | else |
---|
| 1313 | infile.read(reinterpret_cast<char*>(&this->snrCut), sizeof this->snrCut); |
---|
| 1314 | } |
---|
| 1315 | infile.read(reinterpret_cast<char*>(&this->flagGrowth), sizeof this->flagGrowth); |
---|
| 1316 | if(this->flagGrowth){ |
---|
| 1317 | if(this->flagUserGrowthThreshold) |
---|
| 1318 | infile.read(reinterpret_cast<char*>(&this->growthThreshold), sizeof this->growthThreshold); |
---|
| 1319 | else |
---|
| 1320 | infile.read(reinterpret_cast<char*>(&this->growthCut), sizeof this->growthCut); |
---|
| 1321 | } |
---|
| 1322 | infile.read(reinterpret_cast<char*>(&this->minVoxels), sizeof this->minVoxels); |
---|
| 1323 | infile.read(reinterpret_cast<char*>(&this->minPix), sizeof this->minPix); |
---|
| 1324 | infile.read(reinterpret_cast<char*>(&this->minChannels), sizeof this->minChannels); |
---|
| 1325 | infile.read(reinterpret_cast<char*>(&this->flagAdjacent), sizeof this->flagAdjacent); |
---|
| 1326 | if(!this->flagAdjacent) |
---|
| 1327 | infile.read(reinterpret_cast<char*>(&this->threshSpatial), sizeof this->threshSpatial); |
---|
| 1328 | infile.read(reinterpret_cast<char*>(&this->threshVelocity), sizeof this->threshVelocity); |
---|
| 1329 | infile.read(reinterpret_cast<char*>(&this->flagRejectBeforeMerge), sizeof this->flagRejectBeforeMerge); |
---|
| 1330 | infile.read(reinterpret_cast<char*>(&this->flagTwoStageMerging), sizeof this->flagTwoStageMerging); |
---|
| 1331 | infile.read(reinterpret_cast<char*>(&this->flagSmooth), sizeof this->flagSmooth); |
---|
| 1332 | if(this->flagSmooth){ |
---|
| 1333 | bool type; |
---|
| 1334 | infile.read(reinterpret_cast<char*>(&type), sizeof type); |
---|
| 1335 | this->smoothType = type ? "spectral" : "spatial"; |
---|
| 1336 | if(type) |
---|
| 1337 | infile.read(reinterpret_cast<char*>(&this->hanningWidth), sizeof this->hanningWidth); |
---|
| 1338 | else{ |
---|
| 1339 | infile.read(reinterpret_cast<char*>(&this->kernMaj), sizeof this->kernMaj); |
---|
| 1340 | infile.read(reinterpret_cast<char*>(&this->kernMin), sizeof this->kernMin); |
---|
| 1341 | infile.read(reinterpret_cast<char*>(&this->kernPA), sizeof this->kernPA); |
---|
| 1342 | } |
---|
| 1343 | } |
---|
| 1344 | infile.read(reinterpret_cast<char*>(&this->flagATrous), sizeof this->flagATrous); |
---|
| 1345 | if(this->flagATrous){ |
---|
| 1346 | infile.read(reinterpret_cast<char*>(&this->reconDim), sizeof this->reconDim); |
---|
| 1347 | infile.read(reinterpret_cast<char*>(&this->scaleMin), sizeof this->scaleMin); |
---|
| 1348 | infile.read(reinterpret_cast<char*>(&this->scaleMax), sizeof this->scaleMax); |
---|
| 1349 | infile.read(reinterpret_cast<char*>(&this->snrRecon), sizeof this->snrRecon); |
---|
| 1350 | infile.read(reinterpret_cast<char*>(&this->reconConvergence), sizeof this->reconConvergence); |
---|
| 1351 | infile.read(reinterpret_cast<char*>(&this->filterCode), sizeof this->filterCode); |
---|
| 1352 | } |
---|
| 1353 | infile.read(reinterpret_cast<char*>(&this->flagMW), sizeof this->flagMW); |
---|
| 1354 | if(this->flagMW){ |
---|
| 1355 | infile.read(reinterpret_cast<char*>(&this->minMW), sizeof this->minMW); |
---|
| 1356 | infile.read(reinterpret_cast<char*>(&this->maxMW), sizeof this->maxMW); |
---|
| 1357 | } |
---|
| 1358 | |
---|
[1146] | 1359 | std::streampos newloc = infile.tellg(); |
---|
[1145] | 1360 | infile.close(); |
---|
[1146] | 1361 | return newloc; |
---|
[1145] | 1362 | |
---|
| 1363 | } |
---|
| 1364 | |
---|
| 1365 | |
---|
| 1366 | |
---|
| 1367 | |
---|
[378] | 1368 | void Param::copyHeaderInfo(FitsHeader &head) |
---|
| 1369 | { |
---|
[528] | 1370 | /// A function to copy across relevant header keywords from the |
---|
| 1371 | /// FitsHeader class to the Param class, as they are needed by |
---|
| 1372 | /// functions in the Param class. |
---|
| 1373 | /// The parameters are the keywords BLANK, BSCALE, BZERO, and the beam size. |
---|
[112] | 1374 | |
---|
[378] | 1375 | this->blankKeyword = head.getBlankKeyword(); |
---|
| 1376 | this->bscaleKeyword = head.getBscaleKeyword(); |
---|
| 1377 | this->bzeroKeyword = head.getBzeroKeyword(); |
---|
| 1378 | this->blankPixValue = this->blankKeyword * this->bscaleKeyword + |
---|
| 1379 | this->bzeroKeyword; |
---|
| 1380 | } |
---|
[112] | 1381 | |
---|
[379] | 1382 | std::string Param::outputMaskFile() |
---|
| 1383 | { |
---|
[528] | 1384 | /// This function produces the required filename in which to save |
---|
| 1385 | /// the mask image, indicating which pixels have been detected as |
---|
| 1386 | /// part of an object. If the input image is image.fits, then the |
---|
| 1387 | /// output will be image.MASK.fits. |
---|
| 1388 | |
---|
[525] | 1389 | if(this->fileOutputMask==""){ |
---|
| 1390 | std::string inputName = this->imageFile; |
---|
[1092] | 1391 | std::string outputName = inputName; |
---|
| 1392 | if(inputName.substr(inputName.size()-5,5)==".fits") |
---|
| 1393 | outputName = inputName.substr(0,inputName.size()-5); |
---|
[525] | 1394 | // remove the ".fits" on the end. |
---|
[1092] | 1395 | outputName += ".MASK.fits"; |
---|
| 1396 | return outputName; |
---|
[525] | 1397 | } |
---|
| 1398 | else return this->fileOutputMask; |
---|
[379] | 1399 | } |
---|
| 1400 | |
---|
[670] | 1401 | std::string Param::outputMomentMapFile() |
---|
| 1402 | { |
---|
| 1403 | /// This function produces the required filename in which to save |
---|
| 1404 | /// the moment-0 FITS image. If the input image is image.fits, then the |
---|
| 1405 | /// output will be image.MOM0.fits. |
---|
| 1406 | |
---|
| 1407 | if(this->fileOutputMomentMap==""){ |
---|
| 1408 | std::string inputName = this->imageFile; |
---|
[1092] | 1409 | std::string outputName = inputName; |
---|
| 1410 | if(inputName.substr(inputName.size()-5,5)==".fits") |
---|
| 1411 | outputName = inputName.substr(0,inputName.size()-5); |
---|
[670] | 1412 | // remove the ".fits" on the end. |
---|
[1092] | 1413 | outputName += ".MOM0.fits"; |
---|
| 1414 | return outputName; |
---|
[670] | 1415 | } |
---|
| 1416 | else return this->fileOutputMomentMap; |
---|
| 1417 | } |
---|
| 1418 | |
---|
[1142] | 1419 | std::string Param::outputMomentMaskFile() |
---|
| 1420 | { |
---|
| 1421 | /// This function produces the required filename in which to save |
---|
| 1422 | /// the moment-0 FITS image. If the input image is image.fits, then the |
---|
| 1423 | /// output will be image.MOM0.fits. |
---|
| 1424 | |
---|
| 1425 | if(this->fileOutputMomentMask==""){ |
---|
| 1426 | std::string inputName = this->imageFile; |
---|
| 1427 | std::string outputName = inputName; |
---|
| 1428 | if(inputName.substr(inputName.size()-5,5)==".fits") |
---|
| 1429 | outputName = inputName.substr(0,inputName.size()-5); |
---|
| 1430 | // remove the ".fits" on the end. |
---|
| 1431 | outputName += ".MOM0MASK.fits"; |
---|
| 1432 | return outputName; |
---|
| 1433 | } |
---|
| 1434 | else return this->fileOutputMomentMask; |
---|
| 1435 | } |
---|
| 1436 | |
---|
[1120] | 1437 | std::string Param::outputBaselineFile() |
---|
| 1438 | { |
---|
| 1439 | /// This function produces the required filename in which to save |
---|
| 1440 | /// the baseline FITS image. If the input image is image.fits, then the |
---|
| 1441 | /// output will be image.BASE.fits. |
---|
| 1442 | |
---|
[1121] | 1443 | if(this->fileOutputBaseline==""){ |
---|
[1120] | 1444 | std::string inputName = this->imageFile; |
---|
| 1445 | std::string outputName = inputName; |
---|
| 1446 | if(inputName.substr(inputName.size()-5,5)==".fits") |
---|
| 1447 | outputName = inputName.substr(0,inputName.size()-5); |
---|
| 1448 | // remove the ".fits" on the end. |
---|
| 1449 | outputName += ".BASE.fits"; |
---|
| 1450 | return outputName; |
---|
| 1451 | } |
---|
[1121] | 1452 | else return this->fileOutputBaseline; |
---|
[1120] | 1453 | } |
---|
| 1454 | |
---|
[378] | 1455 | std::string Param::outputSmoothFile() |
---|
| 1456 | { |
---|
[528] | 1457 | /// This function produces the required filename in which to save |
---|
| 1458 | /// the smoothed array. If the input image is image.fits, then |
---|
| 1459 | /// the output will be: |
---|
| 1460 | /// <ul><li> Spectral smoothing: image.SMOOTH-1D-3.fits, where the |
---|
| 1461 | /// width of the Hanning filter was 3 pixels. |
---|
| 1462 | /// <li> Spatial smoothing : image.SMOOTH-2D-3-2-20.fits, where |
---|
| 1463 | /// kernMaj=3, kernMin=2 and kernPA=20 degrees. |
---|
| 1464 | /// </ul> |
---|
| 1465 | |
---|
[525] | 1466 | if(this->fileOutputSmooth==""){ |
---|
| 1467 | std::string inputName = this->imageFile; |
---|
| 1468 | std::stringstream ss; |
---|
[1092] | 1469 | if(inputName.substr(inputName.size()-5,5)==".fits") |
---|
| 1470 | ss << inputName.substr(0,inputName.size()-5); |
---|
| 1471 | else |
---|
| 1472 | ss << inputName; |
---|
| 1473 | // remove the ".fits" on the end if necessary. |
---|
[525] | 1474 | if(this->flagSubsection) ss<<".sub"; |
---|
| 1475 | if(this->smoothType=="spectral") |
---|
| 1476 | ss << ".SMOOTH-1D-" << this->hanningWidth << ".fits"; |
---|
| 1477 | else if(this->smoothType=="spatial") |
---|
| 1478 | ss << ".SMOOTH-2D-" |
---|
| 1479 | << this->kernMaj << "-" |
---|
| 1480 | << this->kernMin << "-" |
---|
| 1481 | << this->kernPA << ".fits"; |
---|
| 1482 | return ss.str(); |
---|
| 1483 | } |
---|
| 1484 | else return this->fileOutputSmooth; |
---|
[378] | 1485 | } |
---|
[208] | 1486 | |
---|
[378] | 1487 | std::string Param::outputReconFile() |
---|
| 1488 | { |
---|
[528] | 1489 | /// This function produces the required filename in which to save |
---|
| 1490 | /// the reconstructed array. If the input image is image.fits, then |
---|
| 1491 | /// the output will be eg. image.RECON-3-2-4-1.fits, where the numbers are |
---|
| 1492 | /// 3=reconDim, 2=filterCode, 4=snrRecon, 1=minScale |
---|
| 1493 | |
---|
[525] | 1494 | if(this->fileOutputRecon==""){ |
---|
| 1495 | std::string inputName = this->imageFile; |
---|
| 1496 | std::stringstream ss; |
---|
| 1497 | // First we remove the ".fits" from the end of the filename. |
---|
| 1498 | ss << inputName.substr(0,inputName.size()-5); |
---|
| 1499 | if(this->flagSubsection) ss<<".sub"; |
---|
| 1500 | ss << ".RECON-" << this->reconDim |
---|
| 1501 | << "-" << this->filterCode |
---|
| 1502 | << "-" << this->snrRecon |
---|
| 1503 | << "-" << this->scaleMin |
---|
[1027] | 1504 | << "-" << this->scaleMax |
---|
[1026] | 1505 | << "-" << this->reconConvergence |
---|
[525] | 1506 | << ".fits"; |
---|
| 1507 | return ss.str(); |
---|
| 1508 | } |
---|
| 1509 | else return this->fileOutputRecon; |
---|
[378] | 1510 | } |
---|
[103] | 1511 | |
---|
[378] | 1512 | std::string Param::outputResidFile() |
---|
| 1513 | { |
---|
[528] | 1514 | /// This function produces the required filename in which to save |
---|
| 1515 | /// the reconstructed array. If the input image is image.fits, then |
---|
| 1516 | /// the output will be eg. image.RESID-3-2-4-1.fits, where the numbers are |
---|
| 1517 | /// 3=reconDim, 2=filterCode, 4=snrRecon, 1=scaleMin |
---|
| 1518 | |
---|
[525] | 1519 | if(this->fileOutputResid==""){ |
---|
| 1520 | std::string inputName = this->imageFile; |
---|
| 1521 | std::stringstream ss; |
---|
| 1522 | // First we remove the ".fits" from the end of the filename. |
---|
| 1523 | ss << inputName.substr(0,inputName.size()-5); |
---|
| 1524 | if(this->flagSubsection) ss<<".sub"; |
---|
| 1525 | ss << ".RESID-" << this->reconDim |
---|
| 1526 | << "-" << this->filterCode |
---|
| 1527 | << "-" << this->snrRecon |
---|
| 1528 | << "-" << this->scaleMin |
---|
[1027] | 1529 | << "-" << this->scaleMax |
---|
[1026] | 1530 | << "-" << this->reconConvergence |
---|
[525] | 1531 | << ".fits"; |
---|
| 1532 | return ss.str(); |
---|
| 1533 | } |
---|
| 1534 | else return this->fileOutputResid; |
---|
[378] | 1535 | } |
---|
| 1536 | |
---|
[103] | 1537 | } |
---|