source: tags/release-1.1/src/Devel/spectralSelection.cc @ 1391

Last change on this file since 1391 was 301, checked in by Matthew Whiting, 17 years ago

Mostly adding the distribution text to the start of files, with a few additional comments added too.

File size: 4.8 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 <param.hh>
35#include <Devel/devel.hh>
36#include <Cubes/cubes.hh>
37#include <vector>
38
39using std::stringstream;
40
41void spectralSelection(std::vector<float> &xvalues,
42                       std::vector<float> &yvalues,
43                       long &zdim)
44{
45  std::cout << "Do you want:\t1) HI Cubes?\n";
46  std::cout << "\t\t2) PHFS quasar spectra?\n";
47  std::cout << "\t\t3) Orion Chandra time series?\n";
48  std::cout << "\t\t4) 2BL spectra?\n";
49  std::cout << "\t\t5) Gaussian noise?\n";
50  std::cout << "\t\t6) Gaussian noise with a single Gaussian source?\n";
51  std::cout << "\t\t7) A unit pulse at the central pixel?\n";
52  std::cout << "\t\t8) To enter your own filename (text file only)?\n";
53  int choice=0;
54  while((choice<1)||(choice>8)){
55    std::cout << "Enter choice (1 -- 8) : ";
56    std::cin >> choice;
57  }
58 
59  std::string fname;
60  zdim=0;
61
62  std::vector<float> specx,specy;
63
64  if(choice==1){
65    fname=menu();
66    std::cerr << fname <<std::endl;
67    Cube *cube = new Cube;
68    Param par;
69    par.setImageFile(fname);
70    par.setVerbosity(false);
71    cube->saveParam(par);
72    cube->getCube();
73    zdim = cube->getDimZ();
74//     if(par.getFlagMW()) cube->removeMW();
75    zdim = cube->getDimZ();
76
77    long xpos,ypos;
78    std::cout << "Enter x (1--"<<cube->getDimX()
79              << ") and y (1--"<<cube->getDimY()
80              << ") positions: ";
81    std::cin >> xpos >> ypos;
82
83    xpos -= cube->pars().getXOffset();
84    ypos -= cube->pars().getYOffset();
85    float *array = new float[cube->getSize()];
86    cube->getArray(array);
87    specx.resize(zdim);
88    specy.resize(zdim);
89    const int offset = 0;
90    int ct=0;
91    for(int zpos=0;zpos<zdim;zpos++){
92      specx[ct] = float(zpos);
93      specy[ct] = 0.;
94      for(int x=xpos-offset;x<=xpos+offset;x++){
95        for(int y=ypos-offset;y<=ypos+offset;y++){
96          int cubepos = y * cube->getDimX() + x
97            + zpos * cube->getDimX() * cube->getDimY();
98          specy[ct] += array[cubepos];
99        }
100      }
101      specy[ct] /= (2*offset+1)*(2*offset+1);
102      ct++;
103    }
104    delete cube;
105    delete [] array;
106  }
107  else if((choice==6)||(choice==5)){
108    zdim=1024;
109    specx.resize(zdim);
110    specy.resize(zdim);
111    float *tempx = new float[zdim];
112    float *tempy = new float[zdim];
113    getRandomSpectrum(zdim,tempx,tempy);
114    for(int i=0;i<zdim;i++) specx[i] = tempx[i];
115    for(int i=0;i<zdim;i++) specy[i] = tempy[i];
116    delete [] tempx;
117    delete [] tempy;
118    if(choice==6){
119      float src,snr,loc,fwhm;
120      std::cout << "Enter signal-to-noise of source: ";
121      std::cin >> snr;
122      while((loc<0)||(loc>=zdim)){
123        std::cout << "Enter location of source (0 -- "<<zdim<<"), and FHWM: ";
124        std::cin >> loc >> fwhm;
125      }
126      for(int i=0;i<zdim;i++){
127        src = snr * exp( -(specx[i]-loc)*(specx[i]-loc)/(fwhm*fwhm) );
128        specy[i] += src;
129      }
130    }
131  }
132  else if(choice==7){
133    zdim=1024;
134    specx.resize(zdim);
135    specy.resize(zdim);
136    for(int i=0;i<zdim;i++){
137      specx[i] = i;
138      specy[i] = 0.;
139    }
140    specy[zdim/2] = 1.;
141  }
142  else{
143    if(choice==2) fname=specMenu();
144    else if(choice==3) fname=orionMenu();
145    else if(choice==4) fname=twoblMenu();
146    else {
147      std::cout << "Enter filename (full path): ";
148      std::cin >> fname;
149    }
150    std::ifstream fin(fname.c_str());
151    float a; float b;
152    specx.resize(0);
153    specy.resize(0);
154    while(fin>>a>>b){
155      specx.push_back(a);
156      specy.push_back(b);
157      zdim++;
158    }
159   
160  }
161
162  xvalues = specx;
163  yvalues = specy;
164
165}
Note: See TracBrowser for help on using the repository browser.