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