1 | // ----------------------------------------------------------------------- |
---|
2 | // spectralSelection.cc: A text-based menu to select a particular 1D |
---|
3 | // spectrum. |
---|
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 | // ----------------------------------------------------------------------- |
---|
29 | #include <iostream> |
---|
30 | #include <fstream> |
---|
31 | #include <iomanip> |
---|
32 | #include <sstream> |
---|
33 | #include <string> |
---|
34 | #include <duchamp/param.hh> |
---|
35 | #include <duchamp/Devel/devel.hh> |
---|
36 | #include <duchamp/Cubes/cubes.hh> |
---|
37 | #include <vector> |
---|
38 | |
---|
39 | using namespace duchamp; |
---|
40 | |
---|
41 | void spectralSelection(std::vector<float> &xvalues, |
---|
42 | std::vector<float> &yvalues, |
---|
43 | long &zdim) |
---|
44 | { |
---|
45 | std::cout << "Do you want:\t 1) HI Cubes?\n"; |
---|
46 | std::cout << "\t\t 2) PHFS quasar spectra?\n"; |
---|
47 | std::cout << "\t\t 3) Orion Chandra time series?\n"; |
---|
48 | std::cout << "\t\t 4) 2BL spectra?\n"; |
---|
49 | std::cout << "\t\t 5) Gaussian noise?\n"; |
---|
50 | std::cout << "\t\t 6) Gaussian noise with a single Gaussian source?\n"; |
---|
51 | std::cout << "\t\t 7) As for 6) but with absorption as well?"<<std::endl; |
---|
52 | std::cout << "\t\t 8) A unit pulse at the central pixel?\n"; |
---|
53 | std::cout << "\t\t 9) B1555-140 spectra?\n"; |
---|
54 | std::cout << "\t\t10) To enter your own filename (text file only)?\n"; |
---|
55 | int choice=0; |
---|
56 | while((choice<1)||(choice>10)){ |
---|
57 | std::cout << "Enter choice (1 -- 10) : "; |
---|
58 | std::cin >> choice; |
---|
59 | } |
---|
60 | |
---|
61 | std::string fname; |
---|
62 | zdim=0; |
---|
63 | |
---|
64 | std::vector<float> specx,specy; |
---|
65 | |
---|
66 | if(choice==1){ |
---|
67 | fname=menu(); |
---|
68 | std::cerr << fname <<std::endl; |
---|
69 | char ans; |
---|
70 | duchamp::Cube *cube = new duchamp::Cube; |
---|
71 | duchamp::Param par; |
---|
72 | std::cout << "Remove Milky Way emission (y/n)? : "; |
---|
73 | std::cin >> ans; |
---|
74 | par.setFlagMW(ans=='y'); |
---|
75 | par.setImageFile(fname); |
---|
76 | par.setVerbosity(false); |
---|
77 | cube->saveParam(par); |
---|
78 | cube->getCube(); |
---|
79 | zdim = cube->getDimZ(); |
---|
80 | if(par.getFlagMW()) cube->removeMW(); |
---|
81 | zdim = cube->getDimZ(); |
---|
82 | |
---|
83 | long xpos,ypos; |
---|
84 | std::cout << "Enter x (1--"<<cube->getDimX() |
---|
85 | << ") and y (1--"<<cube->getDimY() |
---|
86 | << ") positions: "; |
---|
87 | std::cin >> xpos >> ypos; |
---|
88 | |
---|
89 | xpos -= cube->pars().getXOffset(); |
---|
90 | ypos -= cube->pars().getYOffset(); |
---|
91 | float *array = new float[cube->getSize()]; |
---|
92 | cube->getArray(array); |
---|
93 | specx.resize(zdim); |
---|
94 | specy.resize(zdim); |
---|
95 | const int offset = 0; |
---|
96 | int ct=0; |
---|
97 | for(int zpos=0;zpos<zdim;zpos++){ |
---|
98 | specx[ct] = float(zpos); |
---|
99 | specy[ct] = 0.; |
---|
100 | for(int x=xpos-offset;x<=xpos+offset;x++){ |
---|
101 | for(int y=ypos-offset;y<=ypos+offset;y++){ |
---|
102 | int cubepos = y * cube->getDimX() + x |
---|
103 | + zpos * cube->getDimX() * cube->getDimY(); |
---|
104 | specy[ct] += array[cubepos]; |
---|
105 | } |
---|
106 | } |
---|
107 | specy[ct] /= (2*offset+1)*(2*offset+1); |
---|
108 | ct++; |
---|
109 | } |
---|
110 | delete cube; |
---|
111 | delete [] array; |
---|
112 | } |
---|
113 | else if((choice==7)||(choice==6)||(choice==5)){ |
---|
114 | zdim=1024; |
---|
115 | specx.resize(zdim); |
---|
116 | specy.resize(zdim); |
---|
117 | float *tempx = new float[zdim]; |
---|
118 | float *tempy = new float[zdim]; |
---|
119 | getRandomSpectrum(zdim,tempx,tempy); |
---|
120 | for(int i=0;i<zdim;i++) specx[i] = tempx[i]; |
---|
121 | for(int i=0;i<zdim;i++) specy[i] = tempy[i]; |
---|
122 | delete [] tempx; |
---|
123 | delete [] tempy; |
---|
124 | if((choice==7)||(choice==6)){ |
---|
125 | float src,snr,loc=-1,fwhm,snrAbs,fwhmAbs; |
---|
126 | std::cout << "Enter signal-to-noise of source: "; |
---|
127 | std::cin >> snr; |
---|
128 | while((loc<0)||(loc>=zdim)){ |
---|
129 | std::cout << "Enter location of source (0 -- "<<zdim<<"), and FHWM: "; |
---|
130 | std::cin >> loc >> fwhm; |
---|
131 | } |
---|
132 | for(int i=0;i<zdim;i++){ |
---|
133 | src = snr * exp( -(specx[i]-loc)*(specx[i]-loc)/(fwhm*fwhm) ); |
---|
134 | specy[i] += src; |
---|
135 | } |
---|
136 | if(choice==7){ |
---|
137 | fwhmAbs=fwhm; |
---|
138 | snrAbs = snr; |
---|
139 | while(fwhmAbs>=fwhm && snrAbs>=snr){ |
---|
140 | std::cout << "Enter SNR (<" << snr |
---|
141 | << ") and FWHM (<" << fwhm |
---|
142 | << ") of absorption line: "; |
---|
143 | std::cin >> snrAbs >> fwhmAbs; |
---|
144 | } |
---|
145 | for(int i=0;i<zdim;i++){ |
---|
146 | src = snrAbs * exp(-(specx[i]-loc)*(specx[i]-loc)/(fwhmAbs*fwhmAbs)); |
---|
147 | specy[i] -= src; |
---|
148 | } |
---|
149 | } |
---|
150 | } |
---|
151 | } |
---|
152 | else if(choice==8){ |
---|
153 | zdim=1024; |
---|
154 | specx.resize(zdim); |
---|
155 | specy.resize(zdim); |
---|
156 | for(int i=0;i<zdim;i++){ |
---|
157 | specx[i] = i; |
---|
158 | specy[i] = 0.; |
---|
159 | } |
---|
160 | specy[zdim/2] = 1.; |
---|
161 | } |
---|
162 | else{ |
---|
163 | if(choice==2) fname=specMenu(); |
---|
164 | else if(choice==3) fname=orionMenu(); |
---|
165 | else if(choice==4) fname=twoblMenu(); |
---|
166 | else if(choice==9) fname=b1555Menu(); |
---|
167 | else { |
---|
168 | std::cout << "Enter filename (full path): "; |
---|
169 | std::cin >> fname; |
---|
170 | } |
---|
171 | std::ifstream fin(fname.c_str()); |
---|
172 | float a; float b; |
---|
173 | specx.resize(0); |
---|
174 | specy.resize(0); |
---|
175 | while(fin>>a>>b){ |
---|
176 | specx.push_back(a); |
---|
177 | specy.push_back(b); |
---|
178 | zdim++; |
---|
179 | } |
---|
180 | |
---|
181 | } |
---|
182 | |
---|
183 | xvalues = specx; |
---|
184 | yvalues = specy; |
---|
185 | |
---|
186 | } |
---|