source: trunk/src/Cubes/plots.hh @ 1095

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

Better way of marking the detected pixels in the one-dim spectrum - read them straight out of the detection map

File size: 17.4 KB
RevLine 
[299]1// -----------------------------------------------------------------------
2// plots.hh: Definition of the SpectralPlot and ImagePlot classes, for
3//           plotting spectra and maps of detected objects.
4// -----------------------------------------------------------------------
5// Copyright (C) 2006, Matthew Whiting, ATNF
6//
7// This program is free software; you can redistribute it and/or modify it
8// under the terms of the GNU General Public License as published by the
9// Free Software Foundation; either version 2 of the License, or (at your
10// option) any later version.
11//
12// Duchamp is distributed in the hope that it will be useful, but WITHOUT
13// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15// for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with Duchamp; if not, write to the Free Software Foundation,
19// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
20//
21// Correspondence concerning Duchamp may be directed to:
22//    Internet email: Matthew.Whiting [at] atnf.csiro.au
23//    Postal address: Dr. Matthew Whiting
24//                    Australia Telescope National Facility, CSIRO
25//                    PO Box 76
26//                    Epping NSW 1710
27//                    AUSTRALIA
28// -----------------------------------------------------------------------
[103]29#ifndef PLOTS_H
30#define PLOTS_H
31
[11]32#include <iostream>
33#include <sstream>
34#include <string>
35#include <math.h>
[581]36#include <duchamp/duchamp.hh>
[987]37#include <duchamp/param.hh>
38#include <duchamp/fitsHeader.hh>
[393]39#include <duchamp/pgheader.hh>
[987]40#include <duchamp/Utils/Statistics.hh>
[11]41
[378]42namespace duchamp
[11]43{
44
[581]45  /// @brief A function to handle plotting of WCS axes, with duchamp-suitable defaults.
[884]46  void plotWCSaxes(struct wcsprm *wcs, size_t *axes, int textColour=DUCHAMP_ID_TEXT_COLOUR, int axisColour=DUCHAMP_WCS_AXIS_COLOUR);
[581]47
[528]48  /// @brief A namespace to control plotting of the spectral output and the
49  /// spatial image output.
[11]50
[378]51  namespace Plot
52  {
[485]53    const float inchToCm=2.54;        ///< Conversion factor from inches to centimetres.
[378]54    const float a4width=21.0;         ///< A4 width in cm
55    const float a4height=29.7;        ///< A4 height in cm
[485]56    const float psHoffset=0.35;       ///< The default horizontal pgplot offset applied to ps files
57    const float psVoffset=0.25;       ///< The default vertical pgplot offset applied to ps files
[284]58
[378]59    // These are the constants used for spacing out elements in SpectralPlot.
60    const float spMainX1 =  2.0;      ///< min X-value of main box [cm]
61    const float spMainX2 = 13.7;      ///< max X-value of main box [cm]
62    const float spZoomX1 = 15.0;      ///< min X-value of zoom box [cm]
63    const float spZoomX2 = 16.8;      ///< max X-value of zoom box [cm]
64    const float spMapX1  = 17.0;      ///< min X-value of map box [cm]
[485]65    const float spMainY1 =  1.5;      ///< min Y-value of box wrt base of current spectrum [cm]
66    const float spMainY2 =  3.4;      ///< max Y-value of box wrt base of current spectrum [cm]
[378]67    const float spXlabelOffset = 3.0; ///< Offset for X-axis label.
68    const float spYlabelOffset = 4.0; ///< Offset for Y-axis label.
69    const float spTitleOffset1 = 5.1; ///< Offset for first title line.
70    const float spTitleOffset2 = 3.6; ///< Offset for second title line.
71    const float spTitleOffset3 = 2.1; ///< Offset for third title line.
72    const float spTitleOffset4 = 0.6; ///< Offset for fourth title line.
[220]73
[485]74    const float spIndexSize = 0.6;    ///< PGPlot character height for tick mark labels
75    const float spLabelSize = 0.7;    ///< PGPlot character height for axis labels
76    const float spTitleSize = 0.8;    ///< PGPlot character height for plot title line
[367]77
[378]78    // These are the constants used for spacing out elements in ImagePlot.
79    const float imTitleOffset = 2.7;  ///< Offset for title of map.
[11]80
[378]81    // These are the constants used for spacing out elements in CutoutPlot.
82    const float cuMainX1 = 1.0;
83    const float cuMainX2 = 15.8;
84    const float cuMainY1 = 1.0;
85    const float cuMainY2 = 3.8;
86    const float cuMapX1 = 16.0;
[11]87
[378]88    //***************************************************************************
89    //***************************************************************************
[274]90
[528]91    ///  @brief A class for plotting spectra of detections.
92    ///  @details This class is designed to hold the dimensions and
93    ///  set up for the plotting of the spectra (including the full
94    ///  spectra, the zoomed in part, and the moment map).  The
95    ///  physical dimensions (in inches) of the plot and the elements
96    ///  within it are stored, on the assumption that the plot will go
97    ///  on an A4 page.  Simple accessor functions are provided to
98    ///  enable access to quantities needed for pgplot routines.
99
[378]100    class SpectralPlot
101    {
102    public:
103      SpectralPlot();    ///< Constructor
104      virtual ~SpectralPlot(); ///< Destructor
105      SpectralPlot(const SpectralPlot& p);
106      SpectralPlot& operator=(const SpectralPlot& p);
[274]107
[528]108      /// @brief Set up PGPLOT output.
[378]109      int setUpPlot(std::string pgDestination);
110
[985]111      /// @brief Close the PGPLOT device
112      void close();
113
[528]114      /// @brief Calculate boundaries for boxes.
[378]115      void calcCoords();
[528]116      /// @brief Set up the header & write the X-label.
[378]117      void gotoHeader(std::string xlabel);
118
[528]119      /// @brief Write first line of header information (position/velocity info) in correct place.
[378]120      void firstHeaderLine(std::string line);   
[274]121   
[528]122      /// @brief Write second line of header information (fluxes) in correct place.
[378]123      void secondHeaderLine(std::string line); 
[274]124
[528]125      /// @brief Write third line of header information (WCS widths) in correct place.
[378]126      void thirdHeaderLine(std::string line);   
[274]127
[528]128      /// @brief Write fourth line of header information (pixel coordinates) in correct place.
[378]129      void fourthHeaderLine(std::string line);   
[282]130
[528]131      /// @brief Set up main spectral plotting region.
[378]132      void gotoMainSpectrum(float x1, float x2, float y1, float y2,
133                            std::string ylabel);
[274]134   
[528]135      /// @brief Set up zoomed-in spectral plotting region.
[378]136      void gotoZoomSpectrum(float x1, float x2, float y1, float y2);   
[11]137   
[528]138      /// @brief Defines the region for the moment map.
[378]139      void gotoMap();
[274]140
[528]141      /// @brief Draw lines indicating velocity range.
[378]142      void drawVelRange(float v1, float v2);
[274]143
[528]144      /// @brief Draw box showing excluded range due to Milky Way.
[378]145      void drawMWRange(float v1, float v2);
[274]146   
[987]147      /// @brief Draw thresholds
148      void drawThresholds(Param &par, Statistics::StatsContainer<float> &stats);
149
[528]150      /// @brief Return number of spectra that go on a page.
[378]151      int   getNumOnPage();
[274]152
[528]153      /// @brief Set number of spectra that go on a page.
[378]154      void  setNumOnPage(int i);
155      float getPaperWidth();         ///< Return width of plottable region.
156      void  setPaperWidth(float f);  ///< Set width of plottable region.
157      float getPaperHeight();        ///< Return height of plottable region.
158      void  setPaperHeight(float f); ///< Set height of plottable region.
[985]159      float getAspectRatio();        ///< Return aspect ratio
160      void  setAspectRatio(float f); ///< Set aspect ratio
[528]161      void  goToPlot();              ///< Goes to the plot when more than one are open.
[11]162
[378]163    private:
164      int numOnPage;       ///< Number of spectra to put on one page.
165      int spectraCount;    ///< Number of spectra done so far: where on the page?
166      float mainCoords[4]; ///< Boundaries for the main spectrum [inches]
167      float zoomCoords[4]; ///< Boundaries for the zoomed-in spectrum [inches]
168      float mapCoords[4];  ///< Boundaries for the map box [inches]
169      float paperWidth;    ///< Width of plottable region of the paper [inches]
170      float paperHeight;   ///< Height of plottable region of the paper [inches]
[985]171      float aspectRatio;   ///< Aspect ratio height/width (as used by PGPlot calls)
[378]172      int   identifier;    ///< The identifier code used by cpgslct.
[11]173   
[378]174    };
[11]175
[378]176    inline int   SpectralPlot::getNumOnPage(){return numOnPage;}
177    inline void  SpectralPlot::setNumOnPage(int i){numOnPage=i;}
178    inline float SpectralPlot::getPaperWidth(){return paperWidth;}
179    inline void  SpectralPlot::setPaperWidth(float f){paperWidth=f;}
180    inline float SpectralPlot::getPaperHeight(){return paperHeight;}
181    inline void  SpectralPlot::setPaperHeight(float f){paperHeight=f;}
[985]182    inline float SpectralPlot::getAspectRatio(){return aspectRatio;}
183    inline void  SpectralPlot::setAspectRatio(float f){aspectRatio=f;}
[220]184
[378]185    //***************************************************************************
186    //***************************************************************************
[11]187
[985]188    ///  @brief A class for plotting a single spectrum.
189    ///  @details This class is designed to hold the dimensions and
190    ///  set up for the plotting of the spectra (including the full
191    ///  spectra, the zoomed in part, and the moment map).  The
192    ///  physical dimensions (in inches) of the plot and the elements
193    ///  within it are stored, on the assumption that the plot will go
194    ///  on an A4 page.  Simple accessor functions are provided to
195    ///  enable access to quantities needed for pgplot routines.
196
197    class SimpleSpectralPlot
198    {
199    public:
200      SimpleSpectralPlot();    ///< Constructor
201      virtual ~SimpleSpectralPlot(); ///< Destructor
202      SimpleSpectralPlot(const SimpleSpectralPlot& p);
203      SimpleSpectralPlot& operator=(const SimpleSpectralPlot& p);
204
205      /// @brief Set up PGPLOT output.
206      int setUpPlot(std::string pgDestination);
207
208      /// @brief Close the PGPLOT device
209      void close();
210
211      /// @brief Write the labels
212      void label(std::string xlabel, std::string ylabel, std::string title);
213
214      /// @brief Set up main spectral plotting region.
215      void gotoMainSpectrum(float x1, float x2, float y1, float y2);
216
[1013]217      /// @brief Draw a line indicating the pixels that have been detected
218      void markDetectedPixels(short *detectMap, size_t size, FitsHeader &head);
[986]219
[985]220      /// @brief Draw lines indicating velocity range.
221      void drawVelRange(float v1, float v2);
222
223      /// @brief Draw box showing excluded range due to Milky Way.
224      void drawMWRange(float v1, float v2);
225   
226      float getPaperWidth();         ///< Return width of plottable region.
227      void  setPaperWidth(float f);  ///< Set width of plottable region.
228      float getPaperHeight();        ///< Return height of plottable region.
229      void  setPaperHeight(float f); ///< Set height of plottable region.
230      float getAspectRatio();        ///< Return aspect ratio
231      void  setAspectRatio(float f); ///< Set aspect ratio
232      void  goToPlot();              ///< Goes to the plot when more than one are open.
233
234    private:
235      float mainCoords[4]; ///< Boundaries for the main spectrum [inches]
236      float paperWidth;    ///< Width of plottable region of the paper [inches]
237      float paperHeight;   ///< Height of plottable region of the paper [inches]
238      float aspectRatio;   ///< Aspect ratio height/width (as used by PGPlot calls)
239      int   identifier;    ///< The identifier code used by cpgslct.
240 
241    };
242 
243    inline float SimpleSpectralPlot::getPaperWidth(){return paperWidth;}
244    inline void  SimpleSpectralPlot::setPaperWidth(float f){paperWidth=f;}
245    inline float SimpleSpectralPlot::getPaperHeight(){return paperHeight;}
246    inline void  SimpleSpectralPlot::setPaperHeight(float f){paperHeight=f;}
247    inline float SimpleSpectralPlot::getAspectRatio(){return aspectRatio;}
248    inline void  SimpleSpectralPlot::setAspectRatio(float f){aspectRatio=f;}
249
250
251    //***************************************************************************
252    //***************************************************************************
253
[528]254    ///  @brief A class for plotting 2-dimensional maps.
255    ///  @details A class to hold the dimensions and set up for the
256    ///  plotting of maps in Duchamp.
257    ///    The physical dimensions (in inches) of the plot and the elements
258    ///     within it are stored, including maximum widths and heights
259    ///     (so that the plot will fit on an A4 page).
260    ///    Simple accessor functions are provided to enable access to quantities
261    ///     needed for pgplot routines.
262
[378]263    class ImagePlot
264    {
265    public:
266      ImagePlot();  ///< Constructor
267      virtual ~ImagePlot(); ///< Destructor
268      ImagePlot(const ImagePlot& p);
269      ImagePlot& operator=(const ImagePlot& p);
[11]270 
[528]271      /// @brief Set up PGPLOT output.
[378]272      int   setUpPlot(std::string pgDestination, float x, float y);
[274]273
[985]274      /// @brief Close the PGPLOT device
275      void close();
276
[528]277      /// @brief Defines and draws box.
[378]278      void  drawMapBox(float x1, float x2, float y1, float y2,
279                       std::string xlabel, std::string ylabel);
[103]280
[528]281      /// @brief Write plot title.
[378]282      void  makeTitle(std::string title);
[274]283
[485]284      float cmToCoord(float cm);///< Converts distance in cm to coordinate distance on the plot.
[378]285      float getMargin();        ///< Returns width of margin.
286      float getPaperWidth();    ///< Returns width of paper.
[485]287      float imageWidth();       ///< Returns the calculated total width of the image part of the plot [inches]
[378]288      float getImageHeight();   ///< Returns height of image [inches]
289      float getAspectRatio();   ///< Returns the aspect ratio of the image.
[485]290      void  goToPlot();         ///< Goes to the plot when more than one are open
[103]291
[378]292    private:
293      float paperWidth;     ///< Default (maximum) width of "paper" [inches]
294      float maxPaperHeight; ///< Maximum allowed height of paper [inches]
[485]295      float marginWidth;    ///< Width allowed for margins around main plot (ie. label & numbers) [inches]
296      float wedgeWidth;     ///< Width allowed for placement of wedge on right-hand side of plot. [inches]
297      float imageRatio;     ///< Aspect ratio of the image only (ie. y-value range / x-value range).
[378]298      float aspectRatio;    ///< Aspect ratio of whole plot.
299      float xdim;           ///< Width of main plot, in display units.
300      float ydim;           ///< Height of main plot, in display units.
301      int   identifier;     ///< The identifier code used by cpgslct.
302    };
303    //----------------------------------------------------------
304    // Inline ImagePlot functions...
305    //----------------------------------------------------------
[11]306
[378]307    inline float ImagePlot::getMargin()     {return marginWidth;}
308    inline float ImagePlot::getPaperWidth() {return paperWidth;}
309    inline float ImagePlot::getImageHeight(){return imageWidth()*imageRatio;}
310    inline float ImagePlot::getAspectRatio(){return aspectRatio;}
[220]311 
[378]312    //***************************************************************************
313    //***************************************************************************
[367]314
[528]315    ///  @brief A class for plotting just the image cutouts of individual sources.
316    ///  @details This class is designed to hold the dimensions and set up for the
317    ///  plotting of the cutouts, plus the textual information for each source.
318    ///  The physical dimensions (in inches) of the plot and the elements
319    ///   within it are stored, on the assumption that the plot will go on
320    ///   an A4 page.
321    ///  Simple accessor functions are provided to enable access to quantities
322    ///   needed for pgplot routines.
323
[378]324    class CutoutPlot
325    {
326    public:
327      CutoutPlot();    ///< Constructor
328      virtual ~CutoutPlot(); ///< Destructor
329      CutoutPlot(const CutoutPlot& p);
330      CutoutPlot& operator=(const CutoutPlot& p);
[367]331
[528]332      /// @brief Set up PGPLOT output.
[378]333      int setUpPlot(std::string pgDestination);
[367]334
[528]335      /// @brief Calculate boundaries for boxes.
[378]336      void calcCoords();
[528]337      /// @brief Set up the header box
[378]338      void gotoHeader();
[367]339
[528]340      /// @brief Write first line of header information (position/velocity info) in correct place.
[378]341      void firstHeaderLine(std::string line);   
[367]342   
[528]343      /// @brief Write second line of header information (fluxes) in correct place.
[378]344      void secondHeaderLine(std::string line); 
[367]345
[528]346      /// @brief Write third line of header information (WCS widths) in correct place.
[378]347      void thirdHeaderLine(std::string line);   
[367]348
[528]349      /// @brief Write fourth line of header information (pixel coordinates) in correct place.
[378]350      void fourthHeaderLine(std::string line);   
[367]351
[528]352      /// @brief Defines the region for the moment map.
[378]353      void gotoMap();
[367]354
[528]355      /// @brief Goes to the plot when more than one are open.
[378]356      void  goToPlot();   
[367]357
[528]358      /// @brief Return the number of objects that go on a page.
[378]359      int   getNumOnPage(){return numOnPage;}
[528]360      /// @brief Set number of objects that go on a page.
[378]361      void  setNumOnPage(int i){numOnPage=i;}
[367]362
[528]363      /// @brief Return width of plottable region.
[378]364      float getPaperWidth(){return paperWidth;}
[528]365      /// @brief Set width of plottable region.
[378]366      void  setPaperWidth(float f){paperWidth=f;}
[528]367      /// @brief Return height of plottable region.
[378]368      float getPaperHeight(){return paperHeight;}
[528]369      /// @brief Set height of plottable region.
[378]370      void  setPaperHeight(float f){paperHeight=f;}
[367]371
[378]372    private:
373      int numOnPage;       ///< Number of sources to put on one page.
374      int sourceCount;     ///< Number of sources done so far: where on the page?
375      float mainCoords[4]; ///< Boundaries for the main spectrum [inches]
376      float mapCoords[4];  ///< Boundaries for the map box [inches]
377      float paperWidth;    ///< Width of plottable region of the paper [inches]
378      float paperHeight;   ///< Height of plottable region of the paper [inches]
379      int   identifier;    ///< The identifier code used by cpgslct.
[367]380   
[378]381    };
[367]382
383
[378]384  }
385
[11]386}
[103]387
388#endif
389
Note: See TracBrowser for help on using the repository browser.