Changeset 2177 in Sophya for trunk/SophyaPI
- Timestamp:
- Aug 11, 2002, 4:53:54 PM (23 years ago)
- Location:
- trunk/SophyaPI/ProgPI
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaPI/ProgPI/skymapmodule.cc
r2175 r2177 13 13 #include "pistdimgapp.h" 14 14 #include "servnobjm.h" 15 #include "tvector.h"16 15 #include "pidrawer.h" 17 16 #include "nomgadapter.h" 18 17 19 #include "skymap.h" 18 #include "tvector.h" 19 #include "ntuple.h" 20 #include "slinparbuff.h" 21 #include "localmap.h" 22 #include "spherehealpix.h" 23 #include "spherethetaphi.h" 20 24 #include "sphericaltransformserver.h" 21 25 … … 43 47 void TypeMap(vector<string>& tokens); 44 48 void Map2Double(vector<string>& tokens); 49 void Map2Float(vector<string>& tokens); 45 50 void Map2Map(vector<string>& tokens); 46 51 void MapMult(vector<string>& tokens); … … 57 62 void MapOper(vector<string>& tokens); 58 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); 59 71 protected: 60 72 void SetTypeMap(vector<string>& tokens); … … 77 89 78 90 kw = "settypemap"; 79 usage = "Set le type de map par default"; 91 usage = "Set le type de map(double) par default"; 92 usage += "\n Usage: settypemap type"; 80 93 usage += "\n type= H for Healpix (default)"; 81 94 usage += "\n T for ThetaPhi"; 82 usage += "\n Usage: settypemap type";83 95 mpiac->RegisterCommand(kw, usage, this, hgrp); 84 96 … … 90 102 kw = "map2double"; 91 103 usage = "Convert a float map to a double map"; 92 usage += "\n Usage: map2double 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)"; 93 110 mpiac->RegisterCommand(kw, usage, this, hgrp); 94 111 95 112 kw = "map2map"; 96 usage = "Convert a map into an other map type"; 113 usage = "Convert a map(double) into an other map type"; 114 usage += "\n Usage: map2map map(double) type [nside]"; 97 115 usage += "\n type= H for Healpix"; 98 116 usage += "\n T for ThetaPhi"; 99 117 usage += "\n if nside <=1 use nside from map"; 100 usage += "\n Usage: map2map map type [nside]";101 118 mpiac->RegisterCommand(kw, usage, this, hgrp); 102 119 103 120 kw = "mapmult"; 104 usage = "Multiply a map by a constant";105 usage += "\n Usage: mapmult map cste";121 usage = "Multiply a map(double) by a constant"; 122 usage += "\n Usage: mapmult map(double) cste"; 106 123 mpiac->RegisterCommand(kw, usage, this, hgrp); 107 124 108 125 kw = "mapcover"; 109 usage = "Print the covering of a map ";110 usage += "\n Usage: mapcover map v1,v2 [varname]";126 usage = "Print the covering of a map(double)"; 127 usage += "\n Usage: mapcover map(double) v1,v2 [varname]"; 111 128 usage += "\n v1,v2: good pixels have v1<=val<=v2 (def=0.99,1.01)"; 112 129 usage += "\n (use default (0.99,1.01): \"!\")"; … … 115 132 116 133 kw = "map2cl"; 117 usage = "SkyMap to Cl";134 usage = "SkyMap map(double) to Cl"; 118 135 usage += "\n Usage: map2cl map(double) clvec [lmax] [niter]"; 119 136 usage += "\n lmax: if <=0 or \"!\" use default (3*nside-1)"; … … 122 139 123 140 kw = "cl2map"; 124 usage = "Generate SkyMap from Cl";125 usage += "\n Usage: cl2map clvec map nside [fwhm]";141 usage = "Generate SkyMap map(double) from Cl"; 142 usage += "\n Usage: cl2map clvec map(double) nside [fwhm]"; 126 143 usage += "\n (see command settypemap)"; 127 144 mpiac->RegisterCommand(kw, usage, this, hgrp); 128 145 129 146 kw = "map2alm"; 130 usage = "SkyMap to Alm";147 usage = "SkyMap map(double) to Alm"; 131 148 usage += "\n Usage: map2alm map(double) almmat [lmax] [niter]"; 132 149 usage += "\n lmax: if <=0 or \"!\" use default (3*nside-1)"; … … 135 152 136 153 kw = "alm2map"; 137 usage = "Generate SkyMap from Alm";138 usage += "\n Usage: alm2map almmat map nside";154 usage = "Generate SkyMap map(double) from Alm"; 155 usage += "\n Usage: alm2map almmat map(double) nside"; 139 156 usage += "\n (see command settypemap)"; 140 157 mpiac->RegisterCommand(kw, usage, this, hgrp); 141 158 142 159 kw = "crmapmask"; 143 usage = "Create a map mask (nside) between latitudes lat1,lat2 longitudes lon1,lon2";144 usage += "\n Usage: crmapmask mapmsk nside lat1,lat2 lon1,lon2 [valmsk,valnomsk]";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]"; 145 162 usage += "\n mask pixels between [lat1,lat2] ([-90,90] in degrees)"; 146 163 usage += "\n and [lon1,lon2] ([0,360[ in degrees)"; … … 152 169 153 170 kw = "crmaskfrmap"; 154 usage = "Create a map mask (nside) relative to an other mappixels values";155 usage += "\n Usage: crmaskfrmap mapmsk nside map(double) v1,v2 [valmsk,valnomsk]";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]"; 156 173 usage += "\n mask if v1<mapmsk(i)<v2"; 157 174 usage += "\n valmsk=value to be written into masked pixels (def=0)"; … … 160 177 161 178 kw = "maskmap"; 162 usage = "Mask a map with a mask map";179 usage = "Mask a map(double) with a mask map(double)"; 163 180 usage += "\n Usage: maskmap map msk"; 164 181 usage += "\n operation is map(i) *= msk(theta,phi)"; … … 166 183 167 184 kw = "maproj"; 168 usage = "Project a map into an other one";169 usage += "\n Usage: maproj map mapproj[nside]";185 usage = "Project a map(double) into an other one"; 186 usage += "\n Usage: maproj map(double) mapproj(double) [nside]"; 170 187 usage += "\n Create mapproj(nside) and project map into mapproj"; 171 188 usage += "\n (use \"maproj map mapproj\" to make a copy)"; … … 173 190 174 191 kw = "map2local"; 175 usage = "Project a map into a local map";176 usage += "\n Usage: map2local map localmapnx,ny angleX,angleY phi0,theta0 [x0,y0] [angle]";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]"; 177 194 usage += "\n nx,ny: number of pixels in x(col),y(row) direction"; 178 195 usage += "\n X-axis==phi, Y-axis==theta"; … … 185 202 186 203 kw = "mapop"; 187 usage = "operation on a map ";188 usage += "\n Usage: mapop map op1 map1 [op2 map2] [op2 map3] [...]";204 usage = "operation on a map(double)"; 205 usage += "\n Usage: mapop map(double) op1 map1(double) [op2 map2(double)] [op2 map3(double)] [...]"; 189 206 usage += "\n Do \"map op1= map1\", \"map op2=map2\", ..."; 190 207 usage += "\n where op = +,-,*,/"; … … 192 209 193 210 kw = "mapstat"; 194 usage = "Statistics from a map ";195 usage += "\n Usage: mapstat map [msk] [meanvarname] [sigmavarname]";211 usage = "Statistics from a map(double)"; 212 usage += "\n Usage: mapstat map(double) [msk(double)] [meanvarname] [sigmavarname]"; 196 213 usage += "\n msk = mask sphere used as weight"; 197 214 usage += "\n if msk(i)<=0 do not use that pixel"; … … 203 220 mpiac->RegisterCommand(kw, usage, this, hgrp); 204 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 205 266 DefTypMap = HealPix; 206 267 } … … 229 290 } 230 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); 231 298 } else if(kw == "map2map") { 232 299 if(tokens.size()<2) { … … 313 380 } 314 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); 315 424 } 316 425 … … 372 481 373 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]); 374 511 } 375 512 … … 508 645 if(lmax<=0) lmax = 3*nside-1; 509 646 510 cout<<"Map2Cl: "<<tokens[0]<<" -> "<<tokens[1]511 <<" lmax="<<lmax<<" niter="<<niter<<endl;512 513 647 SphericalMap<r_8>* tmpmap = NULL; 514 648 if(t&HealPix) tmpmap = new SphereHEALPix<r_8>(*((SphereHEALPix<r_8>*)map),false); … … 516 650 else return; 517 651 652 cout<<"Map2Cl: "<<tokens[0]<<"(nside="<<nside 653 <<") lmax="<<lmax<<" niter="<<niter<<" -> "<<tokens[1]; 654 518 655 TVector<r_8> cltmp = ylmserver.DecomposeToCl(*tmpmap,lmax,0.,niter); 656 cout<<"("<<cltmp.Size()<<")"<<endl; 519 657 delete tmpmap; 520 658 … … 553 691 SphericalTransformServer<r_8> ylmserver; 554 692 cout<<"Cl2Map: Generate map "<<tokens[1]<<" with nside="<<nside 555 <<" from cl "<<tokens[0]<<" with fwhm="<<fwhm<<endl; 693 <<" from cl "<<tokens[0]<<"("<<cl->Size()<<")" 694 <<" with fwhm="<<fwhm<<endl; 556 695 ylmserver.GenerateFromCl(*map,nside,*cl,fwhm); 557 696 … … 587 726 if(lmax<=0) lmax = 3*nside-1; 588 727 589 cout<<"Map2Alm: "<<tokens[0]<<" -> "<<tokens[1]590 <<" lmax="<<lmax<<" niter="<<niter<<endl;591 592 728 SphericalMap<r_8>* tmpmap = NULL; 593 729 if(t&HealPix) tmpmap = new SphereHEALPix<r_8>(*((SphereHEALPix<r_8>*)map),false); … … 595 731 else return; 596 732 733 cout<<"Map2Alm: "<<tokens[0]<<"(nside="<<nside 734 <<") lmax="<<lmax<<" niter="<<niter<<" -> "<<tokens[1]; 735 597 736 Alm<r_8> almtmp; 598 737 ylmserver.DecomposeToAlm(*tmpmap,almtmp,lmax,0.,niter); 738 cout<<"("<<almtmp.rowNumber()<<")"<<endl; 599 739 delete tmpmap; 600 740 … … 639 779 SphericalTransformServer<r_8> ylmserver; 640 780 cout<<"Alm2Map: Generate map "<<tokens[1]<<" with nside="<<nside 641 <<" from alm "<<tokens[0]<< endl;781 <<" from alm "<<tokens[0]<<"("<<alm.rowNumber()<<")"<<endl; 642 782 ylmserver.GenerateFromAlm(*map,nside,alm); 643 783 … … 931 1071 cout<<"MapOper: "<<tokens[0]; 932 1072 for(unsigned short iop=1;iop<tokens.size()-1;iop+=2) { 933 char op = tokens[iop][0];934 if(op!= '+' && op!='-' && op!='*' && op!='/') continue;1073 string op = tokens[iop]; 1074 if(op!="+" && op!="-" && op!="*" && op!="/") continue; 935 1075 AnyDataObj* obj1=omg.GetObj(tokens[iop+1]); 936 1076 if(obj1==NULL) … … 946 1086 int_4 ip = map1->PixIndexSph(theta,phi); 947 1087 if(ip<0 || ip>=map1->NbPixels()) continue; 948 if(op=='+') (*map)(i) += (*map1)(ip); 949 else if(op=='-') (*map)(i) -= (*map1)(ip); 950 else if(op=='*') (*map)(i) *= (*map1)(ip); 951 else if(op=='/') 952 {if((*map1)(ip)!=0.) (*map)(i) /= (*map1)(ip); 953 else (*map)(i) = 0.;} 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.;} 954 1093 } 955 1094 } … … 1035 1174 } 1036 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 xnt[0] = ll / (r_8) slp.NPoints(); 1389 xnt[1] = slp.NPoints(); 1390 r_8 s,a0,a1,a2; 1391 s = slp.Compute(a0); 1392 if(s>0.) {xnt[2]=a0; xnt[5]=s;} 1393 s = slp.Compute(a0,a1); 1394 if(s>0.) {xnt[3]=a0+a1*ll; xnt[6]=s;} 1395 s = slp.Compute(a0,a1,a2); 1396 if(s>0.) {xnt[4]=a0+a1*ll+a2*ll*ll; xnt[7]=s;} 1397 clbin.Fill(xnt); 1398 } 1399 1400 omg.AddObj(clbin,tokens[1]); 1401 } 1402 1403 /* --Methode-- */ 1404 void skymapmoduleExecutor::VarOper(vector<string>& tokens) 1405 { 1406 NamedObjMgr omg; 1407 1408 double var1=0., var2=0.; string op = "?"; 1409 if(tokens.size()>0) var1 = atof(tokens[0].c_str()); 1410 if(tokens.size()>1) op = tokens[1]; 1411 if(tokens.size()>2) if(tokens[2][0]!='!') var2 = atof(tokens[2].c_str()); 1412 1413 double result = 0.; 1414 try { 1415 if(op=="+") result = var1 + var2; 1416 else if(op=="-") result = var1 - var2; 1417 else if(op=="*") result = var1 * var2; 1418 else if(op=="/" && var2!=0.) result = var1 / var2; else if(op=="^" && var2>0.) result = pow(var1,var2); 1419 else if(op=="pow" && var2>0.) result = pow(var1,var2); 1420 else if(op=="exp") result = exp(var1); 1421 else if(op=="sqrt" && var1>0.) result = sqrt(var1); 1422 else if(op=="log" && var1>0.) result = log(var1); 1423 else if(op=="log10" && var1>0.) result = log10(var1); 1424 } catch ( ... ) { 1425 cout<<"An operation exception occurs"<<endl; 1426 return; 1427 } 1428 1429 cout<<"VarOper: "<<var1<<" "<<op<<" "<<var2<<" = "<<result; 1430 1431 if(tokens.size()>3) { 1432 if(omg.HasVar(tokens[3])) omg.DeleteVar(tokens[3]); 1433 char str[128]; sprintf(str,"%.8f",result); 1434 omg.SetVar(tokens[3],(string)str); 1435 cout<<" stored into $"<<tokens[3]; 1436 } 1437 cout<<endl; 1438 1439 } 1440 1037 1441 //////////////////////////////////////////////////////////// 1038 1442 -
trunk/SophyaPI/ProgPI/skymapmodule.pic
r2175 r2177 1 #---------------------- 1 #---------------------- Create Maps and Save 2 2 shell rm -f h4*.fits t4*.ppf h8*.fits t8*.ppf clh*.ppf clt*.ppf almh*.ppf almt*.ppf 3 3 delobjs * … … 39 39 disp h4 zoom/4 40 40 disp t4 zoom/4 41 zone 42 43 #---------------------- 44 delobjs * 41 42 #---------------------- test Map2Double 43 delobjs * 44 zone 45 45 openfits h4.fits 46 46 … … 50 50 51 51 delobjs * 52 zone 52 53 openppf t4.ppf 53 54 map2double t4 … … 55 56 saveppf t8 t8.ppf 56 57 57 #---------------------- 58 delobjs * 58 #---------------------- test Map2Float 59 delobjs * 60 zone 61 openfits h8.fits 62 openppf t8.ppf 63 64 map2float h8 65 map2float t8 66 typemap h8 67 typemap t8 68 69 #---------------------- test TypeMap 70 delobjs * 71 zone 59 72 openfits h4.fits 60 73 openfits h8.fits … … 66 79 typemap t8 67 80 68 #---------------------- 69 delobjs * 81 #---------------------- test Map2Map 82 delobjs * 83 zone 70 84 openfits h8.fits 71 85 openppf t8.ppf … … 73 87 map2map t8 h 74 88 75 #---------------------- 76 delobjs * 89 #---------------------- test MapMult 90 delobjs * 91 zone 77 92 openfits h8.fits 78 93 openppf t8.ppf … … 80 95 mapmult t8 1000 81 96 82 #---------------------- 83 delobjs * 97 #---------------------- test MapProj 98 delobjs * 99 zone 84 100 openfits h8.fits 85 101 maproj h8 h8p … … 92 108 93 109 delobjs * 110 zone 94 111 openppf t8.ppf 95 112 maproj t8 t8p … … 101 118 saveppf t8p100 t8p100.ppf 102 119 103 #---------------------- 104 delobjs * 120 #---------------------- test Map2Cl 121 delobjs * 122 zone 105 123 openfits h8p64.fits 106 124 map2cl h8p64 clh64 … … 112 130 113 131 delobjs * 132 zone 114 133 openppf t8p100.ppf 115 134 map2cl t8p100 clt100 191 … … 117 136 n/plot clt100.n*(n+1)*val%n ! ! crossmarker5 118 137 119 #---------------------- 120 delobjs * 138 #---------------------- test Map2Alm 139 delobjs * 140 zone 121 141 openfits h8p64.fits 122 142 map2alm h8p64 almh64 … … 125 145 126 146 delobjs * 147 zone 127 148 openppf t8p100.ppf 128 149 map2alm t8p100 almt100 191 … … 130 151 disp almt100 131 152 132 #---------------------- 133 delobjs * 153 #---------------------- test Alm2Cl 154 delobjs * 155 zone 156 openppf clh64.ppf 157 openppf almh64.ppf 158 alm2cl almh64 clh64fralm 159 n/plot clh64.n*(n+1)*val%n ! ! crossmarker5 160 n/plot clh64fralm.n*(n+1)*val%n ! ! "red same circlemarker5" 161 c++exec clh64fralm -= clh64; 162 n/plot clh64fralm.n*(n+1)*val%n ! ! crossmarker5 163 164 delobjs * 165 zone 166 openppf clt100.ppf 167 openppf almt100.ppf 168 alm2cl almt100 clt100fralm 169 n/plot clt100.n*(n+1)*val%n ! ! crossmarker5 170 n/plot clt100fralm.n*(n+1)*val%n ! ! "red same circlemarker5" 171 c++exec clt100fralm -= clt100; 172 n/plot clt100fralm.n*(n+1)*val%n ! ! crossmarker5 173 174 #---------------------- test Cl2Map et SetTypeMap 175 delobjs * 176 zone 134 177 openppf clh64.ppf 135 178 settypemap h … … 139 182 140 183 delobjs * 184 zone 141 185 openppf clt100.ppf 142 186 settypemap t … … 145 189 disp t8p100frcl 146 190 147 #---------------------- 148 delobjs * 191 #---------------------- test Alm2Map et SetTypeMap 192 delobjs * 193 zone 149 194 openppf almh64.ppf 150 195 settypemap h … … 154 199 155 200 delobjs * 201 zone 156 202 openppf almt100.ppf 157 203 settypemap t … … 160 206 disp t8p100fralm 161 207 162 #---------------------- 163 delobjs * 208 #---------------------- test Cl2llCl 209 delobjs * 210 zone 211 openppf clh64.ppf 212 cl2llcl clh64 llclh64 213 n/plot clh64.n*(n+1)*val%n ! ! crossmarker5 214 n/plot llclh64.val%n ! ! "red same circlemarker5" 215 216 delobjs * 217 zone 218 openppf clt100.ppf 219 cl2llcl clt100 llclt100 220 n/plot clt100.n*(n+1)*val%n ! ! crossmarker5 221 n/plot llclt100.val%n ! ! "red same circlemarker5" 222 223 #---------------------- test ClMean 224 delobjs * 225 zone 226 openppf clh64.ppf 227 cl2llcl clh64 llclh64 228 n/plot llclh64.val%n ! ! circlemarker5 229 clmean llclh64 230 clmean llclh64 ! 231 clmean llclh64 100,9999 mean 232 echo $mean 233 234 delobjs * 235 zone 236 openppf clt100.ppf 237 cl2llcl clt100 llclt100 238 n/plot llclt100.val%n ! ! circlemarker5 239 clmean llclt100 240 clmean llclt100 ! 241 clmean llclt100 100,9999 mean 242 echo $mean 243 244 #---------------------- test ClMult 245 delobjs * 246 openppf clh64.ppf 247 zone 1 2 248 n/plot clh64.val%n ! ! circlemarker5 249 clmult clh64 1000. 250 n/plot clh64.val%n ! ! circlemarker5 251 252 delobjs * 253 openppf clt100.ppf 254 zone 1 2 255 n/plot clt100.val%n ! ! circlemarker5 256 clmult clt100 1000. 257 n/plot clt100.val%n ! ! circlemarker5 258 259 #---------------------- test ClOper 260 delobjs * 261 zone 262 openppf clh64.ppf 263 cp clh64 dum 264 clop dum + clh64 - clh64 * clh64 / clh64 265 n/plot clh64.val%n ! ! crossmarker5 266 n/plot dum.val%n ! ! "same red circlemarker5" 267 268 delobjs * 269 zone 270 openppf clt100.ppf 271 cp clt100 dum 272 clop dum + clt100 - clt100 * clt100 / clt100 273 n/plot clt100.val%n ! ! crossmarker5 274 n/plot dum.val%n ! ! "same red circlemarker5" 275 276 delobjs * 277 zone 278 openppf clh64.ppf 279 openppf clt100.ppf 280 clop clh64 - clt100 281 n/plot clh64.val%n ! ! crossmarker5 282 283 #---------------------- test ClRebin 284 delobjs * 285 zone 286 openppf clh64.ppf 287 cl2llcl clh64 llclh64 288 clrebin llclh64 clntu 10,0 289 290 n/plot clntu.n%l ! ! crossmarker5 291 292 n/plot llclh64.val%n ! ! "crossmarker3" 293 n/plot clntu.clmean%l ! ! "same circlemarker5 red" 294 n/plot clntu.cllin%l ! ! "same boxmarker5 blue" 295 n/plot clntu.clpar%l ! ! "same trianglemarker5 violet" 296 297 n/plot llclh64.val%n ! ! "crossmarker3" 298 nt2d clntu l clmean 0 sclmean 1 " " "same circlemarker5 red thinline" 299 300 n/plot llclh64.val%n ! ! "crossmarker3" 301 nt2d clntu l cllin 0 scllin 1 " " "same boxmarker5 blue thinline" 302 303 n/plot llclh64.val%n ! ! "crossmarker3" 304 nt2d clntu l clpar 0 sclpar 1 " " "same trianglemarker5 violet thinline" 305 306 #---------------------- test CrMaskMap et SetTypeMap 307 delobjs * 308 zone 164 309 settypemap h 165 310 crmapmask h8m 256 -20,20 100,130 0,1 … … 168 313 169 314 delobjs * 315 zone 170 316 settypemap t 171 317 crmapmask t8m 400 -20,20 100,130 0,1 … … 173 319 disp t8m zoom/4 174 320 175 #---------------------- 176 delobjs * 321 #---------------------- test CrMaskFrMap 322 delobjs * 323 zone 177 324 openfits h8.fits 178 325 crmaskfrmap h8fm 256 h8 -1.e-30,1.e-30 0,1 … … 181 328 182 329 delobjs * 330 zone 183 331 openppf t8.ppf 184 332 crmaskfrmap t8fm 400 t8 -1.e-30,1.e-30 0,1 … … 186 334 disp t8fm zoom/4 187 335 188 #---------------------- 189 delobjs * 336 #---------------------- test MaskMap 337 delobjs * 338 zone 190 339 openfits h8.fits 191 340 openfits h8m.fits … … 194 343 195 344 delobjs * 345 zone 196 346 openppf t8.ppf 197 347 openppf t8m.ppf … … 200 350 201 351 delobjs * 352 zone 202 353 openfits h8.fits 203 354 openppf t8m.ppf … … 206 357 207 358 delobjs * 359 zone 208 360 openppf t8.ppf 209 361 openfits h8m.fits … … 211 363 disp t8 zoom/4 212 364 213 #---------------------- 214 delobjs * 365 #---------------------- test MapCover 366 delobjs * 367 zone 215 368 openfits h8m.fits 216 369 mapcover h8m 0.9,1 couvh8m … … 218 371 219 372 delobjs * 373 zone 220 374 openppf t8m.ppf 221 375 mapcover t8m 0.9,1 couvt8m 222 376 echo $couvt8m 223 377 224 #---------------------- 225 delobjs * 378 #---------------------- test Map2Local 379 delobjs * 380 zone 226 381 openfits h8.fits 227 382 map2local h8 h8loc 200,300 20,30 0,90 ! … … 231 386 232 387 delobjs * 388 zone 233 389 openppf t8.ppf 234 390 map2local t8 t8loc 200,300 20,30 0,90 ! … … 237 393 disp t8loc 238 394 239 #---------------------- 240 delobjs * 241 openfits h8.fits 242 rename h8 h8save 243 openfits h8.fits 244 mapop h8 + h8save - h8save * h8save / h8save 395 #---------------------- test MapOper 396 delobjs * 397 zone 398 openfits h8.fits 399 cp h8 h8save 400 mapop h8save + h8 - h8 * h8 / h8 401 disp h8save zoom/4 402 mapop h8save - h8 403 disp h8save zoom/4 404 405 delobjs * 406 zone 407 openppf t8.ppf 408 cp t8 t8save 409 mapop t8save + t8 - t8 * t8 / t8 410 disp t8save zoom/4 411 mapop t8save - t8 412 disp t8save zoom/4 413 414 delobjs * 415 zone 416 openfits h8.fits 417 openppf t8.ppf 418 mapop h8 - t8 245 419 disp h8 zoom/4 246 420 247 openppf t8.ppf 248 rename t8 t8save 249 openppf t8.ppf 250 mapop t8 + t8save - t8save * t8save / t8save 251 disp t8 zoom/4 252 253 mapop h8 - t8save 254 disp h8 zoom/4 255 mapop t8 - h8save 256 disp t8 zoom/4 257 258 #---------------------- 259 delobjs * 421 #---------------------- test MapStat 422 delobjs * 423 zone 260 424 openfits h8.fits 261 425 openfits h8fm.fits … … 271 435 mapstat t8 t8fm mean sig 272 436 echo mean=$mean sig=$sig 437 438 #---------------------- test VarOper 439 varop 1000 + 100 result 440 echo result is $result 441 varop 1000 - 100 result 442 echo result is $result 443 varop 1000 * 100 result 444 echo result is $result 445 varop 1000 / 100 result 446 echo result is $result 447 varop 1000 / 0 result 448 echo result is $result 449 450 varop 1000 sqrt ! result 451 echo result is $result 452 varop -1000 sqrt ! result 453 echo result is $result 454 varop 10 exp ! result 455 echo result is $result 456 varop 1000 log ! result 457 echo result is $result 458 varop -1000 log ! result 459 echo result is $result 460 varop 1000 log10 ! result 461 echo result is $result 462 varop -1000 log10 ! result 463 echo result is $result 464 465 varop 1000 pow 2 result 466 echo result is $result 467 varop 1000 pow 1000 result 468 echo result is $result
Note:
See TracChangeset
for help on using the changeset viewer.