source: tags/release-1.0.7/src/ATrous/baselineSubtract.cc

Last change on this file was 213, checked in by Matthew Whiting, 18 years ago

Summary:

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