1 | #include "machdefs.h"
|
---|
2 | #include <stdlib.h>
|
---|
3 | #include <stdio.h>
|
---|
4 |
|
---|
5 | #include <iostream.h>
|
---|
6 | #include <math.h>
|
---|
7 |
|
---|
8 | #include <string>
|
---|
9 | #include <vector>
|
---|
10 |
|
---|
11 | #include "timing.h"
|
---|
12 | #include "sambainit.h"
|
---|
13 | #include "pexceptions.h"
|
---|
14 | #include "datacards.h"
|
---|
15 | #include "fitsioserver.h"
|
---|
16 |
|
---|
17 | #include "spheregorski.h"
|
---|
18 |
|
---|
19 | #include "radspecvector.h"
|
---|
20 | #include "blackbody.h"
|
---|
21 | #include "nupower.h"
|
---|
22 |
|
---|
23 | #include "squarefilt.h"
|
---|
24 | #include "trianglefilt.h"
|
---|
25 | #include "specrespvector.h"
|
---|
26 | #include "gaussfilt.h"
|
---|
27 |
|
---|
28 | // ------ Function declaration
|
---|
29 | void addComponent(SpectralResponse& sr, PixelMap<float>& finalMap,
|
---|
30 | PixelMap<float>& mapToAdd, RadSpectra& rs, double K=1.);
|
---|
31 | void addComponent(SpectralResponse& sr, PixelMap<double>& finalMap,
|
---|
32 | PixelMap<double>& mapToAdd, RadSpectra& rs, double K=1.);
|
---|
33 |
|
---|
34 | // -------------------------------------------------------------------------
|
---|
35 | // main program
|
---|
36 | // -------------------------------------------------------------------------
|
---|
37 | int main(int narg, char * arg[])
|
---|
38 | {
|
---|
39 | if ((narg < 2) || (strcmp(arg[1], "-h") == 0) ) {
|
---|
40 | cout << " skymixer / Error args \n Usage: skymixer parameterFile " << endl;
|
---|
41 | exit(0);
|
---|
42 | }
|
---|
43 |
|
---|
44 | InitTim();
|
---|
45 |
|
---|
46 | string msg;
|
---|
47 | int rc = 0;
|
---|
48 |
|
---|
49 | try {
|
---|
50 | string dcard = arg[1];
|
---|
51 | cout << " Decoding parameters from file " << dcard << endl;
|
---|
52 | DataCards dc(dcard);
|
---|
53 |
|
---|
54 | // Cheking datacards
|
---|
55 | if ( (!dc.HasKey("SKYMIX")) || (!dc.HasKey("FILTER")) ) {
|
---|
56 | rc = 71;
|
---|
57 | msg = "Invalid parameters - NO @SKYMIX or @FILTER card ";
|
---|
58 | goto problem;
|
---|
59 | }
|
---|
60 |
|
---|
61 | // Decoding number of component and pixelisation parameter
|
---|
62 | int mg = 32;
|
---|
63 | int ncomp = 0;
|
---|
64 | ncomp = dc.IParam("SKYMIX", 0, 0);
|
---|
65 | mg = dc.IParam("SKYMIX", 1, 32);
|
---|
66 | if (ncomp < 1) {
|
---|
67 | msg = "Invalid parameters - Check datacards @SKYMIX ";
|
---|
68 | rc = 72;
|
---|
69 | goto problem;
|
---|
70 | }
|
---|
71 |
|
---|
72 | int kc;
|
---|
73 | string key;
|
---|
74 | char buff[256];
|
---|
75 | bool pb = false;
|
---|
76 | for(kc=0; kc<ncomp; kc++) {
|
---|
77 | sprintf(buff, "SCMFILE%d", kc+1);
|
---|
78 | key = buff;
|
---|
79 | if (dc.NbParam(key) < 1) {
|
---|
80 | msg = "Missing or invalid card : " + key;
|
---|
81 | pb = true; break;
|
---|
82 | }
|
---|
83 | sprintf(buff, "SCSPEC%d", kc+1);
|
---|
84 | key = buff;
|
---|
85 | if (dc.NbParam(key) < 1) {
|
---|
86 | msg = "Missing or invalid card : " + key;
|
---|
87 | pb = true; break;
|
---|
88 | }
|
---|
89 |
|
---|
90 | }
|
---|
91 |
|
---|
92 | if (pb) {
|
---|
93 | rc = 72;
|
---|
94 | goto problem;
|
---|
95 | }
|
---|
96 |
|
---|
97 | cout << " skymix/Info : NComp = " << ncomp << " M_SphereGorski= " << mg << endl;
|
---|
98 |
|
---|
99 | SphereGorski<float> outgs(mg);
|
---|
100 | cout << " Creating Output Gorski Map NbPixels= " << outgs.NbPixels() << endl;
|
---|
101 | outgs.SetPixels(0.);
|
---|
102 |
|
---|
103 | // Decoding detection pass-band filter
|
---|
104 | double nu0 = dc.DParam("FILTER", 0, 10.);
|
---|
105 | double s = dc.DParam("FILTER", 1, 1.);
|
---|
106 | double a = dc.DParam("FILTER", 2, 1.);
|
---|
107 | double numin = dc.DParam("FILTER", 3, 0.1);
|
---|
108 | double numax = dc.DParam("FILTER", 4, 9999);
|
---|
109 | GaussianFilter filt(nu0, s, a, numin, numax);
|
---|
110 | cout << " Filter decoded - Created " << endl;
|
---|
111 | cout << filt << endl;
|
---|
112 |
|
---|
113 | PrtTim(" After FilterCreation ");
|
---|
114 | }
|
---|
115 |
|
---|
116 | catch (PException exc) {
|
---|
117 | msg = exc.Msg();
|
---|
118 | cerr << " !!!! skymixer - Catched exception - Msg= " << exc.Msg() << endl;
|
---|
119 | rc = 70;
|
---|
120 | }
|
---|
121 |
|
---|
122 |
|
---|
123 | problem:
|
---|
124 | if (rc == 0) return(0);
|
---|
125 | cerr << " Error condition -> Rc= " << rc << endl;
|
---|
126 | cerr << " Msg= " << msg << endl;
|
---|
127 | return(rc);
|
---|
128 | }
|
---|
129 |
|
---|
130 | // template <class T>
|
---|
131 | void addComponent(SpectralResponse& sr, PixelMap<float>& finalMap,
|
---|
132 | PixelMap<float>& mapToAdd, RadSpectra& rs, double K)
|
---|
133 | {
|
---|
134 | // finalMap = finalMap + coeff* mapToAdd
|
---|
135 | // coeff = convolution of sr and rs
|
---|
136 | // compute the coefficient corresponding to mapToAdd
|
---|
137 | if (finalMap.NbPixels() != mapToAdd.NbPixels())
|
---|
138 | throw SzMismatchError("addComponent()/Error: Unequal number of Input/Output map pixels");
|
---|
139 | double coeff = rs.filteredIntegratedFlux(sr) * K;
|
---|
140 | for(int i=0; i<finalMap.NbPixels(); i++)
|
---|
141 | {
|
---|
142 | finalMap(i) += coeff * mapToAdd(i);
|
---|
143 | }
|
---|
144 | }
|
---|
145 |
|
---|
146 | void addComponent(SpectralResponse& sr, PixelMap<double>& finalMap,
|
---|
147 | PixelMap<double>& mapToAdd, RadSpectra& rs, double K)
|
---|
148 | {
|
---|
149 | // finalMap = finalMap + coeff* mapToAdd
|
---|
150 | // coeff = convolution of sr and rs
|
---|
151 | // compute the coefficient corresponding to mapToAdd
|
---|
152 | if (finalMap.NbPixels() != mapToAdd.NbPixels())
|
---|
153 | throw SzMismatchError("addComponent()/Error: Unequal number of Input/Output map pixels");
|
---|
154 | double coeff = rs.filteredIntegratedFlux(sr) * K;
|
---|
155 | for(int i=0; i<finalMap.NbPixels(); i++)
|
---|
156 | {
|
---|
157 | finalMap(i) += coeff * mapToAdd(i);
|
---|
158 | }
|
---|
159 | }
|
---|