Changeset 876 in Sophya


Ignore:
Timestamp:
Apr 11, 2000, 3:23:03 PM (25 years ago)
Author:
ansari
Message:

sophie: new functionnalities added according to Garching meeting:
:

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaProg/PMixer/skymixer.cc

    r856 r876  
    1515#include "fitsioserver.h"
    1616
    17 #include "spherehealpix.h"
    18 #include "fiospherehealpix.h"
     17#include "spheregorski.h"
    1918
    2019#include "radspecvector.h"
    2120#include "blackbody.h"
     21#include "derivblackbody.h"
    2222#include "nupower.h"
    2323
     
    3636void SpectralResponse2Nt(SpectralResponse& sr, POutPersist & so, string name);
    3737
     38//
     39// treating maps
     40//---------------------------------------------------------
     41template <class T> void  MeanSig(NDataBlock<T> const & dbl, double& gmoy, double& gsig);
     42template <class T> void Sph2Sph(PixelMap<T>& in, PixelMap<T>& out);
     43//
     44// to add different sky components and corresponding tools
     45//----------------------------------------------------------
     46template <class T>
     47void addComponent(SpectralResponse&  sr,
     48                                     PixelMap<T>& finalMap,
     49                                     PixelMap<T>& mapToAdd,
     50                                     RadSpectra& rs, double K=1.);
     51//
    3852template <class T>
    39 void addComponent(SpectralResponse&  sr, PixelMap<T>& finalMap,
    40                   PixelMap<T>& mapToAdd, RadSpectra& rs, double K=1.);
     53void addComponentBeta(SphereGorski<T>& finalMap,
     54                      SphereGorski<T>& mapToAdd,SpectralResponse& sr,
     55                      SphereGorski<T>& betaMap, double normFreq, double K);
     56//
    4157template <class T>
    42 void  MeanSig(NDataBlock<T> const & dbl, double& gmoy, double& gsig);
     58void 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);
     65template <class T>
     66void addComponentBeta(SphereGorski<T>& finalMap,
     67                      SphereGorski<T>& mapToAdd,
     68                      SphereGorski<T>& intBetaMap, double K);
     69//
    4370// -----------------------------------------------------------------
    4471
     
    92119
    93120
    94 cout << " skymix/Info : NComp = " <<  nskycomp << " SphereHEALPix_NSide= " << hp_nside << endl;
     121cout << " skymix/Info : NComp = " <<  nskycomp << " SphereGorski_NSide= " << hp_nside << endl;
    95122cout << "  ... MapPath = " << (string)mapPath << "  DebugLev= " << debuglev
    96123     << "  PrintLev= " << printlev << endl;
     
    99126if (debuglev > 0) so = new POutPersist("skymixdbg.ppf");
    100127
    101 SphereHEALPix<float> outgs(hp_nside);
     128SphereGorski<float> outgs(hp_nside);
    102129bool okout = false;
    103130
     
    129156  string key;
    130157
    131   SphereHEALPix<float> ings(hp_nside);  // The input map
     158  SphereGorski<float> ings(hp_nside);  // The input map
    132159  double K = 1.;
     160  double freqOfMap = 1.;
    133161  // Loop over sky component
    134162  int sk;
    135163  for(sk = 0; sk<nskycomp; sk++) {
    136164    cout << " Processing sky component No " << sk+1 << endl;
     165   
    137166    sprintf(buff, "%d", sk+1);
    138167    key = (string)"MAPFITSFILE" + buff;
    139168    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
    140181    cout << " Reading Input FITS map " << (string)flnm << endl;
    141182    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);
    145185      fiog.Write(*so, key);
    146       }
    147     // getting Emission spectra 
    148     if (es) { delete es; es = NULL; }
    149     es = getEmissionSpectra(dc, sk);
    150    
     186    }
    151187    if (printlev > 2) {
    152188      MeanSig(ings.DataBlock(), moy, sig );
    153189      cout << " MeanSig for input map - Mean= " << moy << " Sigma= " << sig << endl;
    154190    }
    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
    156229    okout = true;
    157230    if (printlev > 1) {
     
    175248  FitsIoServer fios;
    176249  fios.save(outgs, arg[2]);
    177   cout << "Output Map (SphereHEALPix<float>) written to FITS file "
     250  cout << "Output Map (SphereGorski<float>) written to FITS file "
    178251       << (string)(arg[2]) << endl;
    179252  PrtTim("End of WriteFITS ");
    180 // Saving the output map in PPF format
     253  // Saving the output map in PPF format
    181254  if (narg > 3) {
    182255   POutPersist s(arg[3]);
    183    FIO_SphereHEALPix<float> fiog(&outgs) ;
     256   FIO_SphereGorski<float> fiog(&outgs) ;
    184257   fiog.Write(s);
    185    cout << "Output Map (SphereHEALPix<float>) written to POutPersist file " 
     258   cout << "Output Map (SphereGorski<float>) written to POutPersist file " 
    186259        << (string)(arg[3]) << endl;
    187260   PrtTim("End of WritePPF ");
     
    242315
    243316  // Checking detection filter specification
    244 //  Checking input FITS file specifications
     317  //  Checking input FITS file specifications
    245318  int kc;
    246319  char buff[256];
    247320  bool pb = false;
    248321  string key3;
     322  string key4;
     323  string key5;
    249324  for(kc=0; kc<ncomp; kc++) {
    250325    sprintf(buff, "MAPFITSFILE%d", kc+1);
    251326    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 ;
    254329      pb = true;  break;
    255330    }
     
    260335    sprintf(buff, "POWERLAWSPECTRA%d", kc+1);
    261336    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;
    264344      pb = true;  break;
    265345    }
     
    352432  string key = (string)"SPECTRAFITSFILE" + numb;
    353433  string key2 = (string)"BLACKBODY" + numb;
     434  string key5 = (string)"DIPOLE" + numb;
    354435  string key3 = (string)"POWERLAWSPECTRA" + numb;
    355436  string ppfname = "espectra";
     
    377458    ppfname = key2;
    378459  }
     460  else if (dc.HasKey(key5) ) { // Creating Dipole
     461    rs = new DerivBlackBody(dc.DParam(key5, 0, 2.726));
     462    ppfname = key5;
     463  }
    379464  else if (dc.HasKey(key3) ) { // Creating PowerLaw emission spectra
    380465    double a = dc.DParam(key3, 0, 1.);
     
    416501    }
    417502}
     503/* Nouvelle-Fonction */
     504template <class T>
     505void 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
     537template <class T>
     538void 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
     555template <class T>
     556void 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
     600template <class T>
     601void 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
    418645
    419646/* Nouvelle-Fonction */
Note: See TracChangeset for help on using the changeset viewer.