source: trunk/src/Utils/spectralSelection.cc @ 258

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

Merging pixel-map-branch revisions 236:257 back into trunk.
The use of the PixelMap? functions is sorted now, so we put everything back into a uniform location.

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