source: trunk/src/Cubes/baseline.cc @ 187

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

Large suite of edits, mostly due to testing with valgrind, which clear up bad memory allocations and so on.
Improved the printing of progress bars in some routines by introducing a new ProgressBar? class, with associated functions to do the printing (now much cleaner).

File size: 2.7 KB
Line 
1#include <iostream>
2#include <iomanip>
3#include <duchamp.hh>
4#include <param.hh>
5#include <ATrous/atrous.hh>
6#include <Cubes/cubes.hh>
7
8void Cube::removeBaseline()
9{
10  /**
11   *  Cube::removeBaseline()
12   *   A front-end to the getBaseline routine, specialised for the
13   *   Cube data structure. Calls getBaseline on each spectrum individually.
14   *   Upon exit, the original array minus its spectral baseline is stored
15   *    in this->array and the baseline is in this->baseline.
16   *   If the reconstructed array exists, the baseline is subtracted from
17   *    it as well.
18   */
19
20  float *spec     = new float[this->axisDim[2]];
21  float *thisBaseline = new float[this->axisDim[2]];
22  int numSpec = this->axisDim[0]*this->axisDim[1];
23
24  ProgressBar bar;
25  if(this->par.isVerbose()) bar.init(numSpec);
26  for(int pix=0; pix<numSpec; pix++){ // for each spatial pixel...
27
28    if(this->par.isVerbose() ) bar.update(pix+1);
29
30    for(int z=0; z<this->axisDim[2]; z++) 
31      spec[z] = this->array[z*numSpec + pix];
32
33    getBaseline(this->axisDim[2], spec, thisBaseline, this->par);
34
35    for(int z=0; z<this->axisDim[2]; z++) {
36      this->baseline[z*numSpec+pix] = thisBaseline[z];
37      if(!par.isBlank(this->array[z*numSpec+pix])){
38        this->array[z*numSpec+pix] -= thisBaseline[z];
39        if(this->reconExists) this->recon[z*numSpec+pix] -= thisBaseline[z];
40      }     
41    }
42
43  } 
44
45  delete [] spec;
46  delete [] thisBaseline;
47 
48  if(this->par.isVerbose()) printBackSpace(22);
49}
50
51
52
53void Cube::replaceBaseline()
54{
55  /**
56   *  Cube::replaceBaseline()
57   *   A routine to replace the baseline flux on the reconstructed array
58   *    (if it exists) and the fluxes of each of the detected objects (if any).
59   */
60
61  if(this->par.getFlagBaseline()){
62
63    for(int i=0;i<this->numPixels;i++){
64      if(!(this->par.isBlank(this->array[i])))
65        this->array[i] += this->baseline[i];
66    }
67
68    if(this->reconExists){
69      // if we made a reconstruction, we need to add the baseline back in
70      //   for plotting purposes
71      for(int i=0;i<this->numPixels;i++){
72        if(!(this->par.isBlank(this->array[i])))
73          this->recon[i] += this->baseline[i];
74      }
75    }
76 
77    int pos;
78    float flux;
79    // Now add the baseline to the flux for all the objects.
80    for(int obj=0;obj<this->objectList.size();obj++){ // for each detection
81      for(int vox=0;vox<this->objectList[obj].getSize();vox++){
82        // for each of its voxels
83
84        pos = this->objectList[obj].getX(vox) +
85          this->axisDim[0]*this->objectList[obj].getY(vox) +
86          this->axisDim[0]*this->axisDim[1]*this->objectList[obj].getZ(vox);
87
88        flux = this->objectList[obj].getF(vox) + this->baseline[pos];
89
90        this->objectList[obj].setF(vox, flux);
91
92      }
93      this->objectList[obj].calcParams();  // correct the flux calculations.
94
95    }
96 
97  }
98
99}
Note: See TracBrowser for help on using the repository browser.