1 | #include <iostream> |
---|
2 | #include <iomanip> |
---|
3 | #include <ATrous/atrous.hh> |
---|
4 | #include <Cubes/cubes.hh> |
---|
5 | #include <param.hh> |
---|
6 | |
---|
7 | void baselineSubtract(long numSpec, long specLength, float *originalCube, float *baselineValues, Param &par) |
---|
8 | { |
---|
9 | /** |
---|
10 | * baselineSubtract(long numSpec, long specLength, float *originalCube, float *baselineValues, Param &par) |
---|
11 | * |
---|
12 | * A routine to find the baseline of spectra in a cube (spectral direction assumed |
---|
13 | * to be the third dimension) and subtract it off the original. |
---|
14 | * The original cube has numSpec spatial pixels, each containing a spectrum of length specLength. |
---|
15 | * The original cube is read in, and returned with the baseline removed. |
---|
16 | * This baseline is stored in the array baselineValues. |
---|
17 | * The Param variable par is needed to test for blank pixels -- these are kept as blank. |
---|
18 | */ |
---|
19 | extern Filter reconFilter; |
---|
20 | float *spec = new float[specLength]; |
---|
21 | float *thisBaseline = new float[specLength]; |
---|
22 | int minscale = par.getMinScale(); |
---|
23 | par.setMinScale(reconFilter.getNumScales(specLength)); |
---|
24 | float atrouscut = par.getAtrousCut(); |
---|
25 | par.setAtrousCut(1); |
---|
26 | bool flagVerb = par.isVerbose(); |
---|
27 | par.setVerbosity(false); |
---|
28 | |
---|
29 | std::cout << "| |" << std::flush; |
---|
30 | for(int pix=0; pix<numSpec; pix++){ // for each spatial pixel... |
---|
31 | |
---|
32 | // if(flagVerb) std::cout << std::setw(6) << pix << "\b\b\b\b\b\b" << std::flush; |
---|
33 | |
---|
34 | if(flagVerb && ((100*(pix+1)/numSpec)%5 == 0) ){ |
---|
35 | std::cout << "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b|"; |
---|
36 | for(int i=0;i<(100*(pix+1)/numSpec)/5;i++) std::cout << "#"; |
---|
37 | for(int i=(100*(pix+1)/numSpec)/5;i<20;i++) std::cout << " "; |
---|
38 | std::cout << "|" << std::flush; |
---|
39 | } |
---|
40 | |
---|
41 | for(int z=0; z<specLength; z++) |
---|
42 | spec[z] = originalCube[z*numSpec + pix]; |
---|
43 | |
---|
44 | atrous1DReconstruct(specLength,spec,thisBaseline,par); |
---|
45 | |
---|
46 | for(int z=0; z<specLength; z++) { |
---|
47 | baselineValues[z*numSpec+pix] = thisBaseline[z]; |
---|
48 | if(!par.isBlank(originalCube[z*numSpec+pix])) |
---|
49 | originalCube[z*numSpec+pix] = originalCube[z*numSpec+pix] - baselineValues[z*numSpec+pix]; |
---|
50 | } |
---|
51 | |
---|
52 | } |
---|
53 | if(flagVerb) std::cout << "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"; |
---|
54 | |
---|
55 | par.setMinScale(minscale); |
---|
56 | par.setAtrousCut(atrouscut); |
---|
57 | par.setVerbosity(flagVerb); |
---|
58 | |
---|
59 | delete [] spec; |
---|
60 | delete [] thisBaseline; |
---|
61 | |
---|
62 | } |
---|
63 | |
---|
64 | |
---|
65 | void Cube::removeBaseline() |
---|
66 | { |
---|
67 | /** |
---|
68 | * Cube::removeBaseline() |
---|
69 | * A front-end to the baselineSubtract routine, specialised for the |
---|
70 | * Cube data structure. |
---|
71 | * Upon exit, the original array minus its spectral baseline is stored |
---|
72 | * in this->array and the baseline is in this->baseline. |
---|
73 | */ |
---|
74 | |
---|
75 | baselineSubtract(this->axisDim[0]*this->axisDim[1], this->axisDim[2], |
---|
76 | this->array, this->baseline, this->par); |
---|
77 | } |
---|
78 | |
---|
79 | void Cube::replaceBaseline() |
---|
80 | { |
---|
81 | /** |
---|
82 | * Cube::replaceBaseline() |
---|
83 | * A routine to replace the baseline flux on the reconstructed array (if it exists) |
---|
84 | * and the fluxes of each of the detected objects (if any). |
---|
85 | */ |
---|
86 | |
---|
87 | if(this->par.getFlagBaseline()){ |
---|
88 | |
---|
89 | for(int i=0;i<this->numPixels;i++){ |
---|
90 | if(!(this->par.isBlank(this->array[i]))) |
---|
91 | this->array[i] += this->baseline[i]; |
---|
92 | } |
---|
93 | |
---|
94 | if(this->reconExists){ |
---|
95 | // if we made a reconstruction, we need to add the baseline back in 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 | int pos; |
---|
103 | float flux; |
---|
104 | // Now add the baseline to the flux for all the objects. |
---|
105 | for(int obj=0;obj<this->objectList.size();obj++){ // for each detection |
---|
106 | for(int vox=0;vox<this->objectList[obj].getSize();vox++){ // for each of its voxels |
---|
107 | |
---|
108 | pos = this->objectList[obj].getX(vox) + |
---|
109 | this->axisDim[0]*this->objectList[obj].getY(vox) + |
---|
110 | this->axisDim[0]*this->axisDim[1]*this->objectList[obj].getZ(vox); |
---|
111 | |
---|
112 | flux = this->objectList[obj].getF(vox) + this->baseline[pos]; |
---|
113 | |
---|
114 | this->objectList[obj].setF(vox, flux); |
---|
115 | |
---|
116 | } |
---|
117 | this->objectList[obj].calcParams(); // correct the flux calculations. |
---|
118 | |
---|
119 | } |
---|
120 | |
---|
121 | } |
---|
122 | |
---|
123 | } |
---|