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/Detection/columns.hh> |
---|
46 | |
---|
47 | namespace duchamp |
---|
48 | { |
---|
49 | |
---|
50 | /****************************************************************/ |
---|
51 | /////////////////////////////////////////////////// |
---|
52 | //// Accessor Functions for Parameter class: |
---|
53 | /////////////////////////////////////////////////// |
---|
54 | Param::~Param() |
---|
55 | { |
---|
56 | /// Deletes the offsets array if the sizeOffsets parameter is |
---|
57 | /// positive. |
---|
58 | if(this->sizeOffsets>0) delete [] this->offsets; |
---|
59 | } |
---|
60 | |
---|
61 | Param::Param() |
---|
62 | { |
---|
63 | this->defaultValues(); |
---|
64 | } |
---|
65 | |
---|
66 | void Param::defaultValues() |
---|
67 | { |
---|
68 | /// Provides default intial values for the parameters. Note that |
---|
69 | /// imageFile has no default value! |
---|
70 | |
---|
71 | std::string baseSection = "[*,*,*]"; |
---|
72 | // Input files |
---|
73 | this->imageFile = ""; |
---|
74 | this->flagSubsection = false; |
---|
75 | this->pixelSec.setSection(baseSection); |
---|
76 | this->flagReconExists = false; |
---|
77 | this->reconFile = ""; |
---|
78 | this->flagSmoothExists = false; |
---|
79 | this->smoothFile = ""; |
---|
80 | this->usePrevious = false; |
---|
81 | this->objectList = ""; |
---|
82 | // Output files |
---|
83 | this->flagLog = false; |
---|
84 | this->logFile = "duchamp-Logfile.txt"; |
---|
85 | this->outFile = "duchamp-Results.txt"; |
---|
86 | this->flagSeparateHeader= false; |
---|
87 | this->headerFile = "duchamp-Results.hdr"; |
---|
88 | this->spectraFile = "duchamp-Spectra.ps"; |
---|
89 | this->flagTextSpectra = false; |
---|
90 | this->spectraTextFile = "duchamp-Spectra.txt"; |
---|
91 | this->flagOutputMomentMap = false; |
---|
92 | this->fileOutputMomentMap = ""; |
---|
93 | this->flagOutputMask = false; |
---|
94 | this->fileOutputMask = ""; |
---|
95 | this->flagMaskWithObjectNum = false; |
---|
96 | this->flagOutputSmooth = false; |
---|
97 | this->fileOutputSmooth = ""; |
---|
98 | this->flagOutputRecon = false; |
---|
99 | this->fileOutputRecon = ""; |
---|
100 | this->flagOutputResid = false; |
---|
101 | this->fileOutputResid = ""; |
---|
102 | this->flagVOT = false; |
---|
103 | this->votFile = "duchamp-Results.xml"; |
---|
104 | this->flagKarma = false; |
---|
105 | this->karmaFile = "duchamp-Results.ann"; |
---|
106 | this->annotationType = "borders"; |
---|
107 | this->flagMaps = true; |
---|
108 | this->detectionMap = "duchamp-DetectionMap.ps"; |
---|
109 | this->momentMap = "duchamp-MomentMap.ps"; |
---|
110 | this->flagXOutput = true; |
---|
111 | this->precFlux = Column::prFLUX; |
---|
112 | this->precVel = Column::prVEL; |
---|
113 | this->precSNR = Column::prSNR; |
---|
114 | // Cube related parameters |
---|
115 | this->flagBlankPix = true; |
---|
116 | this->blankPixValue = -8.00061; |
---|
117 | this->blankKeyword = 1; |
---|
118 | this->bscaleKeyword = -8.00061; |
---|
119 | this->bzeroKeyword = 0.; |
---|
120 | this->newFluxUnits = ""; |
---|
121 | // Milky-Way parameters |
---|
122 | this->flagMW = false; |
---|
123 | this->maxMW = 112; |
---|
124 | this->minMW = 75; |
---|
125 | this->areaBeam = 10.; |
---|
126 | this->fwhmBeam = -1.; |
---|
127 | this->flagUsingBeam = false; |
---|
128 | this->searchType = "spatial"; |
---|
129 | // Trim-related |
---|
130 | this->flagTrim = false; |
---|
131 | this->hasBeenTrimmed = false; |
---|
132 | this->borderLeft = 0; |
---|
133 | this->borderRight = 0; |
---|
134 | this->borderBottom = 0; |
---|
135 | this->borderTop = 0; |
---|
136 | // Subsection offsets |
---|
137 | this->sizeOffsets = 0; |
---|
138 | this->xSubOffset = 0; |
---|
139 | this->ySubOffset = 0; |
---|
140 | this->zSubOffset = 0; |
---|
141 | // Baseline related |
---|
142 | this->flagBaseline = false; |
---|
143 | // Detection-related |
---|
144 | this->flagNegative = false; |
---|
145 | // Object growth |
---|
146 | this->flagGrowth = false; |
---|
147 | this->growthCut = 3.; |
---|
148 | this->flagUserGrowthThreshold = false; |
---|
149 | this->growthThreshold = 0.; |
---|
150 | // FDR analysis |
---|
151 | this->flagFDR = false; |
---|
152 | this->alphaFDR = 0.01; |
---|
153 | this->FDRnumCorChan = 2; |
---|
154 | // Other detection |
---|
155 | this->flagStatSec = false; |
---|
156 | this->statSec.setSection(baseSection); |
---|
157 | this->flagRobustStats = true; |
---|
158 | this->snrCut = 3.; |
---|
159 | this->threshold = 0.; |
---|
160 | this->flagUserThreshold = false; |
---|
161 | // Smoothing |
---|
162 | this->flagSmooth = false; |
---|
163 | this->smoothType = "spectral"; |
---|
164 | this->hanningWidth = 5; |
---|
165 | this->kernMaj = 3.; |
---|
166 | this->kernMin = -1.; |
---|
167 | this->kernPA = 0.; |
---|
168 | // A trous reconstruction parameters |
---|
169 | this->flagATrous = false; |
---|
170 | this->reconDim = 1; |
---|
171 | this->scaleMin = 1; |
---|
172 | this->scaleMax = 0; |
---|
173 | this->snrRecon = 4.; |
---|
174 | this->filterCode = 1; |
---|
175 | this->reconFilter.define(this->filterCode); |
---|
176 | // Volume-merging parameters |
---|
177 | this->flagAdjacent = true; |
---|
178 | this->threshSpatial = 3.; |
---|
179 | this->threshVelocity = 7.; |
---|
180 | this->minChannels = 3; |
---|
181 | this->minPix = 2; |
---|
182 | this->minVoxels = 4; |
---|
183 | this->flagRejectBeforeMerge = false; |
---|
184 | this->flagTwoStageMerging = true; |
---|
185 | // Input-Output related |
---|
186 | this->spectralMethod = "peak"; |
---|
187 | this->spectralUnits = "km/s"; |
---|
188 | this->pixelCentre = "centroid"; |
---|
189 | this->sortingParam = "vel"; |
---|
190 | this->borders = true; |
---|
191 | this->blankEdge = true; |
---|
192 | this->verbose = true; |
---|
193 | } |
---|
194 | |
---|
195 | Param::Param (const Param& p) |
---|
196 | { |
---|
197 | operator=(p); |
---|
198 | } |
---|
199 | |
---|
200 | Param& Param::operator= (const Param& p) |
---|
201 | { |
---|
202 | if(this == &p) return *this; |
---|
203 | this->imageFile = p.imageFile; |
---|
204 | this->flagSubsection = p.flagSubsection; |
---|
205 | this->pixelSec = p.pixelSec; |
---|
206 | this->flagReconExists = p.flagReconExists; |
---|
207 | this->reconFile = p.reconFile; |
---|
208 | this->flagSmoothExists = p.flagSmoothExists; |
---|
209 | this->smoothFile = p.smoothFile; |
---|
210 | this->usePrevious = p.usePrevious; |
---|
211 | this->objectList = p.objectList; |
---|
212 | this->flagLog = p.flagLog; |
---|
213 | this->logFile = p.logFile; |
---|
214 | this->outFile = p.outFile; |
---|
215 | this->flagSeparateHeader= p.flagSeparateHeader; |
---|
216 | this->headerFile = p.headerFile; |
---|
217 | this->spectraFile = p.spectraFile; |
---|
218 | this->flagTextSpectra = p.flagTextSpectra; |
---|
219 | this->spectraTextFile = p.spectraTextFile; |
---|
220 | this->flagOutputMomentMap = p.flagOutputMomentMap; |
---|
221 | this->fileOutputMomentMap = p.fileOutputMomentMap; |
---|
222 | this->flagOutputMask = p.flagOutputMask; |
---|
223 | this->fileOutputMask = p.fileOutputMask; |
---|
224 | this->flagMaskWithObjectNum = p.flagMaskWithObjectNum; |
---|
225 | this->flagOutputSmooth = p.flagOutputSmooth; |
---|
226 | this->fileOutputSmooth = p.fileOutputSmooth; |
---|
227 | this->flagOutputRecon = p.flagOutputRecon; |
---|
228 | this->fileOutputRecon = p.fileOutputRecon; |
---|
229 | this->flagOutputResid = p.flagOutputResid; |
---|
230 | this->fileOutputResid = p.fileOutputResid; |
---|
231 | this->flagVOT = p.flagVOT; |
---|
232 | this->votFile = p.votFile; |
---|
233 | this->flagKarma = p.flagKarma; |
---|
234 | this->karmaFile = p.karmaFile; |
---|
235 | this->annotationType = p.annotationType; |
---|
236 | this->flagMaps = p.flagMaps; |
---|
237 | this->detectionMap = p.detectionMap; |
---|
238 | this->momentMap = p.momentMap; |
---|
239 | this->flagXOutput = p.flagXOutput; |
---|
240 | this->precFlux = p.precFlux; |
---|
241 | this->precVel = p.precVel; |
---|
242 | this->precSNR = p.precSNR; |
---|
243 | this->flagBlankPix = p.flagBlankPix; |
---|
244 | this->blankPixValue = p.blankPixValue; |
---|
245 | this->blankKeyword = p.blankKeyword; |
---|
246 | this->bscaleKeyword = p.bscaleKeyword; |
---|
247 | this->bzeroKeyword = p.bzeroKeyword; |
---|
248 | this->newFluxUnits = p.newFluxUnits; |
---|
249 | this->flagMW = p.flagMW; |
---|
250 | this->maxMW = p.maxMW; |
---|
251 | this->minMW = p.minMW; |
---|
252 | this->areaBeam = p.areaBeam; |
---|
253 | this->fwhmBeam = p.fwhmBeam; |
---|
254 | this->searchType = p.searchType; |
---|
255 | this->flagTrim = p.flagTrim; |
---|
256 | this->hasBeenTrimmed = p.hasBeenTrimmed; |
---|
257 | this->borderLeft = p.borderLeft; |
---|
258 | this->borderRight = p.borderRight; |
---|
259 | this->borderBottom = p.borderBottom; |
---|
260 | this->borderTop = p.borderTop; |
---|
261 | if(this->sizeOffsets>0) delete [] this->offsets; |
---|
262 | this->sizeOffsets = p.sizeOffsets; |
---|
263 | if(this->sizeOffsets>0){ |
---|
264 | this->offsets = new long[this->sizeOffsets]; |
---|
265 | for(int i=0;i<this->sizeOffsets;i++) this->offsets[i] = p.offsets[i]; |
---|
266 | } |
---|
267 | this->xSubOffset = p.xSubOffset; |
---|
268 | this->ySubOffset = p.ySubOffset; |
---|
269 | this->zSubOffset = p.zSubOffset; |
---|
270 | this->flagBaseline = p.flagBaseline; |
---|
271 | this->flagNegative = p.flagNegative; |
---|
272 | this->flagGrowth = p.flagGrowth; |
---|
273 | this->growthCut = p.growthCut; |
---|
274 | this->growthThreshold = p.growthThreshold; |
---|
275 | this->flagUserGrowthThreshold = p.flagUserGrowthThreshold; |
---|
276 | this->flagFDR = p.flagFDR; |
---|
277 | this->alphaFDR = p.alphaFDR; |
---|
278 | this->FDRnumCorChan = p.FDRnumCorChan; |
---|
279 | this->flagStatSec = p.flagStatSec; |
---|
280 | this->statSec = p.statSec; |
---|
281 | this->flagRobustStats = p.flagRobustStats; |
---|
282 | this->snrCut = p.snrCut; |
---|
283 | this->threshold = p.threshold; |
---|
284 | this->flagUserThreshold = p.flagUserThreshold; |
---|
285 | this->flagSmooth = p.flagSmooth; |
---|
286 | this->smoothType = p.smoothType; |
---|
287 | this->hanningWidth = p.hanningWidth; |
---|
288 | this->kernMaj = p.kernMaj; |
---|
289 | this->kernMin = p.kernMin; |
---|
290 | this->kernPA = p.kernPA; |
---|
291 | this->flagATrous = p.flagATrous; |
---|
292 | this->reconDim = p.reconDim; |
---|
293 | this->scaleMin = p.scaleMin; |
---|
294 | this->scaleMax = p.scaleMax; |
---|
295 | this->snrRecon = p.snrRecon; |
---|
296 | this->filterCode = p.filterCode; |
---|
297 | this->reconFilter = p.reconFilter; |
---|
298 | this->flagAdjacent = p.flagAdjacent; |
---|
299 | this->threshSpatial = p.threshSpatial; |
---|
300 | this->threshVelocity = p.threshVelocity; |
---|
301 | this->minChannels = p.minChannels; |
---|
302 | this->minPix = p.minPix; |
---|
303 | this->minVoxels = p.minVoxels; |
---|
304 | this->flagRejectBeforeMerge = p.flagRejectBeforeMerge; |
---|
305 | this->flagTwoStageMerging = p.flagTwoStageMerging; |
---|
306 | this->spectralMethod = p.spectralMethod; |
---|
307 | this->spectralUnits = p.spectralUnits; |
---|
308 | this->pixelCentre = p.pixelCentre; |
---|
309 | this->sortingParam = p.sortingParam; |
---|
310 | this->borders = p.borders; |
---|
311 | this->blankEdge = p.blankEdge; |
---|
312 | this->verbose = p.verbose; |
---|
313 | return *this; |
---|
314 | } |
---|
315 | //-------------------------------------------------------------------- |
---|
316 | |
---|
317 | OUTCOME Param::getopts(int argc, char ** argv, std::string progname) |
---|
318 | { |
---|
319 | /// A function that reads in the command-line options, in a manner |
---|
320 | /// tailored for use with the main Duchamp program. |
---|
321 | /// |
---|
322 | /// \param argc The number of command line arguments. |
---|
323 | /// \param argv The array of command line arguments. |
---|
324 | |
---|
325 | OUTCOME returnValue = FAILURE; |
---|
326 | if(argc==1){ |
---|
327 | if(progname=="Selavy") std::cout << SELAVY_ERR_USAGE_MSG; |
---|
328 | else if(progname=="Duchamp") std::cout << ERR_USAGE_MSG; |
---|
329 | else std::cout << ERR_USAGE_MSG; |
---|
330 | returnValue = FAILURE; |
---|
331 | } |
---|
332 | else { |
---|
333 | std::string file; |
---|
334 | bool changeX = false; |
---|
335 | this->defaultValues(); |
---|
336 | char c; |
---|
337 | while( ( c = getopt(argc,argv,"p:f:hvx") )!=-1){ |
---|
338 | switch(c) { |
---|
339 | case 'p': |
---|
340 | file = optarg; |
---|
341 | if(this->readParams(file)==FAILURE){ |
---|
342 | std::stringstream errmsg; |
---|
343 | errmsg << "Could not open parameter file " << file << ".\n"; |
---|
344 | duchampError(progname,errmsg.str()); |
---|
345 | } |
---|
346 | else returnValue = SUCCESS; |
---|
347 | break; |
---|
348 | case 'f': |
---|
349 | file = optarg; |
---|
350 | this->imageFile = file; |
---|
351 | returnValue = SUCCESS; |
---|
352 | break; |
---|
353 | case 'v': |
---|
354 | std::cout << PROGNAME << " version " << VERSION << std::endl; |
---|
355 | break; |
---|
356 | case 'x': |
---|
357 | changeX = true; |
---|
358 | break; |
---|
359 | case 'h': |
---|
360 | default : |
---|
361 | if(progname=="Selavy") std::cout << SELAVY_ERR_USAGE_MSG; |
---|
362 | else if(progname=="Duchamp") std::cout << ERR_USAGE_MSG; |
---|
363 | else std::cout << ERR_USAGE_MSG; |
---|
364 | break; |
---|
365 | } |
---|
366 | } |
---|
367 | if(changeX){ |
---|
368 | if(returnValue == SUCCESS) this->setFlagXOutput(false); |
---|
369 | else { |
---|
370 | duchampError(progname, |
---|
371 | "You need to specify either a parameter file or FITS image.\n"); |
---|
372 | std::cout << "\n" << ERR_USAGE_MSG; |
---|
373 | } |
---|
374 | } |
---|
375 | } |
---|
376 | return returnValue; |
---|
377 | } |
---|
378 | //-------------------------------------------------------------------- |
---|
379 | |
---|
380 | bool Param::isBlank(float &value) |
---|
381 | { |
---|
382 | /// Tests whether the value passed as the argument is BLANK or not. |
---|
383 | /// \param value Pixel value to be tested. |
---|
384 | /// \return False if flagBlankPix is false. Else, compare to the |
---|
385 | /// relevant FITS keywords, using integer comparison. |
---|
386 | |
---|
387 | return this->flagBlankPix && |
---|
388 | (this->blankKeyword == int((value-this->bzeroKeyword)/this->bscaleKeyword)); |
---|
389 | } |
---|
390 | |
---|
391 | bool *Param::makeBlankMask(float *array, int size) |
---|
392 | { |
---|
393 | /// This returns an array of bools, saying whether each pixel in the |
---|
394 | /// given array is BLANK or not. If the pixel is BLANK, set mask to |
---|
395 | /// false, else set to true. The array is allocated by the function. |
---|
396 | |
---|
397 | bool *mask = new bool[size]; |
---|
398 | for(int i=0;i<size;i++) mask[i] = !this->isBlank(array[i]); |
---|
399 | return mask; |
---|
400 | } |
---|
401 | |
---|
402 | |
---|
403 | bool *Param::makeStatMask(float *array, long *dim) |
---|
404 | { |
---|
405 | /// This returns an array of bools, saying whether each pixel in |
---|
406 | /// the given array is suitable for a stats calculation. It needs |
---|
407 | /// to be in the StatSec (if defined), not blank and not a MW |
---|
408 | /// channel. The array is allocated by the function with a 'new' call. |
---|
409 | |
---|
410 | bool *mask = new bool[dim[0]*dim[1]*dim[2]]; |
---|
411 | for(int x=0;x<dim[0];x++) { |
---|
412 | for(int y=0;y<dim[1];y++) { |
---|
413 | for(int z=0;z<dim[2];z++) { |
---|
414 | int i = x+y*dim[0]+z*dim[0]*dim[1]; |
---|
415 | mask[i] = !this->isBlank(array[i]) && !this->isInMW(z) && this->isStatOK(x,y,z); |
---|
416 | } |
---|
417 | } |
---|
418 | } |
---|
419 | return mask; |
---|
420 | } |
---|
421 | |
---|
422 | |
---|
423 | bool Param::isInMW(int z) |
---|
424 | { |
---|
425 | /// Tests whether we are flagging Milky Way channels, and if so |
---|
426 | /// whether the given channel number is in the Milky Way range. The |
---|
427 | /// channels are assumed to start at number 0. |
---|
428 | /// \param z The channel number |
---|
429 | /// \return True if we are flagging Milky Way channels and z is in |
---|
430 | /// the range. |
---|
431 | |
---|
432 | return ( this->flagMW && (z>=this->getMinMW()) && (z<=this->getMaxMW()) ); |
---|
433 | } |
---|
434 | |
---|
435 | bool Param::isStatOK(int x, int y, int z) |
---|
436 | { |
---|
437 | /// Test whether a given pixel position lies within the subsection |
---|
438 | /// given by the statSec parameter. Only tested if the flagSubsection |
---|
439 | /// parameter is true -- if it isn't, we just return true since all |
---|
440 | /// pixels are therefore available for statstical calculations. |
---|
441 | /// \param x X-value of pixel being tested. |
---|
442 | /// \param y Y-value of pixel being tested. |
---|
443 | /// \param z Z-value of pixel being tested. |
---|
444 | /// \return True if pixel is able to be used for statistical |
---|
445 | /// calculations. False otherwise. |
---|
446 | |
---|
447 | int xval=x,yval=y,zval=z; |
---|
448 | if(flagSubsection){ |
---|
449 | xval += pixelSec.getStart(0); |
---|
450 | yval += pixelSec.getStart(1); |
---|
451 | zval += pixelSec.getStart(2); |
---|
452 | } |
---|
453 | return !flagStatSec || statSec.isInside(xval,yval,zval); |
---|
454 | } |
---|
455 | |
---|
456 | std::vector<int> Param::getObjectRequest() |
---|
457 | { |
---|
458 | /// Returns a list of the object numbers requested via the objectList parameter. |
---|
459 | /// \return a vector of integers, one for each number in the objectList set. |
---|
460 | |
---|
461 | std::stringstream ss1; |
---|
462 | std::string tmp; |
---|
463 | std::vector<int> tmplist; |
---|
464 | ss1.str(this->objectList); |
---|
465 | while(!ss1.eof()){ |
---|
466 | getline(ss1,tmp,','); |
---|
467 | for(size_t i=0;i<tmp.size();i++) if(tmp[i]=='-') tmp[i]=' '; |
---|
468 | int a,b; |
---|
469 | std::stringstream ss2; |
---|
470 | ss2.str(tmp); |
---|
471 | ss2 >>a; |
---|
472 | if(!ss2.eof()) ss2 >> b; |
---|
473 | else b=a; |
---|
474 | for(int n=a;n<=b;n++){ |
---|
475 | tmplist.push_back(n); |
---|
476 | } |
---|
477 | } |
---|
478 | return tmplist; |
---|
479 | } |
---|
480 | |
---|
481 | std::vector<bool> Param::getObjectChoices() |
---|
482 | { |
---|
483 | /// Returns a list of bool values, indicating whether a given |
---|
484 | /// object was requested or not. The size of the vector is |
---|
485 | /// determined by the maximum value in objectList. For instance, |
---|
486 | /// if objectList="2,3,5-8", then the returned vector will be |
---|
487 | /// [0,1,1,0,1,1,1,1]. |
---|
488 | /// \return Vector of bool values. |
---|
489 | |
---|
490 | std::vector<int> objectChoices = this->getObjectRequest(); |
---|
491 | int maxNum = *std::max_element(objectChoices.begin(), objectChoices.end()); |
---|
492 | std::vector<bool> choices(maxNum,false); |
---|
493 | for(std::vector<int>::iterator obj = objectChoices.begin();obj!=objectChoices.end();obj++) |
---|
494 | choices[*obj-1] = true; |
---|
495 | return choices; |
---|
496 | } |
---|
497 | |
---|
498 | std::vector<bool> Param::getObjectChoices(int numObjects) |
---|
499 | { |
---|
500 | /// Returns a list of bool values, indicating whether a given |
---|
501 | /// object was requested or not. The size of the vector is given |
---|
502 | /// by the numObjects parameter. So, if objectList="2,3,5-8", then |
---|
503 | /// the returned vector from a getObjectChoices(10) call will be |
---|
504 | /// [0,1,1,0,1,1,1,1,0,0]. |
---|
505 | /// \param numObjects How many objects there are in total. |
---|
506 | /// \return Vector of bool values. |
---|
507 | |
---|
508 | if(this->objectList==""){ |
---|
509 | std::vector<bool> choices(numObjects,true); |
---|
510 | return choices; |
---|
511 | } |
---|
512 | else{ |
---|
513 | std::vector<int> objectChoices = this->getObjectRequest(); |
---|
514 | std::vector<bool> choices(numObjects,false); |
---|
515 | for(std::vector<int>::iterator obj = objectChoices.begin();obj!=objectChoices.end();obj++) |
---|
516 | if(*obj<=numObjects) choices[*obj-1] = true; |
---|
517 | return choices; |
---|
518 | } |
---|
519 | } |
---|
520 | |
---|
521 | /****************************************************************/ |
---|
522 | /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// |
---|
523 | /// / Other Functions using the Parameter class: |
---|
524 | /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// |
---|
525 | |
---|
526 | std::string makelower( std::string s ) |
---|
527 | { |
---|
528 | // "borrowed" from Matt Howlett's 'fred' |
---|
529 | std::string out = ""; |
---|
530 | for( size_t i=0; i<s.size(); ++i ) { |
---|
531 | out += tolower(s[i]); |
---|
532 | } |
---|
533 | return out; |
---|
534 | } |
---|
535 | |
---|
536 | inline std::string stringize(bool b) |
---|
537 | { |
---|
538 | /// Convert a bool variable to the textual equivalent. |
---|
539 | /// \return A std::string with the english equivalent of the bool. |
---|
540 | |
---|
541 | std::string output; |
---|
542 | if(b) output="true"; |
---|
543 | else output="false"; |
---|
544 | return output; |
---|
545 | } |
---|
546 | |
---|
547 | inline bool boolify( std::string s ) |
---|
548 | { |
---|
549 | /// Convert a std::string to a bool variable: |
---|
550 | /// "1" and "true" get converted to true; |
---|
551 | /// "0" and "false" (and anything else) get converted to false. |
---|
552 | /// \return The bool equivalent of the string. |
---|
553 | |
---|
554 | if((s=="1") || (makelower(s)=="true")) return true; |
---|
555 | else if((s=="0") || (makelower(s)=="false")) return false; |
---|
556 | else return false; |
---|
557 | } |
---|
558 | |
---|
559 | inline std::string readSval(std::stringstream& ss) |
---|
560 | { |
---|
561 | std::string val; ss >> val; return val; |
---|
562 | } |
---|
563 | |
---|
564 | inline bool readFlag(std::stringstream& ss) |
---|
565 | { |
---|
566 | std::string val; ss >> val; return boolify(val); |
---|
567 | } |
---|
568 | |
---|
569 | inline float readFval(std::stringstream& ss) |
---|
570 | { |
---|
571 | float val; ss >> val; return val; |
---|
572 | } |
---|
573 | |
---|
574 | inline int readIval(std::stringstream& ss) |
---|
575 | { |
---|
576 | int val; ss >> val; return val; |
---|
577 | } |
---|
578 | |
---|
579 | OUTCOME Param::readParams(std::string paramfile) |
---|
580 | { |
---|
581 | /// The parameters are read in from a disk file, on the assumption that each |
---|
582 | /// line of the file has the format "parameter value" (eg. alphafdr 0.1) |
---|
583 | /// |
---|
584 | /// The case of the parameter name does not matter, nor does the |
---|
585 | /// formatting of the spaces (it can be any amount of whitespace or |
---|
586 | /// tabs). |
---|
587 | /// |
---|
588 | /// \param paramfile A std::string containing the parameter filename. |
---|
589 | /// |
---|
590 | /// \return FAILURE if the parameter file does not exist. SUCCESS if |
---|
591 | /// it is able to read it. |
---|
592 | |
---|
593 | std::ifstream fin(paramfile.c_str()); |
---|
594 | if(!fin.is_open()) return FAILURE; |
---|
595 | std::string line; |
---|
596 | while( !std::getline(fin,line,'\n').eof()){ |
---|
597 | |
---|
598 | if(line[0]!='#'){ |
---|
599 | std::stringstream ss; |
---|
600 | ss.str(line); |
---|
601 | std::string arg; |
---|
602 | ss >> arg; |
---|
603 | arg = makelower(arg); |
---|
604 | if(arg=="imagefile") this->imageFile = readSval(ss); |
---|
605 | if(arg=="flagsubsection") this->flagSubsection = readFlag(ss); |
---|
606 | if(arg=="subsection") this->pixelSec.setSection(readSval(ss)); |
---|
607 | if(arg=="flagreconexists") this->flagReconExists = readFlag(ss); |
---|
608 | if(arg=="reconfile") this->reconFile = readSval(ss); |
---|
609 | if(arg=="flagsmoothexists")this->flagSmoothExists = readFlag(ss); |
---|
610 | if(arg=="smoothfile") this->smoothFile = readSval(ss); |
---|
611 | if(arg=="beamarea") this->areaBeam = readFval(ss); |
---|
612 | if(arg=="beamfwhm") this->fwhmBeam = readFval(ss); |
---|
613 | if(arg=="useprevious") this->usePrevious = readFlag(ss); |
---|
614 | if(arg=="objectlist") this->objectList = readSval(ss); |
---|
615 | |
---|
616 | if(arg=="flaglog") this->flagLog = readFlag(ss); |
---|
617 | if(arg=="logfile") this->logFile = readSval(ss); |
---|
618 | if(arg=="outfile") this->outFile = readSval(ss); |
---|
619 | if(arg=="flagseparateheader") this->flagSeparateHeader = readFlag(ss); |
---|
620 | if(arg=="headerfile") this->headerFile = readSval(ss); |
---|
621 | if(arg=="spectrafile") this->spectraFile = readSval(ss); |
---|
622 | if(arg=="flagtextspectra") this->flagTextSpectra = readFlag(ss); |
---|
623 | if(arg=="spectratextfile") this->spectraTextFile = readSval(ss); |
---|
624 | if(arg=="flagoutputmomentmap") this->flagOutputMomentMap = readFlag(ss); |
---|
625 | if(arg=="fileoutputmomentmap") this->fileOutputMomentMap = readSval(ss); |
---|
626 | if(arg=="flagoutputmask") this->flagOutputMask = readFlag(ss); |
---|
627 | if(arg=="fileoutputmask") this->fileOutputMask = readSval(ss); |
---|
628 | if(arg=="flagmaskwithobjectnum") this->flagMaskWithObjectNum = readFlag(ss); |
---|
629 | if(arg=="flagoutputsmooth")this->flagOutputSmooth = readFlag(ss); |
---|
630 | if(arg=="fileoutputsmooth")this->fileOutputSmooth = readSval(ss); |
---|
631 | if(arg=="flagoutputrecon") this->flagOutputRecon = readFlag(ss); |
---|
632 | if(arg=="fileoutputrecon") this->fileOutputRecon = readSval(ss); |
---|
633 | if(arg=="flagoutputresid") this->flagOutputResid = readFlag(ss); |
---|
634 | if(arg=="fileoutputresid") this->fileOutputResid = readSval(ss); |
---|
635 | if(arg=="flagvot") this->flagVOT = readFlag(ss); |
---|
636 | if(arg=="votfile") this->votFile = readSval(ss); |
---|
637 | if(arg=="flagkarma") this->flagKarma = readFlag(ss); |
---|
638 | if(arg=="karmafile") this->karmaFile = readSval(ss); |
---|
639 | if(arg=="annotationtype") this->annotationType = readSval(ss); |
---|
640 | if(arg=="flagmaps") this->flagMaps = readFlag(ss); |
---|
641 | if(arg=="detectionmap") this->detectionMap = readSval(ss); |
---|
642 | if(arg=="momentmap") this->momentMap = readSval(ss); |
---|
643 | if(arg=="flagxoutput") this->flagXOutput = readFlag(ss); |
---|
644 | if(arg=="newfluxunits") this->newFluxUnits = readSval(ss); |
---|
645 | if(arg=="precflux") this->precFlux = readIval(ss); |
---|
646 | if(arg=="precvel") this->precVel = readIval(ss); |
---|
647 | if(arg=="precsnr") this->precSNR = readIval(ss); |
---|
648 | |
---|
649 | if(arg=="flagtrim") this->flagTrim = readFlag(ss); |
---|
650 | if(arg=="flagmw") this->flagMW = readFlag(ss); |
---|
651 | if(arg=="maxmw") this->maxMW = readIval(ss); |
---|
652 | if(arg=="minmw") this->minMW = readIval(ss); |
---|
653 | if(arg=="flagbaseline") this->flagBaseline = readFlag(ss); |
---|
654 | if(arg=="searchtype") this->searchType = readSval(ss); |
---|
655 | |
---|
656 | if(arg=="flagnegative") this->flagNegative = readFlag(ss); |
---|
657 | if(arg=="minpix") this->minPix = readIval(ss); |
---|
658 | if(arg=="flaggrowth") this->flagGrowth = readFlag(ss); |
---|
659 | if(arg=="growthcut") this->growthCut = readFval(ss); |
---|
660 | if(arg=="growththreshold"){ |
---|
661 | this->growthThreshold = readFval(ss); |
---|
662 | this->flagUserGrowthThreshold = true; |
---|
663 | } |
---|
664 | |
---|
665 | if(arg=="flagfdr") this->flagFDR = readFlag(ss); |
---|
666 | if(arg=="alphafdr") this->alphaFDR = readFval(ss); |
---|
667 | if(arg=="fdrnumcorchan") this->FDRnumCorChan = readIval(ss); |
---|
668 | if(arg=="flagstatsec") this->flagStatSec = readFlag(ss); |
---|
669 | if(arg=="statsec") this->statSec.setSection(readSval(ss)); |
---|
670 | if(arg=="flagrobuststats") this->flagRobustStats = readFlag(ss); |
---|
671 | if(arg=="snrcut") this->snrCut = readFval(ss); |
---|
672 | if(arg=="threshold"){ |
---|
673 | this->threshold = readFval(ss); |
---|
674 | this->flagUserThreshold = true; |
---|
675 | } |
---|
676 | |
---|
677 | if(arg=="flagsmooth") this->flagSmooth = readFlag(ss); |
---|
678 | if(arg=="smoothtype") this->smoothType = readSval(ss); |
---|
679 | if(arg=="hanningwidth") this->hanningWidth = readIval(ss); |
---|
680 | if(arg=="kernmaj") this->kernMaj = readFval(ss); |
---|
681 | if(arg=="kernmin") this->kernMin = readFval(ss); |
---|
682 | if(arg=="kernpa") this->kernPA = readFval(ss); |
---|
683 | |
---|
684 | if(arg=="flagatrous") this->flagATrous = readFlag(ss); |
---|
685 | if(arg=="recondim") this->reconDim = readIval(ss); |
---|
686 | if(arg=="scalemin") this->scaleMin = readIval(ss); |
---|
687 | if(arg=="scalemax") this->scaleMax = readIval(ss); |
---|
688 | if(arg=="snrrecon") this->snrRecon = readFval(ss); |
---|
689 | if(arg=="filtercode"){ |
---|
690 | this->filterCode = readIval(ss); |
---|
691 | this->reconFilter.define(this->filterCode); |
---|
692 | } |
---|
693 | |
---|
694 | if(arg=="flagadjacent") this->flagAdjacent = readFlag(ss); |
---|
695 | if(arg=="threshspatial") this->threshSpatial = readFval(ss); |
---|
696 | if(arg=="threshvelocity") this->threshVelocity = readFval(ss); |
---|
697 | if(arg=="minchannels") this->minChannels = readIval(ss); |
---|
698 | if(arg=="minvoxels") this->minVoxels = readIval(ss); |
---|
699 | if(arg=="flagrejectbeforemerge") this->flagRejectBeforeMerge = readFlag(ss); |
---|
700 | if(arg=="flagtwostagemerging") this->flagTwoStageMerging = readFlag(ss); |
---|
701 | |
---|
702 | if(arg=="spectralmethod") this->spectralMethod=makelower(readSval(ss)); |
---|
703 | if(arg=="spectralunits") this->spectralUnits = makelower(readSval(ss)); |
---|
704 | if(arg=="pixelcentre") this->pixelCentre = makelower(readSval(ss)); |
---|
705 | if(arg=="sortingparam") this->sortingParam = makelower(readSval(ss)); |
---|
706 | if(arg=="drawborders") this->borders = readFlag(ss); |
---|
707 | if(arg=="drawblankedges") this->blankEdge = readFlag(ss); |
---|
708 | if(arg=="verbose") this->verbose = readFlag(ss); |
---|
709 | |
---|
710 | // Dealing with deprecated parameters. |
---|
711 | if(arg=="flagblankpix"){ |
---|
712 | this->flagTrim = readFlag(ss); |
---|
713 | std::stringstream errmsg; |
---|
714 | errmsg <<"The parameter flagBlankPix is deprecated. " |
---|
715 | <<"Please use the flagTrim parameter in future.\n" |
---|
716 | <<"Setting flagTrim = " << stringize(this->flagTrim) << ".\n"; |
---|
717 | duchampWarning("Reading parameters",errmsg.str()); |
---|
718 | } |
---|
719 | if(arg=="blankpixvalue"){ |
---|
720 | std::stringstream errmsg; |
---|
721 | errmsg <<"The parameter blankPixValue is deprecated.\n" |
---|
722 | <<"This value is only taken from the FITS header.\n"; |
---|
723 | duchampWarning("Reading parameters",errmsg.str()); |
---|
724 | } |
---|
725 | if(arg=="beamsize"){ |
---|
726 | this->areaBeam = readFval(ss); |
---|
727 | std::stringstream errmsg; |
---|
728 | errmsg <<"The parameter beamSize is deprecated.\n" |
---|
729 | <<"You can specify the beam size by beamArea or beamFWHM.\n" |
---|
730 | <<"Setting beamArea = " << this->areaBeam << ".\n"; |
---|
731 | duchampWarning("Reading parameters",errmsg.str()); |
---|
732 | } |
---|
733 | |
---|
734 | } |
---|
735 | } |
---|
736 | |
---|
737 | this->checkPars(); |
---|
738 | |
---|
739 | return SUCCESS; |
---|
740 | |
---|
741 | } |
---|
742 | |
---|
743 | void Param::checkPars() |
---|
744 | { |
---|
745 | |
---|
746 | // If we have usePrevious=false, set the objectlist to blank so that we use all of them |
---|
747 | if(!this->usePrevious) this->objectList = ""; |
---|
748 | |
---|
749 | // If pgplot was not included in the compilation, need to set flagXOutput to false |
---|
750 | if(!USE_PGPLOT) this->flagXOutput = false; |
---|
751 | |
---|
752 | // Correcting bad precision values -- if negative, set to 0 |
---|
753 | if(this->precFlux<0) this->precFlux = 0; |
---|
754 | if(this->precVel<0) this->precVel = 0; |
---|
755 | if(this->precSNR<0) this->precSNR = 0; |
---|
756 | |
---|
757 | // Can only have "spatial" or "spectral" as search types |
---|
758 | if(this->searchType != "spatial" && this->searchType != "spectral"){ |
---|
759 | std::stringstream errmsg; |
---|
760 | errmsg << "You have requested a search type of \""<<this->searchType<<"\".\n" |
---|
761 | << "Only \"spectral\" and \"spatial\" are accepted. Setting to \"spatial\".\n"; |
---|
762 | duchampWarning("Reading parameters",errmsg.str()); |
---|
763 | this->searchType = "spatial"; |
---|
764 | } |
---|
765 | |
---|
766 | // The wavelet reconstruction takes precendence over the smoothing. |
---|
767 | if(this->flagATrous) this->flagSmooth = false; |
---|
768 | |
---|
769 | if(this->flagUserThreshold){ |
---|
770 | |
---|
771 | // If we specify a manual threshold, need to also specify a manual growth threshold |
---|
772 | // If we haven't done so, turn growing off |
---|
773 | if(this->flagGrowth && !this->flagUserGrowthThreshold){ |
---|
774 | std::stringstream errmsg; |
---|
775 | errmsg << "You have specified a manual search threshold, but not a manual growth threshold.\n" |
---|
776 | << "You need to do so using the \"growthThreshold\" parameter.\n" |
---|
777 | << "The growth function is being turned off.\n"; |
---|
778 | duchampWarning("Reading parameters",errmsg.str()); |
---|
779 | this->flagGrowth = false; |
---|
780 | } |
---|
781 | |
---|
782 | // If we specify a manual threshold, we don't need the FDR method, so turn it off if requested. |
---|
783 | if(this->flagFDR){ |
---|
784 | std::stringstream errmsg; |
---|
785 | errmsg << "You have specified a manual search threshold, so we don't need to use the FDR method.\n" |
---|
786 | << "Setting \"flagFDR=false\".\n"; |
---|
787 | duchampWarning("Reading parameters",errmsg.str()); |
---|
788 | this->flagFDR = false; |
---|
789 | } |
---|
790 | |
---|
791 | } |
---|
792 | |
---|
793 | // Make sure the growth level is less than the detection level. Else turn off growing. |
---|
794 | if(this->flagGrowth){ |
---|
795 | std::stringstream errmsg; |
---|
796 | bool doWarn = false; |
---|
797 | if(this->flagUserThreshold && |
---|
798 | ( (this->threshold < this->growthThreshold) |
---|
799 | || (this->snrCut < this->growthCut) ) ){ |
---|
800 | errmsg << "Your \"growthThreshold\" parameter is larger than your \"threshold\".\n" |
---|
801 | << "The growth function is being turned off.\n"; |
---|
802 | doWarn = true; |
---|
803 | } |
---|
804 | |
---|
805 | if(!this->flagUserThreshold && |
---|
806 | (this->snrCut < this->growthCut)) { |
---|
807 | errmsg << "Your \"growthCut\" parameter is larger than your \"snrCut\".\n" |
---|
808 | << "The growth function is being turned off.\n"; |
---|
809 | doWarn = true; |
---|
810 | } |
---|
811 | |
---|
812 | if(doWarn) duchampWarning("Reading parameters",errmsg.str()); |
---|
813 | |
---|
814 | } |
---|
815 | |
---|
816 | // Make sure the annnotationType is an acceptable option -- default is "borders" |
---|
817 | if((this->annotationType != "borders") && (this->annotationType!="circles")){ |
---|
818 | std::stringstream errmsg; |
---|
819 | errmsg << "The requested value of the parameter annotationType, \"" |
---|
820 | << this->annotationType << "\", is invalid.\n" |
---|
821 | << "Changing to \"borders\".\n"; |
---|
822 | duchampWarning("Reading parameters",errmsg.str()); |
---|
823 | this->annotationType = "borders"; |
---|
824 | } |
---|
825 | |
---|
826 | // Make sure smoothType is an acceptable type -- default is "spectral" |
---|
827 | if((this->smoothType!="spectral")&& |
---|
828 | (this->smoothType!="spatial")){ |
---|
829 | std::stringstream errmsg; |
---|
830 | errmsg << "The requested value of the parameter smoothType, \"" |
---|
831 | << this->smoothType << "\", is invalid.\n" |
---|
832 | << "Changing to \"spectral\".\n"; |
---|
833 | duchampWarning("Reading parameters",errmsg.str()); |
---|
834 | this->smoothType = "spectral"; |
---|
835 | } |
---|
836 | // If kernMin has not been given, or is negative, make it equal to kernMaj |
---|
837 | if(this->kernMin < 0) this->kernMin = this->kernMaj; |
---|
838 | |
---|
839 | // Make sure spectralMethod is an acceptable type -- default is "peak" |
---|
840 | if((this->spectralMethod!="peak")&& |
---|
841 | (this->spectralMethod!="sum")){ |
---|
842 | std::stringstream errmsg; |
---|
843 | errmsg << "The requested value of the parameter spectralMethod, \"" |
---|
844 | << this->spectralMethod << "\", is invalid.\n" |
---|
845 | << "Changing to \"peak\".\n"; |
---|
846 | duchampWarning("Reading parameters",errmsg.str()); |
---|
847 | this->spectralMethod = "peak"; |
---|
848 | } |
---|
849 | |
---|
850 | // Make sure pixelCentre is an acceptable type -- default is "peak" |
---|
851 | if((this->pixelCentre!="centroid")&& |
---|
852 | (this->pixelCentre!="average") && |
---|
853 | (this->pixelCentre!="peak") ){ |
---|
854 | std::stringstream errmsg; |
---|
855 | errmsg << "The requested value of the parameter pixelCentre, \"" |
---|
856 | << this->pixelCentre << "\", is invalid.\n" |
---|
857 | << "Changing to \"centroid\".\n"; |
---|
858 | duchampWarning("Reading parameters",errmsg.str()); |
---|
859 | this->pixelCentre = "centroid"; |
---|
860 | } |
---|
861 | |
---|
862 | // Make sure sortingParam is an acceptable type -- default is "vel" |
---|
863 | bool OK = false; |
---|
864 | for(int i=0;i<numSortingParamOptions;i++) |
---|
865 | OK = OK || this->sortingParam==sortingParamOptions[i]; |
---|
866 | if(!OK){ |
---|
867 | std::stringstream errmsg; |
---|
868 | errmsg << "The requested value of the parameter sortingParam, \"" |
---|
869 | << this->sortingParam << "\", is invalid.\n" |
---|
870 | << "Changing to \"vel\".\n"; |
---|
871 | duchampWarning("Reading parameters",errmsg.str()); |
---|
872 | this->sortingParam = "vel"; |
---|
873 | } |
---|
874 | |
---|
875 | } |
---|
876 | |
---|
877 | void recordParameters(std::ostream& theStream, std::string paramName, std::string paramDesc, std::string paramValue) |
---|
878 | { |
---|
879 | |
---|
880 | const int width = 56; |
---|
881 | int widthText = width - paramName.size(); |
---|
882 | |
---|
883 | theStream << std::setw(widthText) << paramDesc |
---|
884 | << setiosflags(std::ios::right) << paramName |
---|
885 | << " = " << resetiosflags(std::ios::right) << paramValue |
---|
886 | <<std::endl; |
---|
887 | } |
---|
888 | |
---|
889 | std::string fileOption(bool flag, std::string file) |
---|
890 | { |
---|
891 | std::ostringstream ss; |
---|
892 | ss << stringize(flag); |
---|
893 | if(flag) ss << " --> " << file; |
---|
894 | return ss.str(); |
---|
895 | |
---|
896 | } |
---|
897 | |
---|
898 | std::ostream& operator<< ( std::ostream& theStream, Param& par) |
---|
899 | { |
---|
900 | /// Print out the parameter set in a formatted, easy to read style. |
---|
901 | /// Lists the parameters, a description of them, and their value. |
---|
902 | |
---|
903 | // Only show the [beamSize] bit if we are using the parameter |
---|
904 | // otherwise we have read it from the FITS header. |
---|
905 | std::string beamParam = ""; |
---|
906 | if(par.getFlagUsingBeam()) beamParam = "[beamSize]"; |
---|
907 | |
---|
908 | // BUG -- can get error: `boolalpha' is not a member of type `ios' -- old compilers: gcc 2.95.3? |
---|
909 | // theStream.setf(std::ios::boolalpha); |
---|
910 | theStream.setf(std::ios::left); |
---|
911 | theStream <<"\n---- Parameters ----"<<std::endl; |
---|
912 | theStream << std::setfill('.'); |
---|
913 | if(par.getFlagSubsection()) |
---|
914 | recordParam(theStream, "[imageFile]", "Image to be analysed", par.getImageFile()<<par.getSubsection()); |
---|
915 | else |
---|
916 | recordParam(theStream, "[imageFile]", "Image to be analysed", par.getImageFile()); |
---|
917 | if(par.getFlagReconExists() && par.getFlagATrous()){ |
---|
918 | recordParam(theStream, "[reconExists]", "Reconstructed array exists?", stringize(par.getFlagReconExists())); |
---|
919 | recordParam(theStream, "[reconFile]", "FITS file containing reconstruction", par.getReconFile()); |
---|
920 | } |
---|
921 | if(par.getFlagSmoothExists() && par.getFlagSmooth()){ |
---|
922 | recordParam(theStream, "[smoothExists]", "Smoothed array exists?", stringize(par.getFlagSmoothExists())); |
---|
923 | recordParam(theStream, "[smoothFile]", "FITS file containing smoothed array", par.getSmoothFile()); |
---|
924 | } |
---|
925 | recordParam(theStream, "[logFile]", "Intermediate Logfile", par.getLogFile()); |
---|
926 | recordParam(theStream, "[outFile]", "Final Results file", par.getOutFile()); |
---|
927 | if(par.getFlagSeparateHeader()){ |
---|
928 | recordParam(theStream, "[headerFile]", "Header for results file", par.getHeaderFile()); |
---|
929 | } |
---|
930 | recordParam(theStream, "[spectraFile]", "Spectrum file", par.getSpectraFile()); |
---|
931 | if(par.getFlagTextSpectra()){ |
---|
932 | recordParam(theStream, "[spectraTextFile]", "Text file with ascii spectral data", par.getSpectraTextFile()); |
---|
933 | } |
---|
934 | if(par.getFlagVOT()){ |
---|
935 | recordParam(theStream, "[votFile]", "VOTable file", par.getVOTFile()); |
---|
936 | } |
---|
937 | if(par.getFlagKarma()){ |
---|
938 | recordParam(theStream, "[karmaFile]", "Karma annotation file" , par.getKarmaFile()); |
---|
939 | } |
---|
940 | if(par.getFlagMaps()){ |
---|
941 | recordParam(theStream, "[momentMap]", "0th Moment Map", par.getMomentMap()); |
---|
942 | recordParam(theStream, "[detectionMap]", "Detection Map", par.getDetectionMap()); |
---|
943 | } |
---|
944 | recordParam(theStream, "[flagXOutput]", "Display a map in a pgplot xwindow?", stringize(par.getFlagXOutput())); |
---|
945 | if(par.getFlagATrous()){ |
---|
946 | recordParam(theStream, "[flagOutputRecon]", "Saving reconstructed cube?", fileOption(par.getFlagOutputRecon(),par.outputReconFile())); |
---|
947 | recordParam(theStream, "[flagOutputResid]", "Saving residuals from reconstruction?", fileOption(par.getFlagOutputResid(),par.outputResidFile())); |
---|
948 | } |
---|
949 | if(par.getFlagSmooth()){ |
---|
950 | recordParam(theStream, "[flagOutputSmooth]", "Saving smoothed cube?", fileOption(par.getFlagOutputSmooth(),par.outputSmoothFile())); |
---|
951 | } |
---|
952 | recordParam(theStream, "[flagOutputMask]", "Saving mask cube?", fileOption(par.getFlagOutputMask(),par.outputMaskFile())); |
---|
953 | recordParam(theStream, "[flagOutputMask]", "Saving 0th moment to FITS file?", fileOption(par.getFlagOutputMomentMap(),par.outputMomentMapFile())); |
---|
954 | |
---|
955 | theStream <<"------"<<std::endl; |
---|
956 | |
---|
957 | recordParam(theStream, "[searchType]", "Type of searching performed", par.getSearchType()); |
---|
958 | if(par.getFlagBlankPix()){ |
---|
959 | recordParam(theStream, "", "Blank Pixel Value", par.getBlankPixVal()); |
---|
960 | } |
---|
961 | recordParam(theStream, "[flagTrim]", "Trimming Blank Pixels?", stringize(par.getFlagTrim())); |
---|
962 | recordParam(theStream, "[flagNegative]", "Searching for Negative features?", stringize(par.getFlagNegative())); |
---|
963 | recordParam(theStream, "[flagMW]", "Removing Milky Way channels?", stringize(par.getFlagMW())); |
---|
964 | if(par.getFlagMW()){ |
---|
965 | // need to remove the offset correction, as we want to report the parameters actually entered |
---|
966 | recordParam(theStream, "[minMW - maxMW]", "Milky Way Channels", par.getMinMW()+par.getZOffset()<<"-"<<par.getMaxMW()+par.getZOffset()); |
---|
967 | } |
---|
968 | if(par.getFlagUsingBeam()){ |
---|
969 | if(par.getBeamFWHM()>0.) recordParam(theStream, "[beamFWHM]", "FWHM of Beam (pixels)", par.getBeamFWHM() << " (beam area = " << par.getBeamSize() <<" pixels)"); |
---|
970 | else recordParam(theStream, "[beamArea]", "Area of Beam (pixels)", par.getBeamSize()); |
---|
971 | } |
---|
972 | else { |
---|
973 | recordParam(theStream, "", "Area of Beam (pixels)", par.getBeamSize()); |
---|
974 | } |
---|
975 | recordParam(theStream, "[flagBaseline]", "Removing baselines before search?", stringize(par.getFlagBaseline())); |
---|
976 | recordParam(theStream, "[flagSmooth]", "Smoothing data prior to searching?", stringize(par.getFlagSmooth())); |
---|
977 | if(par.getFlagSmooth()){ |
---|
978 | recordParam(theStream, "[smoothType]", "Type of smoothing", par.getSmoothType()); |
---|
979 | if(par.getSmoothType()=="spectral") |
---|
980 | recordParam(theStream, "[hanningWidth]", "Width of hanning filter", par.getHanningWidth()); |
---|
981 | else{ |
---|
982 | recordParam(theStream, "[kernMaj]", "Gaussian kernel semi-major axis [pix]", par.getKernMaj()); |
---|
983 | recordParam(theStream, "[kernMin]", "Gaussian kernel semi-minor axis [pix]", par.getKernMin()); |
---|
984 | recordParam(theStream, "[kernPA]", "Gaussian kernel position angle [deg]", par.getKernPA()); |
---|
985 | } |
---|
986 | } |
---|
987 | recordParam(theStream, "[flagATrous]", "Using A Trous reconstruction?", stringize(par.getFlagATrous())); |
---|
988 | if(par.getFlagATrous()){ |
---|
989 | recordParam(theStream, "[reconDim]", "Number of dimensions in reconstruction", par.getReconDim()); |
---|
990 | if(par.getMaxScale()>0){ |
---|
991 | recordParam(theStream, "[scaleMin-scaleMax]", "Scales used in reconstruction", par.getMinScale()<<"-"<<par.getMaxScale()); |
---|
992 | } |
---|
993 | else{ |
---|
994 | recordParam(theStream, "[scaleMin]", "Minimum scale in reconstruction", par.getMinScale()); |
---|
995 | } |
---|
996 | recordParam(theStream, "[snrRecon]", "SNR Threshold within reconstruction", par.getAtrousCut()); |
---|
997 | recordParam(theStream, "[filterCode]", "Filter being used for reconstruction", par.getFilterCode()<<" ("<<par.getFilterName()<<")"); |
---|
998 | } |
---|
999 | recordParam(theStream, "[flagRobustStats]", "Using Robust statistics?", stringize(par.getFlagRobustStats())); |
---|
1000 | if(par.getFlagStatSec()){ |
---|
1001 | recordParam(theStream, "[statSec]", "Section used by statistics calculation", par.statSec.getSection()); |
---|
1002 | } |
---|
1003 | recordParam(theStream, "[flagFDR]", "Using FDR analysis?", stringize(par.getFlagFDR())); |
---|
1004 | if(par.getFlagFDR()){ |
---|
1005 | recordParam(theStream, "[alphaFDR]", "Alpha value for FDR analysis", par.getAlpha()); |
---|
1006 | recordParam(theStream, "[FDRnumCorChan]", "Number of correlated channels for FDR", par.getFDRnumCorChan()); |
---|
1007 | } |
---|
1008 | else { |
---|
1009 | if(par.getFlagUserThreshold()){ |
---|
1010 | recordParam(theStream, "[threshold]", "Detection Threshold", par.getThreshold()); |
---|
1011 | } |
---|
1012 | else{ |
---|
1013 | recordParam(theStream, "[snrCut]", "SNR Threshold (in sigma)", par.getCut()); |
---|
1014 | } |
---|
1015 | } |
---|
1016 | recordParam(theStream, "[minPix]", "Minimum # Pixels in a detection", par.getMinPix()); |
---|
1017 | recordParam(theStream, "[minChannels]", "Minimum # Channels in a detection", par.getMinChannels()); |
---|
1018 | recordParam(theStream, "[minVoxels]", "Minimum # Voxels in a detection", par.getMinVoxels()); |
---|
1019 | recordParam(theStream, "[flagGrowth]", "Growing objects after detection?", stringize(par.getFlagGrowth())); |
---|
1020 | if(par.getFlagGrowth()) { |
---|
1021 | if(par.getFlagUserGrowthThreshold()){ |
---|
1022 | recordParam(theStream, "[growthThreshold]", "Threshold for growth", par.getGrowthThreshold()); |
---|
1023 | } |
---|
1024 | else{ |
---|
1025 | recordParam(theStream, "[growthCut]", "SNR Threshold for growth", par.getGrowthCut()); |
---|
1026 | } |
---|
1027 | } |
---|
1028 | recordParam(theStream, "[flagAdjacent]", "Using Adjacent-pixel criterion?", stringize(par.getFlagAdjacent())); |
---|
1029 | if(!par.getFlagAdjacent()){ |
---|
1030 | recordParam(theStream, "[threshSpatial]", "Max. spatial separation for merging", par.getThreshS()); |
---|
1031 | } |
---|
1032 | recordParam(theStream, "[threshVelocity]", "Max. velocity separation for merging", par.getThreshV()); |
---|
1033 | recordParam(theStream, "[flagRejectBeforeMerge]", "Reject objects before merging?", stringize(par.getFlagRejectBeforeMerge())); |
---|
1034 | recordParam(theStream, "[flagTwoStageMerging]", "Merge objects in two stages?", stringize(par.getFlagTwoStageMerging())); |
---|
1035 | recordParam(theStream, "[spectralMethod]", "Method of spectral plotting", par.getSpectralMethod()); |
---|
1036 | recordParam(theStream, "[pixelCentre]", "Type of object centre used in results", par.getPixelCentre()); |
---|
1037 | |
---|
1038 | theStream <<"--------------------\n\n"; |
---|
1039 | theStream << std::setfill(' '); |
---|
1040 | theStream.unsetf(std::ios::left); |
---|
1041 | // theStream.unsetf(std::ios::boolalpha); |
---|
1042 | return theStream; |
---|
1043 | } |
---|
1044 | |
---|
1045 | |
---|
1046 | void Param::copyHeaderInfo(FitsHeader &head) |
---|
1047 | { |
---|
1048 | /// A function to copy across relevant header keywords from the |
---|
1049 | /// FitsHeader class to the Param class, as they are needed by |
---|
1050 | /// functions in the Param class. |
---|
1051 | /// The parameters are the keywords BLANK, BSCALE, BZERO, and the beam size. |
---|
1052 | |
---|
1053 | this->blankKeyword = head.getBlankKeyword(); |
---|
1054 | this->bscaleKeyword = head.getBscaleKeyword(); |
---|
1055 | this->bzeroKeyword = head.getBzeroKeyword(); |
---|
1056 | this->blankPixValue = this->blankKeyword * this->bscaleKeyword + |
---|
1057 | this->bzeroKeyword; |
---|
1058 | |
---|
1059 | this->areaBeam = head.getBeamSize(); |
---|
1060 | } |
---|
1061 | |
---|
1062 | std::string Param::outputMaskFile() |
---|
1063 | { |
---|
1064 | /// This function produces the required filename in which to save |
---|
1065 | /// the mask image, indicating which pixels have been detected as |
---|
1066 | /// part of an object. If the input image is image.fits, then the |
---|
1067 | /// output will be image.MASK.fits. |
---|
1068 | |
---|
1069 | if(this->fileOutputMask==""){ |
---|
1070 | std::string inputName = this->imageFile; |
---|
1071 | std::stringstream ss; |
---|
1072 | ss << inputName.substr(0,inputName.size()-5); |
---|
1073 | // remove the ".fits" on the end. |
---|
1074 | ss << ".MASK.fits"; |
---|
1075 | return ss.str(); |
---|
1076 | } |
---|
1077 | else return this->fileOutputMask; |
---|
1078 | } |
---|
1079 | |
---|
1080 | std::string Param::outputMomentMapFile() |
---|
1081 | { |
---|
1082 | /// This function produces the required filename in which to save |
---|
1083 | /// the moment-0 FITS image. If the input image is image.fits, then the |
---|
1084 | /// output will be image.MOM0.fits. |
---|
1085 | |
---|
1086 | if(this->fileOutputMomentMap==""){ |
---|
1087 | std::string inputName = this->imageFile; |
---|
1088 | std::stringstream ss; |
---|
1089 | ss << inputName.substr(0,inputName.size()-5); |
---|
1090 | // remove the ".fits" on the end. |
---|
1091 | ss << ".MOM0.fits"; |
---|
1092 | return ss.str(); |
---|
1093 | } |
---|
1094 | else return this->fileOutputMomentMap; |
---|
1095 | } |
---|
1096 | |
---|
1097 | std::string Param::outputSmoothFile() |
---|
1098 | { |
---|
1099 | /// This function produces the required filename in which to save |
---|
1100 | /// the smoothed array. If the input image is image.fits, then |
---|
1101 | /// the output will be: |
---|
1102 | /// <ul><li> Spectral smoothing: image.SMOOTH-1D-3.fits, where the |
---|
1103 | /// width of the Hanning filter was 3 pixels. |
---|
1104 | /// <li> Spatial smoothing : image.SMOOTH-2D-3-2-20.fits, where |
---|
1105 | /// kernMaj=3, kernMin=2 and kernPA=20 degrees. |
---|
1106 | /// </ul> |
---|
1107 | |
---|
1108 | if(this->fileOutputSmooth==""){ |
---|
1109 | std::string inputName = this->imageFile; |
---|
1110 | std::stringstream ss; |
---|
1111 | ss << inputName.substr(0,inputName.size()-5); |
---|
1112 | // remove the ".fits" on the end. |
---|
1113 | if(this->flagSubsection) ss<<".sub"; |
---|
1114 | if(this->smoothType=="spectral") |
---|
1115 | ss << ".SMOOTH-1D-" << this->hanningWidth << ".fits"; |
---|
1116 | else if(this->smoothType=="spatial") |
---|
1117 | ss << ".SMOOTH-2D-" |
---|
1118 | << this->kernMaj << "-" |
---|
1119 | << this->kernMin << "-" |
---|
1120 | << this->kernPA << ".fits"; |
---|
1121 | return ss.str(); |
---|
1122 | } |
---|
1123 | else return this->fileOutputSmooth; |
---|
1124 | } |
---|
1125 | |
---|
1126 | std::string Param::outputReconFile() |
---|
1127 | { |
---|
1128 | /// This function produces the required filename in which to save |
---|
1129 | /// the reconstructed array. If the input image is image.fits, then |
---|
1130 | /// the output will be eg. image.RECON-3-2-4-1.fits, where the numbers are |
---|
1131 | /// 3=reconDim, 2=filterCode, 4=snrRecon, 1=minScale |
---|
1132 | |
---|
1133 | if(this->fileOutputRecon==""){ |
---|
1134 | std::string inputName = this->imageFile; |
---|
1135 | std::stringstream ss; |
---|
1136 | // First we remove the ".fits" from the end of the filename. |
---|
1137 | ss << inputName.substr(0,inputName.size()-5); |
---|
1138 | if(this->flagSubsection) ss<<".sub"; |
---|
1139 | ss << ".RECON-" << this->reconDim |
---|
1140 | << "-" << this->filterCode |
---|
1141 | << "-" << this->snrRecon |
---|
1142 | << "-" << this->scaleMin |
---|
1143 | << ".fits"; |
---|
1144 | return ss.str(); |
---|
1145 | } |
---|
1146 | else return this->fileOutputRecon; |
---|
1147 | } |
---|
1148 | |
---|
1149 | std::string Param::outputResidFile() |
---|
1150 | { |
---|
1151 | /// This function produces the required filename in which to save |
---|
1152 | /// the reconstructed array. If the input image is image.fits, then |
---|
1153 | /// the output will be eg. image.RESID-3-2-4-1.fits, where the numbers are |
---|
1154 | /// 3=reconDim, 2=filterCode, 4=snrRecon, 1=scaleMin |
---|
1155 | |
---|
1156 | if(this->fileOutputResid==""){ |
---|
1157 | std::string inputName = this->imageFile; |
---|
1158 | std::stringstream ss; |
---|
1159 | // First we remove the ".fits" from the end of the filename. |
---|
1160 | ss << inputName.substr(0,inputName.size()-5); |
---|
1161 | if(this->flagSubsection) ss<<".sub"; |
---|
1162 | ss << ".RESID-" << this->reconDim |
---|
1163 | << "-" << this->filterCode |
---|
1164 | << "-" << this->snrRecon |
---|
1165 | << "-" << this->scaleMin |
---|
1166 | << ".fits"; |
---|
1167 | return ss.str(); |
---|
1168 | } |
---|
1169 | else return this->fileOutputResid; |
---|
1170 | } |
---|
1171 | |
---|
1172 | } |
---|