1 | #ifndef PARAM_H |
---|
2 | #define PARAM_H |
---|
3 | |
---|
4 | #include <iostream> |
---|
5 | #include <string> |
---|
6 | #include <vector> |
---|
7 | #include <math.h> |
---|
8 | #include <wcs.h> |
---|
9 | |
---|
10 | using std::string; |
---|
11 | using std::vector; |
---|
12 | |
---|
13 | /** |
---|
14 | * Param class. |
---|
15 | * Used for storing parameters used by all functions. |
---|
16 | */ |
---|
17 | |
---|
18 | class FitsHeader; // foreshadow this so that Param knows it exists |
---|
19 | |
---|
20 | class Param |
---|
21 | { |
---|
22 | public: |
---|
23 | Param(); |
---|
24 | virtual ~Param(){}; |
---|
25 | Param& operator= (const Param& p); |
---|
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){ |
---|
32 | return ( this->flagMW && (z>=this->minMW) && (z<=this->maxMW) ); |
---|
33 | }; |
---|
34 | string outputReconFile(); // in param.cc |
---|
35 | string outputResidFile(); // in param.cc |
---|
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;}; |
---|
42 | string getFullImageFile(){ |
---|
43 | if(flagSubsection) return imageFile+subsection; |
---|
44 | else return imageFile; |
---|
45 | }; |
---|
46 | bool getFlagSubsection(){return flagSubsection;}; |
---|
47 | void setFlagSubsection(bool flag){flagSubsection=flag;}; |
---|
48 | string getSubsection(){return subsection;}; |
---|
49 | void setSubsection(string range){subsection = range;}; |
---|
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 | // |
---|
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;}; |
---|
71 | bool getFlagKarma(){return flagKarma;}; |
---|
72 | void setFlagKarma(bool flag){flagKarma=flag;}; |
---|
73 | string getKarmaFile(){return karmaFile;}; |
---|
74 | void setKarmaFile(string fname){karmaFile = fname;}; |
---|
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 | // |
---|
82 | bool getFlagNegative(){return flagNegative;}; |
---|
83 | void setFlagNegative(bool flag){flagNegative=flag;}; |
---|
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;}; |
---|
94 | bool getFlagUsingBlank(){return flagUsingBlank;}; |
---|
95 | void setFlagUsingBlank(bool b){flagUsingBlank=b;}; |
---|
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;}; |
---|
104 | bool getFlagUsingBeam(){return flagUsingBeam;}; |
---|
105 | void setFlagUsingBeam(bool b){flagUsingBeam=b;}; |
---|
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;}; |
---|
146 | int getReconDim(){return reconDim;}; |
---|
147 | void setReconDim(int i){reconDim=i;}; |
---|
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 | // |
---|
166 | string getSpectralMethod(){return spectralMethod;}; |
---|
167 | void setSpectralMethod(string s){spectralMethod=s;}; |
---|
168 | string getSpectralUnits(){return spectralUnits;}; |
---|
169 | void setSpectralUnits(string s){spectralUnits=s;}; |
---|
170 | bool drawBorders(){return borders;}; |
---|
171 | void setDrawBorders(bool f){borders=f;}; |
---|
172 | bool drawBlankEdge(){return blankEdge;}; |
---|
173 | void setDrawBlankEdge(bool f){blankEdge=f;}; |
---|
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 |
---|
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 * |
---|
184 | bool flagReconExists; // The reconstructed array is in a FITS file on disk. |
---|
185 | string reconFile; // The FITS file containing the reconstructed array. |
---|
186 | |
---|
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. |
---|
196 | bool flagKarma; // Should we save results in Karma annotation format? |
---|
197 | string karmaFile; // Where the Karma annotation file goes. |
---|
198 | bool flagMaps; // Should we produce detection and moment maps |
---|
199 | // in postscript form? |
---|
200 | string detectionMap; // The name of the detection map (ps file). |
---|
201 | string momentMap; // The name of the 0th moment map (ps file). |
---|
202 | |
---|
203 | // Cube related parameters |
---|
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. |
---|
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. |
---|
212 | bool flagUsingBlank; // If true, we are using the blankPixValue keyword, |
---|
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. |
---|
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. |
---|
219 | bool flagUsingBeam; // If true, we are using the numPixBeam parameter, |
---|
220 | // otherwise we use the value in the FITS header. |
---|
221 | // Trim-related |
---|
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; |
---|
229 | // Subsection offsets |
---|
230 | long *offsets; // The array of offsets for each FITS axis. |
---|
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; |
---|
235 | bool flagBaseline; // Whether to do baseline subtraction before |
---|
236 | // reconstruction and/or searching. |
---|
237 | // Detection-related |
---|
238 | int minPix; // Minimum number of pixels for a detected object |
---|
239 | // to be counted |
---|
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 |
---|
247 | float snrCut; // How many sigma above mean is a detection |
---|
248 | // when sigma-clipping |
---|
249 | // A trous reconstruction parameters |
---|
250 | bool flagATrous; // Are we using the a trous reconstruction? |
---|
251 | int reconDim; // How many dimensions to use for the reconstruction? |
---|
252 | int scaleMin; // Min scale used in a trous reconstruction |
---|
253 | float snrRecon; // SNR cutoff used in a trous reconstruction |
---|
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. |
---|
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 |
---|
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. |
---|
272 | bool borders; // Whether to draw a border around the individual |
---|
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. |
---|
278 | |
---|
279 | }; |
---|
280 | |
---|
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 | */ |
---|
289 | |
---|
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;}; |
---|
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); |
---|
305 | int getBeamInfo(string fname, Param &par); |
---|
306 | string getSpectralUnits(){return spectralUnits;}; |
---|
307 | void setSpectralUnits(string s){spectralUnits=s;}; |
---|
308 | string getSpectralDescription(){return spectralDescription;}; |
---|
309 | void setSpectralDescription(string s){spectralDescription=s;}; |
---|
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;}; |
---|
320 | int getBlankKeyword(){return blankKeyword;}; |
---|
321 | void setBlankKeyword(int f){blankKeyword=f;}; |
---|
322 | float getBzeroKeyword(){return bzeroKeyword;}; |
---|
323 | void setBzeroKeyword(float f){bzeroKeyword=f;}; |
---|
324 | float getBscaleKeyword(){return bscaleKeyword;}; |
---|
325 | void setBscaleKeyword(float f){bscaleKeyword=f;}; |
---|
326 | float getAvPixScale(){ |
---|
327 | return sqrt( fabs ( (wcs->pc[0]*wcs->cdelt[0])* |
---|
328 | (wcs->pc[wcs->naxis+1]*wcs->cdelt[1]))); |
---|
329 | }; |
---|
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: |
---|
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 |
---|
364 | }; |
---|
365 | |
---|
366 | string makelower( string s ); |
---|
367 | |
---|
368 | #endif |
---|