1 | // ----------------------------------------------------------------------- |
---|
2 | // SimpleSpectralPlot.hh: Definition of the class producing a single spectral plot |
---|
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 | #include <duchamp/Plotting/SimpleSpectralPlot.hh> |
---|
29 | #include <duchamp/Plotting/SpectralPlot.hh> |
---|
30 | #include <duchamp/fitsHeader.hh> |
---|
31 | #include <duchamp/PixelMap/Scan.hh> |
---|
32 | #include <duchamp/PixelMap/Object2D.hh> |
---|
33 | #include <string> |
---|
34 | |
---|
35 | namespace duchamp { |
---|
36 | |
---|
37 | namespace Plot { |
---|
38 | |
---|
39 | SimpleSpectralPlot::SimpleSpectralPlot(): |
---|
40 | SpectralPlot() |
---|
41 | { |
---|
42 | this->numOnPage = 1; |
---|
43 | this->aspectRatio = M_SQRT2/5.; |
---|
44 | } |
---|
45 | |
---|
46 | SimpleSpectralPlot::SimpleSpectralPlot(const SimpleSpectralPlot& other) |
---|
47 | { |
---|
48 | this->operator=(other); |
---|
49 | } |
---|
50 | |
---|
51 | SimpleSpectralPlot& SimpleSpectralPlot::operator=(const SimpleSpectralPlot& other) |
---|
52 | { |
---|
53 | if(this == &other) return *this; |
---|
54 | ((SpectralPlot &) *this) = other; |
---|
55 | return *this; |
---|
56 | } |
---|
57 | |
---|
58 | int SimpleSpectralPlot::setUpPlot(std::string pgDestination) |
---|
59 | { |
---|
60 | if(pgDestination == "/xs") this->paperWidth=12.; |
---|
61 | this->paperHeight = this->paperWidth*this->aspectRatio; |
---|
62 | this->open(pgDestination); |
---|
63 | float scaling = this->paperWidth*inchToCm / a4width; |
---|
64 | this->mainCoords[0] = Plot::spMainX1/inchToCm * scaling; |
---|
65 | this->mainCoords[1] = (Plot::spMapX1+Plot::spMainY2-Plot::spMainY1)/inchToCm * scaling; |
---|
66 | this->mainCoords[2] = Plot::spMainY1/inchToCm * scaling; |
---|
67 | this->mainCoords[3] = Plot::spMainY2/inchToCm * scaling; |
---|
68 | return this->identifier; |
---|
69 | |
---|
70 | } |
---|
71 | |
---|
72 | void SimpleSpectralPlot::label(std::string xlabel, std::string ylabel, std::string title) |
---|
73 | { |
---|
74 | /// @details |
---|
75 | /// Calls calcCoords, to calculate correct coordinates for this spectrum. |
---|
76 | /// Defines the region for the header information, making it centred |
---|
77 | /// on the page. |
---|
78 | /// Also writes the velocity (x axis) label, given by the string argument. |
---|
79 | /// \param xlabel Label to go on the velocity/spectral axis. |
---|
80 | |
---|
81 | cpgvsiz(this->mainCoords[0],this->mainCoords[1],this->mainCoords[2],this->mainCoords[3]); |
---|
82 | cpgsch(2.); |
---|
83 | cpgmtxt("B",3.,0.5,0.5,xlabel.c_str()); |
---|
84 | cpgmtxt("L",4.,0.5,0.5,ylabel.c_str()); |
---|
85 | cpgmtxt("T",2.,0.5,0.5,title.c_str()); |
---|
86 | } |
---|
87 | |
---|
88 | void SimpleSpectralPlot::gotoMainSpectrum(float x1, float x2, float y1, float y2) |
---|
89 | { |
---|
90 | /// @details |
---|
91 | /// Defines the region for the main spectrum. |
---|
92 | /// Draws the box, with tick marks, and |
---|
93 | /// writes the flux (y axis) label, given by the string argument. |
---|
94 | /// \param x1 Minimum X-coordinate of box. |
---|
95 | /// \param x2 Maximum X-coordinate of box. |
---|
96 | /// \param y1 Minimum Y-coordinate of box. |
---|
97 | /// \param y2 Maximum Y-coordinate of box. |
---|
98 | /// \param ylabel Label for the flux (Y) axis. |
---|
99 | |
---|
100 | cpgvsiz(this->mainCoords[0],this->mainCoords[1],this->mainCoords[2],this->mainCoords[3]); |
---|
101 | cpgsch(2.); |
---|
102 | cpgswin(x1,x2,y1,y2); |
---|
103 | cpgbox("1bcnst",0.,0,"bcnst1v",0.,0); |
---|
104 | } |
---|
105 | |
---|
106 | void SimpleSpectralPlot::markDetectedPixels(short *detectMap, size_t size, FitsHeader &head) |
---|
107 | { |
---|
108 | PixelInfo::Object2D detectionLine; |
---|
109 | for(size_t z=0;z<size;z++) |
---|
110 | if(detectMap[z]>0) detectionLine.addPixel(z,0); |
---|
111 | std::vector<PixelInfo::Scan> detlist = detectionLine.getScanlist(); |
---|
112 | // size_t dim[2]; dim[0]=size; dim[1]=1; |
---|
113 | // Image detIm(dim); |
---|
114 | // detIm.setMinSize(1); |
---|
115 | // for(size_t z=0;z<size;z++) detIm.setPixValue(z,float(detectMap[z])); |
---|
116 | // detIm.stats().setThreshold(0.5); |
---|
117 | // std::vector<PixelInfo::Scan> detlist=detIm.findSources1D(); |
---|
118 | for(std::vector<PixelInfo::Scan>::iterator sc=detlist.begin();sc<detlist.end();sc++){ |
---|
119 | float v1,v2; |
---|
120 | double zero=0.; |
---|
121 | if(head.isWCS()){ |
---|
122 | double zpt=double(sc->getX()-0.5); |
---|
123 | v1=head.pixToVel(zero,zero,zpt); |
---|
124 | zpt=double(sc->getXmax()+0.5); |
---|
125 | v2=head.pixToVel(zero,zero,zpt); |
---|
126 | } |
---|
127 | else{ |
---|
128 | v1=float(sc->getX()-0.5); |
---|
129 | v2=float(sc->getXmax()+0.5); |
---|
130 | } |
---|
131 | float x1,x2,y1,y2; |
---|
132 | cpgqwin(&x1,&x2,&y1,&y2); |
---|
133 | float ymax=y2-0.04*(y2-y1); |
---|
134 | float ymin=y2-0.06*(y2-y1); |
---|
135 | int lw,fs; |
---|
136 | cpgqlw(&lw); |
---|
137 | cpgqfs(&fs); |
---|
138 | cpgslw(3); |
---|
139 | cpgsfs(1); |
---|
140 | cpgrect(v1,v2,ymin,ymax); |
---|
141 | cpgslw(lw); |
---|
142 | cpgsfs(fs); |
---|
143 | } |
---|
144 | } |
---|
145 | |
---|
146 | } |
---|
147 | |
---|
148 | } |
---|