source: trunk/src/ATrous/baselineSubtract.cc @ 258

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

Large raft of changes. Most are minor ones related to fixing up the use of std::string and std::vector (whether they are declared as using, or not...). Other changes include:

  • Moving the reconstruction filter class Filter into its own header/implementation files filter.{hh,cc}. As a result, the atrous.cc file is removed, but atrous.hh remains with just the function prototypes.
  • Incorporating a Filter object into the Param set, so that the reconstruction routines can see it without the messy "extern" call. The define() function is now called in both the Param() and Param::readParams() functions, and no longer in the main body.
  • Col functions in columns.cc moved into the Column namespace, while the template function printEntry is moved into the columns.hh file -- it would not compile on delphinus with it in the columns.cc, even though all the implementations were present.
  • Improved the introductory section of the Guide, with a bit more detail about each of the execution steps. This way the reader can read this section and have a reasonably good idea about what is happening.
  • Other minor changes to the Guide.
File size: 4.6 KB
Line 
1#include <iostream>
2#include <iomanip>
3#include <math.h>
4#include <param.hh>
5#include <ATrous/filter.hh>
6#include <ATrous/atrous.hh>
7#include <Utils/utils.hh>
8#include <Utils/feedback.hh>
9
10void baselineSubtract(long numSpec, long specLength, float *originalCube,
11                      float *baselineValues, Param &par)
12{
13  /**
14   *  A routine to find the baseline of each spectrum in a cube (the spectral
15   *    direction is assumed to be the third dimension) and subtract it off
16   *    the original.
17   * \param numSpec Number of spatial pixels in original cube.
18   * \param specLength Size of spectral dimension of original cube.
19   * \param originalCube The cube that is to have its baseline removed.
20   * \param baselineValues The cube of baseline values -- the same size as the original
21   * \param par The Param set: information on BLANK values and on how the subtraction is done.
22   */
23
24  float *spec     = new float[specLength];
25  float *thisBaseline = new float[specLength];
26  int minscale = par.getMinScale();
27  par.setMinScale(par.filter().getNumScales(specLength));
28  float atrouscut = par.getAtrousCut();
29  par.setAtrousCut(1);
30  bool flagVerb = par.isVerbose();
31  par.setVerbosity(false);
32
33  ProgressBar bar;
34  if(flagVerb) bar.init(numSpec);
35  for(int pix=0; pix<numSpec; pix++){ // for each spatial pixel...
36
37    if(flagVerb) bar.update(pix+1);
38
39    for(int z=0; z<specLength; z++)
40      spec[z] = originalCube[z*numSpec + pix];
41
42    atrous1DReconstruct(specLength,spec,thisBaseline,par);
43
44    for(int z=0; z<specLength; z++) {
45      baselineValues[z*numSpec+pix] = thisBaseline[z];
46      if(!par.isBlank(originalCube[z*numSpec+pix]))
47        originalCube[z*numSpec+pix] = originalCube[z*numSpec+pix] -
48          baselineValues[z*numSpec+pix];
49    }
50
51  }   
52  if(flagVerb) bar.rewind();
53
54  par.setMinScale(minscale);
55  par.setAtrousCut(atrouscut);
56  par.setVerbosity(flagVerb);
57 
58  delete [] spec;
59  delete [] thisBaseline;
60   
61}
62
63void getBaseline(long size, float *input, float *baseline, Param &par)
64{
65  /**
66   *   Uses the a trous reconstruction, keeping only the highest two scales,
67   *     to reconstruct the baseline.
68   *    To avoid contamination by very strong signals, the input spectrum is
69   *     trimmed at 8*MADFM above the median before reconstruction.
70   *     This reduces the strong dips created by the presence of very strong
71   *     signals.
72   *  \param size Length of the spectrum.
73   *  \param input The input array : this is not affected.
74   *  \param baseline The returned baseline array. This needs to be allocated
75   *   before the function is called.
76   *  \param par The Param set, needed for the atrous reconstruction.
77   */
78
79  int minscale = par.getMinScale();
80  par.setMinScale(par.filter().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(fabs(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   *  This version is designed for programs not using Param classes -- it
114   *   keeps that side of things hidden from the user.
115   *  Uses the a trous reconstruction, keeping only the highest two scales,
116   *   to reconstruct the baseline.
117   *  To avoid contamination by very strong signals, the input spectrum is
118   *   trimmed at 8*MADFM above the median before reconstruction. This
119   *   reduces the strong dips created by the presence of very strong
120   *   signals.
121   *  \param size Length of the spectrum.
122   *  \param input The input array : this is not affected.
123   *  \param baseline The returned baseline array. This needs to be allocated
124   *   before the function is called.
125   */
126
127  Param par;
128  par.setMinScale(par.filter().getNumScales(size));
129  par.setAtrousCut(1);
130  par.setVerbosity(false);
131
132  float *spec = new float[size];
133  float med,sig;
134  findMedianStats(input,size,med,sig);
135  float threshold = 8. * sig;
136  for(int i=0;i<size;i++) {
137    if(fabs(input[i]-med)>threshold){
138      if(input[i]>med) spec[i] = med + threshold;
139      else spec[i] = med - threshold;
140    }
141    else spec[i] = input[i];
142  }
143
144  atrous1DReconstruct(size, spec, baseline, par);
145
146  delete [] spec;
147
148}
149
Note: See TracBrowser for help on using the repository browser.