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