source: branches/fitshead-branch/ATrous/baselineSubtract.cc @ 89

Last change on this file since 89 was 86, checked in by Matthew Whiting, 18 years ago

Large commit, mostly removing dud commented code, and adding comments and
documentation to the existing code. No new features.

File size: 4.9 KB
Line 
1#include <iostream>
2#include <iomanip>
3#include <ATrous/atrous.hh>
4#include <Utils/utils.hh>
5#include <param.hh>
6
7void baselineSubtract(long numSpec, long specLength, float *originalCube,
8                      float *baselineValues, Param &par)
9{
10  /**
11   *  baselineSubtract(long numSpec, long specLength, float *originalCube,
12   *                   float *baselineValues, Param &par)
13   *   
14   *    A routine to find the baseline of spectra in a cube (spectral direction
15   *     assumed to be the third dimension) and subtract it off the original.
16   *    The original cube has numSpec spatial pixels, each containing a spectrum
17   *     of length specLength.
18   *    The original cube is read in, and returned with the baseline removed.
19   *    This baseline is stored in the array baselineValues.
20   *    The Param variable par is needed to test for blank pixels -- these are kept as blank.
21   */
22  extern Filter reconFilter;
23  float *spec     = new float[specLength];
24  float *thisBaseline = new float[specLength];
25  int minscale = par.getMinScale();
26  par.setMinScale(reconFilter.getNumScales(specLength));
27  float atrouscut = par.getAtrousCut();
28  par.setAtrousCut(1);
29  bool flagVerb = par.isVerbose();
30  par.setVerbosity(false);
31
32  std::cout << "|                    |" << std::flush;
33  for(int pix=0; pix<numSpec; pix++){ // for each spatial pixel...
34
35    if(flagVerb && ((100*(pix+1)/numSpec)%5 == 0) ){
36      std::cout << "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b|";
37      for(int i=0;i<(100*(pix+1)/numSpec)/5;i++) std::cout << "#";
38      for(int i=(100*(pix+1)/numSpec)/5;i<20;i++) std::cout << " ";
39      std::cout << "|" << std::flush;
40    }
41
42    for(int z=0; z<specLength; z++)
43      spec[z] = originalCube[z*numSpec + pix];
44
45    atrous1DReconstruct(specLength,spec,thisBaseline,par);
46
47    for(int z=0; z<specLength; z++) {
48      baselineValues[z*numSpec+pix] = thisBaseline[z];
49      if(!par.isBlank(originalCube[z*numSpec+pix]))
50        originalCube[z*numSpec+pix] = originalCube[z*numSpec+pix] - baselineValues[z*numSpec+pix];
51    }
52
53  }   
54  if(flagVerb) std::cout << "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b";
55
56  par.setMinScale(minscale);
57  par.setAtrousCut(atrouscut);
58  par.setVerbosity(flagVerb);
59 
60  delete [] spec;
61  delete [] thisBaseline;
62   
63}
64
65void getBaseline(long size, float *input, float *baseline, Param &par)
66{
67  /**
68   *  getBaseline(long size, float *input, float *baseline, Param &par)
69   *    A function to find the baseline of an input (1-D) spectrum.
70   *    Uses the a trous reconstruction, keeping only the highest two scales, to
71   *       reconstruct the baseline.
72   *    To avoid contamination by very strong signals, the input spectrum is trimmed
73   *       at 8*MADFM above the median before reconstruction. This reduces the strong
74   *       dips created by the presence of very strong signals.
75   *    The baseline array is returned -- no change is made to the input array.
76   */
77
78  extern Filter reconFilter;
79  int minscale = par.getMinScale();
80  par.setMinScale(reconFilter.getNumScales(size));
81  float atrouscut = par.getAtrousCut();
82  par.setAtrousCut(1);
83  bool flagVerb = par.isVerbose();
84  par.setVerbosity(false);
85
86  float *spec = new float[size];
87  float med,sig;
88  findMedianStats(input,size,med,sig);
89  float threshold = 8. * sig;
90  for(int i=0;i<size;i++) {
91    if(fabsf(input[i]-med)>threshold){
92      if(input[i]>med) spec[i] = med + threshold;
93      else spec[i] = med - threshold;
94    }
95    else spec[i] = input[i];
96  }
97
98  //    atrous1DReconstruct(size, input, baseline, par);
99  atrous1DReconstruct(size, spec, baseline, par);
100
101  par.setMinScale(minscale);
102  par.setAtrousCut(atrouscut);
103  par.setVerbosity(flagVerb);
104
105  delete [] spec;
106
107}
108
109
110void getBaseline(long size, float *input, float *baseline)
111{
112  /**
113   *  getBaseline(long size, float *input, float *baseline)
114   *    A function to find the baseline of an input (1-D) spectrum.
115   *    This version is designed for programs not using Param classes -- it keeps
116   *       that side of things hidden from the user.
117   *    Uses the a trous reconstruction, keeping only the highest two scales, to
118   *       reconstruct the baseline.
119   *    To avoid contamination by very strong signals, the input spectrum is trimmed
120   *       at 8*MADFM above the median before reconstruction. This reduces the strong
121   *       dips created by the presence of very strong signals.
122   *    The baseline array is returned -- no change is made to the input array.
123   */
124
125  extern Filter reconFilter;
126  Param par;
127  par.setMinScale(reconFilter.getNumScales(size));
128  par.setAtrousCut(1);
129  par.setVerbosity(false);
130
131  float *spec = new float[size];
132  float med,sig;
133  findMedianStats(input,size,med,sig);
134  float threshold = 8. * sig;
135  for(int i=0;i<size;i++) {
136    if(fabsf(input[i]-med)>threshold){
137      if(input[i]>med) spec[i] = med + threshold;
138      else spec[i] = med - threshold;
139    }
140    else spec[i] = input[i];
141  }
142
143  atrous1DReconstruct(size, spec, baseline, par);
144
145  delete [] spec;
146
147}
148
Note: See TracBrowser for help on using the repository browser.