source: trunk/src/Devel/spectralSelection.cc @ 1441

Last change on this file since 1441 was 1246, checked in by MatthewWhiting, 11 years ago

Ticket #193 - Removing all the MW-related code. Most of it was commented out, but Param now no longer has anything referring to MW. The flag array in ObjectGrower? has also changed to FLAG from MW.

File size: 5.5 KB
Line 
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
39using namespace duchamp;
40
41void spectralSelection(std::vector<float> &xvalues,
42                       std::vector<float> &yvalues,
43                       size_t &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.setImageFile(fname);
75    par.setVerbosity(false);
76    cube->saveParam(par);
77    if(cube->getCube()==FAILURE) std::cerr << "Cannot read cube!";
78    zdim = cube->getDimZ();
79
80    long xpos,ypos;
81    std::cout << "Enter x (1--"<<cube->getDimX()
82              << ") and y (1--"<<cube->getDimY()
83              << ") positions: ";
84    std::cin >> xpos >> ypos;
85
86    xpos -= cube->pars().getXOffset();
87    ypos -= cube->pars().getYOffset();
88    float *array = new float[cube->getSize()];
89    cube->getArray(array);
90    specx.resize(zdim);
91    specy.resize(zdim);
92    const int offset = 0;
93    int ct=0;
94    for(int zpos=0;zpos<zdim;zpos++){
95      specx[ct] = float(zpos);
96      specy[ct] = 0.;
97      for(int x=xpos-offset;x<=xpos+offset;x++){
98        for(int y=ypos-offset;y<=ypos+offset;y++){
99          size_t cubepos = y * cube->getDimX() + x
100            + zpos * cube->getDimX() * cube->getDimY();
101          specy[ct] += array[cubepos];
102        }
103      }
104      specy[ct] /= (2*offset+1)*(2*offset+1);
105      ct++;
106    }
107    delete cube;
108    delete [] array;
109  }
110  else if((choice==7)||(choice==6)||(choice==5)){
111    zdim=1024;
112    specx.resize(zdim);
113    specy.resize(zdim);
114    float *tempx = new float[zdim];
115    float *tempy = new float[zdim];
116    getRandomSpectrum(zdim,tempx,tempy);
117    for(int i=0;i<zdim;i++) specx[i] = tempx[i];
118    for(int i=0;i<zdim;i++) specy[i] = tempy[i];
119    delete [] tempx;
120    delete [] tempy;
121    if((choice==7)||(choice==6)){
122      float src,snr,loc=-1,fwhm,snrAbs,fwhmAbs;
123      std::cout << "Enter signal-to-noise of source: ";
124      std::cin >> snr;
125      while((loc<0)||(loc>=zdim)){
126        std::cout << "Enter location of source (0 -- "<<zdim<<"), and FHWM: ";
127        std::cin >> loc >> fwhm;
128      }
129      for(int i=0;i<zdim;i++){
130        src = snr * exp( -(specx[i]-loc)*(specx[i]-loc)/(fwhm*fwhm) );
131        specy[i] += src;
132      }
133      if(choice==7){
134        fwhmAbs=fwhm;
135        snrAbs = snr;
136        while(fwhmAbs>=fwhm && snrAbs>=snr){
137          std::cout << "Enter SNR (<" << snr
138                    << ") and FWHM (<" << fwhm
139                    << ") of absorption line: ";
140          std::cin >> snrAbs >> fwhmAbs;
141        }
142        for(int i=0;i<zdim;i++){
143          src = snrAbs * exp(-(specx[i]-loc)*(specx[i]-loc)/(fwhmAbs*fwhmAbs));
144          specy[i] -= src;
145        }
146      }
147    }
148  }
149  else if(choice==8){
150    zdim=1024;
151    specx.resize(zdim);
152    specy.resize(zdim);
153    for(int i=0;i<zdim;i++){
154      specx[i] = i;
155      specy[i] = 0.;
156    }
157    specy[zdim/2] = 1.;
158  }
159  else{
160    if(choice==2) fname=specMenu();
161    else if(choice==3) fname=orionMenu();
162    else if(choice==4) fname=twoblMenu();
163    else if(choice==9) fname=b1555Menu();
164    else {
165      std::cout << "Enter filename (full path): ";
166      std::cin >> fname;
167    }
168    std::ifstream fin(fname.c_str());
169    float a; float b;
170    specx.resize(0);
171    specy.resize(0);
172    while(fin>>a>>b){
173      specx.push_back(a);
174      specy.push_back(b);
175      zdim++;
176    }
177   
178  }
179
180  xvalues = specx;
181  yvalues = specy;
182
183}
Note: See TracBrowser for help on using the repository browser.