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

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

Adding distribution text at the start of each file...

File size: 3.6 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 <param.hh>
31#include <ATrous/atrous.hh>
32#include <Cubes/cubes.hh>
33#include <Utils/feedback.hh>
34
35void Cube::removeBaseline()
36{
37  /**
38   *  A front-end to the getBaseline routine, specialised for the
39   *  Cube data structure. Calls getBaseline on each spectrum individually.
40   *  Upon exit, the original array minus its spectral baseline is stored
41   *   in this->array and the baseline is in this->baseline.
42   *  If the reconstructed array exists, the baseline is subtracted from
43   *   it as well.
44   */
45
46  float *spec     = new float[this->axisDim[2]];
47  float *thisBaseline = new float[this->axisDim[2]];
48  int numSpec = this->axisDim[0]*this->axisDim[1];
49
50  ProgressBar bar;
51  if(this->par.isVerbose()) bar.init(numSpec);
52  for(int pix=0; pix<numSpec; pix++){ // for each spatial pixel...
53
54    if(this->par.isVerbose() ) bar.update(pix+1);
55
56    for(int z=0; z<this->axisDim[2]; z++) 
57      spec[z] = this->array[z*numSpec + pix];
58
59    getBaseline(this->axisDim[2], spec, thisBaseline, this->par);
60
61    for(int z=0; z<this->axisDim[2]; z++) {
62      this->baseline[z*numSpec+pix] = thisBaseline[z];
63      if(!par.isBlank(this->array[z*numSpec+pix])){
64        this->array[z*numSpec+pix] -= thisBaseline[z];
65        if(this->reconExists) this->recon[z*numSpec+pix] -= thisBaseline[z];
66      }     
67    }
68
69  } 
70
71  delete [] spec;
72  delete [] thisBaseline;
73 
74  if(this->par.isVerbose()) bar.remove();
75}
76
77
78
79void Cube::replaceBaseline()
80{
81  /**
82   *  A routine to replace the baseline flux on the reconstructed array
83   *   (if it exists) and the fluxes of each of the detected objects (if any).
84   */
85
86  if(this->par.getFlagBaseline()){
87
88    for(int i=0;i<this->numPixels;i++){
89      if(!(this->par.isBlank(this->array[i])))
90        this->array[i] += this->baseline[i];
91    }
92
93    if(this->reconExists){
94      // if we made a reconstruction, we need to add the baseline back in
95      //   for plotting purposes
96      for(int i=0;i<this->numPixels;i++){
97        if(!(this->par.isBlank(this->array[i])))
98          this->recon[i] += this->baseline[i];
99      }
100    }
101 
102    for(int obj=0;obj<this->objectList->size();obj++){
103      // for each detection, correct the flux calculations.
104      this->objectList->at(obj).calcFluxes(this->array, this->axisDim);
105     
106    }
107   
108  }
109
110}
Note: See TracBrowser for help on using the repository browser.