Changeset 876 in Sophya
- Timestamp:
- Apr 11, 2000, 3:23:03 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaProg/PMixer/skymixer.cc
r856 r876 15 15 #include "fitsioserver.h" 16 16 17 #include "spherehealpix.h" 18 #include "fiospherehealpix.h" 17 #include "spheregorski.h" 19 18 20 19 #include "radspecvector.h" 21 20 #include "blackbody.h" 21 #include "derivblackbody.h" 22 22 #include "nupower.h" 23 23 … … 36 36 void SpectralResponse2Nt(SpectralResponse& sr, POutPersist & so, string name); 37 37 38 // 39 // treating maps 40 //--------------------------------------------------------- 41 template <class T> void MeanSig(NDataBlock<T> const & dbl, double& gmoy, double& gsig); 42 template <class T> void Sph2Sph(PixelMap<T>& in, PixelMap<T>& out); 43 // 44 // to add different sky components and corresponding tools 45 //---------------------------------------------------------- 46 template <class T> 47 void addComponent(SpectralResponse& sr, 48 PixelMap<T>& finalMap, 49 PixelMap<T>& mapToAdd, 50 RadSpectra& rs, double K=1.); 51 // 38 52 template <class T> 39 void addComponent(SpectralResponse& sr, PixelMap<T>& finalMap, 40 PixelMap<T>& mapToAdd, RadSpectra& rs, double K=1.); 53 void addComponentBeta(SphereGorski<T>& finalMap, 54 SphereGorski<T>& mapToAdd,SpectralResponse& sr, 55 SphereGorski<T>& betaMap, double normFreq, double K); 56 // 41 57 template <class T> 42 void MeanSig(NDataBlock<T> const & dbl, double& gmoy, double& gsig); 58 void integratedMap(SpectralResponse& sr, 59 SphereGorski<T>& betaMap, double normFreq, SphereGorski<T>& intBetaMap); 60 //template <class T> 61 //void integratedMap(SpectralResponse& sr, 62 // PixelMap<T>& betaMap, 63 // double normFreq, 64 // PixelMap<T>& outMap); 65 template <class T> 66 void addComponentBeta(SphereGorski<T>& finalMap, 67 SphereGorski<T>& mapToAdd, 68 SphereGorski<T>& intBetaMap, double K); 69 // 43 70 // ----------------------------------------------------------------- 44 71 … … 92 119 93 120 94 cout << " skymix/Info : NComp = " << nskycomp << " Sphere HEALPix_NSide= " << hp_nside << endl;121 cout << " skymix/Info : NComp = " << nskycomp << " SphereGorski_NSide= " << hp_nside << endl; 95 122 cout << " ... MapPath = " << (string)mapPath << " DebugLev= " << debuglev 96 123 << " PrintLev= " << printlev << endl; … … 99 126 if (debuglev > 0) so = new POutPersist("skymixdbg.ppf"); 100 127 101 Sphere HEALPix<float> outgs(hp_nside);128 SphereGorski<float> outgs(hp_nside); 102 129 bool okout = false; 103 130 … … 129 156 string key; 130 157 131 Sphere HEALPix<float> ings(hp_nside); // The input map158 SphereGorski<float> ings(hp_nside); // The input map 132 159 double K = 1.; 160 double freqOfMap = 1.; 133 161 // Loop over sky component 134 162 int sk; 135 163 for(sk = 0; sk<nskycomp; sk++) { 136 164 cout << " Processing sky component No " << sk+1 << endl; 165 137 166 sprintf(buff, "%d", sk+1); 138 167 key = (string)"MAPFITSFILE" + buff; 139 168 flnm = BuildFITSFileName(dc.SParam(key, 0)); 169 170 K = dc.DParam(key, 1, 1.); 171 172 bool mapDependentOfFreq = false; 173 key = (string)"BETAFITSFILE"+ buff; 174 if(dc.HasKey(key)) 175 { 176 mapDependentOfFreq = true; 177 } 178 cout << "the map has a mapDependentOfFreq = " << 179 mapDependentOfFreq << endl; 180 140 181 cout << " Reading Input FITS map " << (string)flnm << endl; 141 182 fios.load(ings, flnm, 2); 142 K = dc.DParam(key, 1, 1.); 143 if (debuglev > 4) { // Writing tne input map to the outppf 144 FIO_SphereHEALPix<float> fiog(ings); 183 if (debuglev > 4) { // Writing the input map to the outppf 184 FIO_SphereGorski<float> fiog(ings); 145 185 fiog.Write(*so, key); 146 } 147 // getting Emission spectra 148 if (es) { delete es; es = NULL; } 149 es = getEmissionSpectra(dc, sk); 150 186 } 151 187 if (printlev > 2) { 152 188 MeanSig(ings.DataBlock(), moy, sig ); 153 189 cout << " MeanSig for input map - Mean= " << moy << " Sigma= " << sig << endl; 154 190 } 155 addComponent(*sr, outgs, ings, *es, K); 191 // getting Emission spectra 192 if(!mapDependentOfFreq) 193 { 194 if (es) { delete es; es = NULL; } 195 es = getEmissionSpectra(dc, sk); 196 addComponent(*sr, outgs, ings, *es, K); 197 } 198 else 199 { 200 key = (string)"BETAFITSFILE"+ buff; 201 SphereGorski<float> betaMap; 202 flnm = BuildFITSFileName(dc.SParam(key, 0)); 203 double normFreq = dc.DParam(key, 1, 1.); 204 if (printlev > 4) cout << "....BetaFits... normalization Freq = " << normFreq << endl; 205 int nSideForInt = dc.DParam(key, 2, 1.); 206 if (printlev > 4) cout << "....BetaFits... NSide for Integration map = " << nSideForInt << endl; 207 cout << "....BetaFits... Reading Beta FITS map " << (string)flnm << endl; 208 fios.load(betaMap, flnm, 2); 209 if(nSideForInt<0) nSideForInt = sqrt(betaMap.NbPixels()/12); 210 211 bool bydefault = true; 212 if(!bydefault) 213 addComponentBeta(outgs,ings,*sr,betaMap,normFreq, K); 214 else 215 { 216 // integrate the betamap over the SpectralResponse 217 SphereGorski<float> intBetaMap(nSideForInt); 218 integratedMap(*sr, betaMap, normFreq, intBetaMap); 219 betaMap.Resize(8); 220 MeanSig(intBetaMap.DataBlock(), moy, sig ); 221 if (printlev > 4) cout << "....BetaFits... MeanSig for intBetaMap - Mean= " << moy << " Sigma= " << sig << endl; 222 // add the integrated beta map 223 addComponentBeta(outgs,ings,intBetaMap, K); 224 } 225 MeanSig(outgs.DataBlock(), moy, sig ); 226 cout << " MeanSig for Sum map - Mean= " << moy << " Sigma= " << sig << endl; 227 } 228 156 229 okout = true; 157 230 if (printlev > 1) { … … 175 248 FitsIoServer fios; 176 249 fios.save(outgs, arg[2]); 177 cout << "Output Map (Sphere HEALPix<float>) written to FITS file "250 cout << "Output Map (SphereGorski<float>) written to FITS file " 178 251 << (string)(arg[2]) << endl; 179 252 PrtTim("End of WriteFITS "); 180 // Saving the output map in PPF format253 // Saving the output map in PPF format 181 254 if (narg > 3) { 182 255 POutPersist s(arg[3]); 183 FIO_Sphere HEALPix<float> fiog(&outgs) ;256 FIO_SphereGorski<float> fiog(&outgs) ; 184 257 fiog.Write(s); 185 cout << "Output Map (Sphere HEALPix<float>) written to POutPersist file "258 cout << "Output Map (SphereGorski<float>) written to POutPersist file " 186 259 << (string)(arg[3]) << endl; 187 260 PrtTim("End of WritePPF "); … … 242 315 243 316 // Checking detection filter specification 244 // Checking input FITS file specifications317 // Checking input FITS file specifications 245 318 int kc; 246 319 char buff[256]; 247 320 bool pb = false; 248 321 string key3; 322 string key4; 323 string key5; 249 324 for(kc=0; kc<ncomp; kc++) { 250 325 sprintf(buff, "MAPFITSFILE%d", kc+1); 251 326 key = buff; 252 if (dc.NbParam(key) < 1 ) {253 msg = "Missing or invalid card : " + key ;327 if (dc.NbParam(key) < 1 ) { 328 msg = "Missing or invalid card : " + key + " " + key2 ; 254 329 pb = true; break; 255 330 } … … 260 335 sprintf(buff, "POWERLAWSPECTRA%d", kc+1); 261 336 key3 = buff; 262 if ( (dc.NbParam(key) < 3) && (dc.NbParam(key2) < 1) && (dc.NbParam(key3) < 6)) { 263 msg = "Missing card or invalid parameters : " + key + " " + key2 + " " + key3; 337 sprintf(buff, "BETAFITSFILE%d", kc+1); 338 key4 = buff; 339 sprintf(buff, "DIPOLE%d", kc+1); 340 key5 = buff; 341 if ( (dc.NbParam(key) < 3) && (dc.NbParam(key2) < 1) && (dc.NbParam(key3) < 6) && (dc.NbParam(key4)<2) 342 && (dc.NbParam(key5)<1)) { 343 msg = "Missing card or invalid parameters : " + key + " " + key2 + " " + key3 + " " + key4+ " " + key5; 264 344 pb = true; break; 265 345 } … … 352 432 string key = (string)"SPECTRAFITSFILE" + numb; 353 433 string key2 = (string)"BLACKBODY" + numb; 434 string key5 = (string)"DIPOLE" + numb; 354 435 string key3 = (string)"POWERLAWSPECTRA" + numb; 355 436 string ppfname = "espectra"; … … 377 458 ppfname = key2; 378 459 } 460 else if (dc.HasKey(key5) ) { // Creating Dipole 461 rs = new DerivBlackBody(dc.DParam(key5, 0, 2.726)); 462 ppfname = key5; 463 } 379 464 else if (dc.HasKey(key3) ) { // Creating PowerLaw emission spectra 380 465 double a = dc.DParam(key3, 0, 1.); … … 416 501 } 417 502 } 503 /* Nouvelle-Fonction */ 504 template <class T> 505 void addComponentBeta(SphereGorski<T>& finalMap, 506 SphereGorski<T>& mapToAdd,SpectralResponse& sr, 507 SphereGorski<T>& betaMap, double normFreq, double K) 508 { 509 // finalMap = finalMap + coeff* mapToAdd 510 // coeff = convolution of sr and rs 511 // compute the coefficient corresponding to mapToAdd 512 // betaMap is the map of (beta(theta,phi)) 513 514 int nbpix = finalMap.NbPixels(); 515 if (nbpix != mapToAdd.NbPixels()) 516 throw SzMismatchError("addComponentBeta()/Error: Unequal number of Input/Output map pixels"); 517 if (printlev > 1) 518 { 519 cout << "addComponentBeta - Coeff= " << K << endl; 520 cout << "nb pixels: " << finalMap.NbPixels() << endl; 521 } 522 SphereGorski<T> bigBetaMap(sqrt(nbpix/12)); 523 if(nbpix != betaMap.NbPixels()) 524 { 525 Sph2Sph(betaMap,bigBetaMap); 526 } 527 for(int i=0; i<finalMap.NbPixels(); i++) 528 { 529 // coeff = integration of (nu/normFreq)^(-beta(theta,phi)) in each pixels 530 RadSpectra* rs = new PowerLawSpectra 531 (1.,-bigBetaMap(i), 0., normFreq, 0.01, 800.); 532 double coeff = rs->filteredIntegratedFlux(sr); 533 finalMap(i) += coeff*K*mapToAdd(i); 534 } 535 } 536 537 template <class T> 538 void integratedMap(SpectralResponse& sr, 539 SphereGorski<T>& betaMap, 540 double normFreq, 541 SphereGorski<T>& intBetaMap) 542 { 543 // int nbpix = intBetaMap.NbPixels(); 544 // SphereGorski<T> newMap(sqrt(nbpix/12)); 545 Sph2Sph(betaMap,intBetaMap); 546 for(int i=0; i<intBetaMap.NbPixels(); i++) 547 { 548 RadSpectra* rs = new PowerLawSpectra 549 (1.,-intBetaMap(i), 0., normFreq); 550 double coeff = rs->filteredIntegratedFlux(sr); 551 intBetaMap(i) = coeff; 552 } 553 } 554 555 template <class T> 556 void addComponentBeta(SphereGorski<T>& finalMap, 557 SphereGorski<T>& mapToAdd,SphereGorski<T>& intBetaMap, double K) 558 { 559 // finalMap = finalMap + coeff* mapToAdd 560 // coeff = convolution of sr and rs 561 // compute the coefficient corresponding to mapToAdd 562 // integBetaMap is the map of the integration (nu/normFreq)^(-beta(theta,phi)) over 563 // the spectralResponse 564 // different from addComponentBeta(PixelMap<T>& finalMap, 565 // PixelMap<T>& mapToAdd,SpectralResponse& sr, PixelMap<T>& betaMap, double normFreq, double K) 566 // since it permits to use a intBetaMap with a different number of pixels than 567 // the other maps 568 569 int nbpix = finalMap.NbPixels(); 570 if (nbpix != mapToAdd.NbPixels()) 571 throw SzMismatchError("addComponentBeta(PixelMap<T>&,PixelMap<T>&,PixelMap<T>&,double)/Error: Unequal number of Input/Output map pixels"); 572 double coeff = K; 573 574 if(nbpix != intBetaMap.NbPixels()) 575 { 576 cout << "nbpix != intBetaMap.NbPixels()" << endl; 577 SphereGorski<T> bigBetaMap(sqrt(nbpix/12)); 578 cout << "new map with size corresponding to mapToAdd" << sqrt(nbpix/12) << endl; 579 Sph2Sph(intBetaMap,bigBetaMap); 580 for(int i=0; i<finalMap.NbPixels();i++) 581 { 582 finalMap(i) += coeff*mapToAdd(i)*bigBetaMap(i); 583 } 584 } 585 else 586 { 587 for(int i=0; i<finalMap.NbPixels();i++) 588 { 589 finalMap(i) += coeff*mapToAdd(i)*intBetaMap(i); 590 } 591 } 592 if (printlev > 1) 593 { 594 cout << "addComponentBeta(SG<T>,SG<T>,SG<T>,double) - Coeff= " << K << endl; 595 } 596 } 597 598 /* Nouvelle-Fonction */ 599 600 template <class T> 601 void Sph2Sph(PixelMap<T>& in, PixelMap<T>& out) 602 // Cette fonction remplit la sphere out a partir de la sphere in 603 // Les spheres peuvent etre de type et de pixelisations differentes 604 { 605 int k,kin,kout; 606 double teta,phi; 607 608 int* cnt = new int[out.NbPixels()+1]; 609 for(kout=0; kout<out.NbPixels(); kout++) 610 { cnt[kout] = 0; out(kout) = 0.; } 611 612 for(kin=0; kin<in.NbPixels(); kin++) { 613 in.PixThetaPhi(kin, teta, phi); 614 kout = out.PixIndexSph(teta, phi); 615 out(kout) += in(kin); 616 617 cnt[kout] ++; 618 619 } 620 621 double moy, sig, dcn; 622 moy = 0.; sig = 0.; 623 for(kout=0; kout<out.NbPixels(); kout++) { 624 dcn = cnt[kout]; moy += dcn; sig += (dcn*dcn); 625 if (cnt[kout] > 0) out(kout) /= dcn; 626 else { 627 out.PixThetaPhi(kout, teta, phi); 628 int pixel = in.PixIndexSph(teta,phi); 629 out(kout) = in.PixVal(pixel); 630 } 631 } 632 633 moy /= out.NbPixels(); 634 sig = sig/out.NbPixels() - moy*moy; 635 if (sig >= 0.) sig = sqrt(sig); 636 637 delete[] cnt; 638 639 printf("Sph2Sph_Info NbPix In= %d Out= %d CntMoy,Sig= %g %g\n", 640 in.NbPixels(), out.NbPixels(), moy, sig); 641 PrtTim("End of Sph2Sph() "); 642 } 643 644 418 645 419 646 /* Nouvelle-Fonction */
Note:
See TracChangeset
for help on using the changeset viewer.