source: Sophya/trunk/SophyaPI/ProgPI/skymapmodule.cc@ 2179

Last change on this file since 2179 was 2179, checked in by cmv, 23 years ago

disparition de varop dans skymapmodule.cc

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