source: trunk/src/duchamp.hh @ 913

Last change on this file since 913 was 913, checked in by MatthewWhiting, 12 years ago

A large swathe of changes aimed at improving warning/error/exception handling. Now make use of macros and streams. Also, there is now a distinction between DUCHAMPERROR and DUCHAMPTHROW.

File size: 11.4 KB
Line 
1// -----------------------------------------------------------------------
2// duchamp.hh: Definitions for use with Duchamp
3// -----------------------------------------------------------------------
4// Copyright (C) 2006, Matthew Whiting, ATNF
5//
6// This program is free software; you can redistribute it and/or modify it
7// under the terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 2 of the License, or (at your
9// option) any later version.
10//
11// Duchamp is distributed in the hope that it will be useful, but WITHOUT
12// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14// for more details.
15//
16// You should have received a copy of the GNU General Public License
17// along with Duchamp; if not, write to the Free Software Foundation,
18// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
19//
20// Correspondence concerning Duchamp may be directed to:
21//    Internet email: Matthew.Whiting [at] atnf.csiro.au
22//    Postal address: Dr. Matthew Whiting
23//                    Australia Telescope National Facility, CSIRO
24//                    PO Box 76
25//                    Epping NSW 1710
26//                    AUSTRALIA
27// -----------------------------------------------------------------------
28#ifndef DUCHAMP_HH
29#define DUCHAMP_HH
30
31#include <iostream>
32#include <stdexcept>
33#include <string>
34#include <sstream>
35
36// need to undef these in case other packages have them defined.
37#undef PACKAGE_BUGREPORT
38#undef PACKAGE_NAME
39#undef PACKAGE_STRING
40#undef PACKAGE_TARNAME
41#undef PACKAGE_VERSION
42#undef HAVE_PGPLOT
43#include <duchamp/config.h>
44
45#ifdef HAVE_PGPLOT
46#include <duchamp/Utils/mycpgplot.hh>
47#endif
48
49/// The primary namespace for all functionality directly related to Duchamp
50namespace duchamp
51{
52
53  /// @brief How to convey whether a function has worked
54  enum OUTCOME {SUCCESS=0, FAILURE};
55
56  /// Usage message for command line help.
57  const std::string ERR_USAGE_MSG =
58    "Usage: Duchamp [OPTION] [FILE]\n\
59Duchamp is an object finder for spectral-line FITS cubes.\n\
60\n\
61  -p FILE      Read in parameters from FILE, including FITS image location.\n\
62  -f FILE      Use default parameters with imageFile=FILE\n\
63  -x           Do not use X-windows PGPLOT output\n\
64               (equivalent to setting flagXOutput=false -- overrides the parameter file)\n\n\
65  -v           Return version number and exit\n\
66  -h           Display this help information and exit\n";
67
68  /// Usage message for command line help for Selavy.
69  const std::string SELAVY_ERR_USAGE_MSG =
70    "Usage: Selavy [OPTION] [FILE]\n\
71Selavy re-analyses and re-plots objects found by Duchamp.\n\
72\n\
73  -p FILE      Read in parameters from FILE, including FITS image location.\n\
74  -f FILE      Use default parameters with imageFile=FILE\n\
75  -x           Do not use X-windows PGPLOT output\n\
76               (equivalent to setting flagXOutput=false -- overrides the parameter file)\n\n\
77  -v           Return version number and exit\n\
78  -h           Display this help information and exit\n";
79
80  /// Shorter Usage message for command line help.
81  const std::string ERR_USAGE_MSG_SHORT="Usage: Duchamp -p [parameter file]\n";
82
83  /// The program name. (Duchamp)
84  const std::string PROGNAME = PACKAGE_NAME;
85
86  /// The program version
87  const std::string VERSION = PACKAGE_VERSION;
88
89  // Specialised functions to report warnings and errors -- in duchamp.cc
90  /// Print a warning message to the stderr
91  void duchampWarning(std::string subroutine, std::string warning);
92  /// Print an error message to the stderr and sound the bell
93  void duchampError(std::string subroutine, std::string error);
94
95  /// Define the duchamp exception class.
96  class DuchampError: public std::runtime_error
97  {
98  public:
99    /// Constructor taking a message
100    explicit DuchampError(const std::string& message);
101    /// empty destructor
102    virtual ~DuchampError() throw();
103  };
104
105  // Macro to handle warnings, specifying the origin of the warning and taking a streamed input
106#define DUCHAMPWARN(origin,stream) \
107  {                                \
108  do {                               \
109   std::ostringstream oss;        \
110    oss << stream;                 \
111    std::cerr << "WARNING <" << origin << "> : " << oss.str()<<"\n"; \
112 } while(0);                        \
113  }     
114 
115  // Macro to handle errors, with origin and streamed input. No exception is thrown (use DUCHAMPTHROW instead)
116#define DUCHAMPERROR(origin,stream) \
117{                                   \
118 do {                               \
119  std::ostringstream oss;           \
120  oss << stream;                    \
121  std::cerr << "ERROR <" << origin << "> : " << oss.str() << "\n"; \
122 } while(0);                        \
123}
124
125#define DUCHAMPTHROW(origin,stream) \
126{                                   \
127  DUCHAMPERROR(origin,"\a"<<stream);\
128  std::ostringstream error;         \
129  error << stream;                  \
130  throw DuchampError(error.str());  \
131}
132
133  /// The spectral type that we want the wcsprm structs to be in.
134    const char duchampVelocityType[9] = "VOPT-F2W";
135  //const char duchampVelocityType[9] = "VELO-F2V";
136  /// The spectral type that we want the wcsprm structs to be in when no velocity info is present.
137  const char duchampFrequencyType[9] = "FREQ    ";
138
139  /// Descriptions of the various spectral axis types
140  enum TYPEDESC {FREQUENCY=0,VELOCITY,WAVELENGTH};
141  /// Human-readable descriptions of the various spectral axis types
142  const std::string duchampSpectralDescription[3]=
143    {"Frequency", "Velocity", "Wavelength"};
144
145  // The following are the FITS Header Keywords corresponding to the
146  // parameters related to the atrous reconstruction.
147
148  /// FITS header keyword for min atrous scale
149  const std::string keyword_scaleMin     = "DU_MINSC";
150  /// FITS header keyword for S/N used in atrous reconstruction
151  const std::string keyword_snrRecon     = "DU_ATCUT";
152  /// FITS header keyword for number of dimensions used in atrous reconstruction
153  const std::string keyword_reconDim     = "DU_ATDIM";
154  /// FITS header keyword for the code number of the filter used in atrous reconstruction
155  const std::string keyword_filterCode   = "DU_FILTR";
156  /// FITS header keyword: does this file hold the reconstructed array or the residual?
157  const std::string keyword_ReconResid   = "DU_RECON";
158  /// FITS header keyword: type of smoothing done.
159  const std::string keyword_smoothtype   = "DU_SMTYP";
160  /// FITS header keyword for the gaussian kernel major axis FWHM
161  const std::string keyword_kernmaj      = "DU_KMAJ";
162  /// FITS header keyword for the gaussian kernel minor axis FWHM
163  const std::string keyword_kernmin      = "DU_KMIN";
164  /// FITS header keyword for the gaussian kernel position angle
165  const std::string keyword_kernpa       = "DU_KPA";
166  /// FITS header keyword for the Hanning filter width
167  const std::string keyword_hanningwidth = "DU_WHANN";
168  /// FITS header keyword for the image subsection used
169  const std::string keyword_subsection   = "DU_IMSUB";
170
171  // And these are the comments corresponding to the relevant keywords
172  /// FITS header comment for DU_MINSC keyword
173  const std::string comment_scaleMin     = "Duchamp parameter scaleMin";
174  /// FITS header comment for DU_ATCUT keyword
175  const std::string comment_snrRecon     = "Duchamp parameter snrRecon";
176  /// FITS header comment for DU_ATDIM keyword
177  const std::string comment_reconDim     = "Duchamp parameter reconDim";
178  /// FITS header comment for DU_FILTR keyword
179  const std::string comment_filterCode   = "Duchamp parameter filterCode";
180  /// FITS header comment for DU_RECON keyword
181  const std::string comment_ReconResid   = "Is this the reconstruction or residual?";
182  /// FITS header comment for DU_SMTYP keyword
183  const std::string comment_smoothtype   = "Type of smoothing done";
184  /// FITS header comment for DU_KMAJ  keyword
185  const std::string comment_kernmaj      = "Duchamp parameter kernMaj";
186  /// FITS header comment for DU_KMIN  keyword
187  const std::string comment_kernmin      = "Duchamp parameter kernMin";
188  /// FITS header comment for DU_KPA   keyword
189  const std::string comment_kernpa       = "Duchamp parameter kernPA";
190  /// FITS header comment for DU_WHANN keyword
191  const std::string comment_hanningwidth = "Duchamp parameter hanningWidth";
192  /// FITS header comment for DU_IMSUB keyword
193  const std::string comment_subsection   = "Subsection of the original image";
194
195  // Descriptive Headers: for the reconstruction case
196  const std::string header_reconHistory1 =
197    "Reconstructed with a trous wavelet technique";
198  const std::string header_reconHistory2 =
199    "Reconstruction by " + PROGNAME + " v." + VERSION;
200  const std::string header_reconHistory_input =
201    "Original (input) image used by " + PROGNAME + " follows";
202  const std::string header_reconSubsection_comment  =
203    "A subsection of the original was reconstructed by " + PROGNAME;
204  const std::string header_atrous_comment  =
205    "The following are the Duchamp parameters used in reconstruction";
206
207  // Descriptive Headers: for the Smoothing case
208  const std::string header_smoothHistory =
209    "Smoothed by " + PROGNAME + " v." + VERSION;
210  const std::string header_smoothHistory_input =
211    "Original (input) image used by " + PROGNAME + " follows";
212  const std::string header_smoothSubsection_comment  =
213    "A subsection of the original was smoothed by " + PROGNAME;
214  const std::string header_smoothSpatial = "Spatial, gaussian kernel";
215  const std::string header_smoothSpectral= "Spectral, hanning filter";
216
217  // Descriptive Headers: for the output Mask image
218  const std::string header_maskHistory =
219    "Results of searching by " + PROGNAME + " v." + VERSION;
220  const std::string header_maskHistory_input =
221    "Input image used by " + PROGNAME + " follows";
222  const std::string header_maskSubsection_comment =
223    "A subsection of the original was searched by " + PROGNAME;
224
225  // Descriptive Headers: for the output Moment-0 image
226  const std::string header_moment0History =
227    "Moment-0 map from searching by " + PROGNAME + " v." + VERSION;
228  const std::string header_moment0History_input =
229    "Input image used by " + PROGNAME + " follows";
230  const std::string header_moment0Subsection_comment =
231    "A subsection of the original was searched by " + PROGNAME;
232
233}
234
235#ifdef HAVE_PGPLOT
236namespace duchamp
237{
238
239  // Colours used in graphical output
240  /// The colour for the Blank edges
241  const int DUCHAMP_BLANK_EDGE_COLOUR = mycpgplot::MAGENTA;
242  /// The colour for the edge of the cube
243  const int DUCHAMP_CUBE_EDGE_COLOUR = mycpgplot::YELLOW;
244  /// The colour for the reconstructed spectra
245  const int DUCHAMP_RECON_SPECTRA_COLOUR = mycpgplot::RED;
246  /// The colour for the baseline spectra
247  const int DUCHAMP_BASELINE_SPECTRA_COLOUR = mycpgplot::YELLOW;
248  /// The colour for the object outline
249  const int DUCHAMP_OBJECT_OUTLINE_COLOUR = mycpgplot::BLUE;
250  /// The colour for the Milky-way region spectral boundaries
251  const int DUCHAMP_MILKY_WAY_COLOUR = mycpgplot::DARKGREEN;
252  /// The colour for the tick marks in the image cutouts
253  const int DUCHAMP_TICKMARK_COLOUR = mycpgplot::RED;
254  /// The colour for the text identifying objects on the maps
255  const int DUCHAMP_ID_TEXT_COLOUR = mycpgplot::RED;
256  /// The colour for the WCS axes on the maps
257  const int DUCHAMP_WCS_AXIS_COLOUR = mycpgplot::WCSGREEN;
258
259}
260
261#else
262namespace duchamp
263{
264  /// The colour for the text identifying objects on the maps
265  const int DUCHAMP_ID_TEXT_COLOUR = 2;
266  /// The colour for the WCS axes on the maps
267  const int DUCHAMP_WCS_AXIS_COLOUR = 3;
268
269}
270
271#endif
272
273
274#endif
Note: See TracBrowser for help on using the repository browser.