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

Last change on this file since 1278 was 1278, checked in by MatthewWhiting, 11 years ago

Commenting on the median baseline capability & removing a bit of unused code.

File size: 3.9 KB
Line 
1// -----------------------------------------------------------------------
2// baseline.cc: Removing and replacing the spectral baseline of a Cube.
3// -----------------------------------------------------------------------
4// Copyright (C) 2006, Matthew Whiting, ATNF
5//
6// This program is free software; you can redistribute it and/or modify it
7// under the terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 2 of the License, or (at your
9// option) any later version.
10//
11// Duchamp is distributed in the hope that it will be useful, but WITHOUT
12// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14// for more details.
15//
16// You should have received a copy of the GNU General Public License
17// along with Duchamp; if not, write to the Free Software Foundation,
18// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
19//
20// Correspondence concerning Duchamp may be directed to:
21//    Internet email: Matthew.Whiting [at] atnf.csiro.au
22//    Postal address: Dr. Matthew Whiting
23//                    Australia Telescope National Facility, CSIRO
24//                    PO Box 76
25//                    Epping NSW 1710
26//                    AUSTRALIA
27// -----------------------------------------------------------------------
28#include <iostream>
29#include <iomanip>
30#include <duchamp/param.hh>
31#include <duchamp/ATrous/atrous.hh>
32#include <duchamp/Cubes/cubes.hh>
33#include <duchamp/Utils/feedback.hh>
34
35namespace duchamp
36{
37
38  void Cube::removeBaseline()
39  {
40    /// @details
41    ///  A front-end to the findAtrousBaseline routine, specialised for the
42    ///  Cube data structure. Calls findAtrousBaseline on each spectrum individually.
43    ///  Upon exit, the original array minus its spectral baseline is stored
44    ///   in this->array and the baseline is in this->baseline.
45    ///  If the reconstructed array exists, the baseline is subtracted from
46    ///   it as well.
47
48    float *spec     = new float[this->axisDim[2]];
49    float *thisBaseline = new float[this->axisDim[2]];
50    size_t numSpec = this->axisDim[0]*this->axisDim[1];
51
52    ProgressBar bar;
53    if(this->par.isVerbose()) bar.init(numSpec);
54    for(size_t pix=0; pix<numSpec; pix++){ // for each spatial pixel...
55
56      if(this->par.isVerbose() ) bar.update(pix+1);
57
58      for(size_t z=0; z<this->axisDim[2]; z++) 
59        spec[z] = this->array[z*numSpec + pix];
60
61      if(this->par.getBaselineType()=="atrous")
62          findAtrousBaseline(this->axisDim[2], spec, thisBaseline, this->par);
63      else
64          findMedianBaseline(this->axisDim[2], spec, this->par.getBaselineBoxWidth(), thisBaseline);
65
66      for(size_t z=0; z<this->axisDim[2]; z++) {
67        this->baseline[z*numSpec+pix] = thisBaseline[z];
68        if(!par.isBlank(this->array[z*numSpec+pix])){
69          this->array[z*numSpec+pix] -= thisBaseline[z];
70          if(this->reconExists) this->recon[z*numSpec+pix] -= thisBaseline[z];
71        }     
72      }
73
74    } 
75
76    delete [] spec;
77    delete [] thisBaseline;
78 
79    if(this->par.isVerbose()) bar.remove();
80  }
81
82
83
84  void Cube::replaceBaseline()
85  {
86    /// @details
87    ///  A routine to replace the baseline flux on the reconstructed array
88    ///   (if it exists) and the fluxes of each of the detected objects (if any).
89
90    if(this->par.getFlagBaseline()){
91
92      for(size_t i=0;i<this->numPixels;i++){
93        if(!(this->par.isBlank(this->array[i])))
94          this->array[i] += this->baseline[i];
95      }
96
97      if(this->reconExists){
98        // if we made a reconstruction, we need to add the baseline back in
99        //   for plotting purposes
100        for(size_t i=0;i<this->numPixels;i++){
101          if(!(this->par.isBlank(this->array[i])))
102            this->recon[i] += this->baseline[i];
103        }
104      }
105 
106      std::vector<Detection>::iterator obj;
107      for(obj=this->objectList->begin();obj<this->objectList->end();obj++){
108        // for each detection, correct the flux calculations.
109        obj->calcFluxes(this->array, this->axisDim);
110      }
111   
112    }
113
114  }
115
116}
Note: See TracBrowser for help on using the repository browser.