[3] | 1 | #ifndef PARAM_H |
---|
| 2 | #define PARAM_H |
---|
| 3 | |
---|
| 4 | #include <iostream> |
---|
| 5 | #include <string> |
---|
| 6 | #include <vector> |
---|
[170] | 7 | #include <math.h> |
---|
[103] | 8 | #include <wcs.h> |
---|
[3] | 9 | |
---|
| 10 | using std::string; |
---|
| 11 | using std::vector; |
---|
| 12 | |
---|
| 13 | /** |
---|
| 14 | * Param class. |
---|
| 15 | * Used for storing parameters used by all functions. |
---|
| 16 | */ |
---|
[112] | 17 | |
---|
| 18 | class FitsHeader; // foreshadow this so that Param knows it exists |
---|
| 19 | |
---|
[3] | 20 | class Param |
---|
| 21 | { |
---|
| 22 | public: |
---|
| 23 | Param(); |
---|
| 24 | virtual ~Param(){}; |
---|
[137] | 25 | Param& operator= (const Param& p); |
---|
[164] | 26 | int verifySubsection(); // in FitsIO/subsection.cc |
---|
| 27 | void setOffsets(wcsprm *wcs); // in FitsIO/subsection.cc |
---|
| 28 | int readParams(string paramfile); // in param.cc |
---|
| 29 | void copyHeaderInfo(FitsHeader &head);// in param.cc |
---|
| 30 | bool isBlank(float &value); // in param.cc |
---|
| 31 | bool isInMW(int z){ |
---|
[160] | 32 | return ( this->flagMW && (z>=this->minMW) && (z<=this->maxMW) ); |
---|
| 33 | }; |
---|
[112] | 34 | string outputReconFile(); // in param.cc |
---|
| 35 | string outputResidFile(); // in param.cc |
---|
[3] | 36 | friend std::ostream& operator<< ( std::ostream& theStream, Param& par); |
---|
| 37 | friend class Image; |
---|
| 38 | |
---|
| 39 | // |
---|
| 40 | string getImageFile(){return imageFile;}; |
---|
| 41 | void setImageFile(string fname){imageFile = fname;}; |
---|
[106] | 42 | string getFullImageFile(){ |
---|
| 43 | if(flagSubsection) return imageFile+subsection; |
---|
| 44 | else return imageFile; |
---|
| 45 | }; |
---|
[3] | 46 | bool getFlagSubsection(){return flagSubsection;}; |
---|
| 47 | void setFlagSubsection(bool flag){flagSubsection=flag;}; |
---|
| 48 | string getSubsection(){return subsection;}; |
---|
| 49 | void setSubsection(string range){subsection = range;}; |
---|
[71] | 50 | bool getFlagReconExists(){return flagReconExists;}; |
---|
| 51 | void setFlagReconExists(bool flag){flagReconExists=flag;}; |
---|
| 52 | string getReconFile(){return reconFile;}; |
---|
| 53 | void setReconFile(string file){reconFile = file;}; |
---|
| 54 | // |
---|
[3] | 55 | bool getFlagLog(){return flagLog;}; |
---|
| 56 | void setFlagLog(bool flag){flagLog=flag;}; |
---|
| 57 | string getLogFile(){return logFile;}; |
---|
| 58 | void setLogFile(string fname){logFile = fname;}; |
---|
| 59 | string getOutFile(){return outFile;}; |
---|
| 60 | void setOutFile(string fname){outFile = fname;}; |
---|
| 61 | string getSpectraFile(){return spectraFile;}; |
---|
| 62 | void setSpectraFile(string fname){spectraFile = fname;}; |
---|
| 63 | bool getFlagOutputRecon(){return flagOutputRecon;}; |
---|
| 64 | void setFlagOutputRecon(bool flag){flagOutputRecon=flag;}; |
---|
| 65 | bool getFlagOutputResid(){return flagOutputResid;}; |
---|
| 66 | void setFlagOutputResid(bool flag){flagOutputResid=flag;}; |
---|
| 67 | bool getFlagVOT(){return flagVOT;}; |
---|
| 68 | void setFlagVOT(bool flag){flagVOT=flag;}; |
---|
| 69 | string getVOTFile(){return votFile;}; |
---|
| 70 | void setVOTFile(string fname){votFile = fname;}; |
---|
[20] | 71 | bool getFlagKarma(){return flagKarma;}; |
---|
| 72 | void setFlagKarma(bool flag){flagKarma=flag;}; |
---|
| 73 | string getKarmaFile(){return karmaFile;}; |
---|
| 74 | void setKarmaFile(string fname){karmaFile = fname;}; |
---|
[3] | 75 | bool getFlagMaps(){return flagMaps;}; |
---|
| 76 | void setFlagMaps(bool flag){flagMaps=flag;}; |
---|
| 77 | string getDetectionMap(){return detectionMap;}; |
---|
| 78 | void setDetectionMap(string fname){detectionMap = fname;}; |
---|
| 79 | string getMomentMap(){return momentMap;}; |
---|
| 80 | void setMomentMap(string fname){momentMap = fname;}; |
---|
| 81 | // |
---|
[60] | 82 | bool getFlagNegative(){return flagNegative;}; |
---|
| 83 | void setFlagNegative(bool flag){flagNegative=flag;}; |
---|
[3] | 84 | bool getFlagBlankPix(){return flagBlankPix;}; |
---|
| 85 | void setFlagBlankPix(bool flag){flagBlankPix=flag;}; |
---|
| 86 | float getBlankPixVal(){return blankPixValue;}; |
---|
| 87 | void setBlankPixVal(float v){blankPixValue=v;}; |
---|
| 88 | int getBlankKeyword(){return blankKeyword;}; |
---|
| 89 | void setBlankKeyword(int v){blankKeyword=v;}; |
---|
| 90 | float getBscaleKeyword(){return bscaleKeyword;}; |
---|
| 91 | void setBscaleKeyword(float v){bscaleKeyword=v;}; |
---|
| 92 | float getBzeroKeyword(){return bzeroKeyword;}; |
---|
| 93 | void setBzeroKeyword(float v){bzeroKeyword=v;}; |
---|
[103] | 94 | bool getFlagUsingBlank(){return flagUsingBlank;}; |
---|
| 95 | void setFlagUsingBlank(bool b){flagUsingBlank=b;}; |
---|
[3] | 96 | bool getFlagMW(){return flagMW;}; |
---|
| 97 | bool setFlagMW(bool flag){flagMW=flag;}; |
---|
| 98 | int getMaxMW(){return maxMW;}; |
---|
| 99 | void setMaxMW(int m){maxMW=m;}; |
---|
| 100 | int getMinMW(){return minMW;}; |
---|
| 101 | void setMinMW(int m){minMW=m;}; |
---|
| 102 | void setBeamSize(float s){numPixBeam = s;}; |
---|
| 103 | float getBeamSize(){return numPixBeam;}; |
---|
[172] | 104 | bool getFlagUsingBeam(){return flagUsingBeam;}; |
---|
| 105 | void setFlagUsingBeam(bool b){flagUsingBeam=b;}; |
---|
[3] | 106 | // |
---|
| 107 | bool getFlagCubeTrimmed(){return flagTrimmed;}; |
---|
| 108 | void setFlagCubeTrimmed(bool flag){flagTrimmed = flag;}; |
---|
| 109 | long getBorderLeft(){return borderLeft;}; |
---|
| 110 | void setBorderLeft(long b){borderLeft = b;}; |
---|
| 111 | long getBorderRight(){return borderRight;}; |
---|
| 112 | void setBorderRight(long b){borderRight = b;}; |
---|
| 113 | long getBorderBottom(){return borderBottom;}; |
---|
| 114 | void setBorderBottom(long b){borderBottom = b;}; |
---|
| 115 | long getBorderTop(){return borderTop;}; |
---|
| 116 | void setBorderTop(long b){borderTop = b;}; |
---|
| 117 | // |
---|
| 118 | long getXOffset(){return xSubOffset;}; |
---|
| 119 | void setXOffset(long o){xSubOffset = o;}; |
---|
| 120 | long getYOffset(){return ySubOffset;}; |
---|
| 121 | void setYOffset(long o){ySubOffset = o;}; |
---|
| 122 | long getZOffset(){return zSubOffset;}; |
---|
| 123 | void setZOffset(long o){zSubOffset = o;}; |
---|
| 124 | // |
---|
| 125 | int getMinPix(){return minPix;}; |
---|
| 126 | void setMinPix(int m){minPix=m;}; |
---|
| 127 | // |
---|
| 128 | bool getFlagGrowth(){return flagGrowth;}; |
---|
| 129 | void setFlagGrowth(bool flag){flagGrowth=flag;}; |
---|
| 130 | float getGrowthCut(){return growthCut;}; |
---|
| 131 | void setGrowthCut(float c){growthCut=c;}; |
---|
| 132 | // |
---|
| 133 | bool getFlagFDR(){return flagFDR;}; |
---|
| 134 | void setFlagFDR(bool flag){flagFDR=flag;}; |
---|
| 135 | float getAlpha(){return alphaFDR;}; |
---|
| 136 | void setAlpha(float a){alphaFDR=a;}; |
---|
| 137 | // |
---|
| 138 | bool getFlagBaseline(){return flagBaseline;}; |
---|
| 139 | void setFlagBaseline(bool flag){flagBaseline = flag;}; |
---|
| 140 | // |
---|
| 141 | float getCut(){return snrCut;}; |
---|
| 142 | void setCut(float c){snrCut=c;}; |
---|
| 143 | // |
---|
| 144 | bool getFlagATrous(){return flagATrous;}; |
---|
| 145 | void setFlagATrous(bool flag){flagATrous=flag;}; |
---|
[103] | 146 | int getReconDim(){return reconDim;}; |
---|
| 147 | void setReconDim(int i){reconDim=i;}; |
---|
[3] | 148 | int getMinScale(){return scaleMin;}; |
---|
| 149 | void setMinScale(int s){scaleMin=s;}; |
---|
| 150 | float getAtrousCut(){return snrRecon;}; |
---|
| 151 | void setAtrousCut(float c){snrRecon=c;}; |
---|
| 152 | int getFilterCode(){return filterCode;}; |
---|
| 153 | void setFilterCode(int c){filterCode=c;}; |
---|
| 154 | string getFilterName(){return filterName;}; |
---|
| 155 | void setFilterName(string s){filterName=s;}; |
---|
| 156 | // |
---|
| 157 | bool getFlagAdjacent(){return flagAdjacent;}; |
---|
| 158 | void setFlagAdjacent(bool flag){flagAdjacent=flag;}; |
---|
| 159 | float getThreshS(){return threshSpatial;}; |
---|
| 160 | void setThreshS(float t){threshSpatial=t;}; |
---|
| 161 | float getThreshV(){return threshVelocity;}; |
---|
| 162 | void setThreshV(float t){threshVelocity=t;}; |
---|
| 163 | int getMinChannels(){return minChannels;}; |
---|
| 164 | void setMinChannels(int n){minChannels=n;}; |
---|
| 165 | // |
---|
[45] | 166 | string getSpectralMethod(){return spectralMethod;}; |
---|
| 167 | void setSpectralMethod(string s){spectralMethod=s;}; |
---|
[103] | 168 | string getSpectralUnits(){return spectralUnits;}; |
---|
| 169 | void setSpectralUnits(string s){spectralUnits=s;}; |
---|
[3] | 170 | bool drawBorders(){return borders;}; |
---|
| 171 | void setDrawBorders(bool f){borders=f;}; |
---|
[142] | 172 | bool drawBlankEdge(){return blankEdge;}; |
---|
| 173 | void setDrawBlankEdge(bool f){blankEdge=f;}; |
---|
[3] | 174 | bool isVerbose(){return verbose;}; |
---|
| 175 | void setVerbosity(bool f){verbose=f;}; |
---|
| 176 | |
---|
| 177 | private: |
---|
| 178 | // Input files |
---|
| 179 | string imageFile; // The image to be analysed. |
---|
| 180 | bool flagSubsection; // Whether we just want a subsection of the image |
---|
[142] | 181 | string subsection; // The subsection requested, taking the form |
---|
| 182 | // [x1:x2,y1:y2,z1:z2] |
---|
| 183 | // If you want the full range of one index, use * |
---|
[71] | 184 | bool flagReconExists; // The reconstructed array is in a FITS file on disk. |
---|
| 185 | string reconFile; // The FITS file containing the reconstructed array. |
---|
| 186 | |
---|
[3] | 187 | // Output files |
---|
| 188 | bool flagLog; // Should we do the intermediate logging? |
---|
| 189 | string logFile; // Where the intermediate logging goes. |
---|
| 190 | string outFile; // Where the final results get put. |
---|
| 191 | string spectraFile; // Where the spectra are displayed |
---|
| 192 | bool flagOutputRecon; // Should the reconstructed cube be written? |
---|
| 193 | bool flagOutputResid; // Should the reconstructed cube be written? |
---|
| 194 | bool flagVOT; // Should we save results in VOTable format? |
---|
| 195 | string votFile; // Where the VOTable goes. |
---|
[20] | 196 | bool flagKarma; // Should we save results in Karma annotation format? |
---|
| 197 | string karmaFile; // Where the Karma annotation file goes. |
---|
[142] | 198 | bool flagMaps; // Should we produce detection and moment maps |
---|
| 199 | // in postscript form? |
---|
[3] | 200 | string detectionMap; // The name of the detection map (ps file). |
---|
[17] | 201 | string momentMap; // The name of the 0th moment map (ps file). |
---|
[3] | 202 | |
---|
| 203 | // Cube related parameters |
---|
[120] | 204 | bool flagNegative; // Are we going to search for negative features? |
---|
| 205 | bool flagBlankPix; // A flag that indicates whether there are pixels |
---|
| 206 | // defined as BLANK and whether we need to remove |
---|
| 207 | // & ignore them in processing. |
---|
[3] | 208 | float blankPixValue; // Pixel value that is considered BLANK. |
---|
| 209 | int blankKeyword; // The FITS header keyword BLANK. |
---|
| 210 | float bscaleKeyword; // The FITS header keyword BSCALE. |
---|
| 211 | float bzeroKeyword; // The FITS header keyword BZERO. |
---|
[112] | 212 | bool flagUsingBlank; // If true, we are using the blankPixValue keyword, |
---|
[142] | 213 | // otherwise we use the value in the FITS header. |
---|
| 214 | bool flagMW; // A flag that indicates whether to ignore the |
---|
| 215 | // Milky Way channels. |
---|
[3] | 216 | int maxMW; // Last Galactic velocity plane for HIPASS cubes |
---|
| 217 | int minMW; // First Galactic velocity plane for HIPASS cubes |
---|
| 218 | float numPixBeam; // Size (area) of the beam in pixels. |
---|
[172] | 219 | bool flagUsingBeam; // If true, we are using the numPixBeam parameter, |
---|
| 220 | // otherwise we use the value in the FITS header. |
---|
[3] | 221 | // Trim-related |
---|
[142] | 222 | bool flagTrimmed; // Has the cube been trimmed of excess BLANKs |
---|
| 223 | // around the edge? |
---|
| 224 | long borderLeft; // The number of BLANK pixels trimmed from the |
---|
| 225 | // Left of the cube; |
---|
| 226 | long borderRight; // The number trimmed from the Right of the cube; |
---|
| 227 | long borderBottom; // The number trimmed from the Bottom of the cube; |
---|
| 228 | long borderTop; // The number trimmed from the Top of the cube; |
---|
[3] | 229 | // Subsection offsets |
---|
[164] | 230 | long *offsets; // The array of offsets for each FITS axis. |
---|
[3] | 231 | long xSubOffset; // The offset in the x-direction from the subsection |
---|
| 232 | long ySubOffset; // The offset in the y-direction from the subsection |
---|
| 233 | long zSubOffset; // The offset in the z-direction from the subsection |
---|
| 234 | // Baseline related; |
---|
[142] | 235 | bool flagBaseline; // Whether to do baseline subtraction before |
---|
| 236 | // reconstruction and/or searching. |
---|
[3] | 237 | // Detection-related |
---|
[142] | 238 | int minPix; // Minimum number of pixels for a detected object |
---|
| 239 | // to be counted |
---|
[3] | 240 | // Object growth |
---|
| 241 | bool flagGrowth; // Are we growing objects once they are found? |
---|
| 242 | float growthCut; // The SNR that we are growing objects down to. |
---|
| 243 | // FDR analysis |
---|
| 244 | bool flagFDR; // Should the FDR method be used? |
---|
| 245 | float alphaFDR; // Alpha value for FDR detection algorithm |
---|
| 246 | // Other detection |
---|
[142] | 247 | float snrCut; // How many sigma above mean is a detection |
---|
| 248 | // when sigma-clipping |
---|
[3] | 249 | // A trous reconstruction parameters |
---|
| 250 | bool flagATrous; // Are we using the a trous reconstruction? |
---|
[103] | 251 | int reconDim; // How many dimensions to use for the reconstruction? |
---|
[3] | 252 | int scaleMin; // Min scale used in a trous reconstruction |
---|
| 253 | float snrRecon; // SNR cutoff used in a trous reconstruction |
---|
[142] | 254 | // (only wavelet coefficients that survive this |
---|
| 255 | // threshold are kept) |
---|
| 256 | int filterCode; // The code number for the filter to be used |
---|
| 257 | // (saves having to parse names) |
---|
| 258 | string filterName; // The code number converted into a name, |
---|
| 259 | // for outputting purposes. |
---|
[3] | 260 | |
---|
| 261 | // Volume-merging parameters |
---|
| 262 | bool flagAdjacent; // Whether to use the adjacent criterion for |
---|
| 263 | // judging if objects are to be merged. |
---|
| 264 | float threshSpatial; // Maximum spatial separation between objects |
---|
| 265 | float threshVelocity; // Maximum channels separation between objects |
---|
| 266 | int minChannels; // Minimum no. of channels to make an object |
---|
| 267 | // Input-Output related |
---|
[142] | 268 | string spectralMethod; // A string indicating choice of spectral plotting |
---|
| 269 | // method: choices are "peak" (default) or "sum" |
---|
| 270 | string spectralUnits; // A string indicating what units the spectral |
---|
| 271 | // axis should be quoted in. |
---|
[3] | 272 | bool borders; // Whether to draw a border around the individual |
---|
[142] | 273 | // pixels of a detection in the spectral display |
---|
| 274 | bool blankEdge; // Whether to draw a border around the BLANK pixel |
---|
| 275 | // region in the moment maps and cutout images |
---|
| 276 | bool verbose; // Whether to use maximum verbosity -- use progress |
---|
| 277 | // indicators in the reconstruction & merging steps. |
---|
[3] | 278 | |
---|
| 279 | }; |
---|
| 280 | |
---|
[103] | 281 | class FitsHeader |
---|
| 282 | { |
---|
| 283 | /** |
---|
| 284 | * FitsHeader Class |
---|
| 285 | * |
---|
| 286 | * Stores information from a FITS header, including WCS information |
---|
| 287 | * in the form of a wcsprm struct, as well as various keywords. |
---|
| 288 | */ |
---|
[3] | 289 | |
---|
[103] | 290 | public: |
---|
| 291 | FitsHeader(); |
---|
| 292 | ~FitsHeader(){}; |
---|
| 293 | FitsHeader(const FitsHeader& h); |
---|
| 294 | FitsHeader& operator= (const FitsHeader& h); |
---|
| 295 | |
---|
| 296 | wcsprm *getWCS(); // in param.cc |
---|
| 297 | void setWCS(wcsprm *w); // in param.cc |
---|
| 298 | bool isWCS(){return wcsIsGood;}; |
---|
| 299 | int getNWCS(){return nwcs;}; |
---|
| 300 | void setNWCS(int i){nwcs=i;}; |
---|
[159] | 301 | int readHeaderInfo(string fname, Param &par); |
---|
| 302 | int defineWCS(string fname, Param &par); |
---|
| 303 | int getBUNIT(string fname); |
---|
| 304 | int getBLANKinfo(string fname, Param &par); |
---|
[172] | 305 | int getBeamInfo(string fname, Param &par); |
---|
[103] | 306 | string getSpectralUnits(){return spectralUnits;}; |
---|
| 307 | void setSpectralUnits(string s){spectralUnits=s;}; |
---|
[183] | 308 | string getSpectralDescription(){return spectralDescription;}; |
---|
| 309 | void setSpectralDescription(string s){spectralDescription=s;}; |
---|
[103] | 310 | string getFluxUnits(){return fluxUnits;}; |
---|
| 311 | void setFluxUnits(string s){fluxUnits=s;}; |
---|
| 312 | string getIntFluxUnits(){return intFluxUnits;}; |
---|
| 313 | void setIntFluxUnits(string s){intFluxUnits=s;}; |
---|
| 314 | float getBeamSize(){return beamSize;}; |
---|
| 315 | void setBeamSize(float f){beamSize=f;}; |
---|
| 316 | float getBmajKeyword(){return bmajKeyword;}; |
---|
| 317 | void setBmajKeyword(float f){bmajKeyword=f;}; |
---|
| 318 | float getBminKeyword(){return bminKeyword;}; |
---|
| 319 | void setBminKeyword(float f){bminKeyword=f;}; |
---|
[112] | 320 | int getBlankKeyword(){return blankKeyword;}; |
---|
| 321 | void setBlankKeyword(int f){blankKeyword=f;}; |
---|
[103] | 322 | float getBzeroKeyword(){return bzeroKeyword;}; |
---|
| 323 | void setBzeroKeyword(float f){bzeroKeyword=f;}; |
---|
| 324 | float getBscaleKeyword(){return bscaleKeyword;}; |
---|
| 325 | void setBscaleKeyword(float f){bscaleKeyword=f;}; |
---|
[145] | 326 | float getAvPixScale(){ |
---|
| 327 | return sqrt( fabs ( (wcs->pc[0]*wcs->cdelt[0])* |
---|
| 328 | (wcs->pc[wcs->naxis+1]*wcs->cdelt[1]))); |
---|
| 329 | }; |
---|
[103] | 330 | |
---|
| 331 | // front ends to WCS functions |
---|
| 332 | int wcsToPix(const double *world, double *pix); |
---|
| 333 | int pixToWCS(const double *pix, double *world); |
---|
| 334 | int wcsToPix(const double *world, double *pix, const int npts); |
---|
| 335 | int pixToWCS(const double *pix, double *world, const int npts); |
---|
| 336 | double pixToVel(double &x, double &y, double &z); |
---|
| 337 | double *pixToVel(double &x, double &y, double *zarray, int size); |
---|
| 338 | double specToVel(const double &z); |
---|
| 339 | double velToSpec(const float &vel); |
---|
| 340 | string getIAUName(double ra, double dec); |
---|
| 341 | |
---|
| 342 | void fixUnits(Param &par); |
---|
| 343 | |
---|
| 344 | private: |
---|
[183] | 345 | wcsprm *wcs; // The WCS parameters for the cube in a |
---|
| 346 | // struct from the wcslib library. |
---|
| 347 | int nwcs; // The number of WCS parameters |
---|
| 348 | bool wcsIsGood; // A flag indicating whether there is a |
---|
| 349 | // valid WCS present. |
---|
| 350 | string spectralUnits; // The units of the spectral dimension |
---|
| 351 | string spectralDescription; // The description of the spectral dimension |
---|
| 352 | // (Frequency, Velocity, ...) |
---|
| 353 | string fluxUnits; // The units of pixel flux (from header) |
---|
| 354 | string intFluxUnits; // The units of pixel flux (from header) |
---|
| 355 | float beamSize; // The calculated beam size in pixels. |
---|
| 356 | float bmajKeyword; // The FITS header keyword BMAJ. |
---|
| 357 | float bminKeyword; // The FITS header keyword BMIN. |
---|
| 358 | int blankKeyword; // The FITS header keyword BLANK. |
---|
| 359 | float bzeroKeyword; // The FITS header keyword BZERO. |
---|
| 360 | float bscaleKeyword; // The FITS header keyword BSCALE. |
---|
| 361 | double scale; // scale param for converting spectral coords |
---|
| 362 | double offset; // offset param for converting spectral coords |
---|
| 363 | double power; // power param for converting spectral coords |
---|
[103] | 364 | }; |
---|
| 365 | |
---|
| 366 | string makelower( string s ); |
---|
| 367 | |
---|
[3] | 368 | #endif |
---|