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