source: trunk/src/param.cc @ 1251

Last change on this file since 1251 was 1248, checked in by MatthewWhiting, 11 years ago

Ticket #193 - Adding a warning message should anyone try to use flagMW.

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