1 | #include "machdefs.h"
|
---|
2 | #include <stdio.h>
|
---|
3 | #include <stdlib.h>
|
---|
4 | #include <iostream.h>
|
---|
5 | #include <math.h>
|
---|
6 |
|
---|
7 | #include <typeinfo>
|
---|
8 | #include <vector>
|
---|
9 | #include <string>
|
---|
10 |
|
---|
11 | #include "piacmd.h"
|
---|
12 | #include "nobjmgr.h"
|
---|
13 | #include "pistdimgapp.h"
|
---|
14 | #include "servnobjm.h"
|
---|
15 | #include "pidrawer.h"
|
---|
16 | #include "nomgadapter.h"
|
---|
17 |
|
---|
18 | #include "tvector.h"
|
---|
19 | #include "ntuple.h"
|
---|
20 | #include "slinparbuff.h"
|
---|
21 | #include "localmap.h"
|
---|
22 | #include "spherehealpix.h"
|
---|
23 | #include "spherethetaphi.h"
|
---|
24 | #include "sphericaltransformserver.h"
|
---|
25 |
|
---|
26 | extern "C" {
|
---|
27 | void skymapmodule_init();
|
---|
28 | void skymapmodule_end();
|
---|
29 | }
|
---|
30 |
|
---|
31 | class skymapmoduleExecutor : public CmdExecutor {
|
---|
32 | public:
|
---|
33 | enum {UnKnown=(uint_2) 0,
|
---|
34 | TypeR8=(uint_2) 16, TypeR4=(uint_2) 32,
|
---|
35 | Spherical=(uint_2) 1, HealPix=(uint_2) 2, ThetaPhi=(uint_2) 4,
|
---|
36 | Spherical8=(uint_2) Spherical|TypeR8,
|
---|
37 | Spherical4=(uint_2) Spherical|TypeR4,
|
---|
38 | HealPix8 =(uint_2) Spherical|HealPix|TypeR8,
|
---|
39 | HealPix4 =(uint_2) Spherical|HealPix|TypeR4,
|
---|
40 | ThetaPhi8 =(uint_2) Spherical|ThetaPhi|TypeR8,
|
---|
41 | ThetaPhi4 =(uint_2) Spherical|ThetaPhi|TypeR4};
|
---|
42 |
|
---|
43 | skymapmoduleExecutor();
|
---|
44 | virtual ~skymapmoduleExecutor();
|
---|
45 | virtual int Execute(string& keyw, vector<string>& args, string& toks);
|
---|
46 |
|
---|
47 | void TypeMap(vector<string>& tokens);
|
---|
48 | void Map2Double(vector<string>& tokens);
|
---|
49 | void Map2Float(vector<string>& tokens);
|
---|
50 | void Map2Map(vector<string>& tokens);
|
---|
51 | void MapMult(vector<string>& tokens);
|
---|
52 | void MapCover(vector<string>& tokens);
|
---|
53 | void Map2Cl(vector<string>& tokens);
|
---|
54 | void Cl2Map(vector<string>& tokens);
|
---|
55 | void Map2Alm(vector<string>& tokens);
|
---|
56 | void Alm2Map(vector<string>& tokens);
|
---|
57 | void CrMapMask(vector<string>& tokens);
|
---|
58 | void CrMaskFrMap(vector<string>& tokens);
|
---|
59 | void MaskMap(vector<string>& tokens);
|
---|
60 | void MapProj(vector<string>& tokens);
|
---|
61 | void Map2Local(vector<string>& tokens);
|
---|
62 | void MapOper(vector<string>& tokens);
|
---|
63 | void MapStat(vector<string>& tokens);
|
---|
64 | void Alm2Cl(vector<string>& tokens);
|
---|
65 | void Cl2llCl(vector<string>& tokens);
|
---|
66 | void ClMean(vector<string>& tokens);
|
---|
67 | void ClMult(vector<string>& tokens);
|
---|
68 | void ClOper(vector<string>& tokens);
|
---|
69 | void ClRebin(vector<string>& tokens);
|
---|
70 | void VarOper(vector<string>& tokens);
|
---|
71 | protected:
|
---|
72 | void SetTypeMap(vector<string>& tokens);
|
---|
73 | bool IsNSideGood(int_4 nside);
|
---|
74 | void GetNSideGood(int_4 &nside);
|
---|
75 | uint_2 typemap(AnyDataObj* obj);
|
---|
76 |
|
---|
77 | uint_2 DefTypMap;
|
---|
78 | };
|
---|
79 |
|
---|
80 | /* --Methode-- */
|
---|
81 | skymapmoduleExecutor::skymapmoduleExecutor()
|
---|
82 | {
|
---|
83 | PIACmd * mpiac;
|
---|
84 | NamedObjMgr omg;
|
---|
85 | mpiac = omg.GetImgApp()->CmdInterpreter();
|
---|
86 |
|
---|
87 | string hgrp = "SkyMapCmd";
|
---|
88 | string kw,usage;
|
---|
89 |
|
---|
90 | kw = "settypemap";
|
---|
91 | usage = "Set le type de map(double) par default";
|
---|
92 | usage += "\n Usage: settypemap type";
|
---|
93 | usage += "\n type= H for Healpix (default)";
|
---|
94 | usage += "\n T for ThetaPhi";
|
---|
95 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
96 |
|
---|
97 | kw = "typemap";
|
---|
98 | usage = "Imprime le type de map";
|
---|
99 | usage += "\n Usage: typemap map";
|
---|
100 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
101 |
|
---|
102 | kw = "map2double";
|
---|
103 | usage = "Convert a float map to a double map";
|
---|
104 | usage += "\n Usage: map2double map(float)";
|
---|
105 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
106 |
|
---|
107 | kw = "map2float";
|
---|
108 | usage = "Convert a double map to a float map";
|
---|
109 | usage += "\n Usage: map2float map(double)";
|
---|
110 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
111 |
|
---|
112 | kw = "map2map";
|
---|
113 | usage = "Convert a map(double) into an other map type";
|
---|
114 | usage += "\n Usage: map2map map(double) type [nside]";
|
---|
115 | usage += "\n type= H for Healpix";
|
---|
116 | usage += "\n T for ThetaPhi";
|
---|
117 | usage += "\n if nside <=1 use nside from map";
|
---|
118 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
119 |
|
---|
120 | kw = "mapmult";
|
---|
121 | usage = "Multiply a map(double) by a constant";
|
---|
122 | usage += "\n Usage: mapmult map(double) cste";
|
---|
123 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
124 |
|
---|
125 | kw = "mapcover";
|
---|
126 | usage = "Print the covering of a map(double)";
|
---|
127 | usage += "\n Usage: mapcover map(double) v1,v2 [varname]";
|
---|
128 | usage += "\n v1,v2: good pixels have v1<=val<=v2 (def=0.99,1.01)";
|
---|
129 | usage += "\n (use default (0.99,1.01): \"!\")";
|
---|
130 | usage += "\n $varname: percent of sky covering";
|
---|
131 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
132 |
|
---|
133 | kw = "map2cl";
|
---|
134 | usage = "SkyMap map(double) to Cl";
|
---|
135 | usage += "\n Usage: map2cl map(double) clvec [lmax] [niter]";
|
---|
136 | usage += "\n lmax: if <=0 or \"!\" use default (3*nside-1)";
|
---|
137 | usage += "\n niter: number of iterations (<=0 or def=3)";
|
---|
138 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
139 |
|
---|
140 | kw = "cl2map";
|
---|
141 | usage = "Generate SkyMap map(double) from Cl";
|
---|
142 | usage += "\n Usage: cl2map clvec map(double) nside [fwhm]";
|
---|
143 | usage += "\n (see command settypemap)";
|
---|
144 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
145 |
|
---|
146 | kw = "map2alm";
|
---|
147 | usage = "SkyMap map(double) to Alm";
|
---|
148 | usage += "\n Usage: map2alm map(double) almmat [lmax] [niter]";
|
---|
149 | usage += "\n lmax: if <=0 or \"!\" use default (3*nside-1)";
|
---|
150 | usage += "\n niter: number of iterations (<=0 or def=3)";
|
---|
151 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
152 |
|
---|
153 | kw = "alm2map";
|
---|
154 | usage = "Generate SkyMap map(double) from Alm";
|
---|
155 | usage += "\n Usage: alm2map almmat map(double) nside";
|
---|
156 | usage += "\n (see command settypemap)";
|
---|
157 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
158 |
|
---|
159 | kw = "crmapmask";
|
---|
160 | usage = "Create a map mask(double) (nside) between latitudes lat1,lat2 longitudes lon1,lon2";
|
---|
161 | usage += "\n Usage: crmapmask mapmsk(double) nside lat1,lat2 lon1,lon2 [valmsk,valnomsk]";
|
---|
162 | usage += "\n mask pixels between [lat1,lat2] ([-90,90] in degrees)";
|
---|
163 | usage += "\n and [lon1,lon2] ([0,360[ in degrees)";
|
---|
164 | usage += "\n (for no mask \"!\")";
|
---|
165 | usage += "\n valmsk=value to be written into masked pixels (def=0)";
|
---|
166 | usage += "\n valnomsk=value to be written into unmasked pixels (def=1)";
|
---|
167 | usage += "\n (see command settypemap)";
|
---|
168 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
169 |
|
---|
170 | kw = "crmaskfrmap";
|
---|
171 | usage = "Create a map mask(double) (nside) relative to an other map(double) pixels values";
|
---|
172 | usage += "\n Usage: crmaskfrmap mapmsk(double) nside map(double) v1,v2 [valmsk,valnomsk]";
|
---|
173 | usage += "\n mask if v1<mapmsk(i)<v2";
|
---|
174 | usage += "\n valmsk=value to be written into masked pixels (def=0)";
|
---|
175 | usage += "\n valnomsk=value to be written into unmasked pixels (def=1)";
|
---|
176 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
177 |
|
---|
178 | kw = "maskmap";
|
---|
179 | usage = "Mask a map(double) with a mask map(double)";
|
---|
180 | usage += "\n Usage: maskmap map msk";
|
---|
181 | usage += "\n operation is map(i) *= msk(theta,phi)";
|
---|
182 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
183 |
|
---|
184 | kw = "maproj";
|
---|
185 | usage = "Project a map(double) into an other one";
|
---|
186 | usage += "\n Usage: maproj map(double) mapproj(double) [nside]";
|
---|
187 | usage += "\n Create mapproj(nside) and project map into mapproj";
|
---|
188 | usage += "\n (use \"maproj map mapproj\" to make a copy)";
|
---|
189 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
190 |
|
---|
191 | kw = "map2local";
|
---|
192 | usage = "Project a map(double) into a local map(double)";
|
---|
193 | usage += "\n Usage: map2local map(double) localmap(double) nx,ny angleX,angleY phi0,theta0 [x0,y0] [angle]";
|
---|
194 | usage += "\n nx,ny: number of pixels in x(col),y(row) direction";
|
---|
195 | usage += "\n X-axis==phi, Y-axis==theta";
|
---|
196 | usage += "\n angleX,angleY: total angle aperture in x,y direction (degrees)";
|
---|
197 | usage += "\n phi0,theta0: define origin in phi,theta (degrees)";
|
---|
198 | usage += "\n x0,y0: map phi0,theta0 to pixel x0,y0 (\"!\" or def=middle of the localmap)";
|
---|
199 | usage += "\n angle: angle (degrees) of rotation between x-axis of map-coordinate system";
|
---|
200 | usage += "\n and the tangent to parallel on the sphere (def: 0.)";
|
---|
201 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
202 |
|
---|
203 | kw = "mapop";
|
---|
204 | usage = "operation on a map(double)";
|
---|
205 | usage += "\n Usage: mapop map(double) op1 map1(double) [op2 map2(double)] [op2 map3(double)] [...]";
|
---|
206 | usage += "\n Do \"map op1= map1\", \"map op2=map2\", ...";
|
---|
207 | usage += "\n where op = +,-,*,/";
|
---|
208 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
209 |
|
---|
210 | kw = "mapstat";
|
---|
211 | usage = "Statistics from a map(double)";
|
---|
212 | usage += "\n Usage: mapstat map(double) [msk(double)] [meanvarname] [sigmavarname]";
|
---|
213 | usage += "\n msk = mask sphere used as weight";
|
---|
214 | usage += "\n if msk(i)<=0 do not use that pixel";
|
---|
215 | usage += "\n if msk(i)>0 use that pixel with weight msk(i)";
|
---|
216 | usage += "\n msk = \"!\" means no mask sphere";
|
---|
217 | usage += "\n meanvarname = variable name to store mean";
|
---|
218 | usage += "\n sigmavarname = variable name to store sigma";
|
---|
219 | usage += "\n (\"!\" means do not store)";
|
---|
220 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
221 |
|
---|
222 | kw = "alm2cl";
|
---|
223 | usage = "Project alm to cl";
|
---|
224 | usage += "\n Usage: alm2cl alm cl";
|
---|
225 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
226 |
|
---|
227 | kw = "cl2llcl";
|
---|
228 | usage = "Project cl to l*(l+1)*cl";
|
---|
229 | usage += "\n Usage: cl2llcl cl llcl";
|
---|
230 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
231 |
|
---|
232 | kw = "clmean";
|
---|
233 | usage = "Compute mean for a cl vector";
|
---|
234 | usage += "\n Usage: clmean cl imin,imax [meanvarname]";
|
---|
235 | usage += "\n imin,imax = compute between these indices";
|
---|
236 | usage += "\n meanvarname = variable name to store mean";
|
---|
237 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
238 |
|
---|
239 | kw = "clmult";
|
---|
240 | usage = "Multiply a cl by a constant";
|
---|
241 | usage += "\n Usage: clmult cl val";
|
---|
242 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
243 |
|
---|
244 | kw = "clop";
|
---|
245 | usage = "operation on a cl";
|
---|
246 | usage += "\n Usage: clop cl(double) op1 cl1(double) [op2 cl2(double)] [op2 cl3(double)] [...]";
|
---|
247 | usage += "\n Do \"cl op1= cl1\", \"cl op2=cl2\", ...";
|
---|
248 | usage += "\n where op = +,-,*,/";
|
---|
249 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
250 |
|
---|
251 | kw = "clrebin";
|
---|
252 | usage = "rebin a cl into an ntuple";
|
---|
253 | usage += "\n Usage: clrebin cl ntuple nbin,bin0";
|
---|
254 | usage += "\n nbin: rebin by nbin";
|
---|
255 | usage += "\n bin0: begin rebinning at bin bin0 (def=0)";
|
---|
256 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
257 |
|
---|
258 | kw = "varop";
|
---|
259 | usage = "operation on variables";
|
---|
260 | usage += "\n Usage: varop var1 op var2 [resultvarname]";
|
---|
261 | usage += "\n Do result = var1 op var2";
|
---|
262 | usage += "\n where op = +,-,*,/,^(pow),exp,sqrt,log,log10";
|
---|
263 | usage += "\n resultvarname = variable name to store the result";
|
---|
264 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
265 |
|
---|
266 | DefTypMap = HealPix;
|
---|
267 | }
|
---|
268 |
|
---|
269 | /* --Methode-- */
|
---|
270 | skymapmoduleExecutor::~skymapmoduleExecutor()
|
---|
271 | {
|
---|
272 | }
|
---|
273 |
|
---|
274 | /* --Methode-- */
|
---|
275 | int skymapmoduleExecutor::Execute(string& kw, vector<string>& tokens, string& toks)
|
---|
276 | {
|
---|
277 |
|
---|
278 | if(kw == "settypemap") {
|
---|
279 | SetTypeMap(tokens);
|
---|
280 | } else if(kw == "typemap") {
|
---|
281 | if(tokens.size()<1) {
|
---|
282 | cout<<"Usage: typemap map"<<endl;
|
---|
283 | return(0);
|
---|
284 | }
|
---|
285 | TypeMap(tokens);
|
---|
286 | } else if(kw == "map2double") {
|
---|
287 | if(tokens.size()<1) {
|
---|
288 | cout<<"Usage: map2double map"<<endl;
|
---|
289 | return(0);
|
---|
290 | }
|
---|
291 | Map2Double(tokens);
|
---|
292 | } else if(kw == "map2float") {
|
---|
293 | if(tokens.size()<1) {
|
---|
294 | cout<<"Usage: map2float map"<<endl;
|
---|
295 | return(0);
|
---|
296 | }
|
---|
297 | Map2Float(tokens);
|
---|
298 | } else if(kw == "map2map") {
|
---|
299 | if(tokens.size()<2) {
|
---|
300 | cout<<"Usage: map2map map type [nside]"<<endl;
|
---|
301 | return(0);
|
---|
302 | }
|
---|
303 | Map2Map(tokens);
|
---|
304 | } else if(kw == "mapmult") {
|
---|
305 | if(tokens.size()<2) {
|
---|
306 | cout<<"Usage: mapmult map cste"<<endl;
|
---|
307 | return(0);
|
---|
308 | }
|
---|
309 | MapMult(tokens);
|
---|
310 | } else if(kw == "mapcover") {
|
---|
311 | if(tokens.size()<1) {
|
---|
312 | cout<<"Usage: mapcover map v1,v2 [varname]"<<endl;
|
---|
313 | return(0);
|
---|
314 | }
|
---|
315 | MapCover(tokens);
|
---|
316 | } else if(kw == "map2cl") {
|
---|
317 | if(tokens.size()<2) {
|
---|
318 | cout<<"Usage: map2cl map clvec [lmax] [niter]"<<endl;
|
---|
319 | return(0);
|
---|
320 | }
|
---|
321 | Map2Cl(tokens);
|
---|
322 | } else if(kw == "cl2map") {
|
---|
323 | if(tokens.size()<2) {
|
---|
324 | cout<<"Usage: cl2map clvec map nside [fwhm]"<<endl;
|
---|
325 | return(0);
|
---|
326 | }
|
---|
327 | Cl2Map(tokens);
|
---|
328 | } else if(kw == "map2alm") {
|
---|
329 | if(tokens.size()<2) {
|
---|
330 | cout<<"Usage: map2alm map(double) almmat [lmax] [niter]"<<endl;
|
---|
331 | return(0);
|
---|
332 | }
|
---|
333 | Map2Alm(tokens);
|
---|
334 | } else if(kw == "alm2map") {
|
---|
335 | if(tokens.size()<3) {
|
---|
336 | cout<<"Usage: alm2map almmat map nside"<<endl;
|
---|
337 | return(0);
|
---|
338 | }
|
---|
339 | Alm2Map(tokens);
|
---|
340 | } else if(kw == "crmapmask") {
|
---|
341 | if(tokens.size()<2) {
|
---|
342 | cout<<"Usage: crmapmask mapmsk nside lat1,lat2 lon1,lon2 [valmsk,valnomsk]"<<endl;
|
---|
343 | return(0);
|
---|
344 | }
|
---|
345 | CrMapMask(tokens);
|
---|
346 | } else if(kw == "crmaskfrmap") {
|
---|
347 | if(tokens.size()<3) {
|
---|
348 | cout<<"Usage: crmaskfrmap mapmsk nside map(double) v1,v2 [valmsk,valnomsk]"<<endl;
|
---|
349 | return(0);
|
---|
350 | }
|
---|
351 | CrMaskFrMap(tokens);
|
---|
352 | } else if(kw == "maskmap") {
|
---|
353 | if(tokens.size()<2) {
|
---|
354 | cout<<"Usage: maskmap map msk"<<endl;
|
---|
355 | return(0);
|
---|
356 | }
|
---|
357 | MaskMap(tokens);
|
---|
358 | } else if(kw == "maproj") {
|
---|
359 | if(tokens.size()<2) {
|
---|
360 | cout<<"Usage: maproj map mapproj [nside]"<<endl;
|
---|
361 | return(0);
|
---|
362 | }
|
---|
363 | MapProj(tokens);
|
---|
364 | } else if(kw == "map2local") {
|
---|
365 | if(tokens.size()<5) {
|
---|
366 | cout<<"Usage: map2local map localmap nx,ny angleX,angleY phi0,theta0 [x0,y0] [angle]"<<endl;
|
---|
367 | return(0);
|
---|
368 | }
|
---|
369 | Map2Local(tokens);
|
---|
370 | } else if(kw == "mapop") {
|
---|
371 | if(tokens.size()<3) {
|
---|
372 | cout<<"Usage: mapop map op map1 [op map2] [op map3] [...]"<<endl;
|
---|
373 | return(0);
|
---|
374 | }
|
---|
375 | MapOper(tokens);
|
---|
376 | } else if(kw == "mapstat") {
|
---|
377 | if(tokens.size()<1) {
|
---|
378 | cout<<"Usage: Usage: mapstat map [msk] [meanvarname] [sigmavarname]"<<endl;
|
---|
379 | return(0);
|
---|
380 | }
|
---|
381 | MapStat(tokens);
|
---|
382 | } else if(kw == "alm2cl") {
|
---|
383 | if(tokens.size()<2) {
|
---|
384 | cout<<"Usage: alm2cl alm cl"<<endl;
|
---|
385 | return(0);
|
---|
386 | }
|
---|
387 | Alm2Cl(tokens);
|
---|
388 | } else if(kw == "cl2llcl") {
|
---|
389 | if(tokens.size()<2) {
|
---|
390 | cout<<"Usage: cl2llcl cl llcl"<<endl;
|
---|
391 | return(0);
|
---|
392 | }
|
---|
393 | Cl2llCl(tokens);
|
---|
394 | } else if(kw == "clmean") {
|
---|
395 | if(tokens.size()<1) {
|
---|
396 | cout<<"Usage: clmean cl imin,imax [meanvarname]"<<endl;
|
---|
397 | return(0);
|
---|
398 | }
|
---|
399 | ClMean(tokens);
|
---|
400 | } else if(kw == "clmult") {
|
---|
401 | if(tokens.size()<1) {
|
---|
402 | cout<<"Usage: clmult cl val"<<endl;
|
---|
403 | return(0);
|
---|
404 | }
|
---|
405 | ClMult(tokens);
|
---|
406 | } else if(kw == "clop") {
|
---|
407 | if(tokens.size()<3) {
|
---|
408 | cout<<"Usage: clop cl op1 cl1 [op2 cl2] [op2 cl3] [...]"<<endl;
|
---|
409 | return(0);
|
---|
410 | }
|
---|
411 | ClOper(tokens);
|
---|
412 | } else if(kw == "clrebin") {
|
---|
413 | if(tokens.size()<2) {
|
---|
414 | cout<<"Usage: clrebin cl ntuple nbin,bin0"<<endl;
|
---|
415 | return(0);
|
---|
416 | }
|
---|
417 | ClRebin(tokens);
|
---|
418 | } else if(kw == "varop") {
|
---|
419 | if(tokens.size()<2) {
|
---|
420 | cout<<"Usage: varop var1 op var2 [resultvarname]"<<endl;
|
---|
421 | return(0);
|
---|
422 | }
|
---|
423 | VarOper(tokens);
|
---|
424 | }
|
---|
425 |
|
---|
426 | return(0);
|
---|
427 | }
|
---|
428 |
|
---|
429 | /* --Methode-- */
|
---|
430 | void skymapmoduleExecutor::TypeMap(vector<string>& tokens)
|
---|
431 | {
|
---|
432 | NamedObjMgr omg;
|
---|
433 | AnyDataObj* obj=omg.GetObj(tokens[0]);
|
---|
434 | uint_2 t = typemap(obj);
|
---|
435 | if(t==UnKnown) {cout<<"TypeMap: UnKnown"<<endl; return;}
|
---|
436 |
|
---|
437 | int nside = 0;
|
---|
438 | if(t&TypeR8) {
|
---|
439 | SphericalMap<r_8>* map = dynamic_cast<SphericalMap<r_8>*>(obj);
|
---|
440 | nside = map->SizeIndex();
|
---|
441 | } else if(t&TypeR4) {
|
---|
442 | SphericalMap<r_4>* map = dynamic_cast<SphericalMap<r_4>*>(obj);
|
---|
443 | nside = map->SizeIndex();
|
---|
444 | }
|
---|
445 |
|
---|
446 | string dum = "";
|
---|
447 | if(t==HealPix8) dum = "SphereHEALPix<r_8>";
|
---|
448 | else if(t==HealPix4) dum = "SphereHEALPix<r_4>";
|
---|
449 | else if(t==ThetaPhi8) dum = "SphereThetaPhi<r_8>";
|
---|
450 | else if(t==ThetaPhi4) dum = "SphereThetaPhi<r_4>";
|
---|
451 | else if(t==Spherical8) dum = "SphericalMap<r_8>";
|
---|
452 | else if(t==Spherical4) dum = "SphericalMap<r_4>";
|
---|
453 |
|
---|
454 | cout<<"TypeMap: "<<dum<<" nside="<<nside<<endl;
|
---|
455 | }
|
---|
456 |
|
---|
457 | /* --Methode-- */
|
---|
458 | void skymapmoduleExecutor::Map2Double(vector<string>& tokens)
|
---|
459 | {
|
---|
460 | NamedObjMgr omg;
|
---|
461 | AnyDataObj* obj=omg.GetObj(tokens[0]);
|
---|
462 | if(obj==NULL) {
|
---|
463 | cout<<"Error: Pas d'objet de nom "<<tokens[0]<<endl;
|
---|
464 | return;
|
---|
465 | }
|
---|
466 | SphericalMap<r_4>* map = dynamic_cast<SphericalMap<r_4>*>(obj);
|
---|
467 | if(map==NULL) {
|
---|
468 | cout<<"Error: "<<tokens[0]<<" is not a SphericalMap<r_4>"<<endl;
|
---|
469 | return;
|
---|
470 | }
|
---|
471 | uint_2 t = typemap(obj);
|
---|
472 | int_4 nside = map->SizeIndex();
|
---|
473 |
|
---|
474 | SphericalMap<r_8>* map8 = NULL;
|
---|
475 | if(t&HealPix) map8 = new SphereHEALPix<r_8>(nside);
|
---|
476 | else if(t&ThetaPhi) map8 = new SphereThetaPhi<r_8>(nside);
|
---|
477 | else return;
|
---|
478 |
|
---|
479 | cout<<"Map2Double: converting to double "<<tokens[0]<<" nside="<<nside<<endl;
|
---|
480 | for(int_4 i=0;i<map8->NbPixels();i++) (*map8)(i) = (r_8) (*map)(i);
|
---|
481 |
|
---|
482 | omg.AddObj(map8,tokens[0]);
|
---|
483 | }
|
---|
484 |
|
---|
485 | /* --Methode-- */
|
---|
486 | void skymapmoduleExecutor::Map2Float(vector<string>& tokens)
|
---|
487 | {
|
---|
488 | NamedObjMgr omg;
|
---|
489 | AnyDataObj* obj=omg.GetObj(tokens[0]);
|
---|
490 | if(obj==NULL) {
|
---|
491 | cout<<"Error: Pas d'objet de nom "<<tokens[0]<<endl;
|
---|
492 | return;
|
---|
493 | }
|
---|
494 | SphericalMap<r_8>* map = dynamic_cast<SphericalMap<r_8>*>(obj);
|
---|
495 | if(map==NULL) {
|
---|
496 | cout<<"Error: "<<tokens[0]<<" is not a SphericalMap<r_8>"<<endl;
|
---|
497 | return;
|
---|
498 | }
|
---|
499 | uint_2 t = typemap(obj);
|
---|
500 | int_4 nside = map->SizeIndex();
|
---|
501 |
|
---|
502 | SphericalMap<r_4>* map4 = NULL;
|
---|
503 | if(t&HealPix) map4 = new SphereHEALPix<r_4>(nside);
|
---|
504 | else if(t&ThetaPhi) map4 = new SphereThetaPhi<r_4>(nside);
|
---|
505 | else return;
|
---|
506 |
|
---|
507 | cout<<"Map2Float: converting to float "<<tokens[0]<<" nside="<<nside<<endl;
|
---|
508 | for(int_4 i=0;i<map4->NbPixels();i++) (*map4)(i) = (r_4) (*map)(i);
|
---|
509 |
|
---|
510 | omg.AddObj(map4,tokens[0]);
|
---|
511 | }
|
---|
512 |
|
---|
513 | /* --Methode-- */
|
---|
514 | void skymapmoduleExecutor::Map2Map(vector<string>& tokens)
|
---|
515 | {
|
---|
516 | NamedObjMgr omg;
|
---|
517 | AnyDataObj* obj=omg.GetObj(tokens[0]);
|
---|
518 | if(obj==NULL) {
|
---|
519 | cout<<"Error: Pas d'objet de nom "<<tokens[0]<<endl;
|
---|
520 | return;
|
---|
521 | }
|
---|
522 | SphericalMap<r_8>* map = dynamic_cast<SphericalMap<r_8>*>(obj);
|
---|
523 | if(map==NULL) {
|
---|
524 | cout<<"Error: "<<tokens[0]<<" is not a SphericalMap<r_8>"<<endl;
|
---|
525 | return;
|
---|
526 | }
|
---|
527 | uint_2 t = typemap(obj);
|
---|
528 | int_4 nside = map->SizeIndex();
|
---|
529 |
|
---|
530 | uint_2 tomap = UnKnown;
|
---|
531 | if(toupper(tokens[1][0])=='H') tomap = HealPix;
|
---|
532 | else if(toupper(tokens[1][0])=='T') tomap = ThetaPhi;
|
---|
533 | else {cout<<"unkown map type "<<(char)toupper(tokens[1][0])<<" (H or T)!"<<endl; return;}
|
---|
534 | if(t&tomap) {cout<<"map of same type, no conversion done"<<endl; return;}
|
---|
535 |
|
---|
536 | int_4 tonside = nside;
|
---|
537 | if(tokens.size()>2) tonside = atoi(tokens[2].c_str());
|
---|
538 | else {
|
---|
539 | if(tomap&HealPix) {tonside=int(nside/1.5); GetNSideGood(tonside);}
|
---|
540 | else tonside=int(map->NbThetaSlices()/2.5);
|
---|
541 | }
|
---|
542 | if(tomap&HealPix && !IsNSideGood(tonside))
|
---|
543 | {cout<<"Bad nside for Healpix "<<tonside<<endl; return;}
|
---|
544 |
|
---|
545 | SphericalMap<r_8>* map8 = NULL;
|
---|
546 | if(tomap&HealPix) map8 = new SphereHEALPix<r_8>(tonside);
|
---|
547 | else if(tomap&ThetaPhi) map8 = new SphereThetaPhi<r_8>(tonside);
|
---|
548 | else return;
|
---|
549 |
|
---|
550 | cout<<"Map2Map: convert "<<tokens[0]<<" nside="<<nside
|
---|
551 | <<" to type "<<tokens[1]<<" tonside="<<tonside
|
---|
552 | <<" ntheta="<<map->NbThetaSlices()<<" -> "<<map8->NbThetaSlices()<<endl;
|
---|
553 |
|
---|
554 | for(int_4 i=0;i<map8->NbPixels();i++) {
|
---|
555 | double theta,phi; map8->PixThetaPhi(i,theta,phi);
|
---|
556 | int_4 ip = map->PixIndexSph(theta,phi);
|
---|
557 | if(ip<0 || ip>=map->NbPixels()) continue;
|
---|
558 | (*map8)(i)=(*map)(ip);
|
---|
559 | }
|
---|
560 |
|
---|
561 | omg.AddObj(map8,tokens[0]);
|
---|
562 | }
|
---|
563 |
|
---|
564 | /* --Methode-- */
|
---|
565 | void skymapmoduleExecutor::MapMult(vector<string>& tokens)
|
---|
566 | {
|
---|
567 | NamedObjMgr omg;
|
---|
568 | AnyDataObj* obj=omg.GetObj(tokens[0]);
|
---|
569 | if(obj==NULL) {
|
---|
570 | cout<<"Error: Pas d'objet de nom "<<tokens[0]<<endl;
|
---|
571 | return;
|
---|
572 | }
|
---|
573 | SphericalMap<r_8>* map = dynamic_cast<SphericalMap<r_8>*>(obj);
|
---|
574 | if(map==NULL) {
|
---|
575 | cout<<"Error: "<<tokens[0]<<" is not a SphericalMap<r_8>"<<endl;
|
---|
576 | return;
|
---|
577 | }
|
---|
578 | double v = atof(tokens[1].c_str());
|
---|
579 | cout<<"MapMult: Multiply "<<tokens[0]<<" by "<<v<<endl;
|
---|
580 | for(int_4 i=0;i<map->NbPixels();i++) (*map)(i) *= v;
|
---|
581 | }
|
---|
582 |
|
---|
583 | /* --Methode-- */
|
---|
584 | void skymapmoduleExecutor::MapCover(vector<string>& tokens)
|
---|
585 | {
|
---|
586 | NamedObjMgr omg;
|
---|
587 | AnyDataObj* obj=omg.GetObj(tokens[0]);
|
---|
588 | if(obj==NULL) {
|
---|
589 | cout<<"Error: Pas d'objet de nom "<<tokens[0]<<endl;
|
---|
590 | return;
|
---|
591 | }
|
---|
592 | SphericalMap<r_8>* map = dynamic_cast<SphericalMap<r_8>*>(obj);
|
---|
593 | if(map==NULL) {
|
---|
594 | cout<<"Error: "<<tokens[0]<<" is not a SphericalMap<r_8>"<<endl;
|
---|
595 | return;
|
---|
596 | }
|
---|
597 |
|
---|
598 | double v1=0.99, v2=1.01;
|
---|
599 | if(tokens.size()>1) if(tokens[1][0]!='!')
|
---|
600 | sscanf(tokens[1].c_str(),"%lf,%lf",&v1,&v2);
|
---|
601 |
|
---|
602 | cout<<"MapCover: "<<tokens[0]<<" good px=["<<v1<<","<<v2<<"]"<<endl;
|
---|
603 |
|
---|
604 | int_4 ngood=0;
|
---|
605 | for(int_4 i=0;i<map->NbPixels();i++)
|
---|
606 | if(v1<=(*map)(i) && (*map)(i)<=v2) ngood++;
|
---|
607 | double per = (double)ngood/(double)map->NbPixels();
|
---|
608 | cout<<"NGood="<<ngood<<" NTot="<<map->NbPixels()
|
---|
609 | <<" -> "<<100.*per<<" %";
|
---|
610 | if(tokens.size()>2) {
|
---|
611 | if(omg.HasVar(tokens[2])) omg.DeleteVar(tokens[2]);
|
---|
612 | char str[128]; sprintf(str,"%g",per);
|
---|
613 | omg.SetVar(tokens[2],(string)str);
|
---|
614 | cout<<" stored into $"<<tokens[2];
|
---|
615 | }
|
---|
616 | cout<<endl;
|
---|
617 | }
|
---|
618 |
|
---|
619 | /* --Methode-- */
|
---|
620 | void skymapmoduleExecutor::Map2Cl(vector<string>& tokens)
|
---|
621 | {
|
---|
622 | NamedObjMgr omg;
|
---|
623 |
|
---|
624 | int_4 lmax=0, niter=3;
|
---|
625 | if(tokens.size()>2) if(tokens[2][0]!='!')
|
---|
626 | lmax = atoi(tokens[2].c_str());
|
---|
627 | if(tokens.size()>3) niter = atoi(tokens[3].c_str());
|
---|
628 | if(niter<=0) niter = 3;
|
---|
629 |
|
---|
630 | AnyDataObj* obj=omg.GetObj(tokens[0]);
|
---|
631 | if(obj==NULL) {
|
---|
632 | cout<<"Error: Pas d'objet de nom "<<tokens[0]<<endl;
|
---|
633 | return;
|
---|
634 | }
|
---|
635 | SphericalMap<r_8>* map = dynamic_cast<SphericalMap<r_8>*>(obj);
|
---|
636 | if(map==NULL) {
|
---|
637 | cout<<"Error: "<<tokens[0]<<" is not a SphericalMap<r_8>"<<endl;
|
---|
638 | return;
|
---|
639 | }
|
---|
640 | uint_2 t = typemap(obj);
|
---|
641 |
|
---|
642 | SphericalTransformServer<r_8> ylmserver;
|
---|
643 |
|
---|
644 | int_4 nside = map->SizeIndex();
|
---|
645 | if(lmax<=0) lmax = 3*nside-1;
|
---|
646 |
|
---|
647 | SphericalMap<r_8>* tmpmap = NULL;
|
---|
648 | if(t&HealPix) tmpmap = new SphereHEALPix<r_8>(*((SphereHEALPix<r_8>*)map),false);
|
---|
649 | else if(t&ThetaPhi) tmpmap = new SphereThetaPhi<r_8>(*((SphereThetaPhi<r_8>*)map),false);
|
---|
650 | else return;
|
---|
651 |
|
---|
652 | cout<<"Map2Cl: "<<tokens[0]<<"(nside="<<nside
|
---|
653 | <<") lmax="<<lmax<<" niter="<<niter<<" -> "<<tokens[1];
|
---|
654 |
|
---|
655 | TVector<r_8> cltmp = ylmserver.DecomposeToCl(*tmpmap,lmax,0.,niter);
|
---|
656 | cout<<"("<<cltmp.Size()<<")"<<endl;
|
---|
657 | delete tmpmap;
|
---|
658 |
|
---|
659 | omg.AddObj(cltmp,tokens[1]);
|
---|
660 | }
|
---|
661 |
|
---|
662 | /* --Methode-- */
|
---|
663 | void skymapmoduleExecutor::Cl2Map(vector<string>& tokens)
|
---|
664 | {
|
---|
665 | NamedObjMgr omg;
|
---|
666 |
|
---|
667 | AnyDataObj* obj=omg.GetObj(tokens[0]);
|
---|
668 | if(obj==NULL) {
|
---|
669 | cout<<"Error: Pas d'objet de nom "<<tokens[0]<<endl;
|
---|
670 | return;
|
---|
671 | }
|
---|
672 | TVector<r_8>* cl = dynamic_cast<TVector<r_8>*>(obj);
|
---|
673 | if(cl==NULL) {
|
---|
674 | cout<<"Error: "<<tokens[0]<<" is not a TVector<r_8>"<<endl;
|
---|
675 | return;
|
---|
676 | }
|
---|
677 |
|
---|
678 | int nside = 128;
|
---|
679 | if(tokens.size()>2) nside = atoi(tokens[2].c_str());
|
---|
680 | if(DefTypMap&HealPix && !IsNSideGood(nside))
|
---|
681 | {cout<<"Cl2Map: Bad nside for HealPix "<<nside<<endl; return;}
|
---|
682 |
|
---|
683 | double fwhm = 0.;
|
---|
684 | if(tokens.size()>3) fwhm = atof(tokens[3].c_str());
|
---|
685 |
|
---|
686 | SphericalMap<r_8>* map = NULL;
|
---|
687 | if(DefTypMap&HealPix) map = new SphereHEALPix<r_8>;
|
---|
688 | else if(DefTypMap&ThetaPhi) map = new SphereThetaPhi<r_8>;
|
---|
689 | else return;
|
---|
690 |
|
---|
691 | SphericalTransformServer<r_8> ylmserver;
|
---|
692 | cout<<"Cl2Map: Generate map "<<tokens[1]<<" with nside="<<nside
|
---|
693 | <<" from cl "<<tokens[0]<<"("<<cl->Size()<<")"
|
---|
694 | <<" with fwhm="<<fwhm<<endl;
|
---|
695 | ylmserver.GenerateFromCl(*map,nside,*cl,fwhm);
|
---|
696 |
|
---|
697 | omg.AddObj(map,tokens[1]);
|
---|
698 | }
|
---|
699 |
|
---|
700 | /* --Methode-- */
|
---|
701 | void skymapmoduleExecutor::Map2Alm(vector<string>& tokens)
|
---|
702 | {
|
---|
703 | NamedObjMgr omg;
|
---|
704 |
|
---|
705 | int_4 lmax=0, niter=3;
|
---|
706 | if(tokens.size()>2) if(tokens[2][0]!='!')
|
---|
707 | lmax = atoi(tokens[2].c_str());
|
---|
708 | if(tokens.size()>3) niter = atoi(tokens[3].c_str());
|
---|
709 | if(niter<=0) niter = 3;
|
---|
710 |
|
---|
711 | AnyDataObj* obj=omg.GetObj(tokens[0]);
|
---|
712 | if(obj==NULL) {
|
---|
713 | cout<<"Error: Pas d'objet de nom "<<tokens[0]<<endl;
|
---|
714 | return;
|
---|
715 | }
|
---|
716 | SphericalMap<r_8>* map = dynamic_cast<SphericalMap<r_8>*>(obj);
|
---|
717 | if(map==NULL) {
|
---|
718 | cout<<"Error: "<<tokens[0]<<" is not a SphericalMap<r_8>"<<endl;
|
---|
719 | return;
|
---|
720 | }
|
---|
721 | uint_2 t = typemap(obj);
|
---|
722 |
|
---|
723 | SphericalTransformServer<r_8> ylmserver;
|
---|
724 |
|
---|
725 | int_4 nside = map->SizeIndex();
|
---|
726 | if(lmax<=0) lmax = 3*nside-1;
|
---|
727 |
|
---|
728 | SphericalMap<r_8>* tmpmap = NULL;
|
---|
729 | if(t&HealPix) tmpmap = new SphereHEALPix<r_8>(*((SphereHEALPix<r_8>*)map),false);
|
---|
730 | else if(t&ThetaPhi) tmpmap = new SphereThetaPhi<r_8>(*((SphereThetaPhi<r_8>*)map),false);
|
---|
731 | else return;
|
---|
732 |
|
---|
733 | cout<<"Map2Alm: "<<tokens[0]<<"(nside="<<nside
|
---|
734 | <<") lmax="<<lmax<<" niter="<<niter<<" -> "<<tokens[1];
|
---|
735 |
|
---|
736 | Alm<r_8> almtmp;
|
---|
737 | ylmserver.DecomposeToAlm(*tmpmap,almtmp,lmax,0.,niter);
|
---|
738 | cout<<"("<<almtmp.rowNumber()<<")"<<endl;
|
---|
739 | delete tmpmap;
|
---|
740 |
|
---|
741 | int n = almtmp.rowNumber();
|
---|
742 | TMatrix< complex<r_8> >* alm = new TMatrix< complex<r_8> >(n,n);
|
---|
743 | *alm = (complex<r_8>)0.;
|
---|
744 | for(int i=0;i<n;i++) for(int j=0;j<=i;j++) (*alm)(i,j)=almtmp(i,j);
|
---|
745 | omg.AddObj(alm,tokens[1]);
|
---|
746 | }
|
---|
747 |
|
---|
748 | /* --Methode-- */
|
---|
749 | void skymapmoduleExecutor::Alm2Map(vector<string>& tokens)
|
---|
750 | {
|
---|
751 | NamedObjMgr omg;
|
---|
752 |
|
---|
753 | AnyDataObj* obj=omg.GetObj(tokens[0]);
|
---|
754 | if(obj==NULL) {
|
---|
755 | cout<<"Error: Pas d'objet de nom "<<tokens[0]<<endl;
|
---|
756 | return;
|
---|
757 | }
|
---|
758 | TMatrix< complex<r_8> >* almmat = dynamic_cast<TMatrix< complex<r_8> >*>(obj);
|
---|
759 | if(almmat==NULL) {
|
---|
760 | cout<<"Error: "<<tokens[0]<<" is not a TMatrix< complex<r_8> >"<<endl;
|
---|
761 | return;
|
---|
762 | }
|
---|
763 |
|
---|
764 | int lmax = almmat->NRows()-1;
|
---|
765 | Alm<r_8> alm(lmax);
|
---|
766 | alm = (complex<r_8>)0.;
|
---|
767 | for(int i=0;i<lmax+1;i++) for(int j=0;j<=i;j++) alm(i,j)=(*almmat)(i,j);
|
---|
768 |
|
---|
769 | int nside = 128;
|
---|
770 | if(tokens.size()>2) nside = atoi(tokens[2].c_str());
|
---|
771 | if(DefTypMap&HealPix && !IsNSideGood(nside))
|
---|
772 | {cout<<"Alm2Map: Bad nside for HealPix "<<nside<<endl; return;}
|
---|
773 |
|
---|
774 | SphericalMap<r_8>* map = NULL;
|
---|
775 | if(DefTypMap&HealPix) map = new SphereHEALPix<r_8>;
|
---|
776 | else if(DefTypMap&ThetaPhi) map = new SphereThetaPhi<r_8>;
|
---|
777 | else return;
|
---|
778 |
|
---|
779 | SphericalTransformServer<r_8> ylmserver;
|
---|
780 | cout<<"Alm2Map: Generate map "<<tokens[1]<<" with nside="<<nside
|
---|
781 | <<" from alm "<<tokens[0]<<"("<<alm.rowNumber()<<")"<<endl;
|
---|
782 | ylmserver.GenerateFromAlm(*map,nside,alm);
|
---|
783 |
|
---|
784 | omg.AddObj(map,tokens[1]);
|
---|
785 | }
|
---|
786 |
|
---|
787 | /* --Methode-- */
|
---|
788 | void skymapmoduleExecutor::CrMapMask(vector<string>& tokens)
|
---|
789 | {
|
---|
790 | NamedObjMgr omg;
|
---|
791 |
|
---|
792 | int_4 nside = atoi(tokens[1].c_str());
|
---|
793 | if(DefTypMap&HealPix && !IsNSideGood(nside))
|
---|
794 | {cout<<"CrMapMask: Bad nside "<<nside<<endl; return;}
|
---|
795 |
|
---|
796 | SphericalMap<r_8>* map = NULL;
|
---|
797 | if(DefTypMap&HealPix) map = new SphereHEALPix<r_8>(nside);
|
---|
798 | else if(DefTypMap&ThetaPhi) map = new SphereThetaPhi<r_8>(nside);
|
---|
799 | else return;
|
---|
800 |
|
---|
801 | bool lat=false, lon=false;
|
---|
802 | double lat1=-99., lat2=99., lon1=-999., lon2=999.;
|
---|
803 | if(tokens.size()>2) if(tokens[2][0]!='!')
|
---|
804 | {lat=true; sscanf(tokens[2].c_str(),"%lf,%lf",&lat1,&lat2);}
|
---|
805 | if(tokens.size()>3) if(tokens[3][0]!='!')
|
---|
806 | {lon=true; sscanf(tokens[3].c_str(),"%lf,%lf",&lon1,&lon2);}
|
---|
807 |
|
---|
808 | double valmsk=0., unvalmsk=1.;
|
---|
809 | if(tokens.size()>4) sscanf(tokens[4].c_str(),"%lf,%lf",&valmsk,&unvalmsk);
|
---|
810 |
|
---|
811 | cout<<"CrMapMask "<<tokens[0]<<" nside="<<nside;
|
---|
812 | if(lat) cout<<" for latitude in ["<<lat1<<","<<lat2<<"]";
|
---|
813 | if(lon) cout<<" for longitude in ["<<lon1<<","<<lon2<<"]";
|
---|
814 | cout<<" valmsk="<<valmsk<<" unvalmsk="<<unvalmsk<<endl;
|
---|
815 |
|
---|
816 | //Attention: conversion en co-latitude ==> inversion: [lat2,lat1]
|
---|
817 | lat1 = (90.-lat1)*M_PI/180.; lat2 = (90.-lat2)*M_PI/180.;
|
---|
818 | lon1 *= M_PI/180.; lon2 *= M_PI/180.;
|
---|
819 | for(int_4 i=0;i<map->NbPixels();i++) {
|
---|
820 | (*map)(i)=unvalmsk;
|
---|
821 | if(!lat && !lon) continue;
|
---|
822 | double theta,phi; map->PixThetaPhi(i,theta,phi);
|
---|
823 | if(lat && (theta<lat2 || lat1<theta)) continue;
|
---|
824 | if(lon && ( phi<lon1 || lon2<phi )) continue;
|
---|
825 | (*map)(i)=valmsk;
|
---|
826 | }
|
---|
827 |
|
---|
828 | omg.AddObj(map,tokens[0]);
|
---|
829 | }
|
---|
830 |
|
---|
831 | /* --Methode-- */
|
---|
832 | void skymapmoduleExecutor::CrMaskFrMap(vector<string>& tokens)
|
---|
833 | {
|
---|
834 | NamedObjMgr omg;
|
---|
835 |
|
---|
836 | AnyDataObj* obj=omg.GetObj(tokens[2]);
|
---|
837 | if(obj==NULL) {
|
---|
838 | cout<<"Error: Pas d'objet de nom "<<tokens[2]<<endl;
|
---|
839 | return;
|
---|
840 | }
|
---|
841 | SphericalMap<r_8>* map = dynamic_cast<SphericalMap<r_8>*>(obj);
|
---|
842 | if(map==NULL) {
|
---|
843 | cout<<"Error: "<<tokens[2]<<" is not a SphericalMap<r_8>"<<endl;
|
---|
844 | return;
|
---|
845 | }
|
---|
846 | uint_2 t = typemap(obj);
|
---|
847 |
|
---|
848 | int_4 nside = atoi(tokens[1].c_str());
|
---|
849 | if(nside<=1) return;
|
---|
850 | if(t&HealPix && !IsNSideGood(nside))
|
---|
851 | {cout<<"CrMapMask: Bad nside for HealPix "<<nside<<endl; return;}
|
---|
852 |
|
---|
853 | SphericalMap<r_8>* msk = NULL;
|
---|
854 | if(t&HealPix) msk = new SphereHEALPix<r_8>(nside);
|
---|
855 | else if(t&ThetaPhi) msk = new SphereThetaPhi<r_8>(nside);
|
---|
856 | else return;
|
---|
857 |
|
---|
858 | double v1=-1.e100, v2=1.e100;
|
---|
859 | if(tokens.size()>3) if(tokens[3][0]!='!')
|
---|
860 | sscanf(tokens[3].c_str(),"%lf,%lf",&v1,&v2);
|
---|
861 |
|
---|
862 | double valmsk=0., unvalmsk=1.;
|
---|
863 | if(tokens.size()>4) sscanf(tokens[4].c_str(),"%lf,%lf",&valmsk,&unvalmsk);
|
---|
864 |
|
---|
865 | cout<<"CrMaskFrMap "<<tokens[0]<<" nside="<<nside<<" with "<<tokens[2]<<endl
|
---|
866 | <<" for value in ["<<v1<<","<<v2<<"]"
|
---|
867 | <<" valmsk="<<valmsk<<" unvalmsk="<<unvalmsk<<endl;
|
---|
868 |
|
---|
869 | for(int_4 i=0;i<msk->NbPixels();i++) {
|
---|
870 | double theta,phi; msk->PixThetaPhi(i,theta,phi);
|
---|
871 | int_4 ip = map->PixIndexSph(theta,phi);
|
---|
872 | if(ip<0 || ip>=map->NbPixels()) continue;
|
---|
873 | double v = (*map)(ip);
|
---|
874 | if(v>v1 && v<v2) (*msk)(i)=valmsk;
|
---|
875 | else (*msk)(i)=unvalmsk;
|
---|
876 | }
|
---|
877 |
|
---|
878 | omg.AddObj(msk,tokens[0]);
|
---|
879 | }
|
---|
880 |
|
---|
881 | /* --Methode-- */
|
---|
882 | void skymapmoduleExecutor::MaskMap(vector<string>& tokens)
|
---|
883 | {
|
---|
884 | NamedObjMgr omg;
|
---|
885 |
|
---|
886 | AnyDataObj* obj=omg.GetObj(tokens[0]);
|
---|
887 | if(obj==NULL) {
|
---|
888 | cout<<"Error: Pas d'objet de nom "<<tokens[0]<<endl;
|
---|
889 | return;
|
---|
890 | }
|
---|
891 | SphericalMap<r_8>* map = dynamic_cast<SphericalMap<r_8>*>(obj);
|
---|
892 | if(map==NULL) {
|
---|
893 | cout<<"Error: "<<tokens[0]<<" is not a SphericalMap<r_8>"<<endl;
|
---|
894 | return;
|
---|
895 | }
|
---|
896 |
|
---|
897 | AnyDataObj* objm=omg.GetObj(tokens[1]);
|
---|
898 | if(obj==NULL) {
|
---|
899 | cout<<"Error: Pas d'objet de nom "<<tokens[1]<<endl;
|
---|
900 | return;
|
---|
901 | }
|
---|
902 | SphericalMap<r_8>* msk = dynamic_cast<SphericalMap<r_8>*>(objm);
|
---|
903 | if(msk==NULL) {
|
---|
904 | cout<<"Error: "<<tokens[1]<<" is not a SphericalMap<r_8>"<<endl;
|
---|
905 | return;
|
---|
906 | }
|
---|
907 |
|
---|
908 | cout<<"MskMap: "<<tokens[0]<<" with mask "<<tokens[1]<<endl;
|
---|
909 |
|
---|
910 | for(int_4 i=0;i<map->NbPixels();i++) {
|
---|
911 | double theta,phi; map->PixThetaPhi(i,theta,phi);
|
---|
912 | int_4 ip = msk->PixIndexSph(theta,phi);
|
---|
913 | if(ip<0 || ip>=msk->NbPixels()) continue;
|
---|
914 | (*map)(i) *= (*msk)(ip);
|
---|
915 | }
|
---|
916 |
|
---|
917 | }
|
---|
918 |
|
---|
919 | /* --Methode-- */
|
---|
920 | void skymapmoduleExecutor::MapProj(vector<string>& tokens)
|
---|
921 | {
|
---|
922 | NamedObjMgr omg;
|
---|
923 |
|
---|
924 | AnyDataObj* obj=omg.GetObj(tokens[0]);
|
---|
925 | if(obj==NULL) {
|
---|
926 | cout<<"Error: Pas d'objet de nom "<<tokens[0]<<endl;
|
---|
927 | return;
|
---|
928 | }
|
---|
929 | SphericalMap<r_8>* map = dynamic_cast<SphericalMap<r_8>*>(obj);
|
---|
930 | if(map==NULL) {
|
---|
931 | cout<<"Error: "<<tokens[0]<<" is not a SphericalMap<r_8>"<<endl;
|
---|
932 | return;
|
---|
933 | }
|
---|
934 | int_4 nsidemap = map->SizeIndex();
|
---|
935 | uint_2 t = typemap(obj);
|
---|
936 |
|
---|
937 | int_4 nside = nsidemap;
|
---|
938 | if(tokens.size()>2) nside = atoi(tokens[2].c_str());
|
---|
939 | if(t&HealPix && !IsNSideGood(nside))
|
---|
940 | {cout<<"MapProj: Bad nside for Healpix "<<nside<<endl; return;}
|
---|
941 |
|
---|
942 | SphericalMap<r_8>* mapproj = NULL;
|
---|
943 | if(t&HealPix) mapproj = new SphereHEALPix<r_8>(nside);
|
---|
944 | else if(t&ThetaPhi) mapproj = new SphereThetaPhi<r_8>(nside);
|
---|
945 | else return;
|
---|
946 |
|
---|
947 | cout<<"MapProj: project "<<tokens[0]<<" n="<<nsidemap
|
---|
948 | <<" to "<<tokens[1]<<" n="<<nside<<endl;
|
---|
949 |
|
---|
950 | if(nsidemap==nside) { // tailles egales
|
---|
951 | for(int_4 i=0;i<mapproj->NbPixels();i++)
|
---|
952 | (*mapproj)(i) = (*map)(i);
|
---|
953 | } else if(nsidemap<nside) { // mapproj>map
|
---|
954 | for(int_4 i=0;i<mapproj->NbPixels();i++) {
|
---|
955 | double theta,phi; mapproj->PixThetaPhi(i,theta,phi);
|
---|
956 | int_4 ip = map->PixIndexSph(theta,phi);
|
---|
957 | if(ip<0 || ip>=map->NbPixels()) continue;
|
---|
958 | (*mapproj)(i) = (*map)(ip);
|
---|
959 | }
|
---|
960 | } else { // mapproj<map
|
---|
961 | SphericalMap<int_4>* nproj= NULL;
|
---|
962 | if(t&HealPix) nproj= new SphereHEALPix<int_4>(nside);
|
---|
963 | else if(t&ThetaPhi) nproj= new SphereThetaPhi<int_4>(nside);
|
---|
964 | for(int_4 i=0;i<nproj->NbPixels();i++) {(*nproj)(i)=0;(*mapproj)(i)=0.;}
|
---|
965 | for(int_4 i=0;i<map->NbPixels();i++) {
|
---|
966 | double theta,phi; map->PixThetaPhi(i,theta,phi);
|
---|
967 | int_4 ip = mapproj->PixIndexSph(theta,phi);
|
---|
968 | if(ip<0 || ip>=mapproj->NbPixels()) continue;
|
---|
969 | (*mapproj)(ip) += (*map)(i);
|
---|
970 | (*nproj)(ip)++;
|
---|
971 | }
|
---|
972 | for(int_4 i=0;i<mapproj->NbPixels();i++)
|
---|
973 | (*mapproj)(i) /= (r_8) (*nproj)(i);
|
---|
974 | delete nproj;
|
---|
975 | }
|
---|
976 |
|
---|
977 | omg.AddObj(mapproj,tokens[1]);
|
---|
978 | }
|
---|
979 |
|
---|
980 | /* --Methode-- */
|
---|
981 | void skymapmoduleExecutor::Map2Local(vector<string>& tokens)
|
---|
982 | {
|
---|
983 | NamedObjMgr omg;
|
---|
984 |
|
---|
985 | AnyDataObj* obj=omg.GetObj(tokens[0]);
|
---|
986 | if(obj==NULL) {
|
---|
987 | cout<<"Error: Pas d'objet de nom "<<tokens[0]<<endl;
|
---|
988 | return;
|
---|
989 | }
|
---|
990 | SphericalMap<r_8>* map = dynamic_cast<SphericalMap<r_8>*>(obj);
|
---|
991 | if(map==NULL) {
|
---|
992 | cout<<"Error: "<<tokens[0]<<" is not a SphericalMap<r_8>"<<endl;
|
---|
993 | return;
|
---|
994 | }
|
---|
995 |
|
---|
996 | int_4 nx=10,ny=10;
|
---|
997 | if(tokens.size()>2) sscanf(tokens[2].c_str(),"%d,%d",&nx,&ny);
|
---|
998 | if(nx<=0)
|
---|
999 | {cout<<"Error: nx="<<nx<<" value >0"<<endl; return;}
|
---|
1000 | if(ny<=0)
|
---|
1001 | {cout<<"Error: ny="<<ny<<" value >0"<<endl; return;}
|
---|
1002 |
|
---|
1003 | double angleX=1., angleY=1.;
|
---|
1004 | if(tokens.size()>3) sscanf(tokens[3].c_str(),"%lf,%lf",&angleX,&angleY);
|
---|
1005 | if(angleX<=0. || angleX>180.)
|
---|
1006 | {cout<<"Error: bad angleX="<<angleX<<" value #]0,180]"<<endl; return;}
|
---|
1007 | if(angleY<=0. || angleY>180.)
|
---|
1008 | {cout<<"Error: bad angleY="<<angleY<<" value #]0,180]"<<endl; return;}
|
---|
1009 |
|
---|
1010 | double phi0=0., theta0=0.;
|
---|
1011 | if(tokens.size()>4) sscanf(tokens[4].c_str(),"%lf,%lf",&phi0,&theta0);
|
---|
1012 | if(phi0<0. || phi0>=360.)
|
---|
1013 | {cout<<"Error: bad phi0="<<phi0<<" value #[0,360["<<endl; return;}
|
---|
1014 | if(theta0<-90. || theta0>90.)
|
---|
1015 | {cout<<"Error: bad theta0="<<theta0<<" value #[-90,90]"<<endl; return;}
|
---|
1016 |
|
---|
1017 | int_4 x0=nx/2, y0=ny/2;
|
---|
1018 | if(tokens.size()>5) if(tokens[5][0]!='!')
|
---|
1019 | sscanf(tokens[5].c_str(),"%d,%d",&x0,&y0);
|
---|
1020 |
|
---|
1021 | double angle=0.;
|
---|
1022 | if(tokens.size()>6) sscanf(tokens[6].c_str(),"%lf",&angle);
|
---|
1023 |
|
---|
1024 | cout<<"Map2Local: proj "<<tokens[0]<<" to local "<<tokens[1]<<endl
|
---|
1025 | <<" nx="<<nx<<" ny="<<ny<<" angleX="<<angleX<<" angleY="<<angleY
|
---|
1026 | <<" phi0="<<phi0<<" theta0="<<theta0<<" x0="<<x0<<" y0="<<y0
|
---|
1027 | <<" angle="<<angle<<endl;
|
---|
1028 | if(angle<-90. || angle>90.)
|
---|
1029 | {cout<<"Error: bad angle="<<angle<<" value #[-90,90]"<<endl; return;}
|
---|
1030 |
|
---|
1031 | theta0 = (90.-theta0);
|
---|
1032 | LocalMap<r_8>* lmap = new LocalMap<r_8>(nx,ny,angleX,angleY,theta0,phi0,x0,y0,angle);
|
---|
1033 | *lmap = 0.; //lmap->print(cout);
|
---|
1034 |
|
---|
1035 | int_4 nbad=0;
|
---|
1036 | double tmax=-9999., pmax=-9999., tmin=9999., pmin=9999.;
|
---|
1037 | for(int_4 i=0;i<lmap->NbPixels();i++) {
|
---|
1038 | double theta,phi;
|
---|
1039 | lmap->PixThetaPhi(i,theta,phi);
|
---|
1040 | int_4 ip = map->PixIndexSph(theta,phi);
|
---|
1041 | if(ip<0 || ip>=map->NbPixels()) {nbad++; continue;}
|
---|
1042 | if(theta<tmin) tmin=theta; if(theta>tmax) tmax=theta;
|
---|
1043 | if(phi<pmin) pmin=phi; if(phi>pmax) pmax=phi;
|
---|
1044 | (*lmap)(i) = (*map)(ip);
|
---|
1045 | }
|
---|
1046 | if(nbad) cout<<"Warning: "<<nbad<<" bad pixels numbers"<<endl;
|
---|
1047 | cout<<" phi=["<<pmin/M_PI*180.<<","<<pmax/M_PI*180.<<"]="
|
---|
1048 | <<(pmax-pmin)/M_PI*180.
|
---|
1049 | <<" theta=["<<tmin/M_PI*180.<<","<<tmax/M_PI*180.<<"]="
|
---|
1050 | <<(tmax-tmin)/M_PI*180.<<endl;
|
---|
1051 |
|
---|
1052 | omg.AddObj(lmap,tokens[1]);
|
---|
1053 | }
|
---|
1054 |
|
---|
1055 | /* --Methode-- */
|
---|
1056 | void skymapmoduleExecutor::MapOper(vector<string>& tokens)
|
---|
1057 | {
|
---|
1058 | NamedObjMgr omg;
|
---|
1059 |
|
---|
1060 | AnyDataObj* obj=omg.GetObj(tokens[0]);
|
---|
1061 | if(obj==NULL) {
|
---|
1062 | cout<<"Error: Pas d'objet de nom "<<tokens[0]<<endl;
|
---|
1063 | return;
|
---|
1064 | }
|
---|
1065 | SphericalMap<r_8>* map = dynamic_cast<SphericalMap<r_8>*>(obj);
|
---|
1066 | if(map==NULL) {
|
---|
1067 | cout<<"Error: "<<tokens[0]<<" is not a SphericalMap<r_8>"<<endl;
|
---|
1068 | return;
|
---|
1069 | }
|
---|
1070 |
|
---|
1071 | cout<<"MapOper: "<<tokens[0];
|
---|
1072 | for(unsigned short iop=1;iop<tokens.size()-1;iop+=2) {
|
---|
1073 | string op = tokens[iop];
|
---|
1074 | if(op!="+" && op!="-" && op!="*" && op!="/") continue;
|
---|
1075 | AnyDataObj* obj1=omg.GetObj(tokens[iop+1]);
|
---|
1076 | if(obj1==NULL)
|
---|
1077 | {cout<<"Error: Pas d'objet de nom "<<tokens[iop+1]<<endl;
|
---|
1078 | continue;}
|
---|
1079 | SphericalMap<r_8>* map1 = dynamic_cast<SphericalMap<r_8>*>(obj1);
|
---|
1080 | if(map1==NULL)
|
---|
1081 | {cout<<"Error: "<<tokens[iop+1]<<" is not a SphericalMap<r_8>"<<endl;
|
---|
1082 | continue;}
|
---|
1083 | cout<<" "<<op<<"= "<<tokens[iop+1];
|
---|
1084 | for(int_4 i=0;i<map->NbPixels();i++) {
|
---|
1085 | double theta,phi; map->PixThetaPhi(i,theta,phi);
|
---|
1086 | int_4 ip = map1->PixIndexSph(theta,phi);
|
---|
1087 | if(ip<0 || ip>=map1->NbPixels()) continue;
|
---|
1088 | if(op=="+") (*map)(i) += (*map1)(ip);
|
---|
1089 | else if(op=="-") (*map)(i) -= (*map1)(ip);
|
---|
1090 | else if(op=="*") (*map)(i) *= (*map1)(ip);
|
---|
1091 | else if(op=="/")
|
---|
1092 | {if((*map1)(ip)!=0.) (*map)(i)/=(*map1)(ip); else (*map)(i)=0.;}
|
---|
1093 | }
|
---|
1094 | }
|
---|
1095 | cout<<endl;
|
---|
1096 | }
|
---|
1097 |
|
---|
1098 | /* --Methode-- */
|
---|
1099 | void skymapmoduleExecutor::MapStat(vector<string>& tokens)
|
---|
1100 | {
|
---|
1101 | NamedObjMgr omg;
|
---|
1102 |
|
---|
1103 | AnyDataObj* obj=omg.GetObj(tokens[0]);
|
---|
1104 | if(obj==NULL) {
|
---|
1105 | cout<<"Error: Pas d'objet de nom "<<tokens[1]<<endl;
|
---|
1106 | return;
|
---|
1107 | }
|
---|
1108 | SphericalMap<r_8>* map = dynamic_cast<SphericalMap<r_8>*>(obj);
|
---|
1109 | if(map==NULL) {
|
---|
1110 | cout<<"Error: "<<tokens[0]<<" is not a SphericalMap<r_8>"<<endl;
|
---|
1111 | return;
|
---|
1112 | }
|
---|
1113 |
|
---|
1114 | SphericalMap<r_8>* msk = NULL;
|
---|
1115 | if(tokens.size()>1) {
|
---|
1116 | if(tokens[1][0]!='!') {
|
---|
1117 | AnyDataObj* objm=omg.GetObj(tokens[1]);
|
---|
1118 | if(objm==NULL) {
|
---|
1119 | cout<<"Error: Pas d'objet de nom "<<tokens[1]<<endl;
|
---|
1120 | return;
|
---|
1121 | }
|
---|
1122 | msk = dynamic_cast<SphericalMap<r_8>*>(objm);
|
---|
1123 | if(msk==NULL) {
|
---|
1124 | cout<<"Error: "<<tokens[1]<<" is not a SphericalMap<r_8>"<<endl;
|
---|
1125 | return;
|
---|
1126 | }
|
---|
1127 | }
|
---|
1128 | }
|
---|
1129 |
|
---|
1130 | cout<<"MapStat for map "<<tokens[0];
|
---|
1131 | if(msk) cout<<" using mask "<<tokens[1];
|
---|
1132 | cout<<endl;
|
---|
1133 |
|
---|
1134 | double sum=0., sum2=0., sumw=0.;
|
---|
1135 | int npix = map->NbPixels(), npixgood=0;
|
---|
1136 | for(int_4 i=0;i<npix;i++) {
|
---|
1137 | double w = 1.;
|
---|
1138 | if(msk) {
|
---|
1139 | double theta,phi; map->PixThetaPhi(i,theta,phi);
|
---|
1140 | int_4 ip = msk->PixIndexSph(theta,phi);
|
---|
1141 | if(ip<0 || ip>=msk->NbPixels()) w=0.;
|
---|
1142 | else w=(*msk)(ip);
|
---|
1143 | }
|
---|
1144 | if(w<=0.) continue;
|
---|
1145 | npixgood++; sumw += w;
|
---|
1146 | sum += (*map)(i)*w;
|
---|
1147 | sum2 += (*map)(i)*(*map)(i)*w*w;
|
---|
1148 | }
|
---|
1149 | if(sumw<=0. || npixgood==0) {
|
---|
1150 | sum = sum2 = sumw=0.;
|
---|
1151 | } else {
|
---|
1152 | sum /= sumw;
|
---|
1153 | sum2 = sum2/sumw - sum*sum;
|
---|
1154 | if(sum2<=0.) sum2=0.; else sum2=sqrt(sum2);
|
---|
1155 | }
|
---|
1156 | cout<<"Number of good px="<<npixgood<<" / "<<npix
|
---|
1157 | <<" ("<<100.*npixgood/npix<<" %)"<<endl;
|
---|
1158 | cout<<" mean="<<sum<<" sigma="<<sum2<<endl;
|
---|
1159 |
|
---|
1160 | if(tokens.size()>2) if(tokens[2][0]!='!') {
|
---|
1161 | if(omg.HasVar(tokens[2])) omg.DeleteVar(tokens[2]);
|
---|
1162 | char str[128]; sprintf(str,"%.8f",sum);
|
---|
1163 | omg.SetVar(tokens[2],(string)str);
|
---|
1164 | cout<<" mean stored into $"<<tokens[2];
|
---|
1165 | }
|
---|
1166 | if(tokens.size()>3) if(tokens[3][0]!='!') {
|
---|
1167 | if(omg.HasVar(tokens[3])) omg.DeleteVar(tokens[3]);
|
---|
1168 | char str[128]; sprintf(str,"%.8f",sum2);
|
---|
1169 | omg.SetVar(tokens[3],(string)str);
|
---|
1170 | cout<<" sigma stored into $"<<tokens[3];
|
---|
1171 | }
|
---|
1172 | if(tokens.size()>2) cout<<endl;
|
---|
1173 |
|
---|
1174 | }
|
---|
1175 |
|
---|
1176 | /* --Methode-- */
|
---|
1177 | void skymapmoduleExecutor::Alm2Cl(vector<string>& tokens)
|
---|
1178 | {
|
---|
1179 | NamedObjMgr omg;
|
---|
1180 |
|
---|
1181 | AnyDataObj* obj=omg.GetObj(tokens[0]);
|
---|
1182 | if(obj==NULL) {
|
---|
1183 | cout<<"Error: Pas d'objet de nom "<<tokens[0]<<endl;
|
---|
1184 | return;
|
---|
1185 | }
|
---|
1186 | TMatrix< complex<r_8> >* almmat = dynamic_cast<TMatrix< complex<r_8> >*>(obj);
|
---|
1187 | if(almmat==NULL) {
|
---|
1188 | cout<<"Error: "<<tokens[0]<<" is not a TMatrix< complex<r_8> >"<<endl;
|
---|
1189 | return;
|
---|
1190 | }
|
---|
1191 |
|
---|
1192 | int lmax = almmat->NRows()-1;
|
---|
1193 | Alm<r_8> alm(lmax);
|
---|
1194 | alm = (complex<r_8>)0.;
|
---|
1195 | for(int i=0;i<lmax+1;i++) for(int j=0;j<=i;j++) alm(i,j)=(*almmat)(i,j);
|
---|
1196 |
|
---|
1197 | TVector<r_8> cl(almmat->NRows());
|
---|
1198 | cl = 0.;
|
---|
1199 |
|
---|
1200 | cout<<"Alm2Cl: project alm "<<tokens[0]<<"("<<alm.rowNumber()
|
---|
1201 | <<") to cl "<<tokens[1]<<"("<<cl.Size()<<")"<<endl;
|
---|
1202 |
|
---|
1203 | for(int_4 l=0;l<alm.rowNumber();l++) {
|
---|
1204 | cl(l) = alm(l,0).real()*alm(l,0).real()+alm(l,0).imag()*alm(l,0).imag();
|
---|
1205 | if(l>0) for(int_4 m=1;m<=l;m++)
|
---|
1206 | cl(l) += 2.*(alm(l,m).real()*alm(l,m).real()+alm(l,m).imag()*alm(l,m).imag());
|
---|
1207 | cl(l) /= 2.*l+1;
|
---|
1208 | }
|
---|
1209 |
|
---|
1210 | omg.AddObj(cl,tokens[1]);
|
---|
1211 | }
|
---|
1212 |
|
---|
1213 | /* --Methode-- */
|
---|
1214 | void skymapmoduleExecutor::Cl2llCl(vector<string>& tokens)
|
---|
1215 | {
|
---|
1216 | NamedObjMgr omg;
|
---|
1217 |
|
---|
1218 | AnyDataObj* obj=omg.GetObj(tokens[0]);
|
---|
1219 | if(obj==NULL) {
|
---|
1220 | cout<<"Error: Pas d'objet de nom "<<tokens[0]<<endl;
|
---|
1221 | return;
|
---|
1222 | }
|
---|
1223 | TVector<r_8>* cl = dynamic_cast<TVector<r_8>*>(obj);
|
---|
1224 | if(cl==NULL) {
|
---|
1225 | cout<<"Error: "<<tokens[0]<<" is not a TVector<r_8>"<<endl;
|
---|
1226 | return;
|
---|
1227 | }
|
---|
1228 |
|
---|
1229 | TVector<r_8> llcl(*cl,false);
|
---|
1230 |
|
---|
1231 | cout<<"Cl2llCl: project "<<tokens[0]<<"("<<cl->Size()
|
---|
1232 | <<") to l*(l+1)*cl "<<tokens[1]<<"("<<llcl.Size()<<")"<<endl;
|
---|
1233 |
|
---|
1234 | for(int_4 l=0;l<llcl.Size();l++) llcl(l) *= (double)l*(l+1.);
|
---|
1235 |
|
---|
1236 | omg.AddObj(llcl,tokens[1]);
|
---|
1237 | }
|
---|
1238 |
|
---|
1239 | /* --Methode-- */
|
---|
1240 | void skymapmoduleExecutor::ClMean(vector<string>& tokens)
|
---|
1241 | {
|
---|
1242 | NamedObjMgr omg;
|
---|
1243 |
|
---|
1244 | AnyDataObj* obj=omg.GetObj(tokens[0]);
|
---|
1245 | if(obj==NULL) {
|
---|
1246 | cout<<"Error: Pas d'objet de nom "<<tokens[0]<<endl;
|
---|
1247 | return;
|
---|
1248 | }
|
---|
1249 | TVector<r_8>* cl = dynamic_cast<TVector<r_8>*>(obj);
|
---|
1250 | if(cl==NULL) {
|
---|
1251 | cout<<"Error: "<<tokens[0]<<" is not a TVector<r_8>"<<endl;
|
---|
1252 | return;
|
---|
1253 | }
|
---|
1254 |
|
---|
1255 | int lmin=0, lmax=-1;
|
---|
1256 | if(tokens.size()>1) if(tokens[1][0]!='!')
|
---|
1257 | sscanf(tokens[1].c_str(),"%d,%d",&lmin,&lmax);
|
---|
1258 | if(lmin<0) lmin=0; if(lmax>=cl->Size()) lmax=cl->Size()-1;
|
---|
1259 | if(lmin>lmax) {lmin=0; lmax=cl->Size()-1;}
|
---|
1260 |
|
---|
1261 | cout<<"ClMean: compute mean "<<tokens[0]<<"("<<cl->Size()
|
---|
1262 | <<") between ["<<lmin<<","<<lmax<<"]";
|
---|
1263 |
|
---|
1264 | double mean = 0.;
|
---|
1265 | for(int_4 l=lmin;l<=lmax;l++) mean += (*cl)(l);
|
---|
1266 | mean /= lmax-lmin+1;
|
---|
1267 |
|
---|
1268 | cout<<" mean="<<mean;
|
---|
1269 |
|
---|
1270 | if(tokens.size()>2) {
|
---|
1271 | if(omg.HasVar(tokens[2])) omg.DeleteVar(tokens[2]);
|
---|
1272 | char str[128]; sprintf(str,"%.8f",mean);
|
---|
1273 | omg.SetVar(tokens[2],(string)str);
|
---|
1274 | cout<<" stored into $"<<tokens[2];
|
---|
1275 | }
|
---|
1276 | cout<<endl;
|
---|
1277 |
|
---|
1278 | }
|
---|
1279 |
|
---|
1280 | /* --Methode-- */
|
---|
1281 | void skymapmoduleExecutor::ClMult(vector<string>& tokens)
|
---|
1282 | {
|
---|
1283 | NamedObjMgr omg;
|
---|
1284 |
|
---|
1285 | AnyDataObj* obj=omg.GetObj(tokens[0]);
|
---|
1286 | if(obj==NULL) {
|
---|
1287 | cout<<"Error: Pas d'objet de nom "<<tokens[0]<<endl;
|
---|
1288 | return;
|
---|
1289 | }
|
---|
1290 | TVector<r_8>* cl = dynamic_cast<TVector<r_8>*>(obj);
|
---|
1291 | if(cl==NULL) {
|
---|
1292 | cout<<"Error: "<<tokens[0]<<" is not a TVector<r_8>"<<endl;
|
---|
1293 | return;
|
---|
1294 | }
|
---|
1295 |
|
---|
1296 | double val = 1.;
|
---|
1297 | if(tokens.size()>1) val=atof(tokens[1].c_str());
|
---|
1298 |
|
---|
1299 | cout<<"ClMult: multiply "<<tokens[0]<<"("<<cl->Size()<<") by "<<val<<endl;
|
---|
1300 |
|
---|
1301 | *cl *= val;
|
---|
1302 |
|
---|
1303 | }
|
---|
1304 |
|
---|
1305 | /* --Methode-- */
|
---|
1306 | void skymapmoduleExecutor::ClOper(vector<string>& tokens)
|
---|
1307 | {
|
---|
1308 | NamedObjMgr omg;
|
---|
1309 |
|
---|
1310 | AnyDataObj* obj=omg.GetObj(tokens[0]);
|
---|
1311 | if(obj==NULL) {
|
---|
1312 | cout<<"Error: Pas d'objet de nom "<<tokens[0]<<endl;
|
---|
1313 | return;
|
---|
1314 | }
|
---|
1315 | TVector<r_8>* cl = dynamic_cast<TVector<r_8>*>(obj);
|
---|
1316 | if(cl==NULL) {
|
---|
1317 | cout<<"Error: "<<tokens[0]<<" is not a TVector<r_8>"<<endl;
|
---|
1318 | return;
|
---|
1319 | }
|
---|
1320 |
|
---|
1321 | cout<<"ClOper: "<<tokens[0]<<"("<<cl->Size()<<")";
|
---|
1322 | for(unsigned short iop=1;iop<tokens.size()-1;iop+=2) {
|
---|
1323 | string op = tokens[iop];
|
---|
1324 | if(op!="+" && op!="-" && op!="*" && op!="/") continue;
|
---|
1325 | AnyDataObj* obj1=omg.GetObj(tokens[iop+1]);
|
---|
1326 | if(obj1==NULL)
|
---|
1327 | {cout<<"Error: Pas d'objet de nom "<<tokens[iop+1]<<endl;
|
---|
1328 | continue;}
|
---|
1329 | TVector<r_8>* cl1 = dynamic_cast<TVector<r_8>*>(obj1);
|
---|
1330 | if(cl1==NULL)
|
---|
1331 | {cout<<"Error: "<<tokens[iop+1]<<" is not a TVector<r_8>"<<endl;
|
---|
1332 | continue;}
|
---|
1333 | cout<<" "<<op<<"= "<<tokens[iop+1]<<"("<<cl1->Size()<<")";
|
---|
1334 | int_4 n=cl->Size(); if(n>cl1->Size()) n=cl1->Size();
|
---|
1335 | for(int_4 i=0;i<n;i++) {
|
---|
1336 | if(op=="+") (*cl)(i) += (*cl1)(i);
|
---|
1337 | else if(op=="-") (*cl)(i) -= (*cl1)(i);
|
---|
1338 | else if(op=="*") (*cl)(i) *= (*cl1)(i);
|
---|
1339 | else if(op=="/")
|
---|
1340 | {if((*cl1)(i)!=0.) (*cl)(i)/=(*cl1)(i); else (*cl)(i)=0.;}
|
---|
1341 | }
|
---|
1342 | }
|
---|
1343 | cout<<endl;
|
---|
1344 | }
|
---|
1345 | /* --Methode-- */
|
---|
1346 | void skymapmoduleExecutor::ClRebin(vector<string>& tokens)
|
---|
1347 | {
|
---|
1348 | NamedObjMgr omg;
|
---|
1349 |
|
---|
1350 | AnyDataObj* obj=omg.GetObj(tokens[0]);
|
---|
1351 | if(obj==NULL) {
|
---|
1352 | cout<<"Error: Pas d'objet de nom "<<tokens[0]<<endl;
|
---|
1353 | return;
|
---|
1354 | }
|
---|
1355 | TVector<r_8>* cl = dynamic_cast<TVector<r_8>*>(obj);
|
---|
1356 | if(cl==NULL) {
|
---|
1357 | cout<<"Error: "<<tokens[0]<<" is not a TVector<r_8>"<<endl;
|
---|
1358 | return;
|
---|
1359 | }
|
---|
1360 | int_4 nn = cl->Size();
|
---|
1361 | if(nn<=0) return;
|
---|
1362 |
|
---|
1363 | int_4 nrebin=1, ibin0=0;
|
---|
1364 | if(tokens.size()>2) sscanf(tokens[2].c_str(),"%d,%d",&nrebin,&ibin0);
|
---|
1365 | if(ibin0<0 || ibin0>=nn) ibin0=0;
|
---|
1366 |
|
---|
1367 | cout<<"ClRebin: rebin "<<tokens[0]<<"("<<nn<<") by nbin="<<nrebin
|
---|
1368 | <<" begin at "<<ibin0<<" -> "<<tokens[1]<<endl;
|
---|
1369 |
|
---|
1370 | const int ndim = 8;
|
---|
1371 | char *nament[ndim] =
|
---|
1372 | {"l","n","clmean","cllin","clpar","sclmean","scllin","sclpar"};
|
---|
1373 | NTuple clbin(ndim,nament);
|
---|
1374 | r_4 xnt[ndim];
|
---|
1375 |
|
---|
1376 | SLinParBuff slp(nrebin+2);
|
---|
1377 |
|
---|
1378 | for(int_4 i=ibin0;i<nn;i+=nrebin) {
|
---|
1379 | r_8 ll=0.;
|
---|
1380 | slp.Reset();
|
---|
1381 | for(int_4 j=0;j<ndim;j++) xnt[j]=0.;
|
---|
1382 | for(int_4 j=i;j<nn;j++) {
|
---|
1383 | ll += (r_8) j;
|
---|
1384 | slp.Push((r_8)j,(*cl)(j));
|
---|
1385 | if((int_4)slp.NPoints()>=nrebin) break;
|
---|
1386 | }
|
---|
1387 | if(slp.NPoints()<=0) continue;
|
---|
1388 | ll /= (r_8) slp.NPoints();
|
---|
1389 | xnt[0] = ll;
|
---|
1390 | xnt[1] = slp.NPoints();
|
---|
1391 | r_8 s,a0,a1,a2;
|
---|
1392 | s = slp.Compute(a0);
|
---|
1393 | if(s>0.) {xnt[2]=a0; xnt[5]=s;}
|
---|
1394 | s = slp.Compute(a0,a1);
|
---|
1395 | if(s>0.) {xnt[3]=a0+a1*ll; xnt[6]=s;}
|
---|
1396 | s = slp.Compute(a0,a1,a2);
|
---|
1397 | if(s>0.) {xnt[4]=a0+a1*ll+a2*ll*ll; xnt[7]=s;}
|
---|
1398 | clbin.Fill(xnt);
|
---|
1399 | }
|
---|
1400 |
|
---|
1401 | omg.AddObj(clbin,tokens[1]);
|
---|
1402 | }
|
---|
1403 |
|
---|
1404 | /* --Methode-- */
|
---|
1405 | void skymapmoduleExecutor::VarOper(vector<string>& tokens)
|
---|
1406 | {
|
---|
1407 | NamedObjMgr omg;
|
---|
1408 |
|
---|
1409 | double var1=0., var2=0.; string op = "?";
|
---|
1410 | if(tokens.size()>0) var1 = atof(tokens[0].c_str());
|
---|
1411 | if(tokens.size()>1) op = tokens[1];
|
---|
1412 | if(tokens.size()>2) if(tokens[2][0]!='!') var2 = atof(tokens[2].c_str());
|
---|
1413 |
|
---|
1414 | double result = 0.;
|
---|
1415 | try {
|
---|
1416 | if(op=="+") result = var1 + var2;
|
---|
1417 | else if(op=="-") result = var1 - var2;
|
---|
1418 | else if(op=="*") result = var1 * var2;
|
---|
1419 | else if(op=="/" && var2!=0.) result = var1 / var2; else if(op=="^" && var2>0.) result = pow(var1,var2);
|
---|
1420 | else if(op=="pow" && var2>0.) result = pow(var1,var2);
|
---|
1421 | else if(op=="exp") result = exp(var1);
|
---|
1422 | else if(op=="sqrt" && var1>0.) result = sqrt(var1);
|
---|
1423 | else if(op=="log" && var1>0.) result = log(var1);
|
---|
1424 | else if(op=="log10" && var1>0.) result = log10(var1);
|
---|
1425 | } catch ( ... ) {
|
---|
1426 | cout<<"An operation exception occurs"<<endl;
|
---|
1427 | return;
|
---|
1428 | }
|
---|
1429 |
|
---|
1430 | cout<<"VarOper: "<<var1<<" "<<op<<" "<<var2<<" = "<<result;
|
---|
1431 |
|
---|
1432 | if(tokens.size()>3) {
|
---|
1433 | if(omg.HasVar(tokens[3])) omg.DeleteVar(tokens[3]);
|
---|
1434 | char str[128]; sprintf(str,"%.8f",result);
|
---|
1435 | omg.SetVar(tokens[3],(string)str);
|
---|
1436 | cout<<" stored into $"<<tokens[3];
|
---|
1437 | }
|
---|
1438 | cout<<endl;
|
---|
1439 |
|
---|
1440 | }
|
---|
1441 |
|
---|
1442 | ////////////////////////////////////////////////////////////
|
---|
1443 |
|
---|
1444 | /* --Methode-- */
|
---|
1445 | void skymapmoduleExecutor::SetTypeMap(vector<string>& tokens)
|
---|
1446 | {
|
---|
1447 | if(tokens.size()<1) {
|
---|
1448 | cout<<"SetTypeMap: Usage: settypemap type"<<endl;
|
---|
1449 | } else {
|
---|
1450 | if(toupper(tokens[0][0])=='H') DefTypMap = HealPix;
|
---|
1451 | else if(toupper(tokens[0][0])=='T') DefTypMap = ThetaPhi;
|
---|
1452 | else cout<<"unkown map type, should be (H or T)!"<<endl;
|
---|
1453 | }
|
---|
1454 | string dum;
|
---|
1455 | if(DefTypMap&HealPix) dum="HealPix";
|
---|
1456 | else if(DefTypMap&ThetaPhi) dum="ThetaPhi";
|
---|
1457 | cout<<"SetTypeMap: type map is "<<dum<<" ("<<DefTypMap<<")"<<endl;
|
---|
1458 | }
|
---|
1459 |
|
---|
1460 | /* --Methode-- */
|
---|
1461 | bool skymapmoduleExecutor::IsNSideGood(int_4 nside)
|
---|
1462 | {
|
---|
1463 | if(nside<=1) return false;
|
---|
1464 | while(nside>1) {if(nside%2!=0) return false; else nside/=2;}
|
---|
1465 | return true;
|
---|
1466 | }
|
---|
1467 |
|
---|
1468 | /* --Methode-- */
|
---|
1469 | void skymapmoduleExecutor::GetNSideGood(int_4 &nside)
|
---|
1470 | // get the nearest good nside for HealPix
|
---|
1471 | {
|
---|
1472 | double n=1.e50; int_4 ns=nside;
|
---|
1473 | for(int_4 i=1;i<66000;i*=2) {
|
---|
1474 | double v = fabs((double)(nside-i));
|
---|
1475 | if(v>n) continue;
|
---|
1476 | n=v; ns=i;
|
---|
1477 | }
|
---|
1478 | nside = ns;
|
---|
1479 | }
|
---|
1480 |
|
---|
1481 | /* --Methode-- */
|
---|
1482 | uint_2 skymapmoduleExecutor::typemap(AnyDataObj* obj)
|
---|
1483 | {
|
---|
1484 | if(obj==NULL) return UnKnown;
|
---|
1485 | if(dynamic_cast<SphereHEALPix<r_4> *>(obj)) return HealPix4;
|
---|
1486 | if(dynamic_cast<SphereHEALPix<r_8> *>(obj)) return HealPix8;
|
---|
1487 | if(dynamic_cast<SphereThetaPhi<r_4>*>(obj)) return ThetaPhi4;
|
---|
1488 | if(dynamic_cast<SphereThetaPhi<r_8>*>(obj)) return ThetaPhi8;
|
---|
1489 | if(dynamic_cast<SphericalMap<r_4> *>(obj)) return Spherical4;
|
---|
1490 | if(dynamic_cast<SphericalMap<r_8> *>(obj)) return Spherical8;
|
---|
1491 | return UnKnown;
|
---|
1492 | }
|
---|
1493 |
|
---|
1494 | ////////////////////////////////////////////////////////////
|
---|
1495 | static skymapmoduleExecutor * piaskmex = NULL;
|
---|
1496 |
|
---|
1497 | void skymapmodule_init()
|
---|
1498 | {
|
---|
1499 | if (piaskmex) delete piaskmex;
|
---|
1500 | piaskmex = new skymapmoduleExecutor;
|
---|
1501 | }
|
---|
1502 |
|
---|
1503 | void skymapmodule_end()
|
---|
1504 | {
|
---|
1505 | // Desactivation du module
|
---|
1506 | if (piaskmex) delete piaskmex;
|
---|
1507 | piaskmex = NULL;
|
---|
1508 | }
|
---|