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

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

Introduced some simple inline functions to duchamp.hh to make the printing of progress bars simpler and of a more unified fashion.

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  initialiseMeter();
25  for(int pix=0; pix<numSpec; pix++){ // for each spatial pixel...
26
27    if(this->par.isVerbose() && ((100*(pix+1)/numSpec)%5 == 0) )
28      updateMeter((100*(pix+1)/numSpec)/5);
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.