source: tags/release-1.1.4/src/Devel/spectralSelection.cc @ 1441

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