Changeset 877 in Sophya for trunk/SophyaProg/PMixer


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

Sophie cf. skymixer : idem::

Location:
trunk/SophyaProg/PMixer
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaProg/PMixer/RSextract.d

    r761 r877  
    11#  EXT_RS  NbComponents  NSide_HealPix
    2 @EXT_RS  31
     2@EXT_RS  31 1024
    33
    44#  RD_EXT_PATH  PathForFITS   
     
    2222@RADSPECMAP11   eran102_441_00150000mhz.fits
    2323@RADSPECMAP12   eran102_441_00188839mhz.fits   
    24 @RADSPECMAP13   eran102_441_00237734mhz.fits    00237734
     24@RADSPECMAP13   eran102_441_00237734mhz.fits
    2525@RADSPECMAP14   eran102_441_00299289mhz.fits
    2626@RADSPECMAP15   eran102_441_00376783mhz.fits
     
    8181# Filter definition now !!
    8282# define the detector (only one)
    83 @GAUSSFILTER 143 12 0.84 50. 300.
     83@GAUSSFILTER 143 16 0.84 50. 300.
    8484
    8585#  ---- wanna print a lot of stuff..---------
    8686#  ----  let's try PRINTLEVEL 5          ----
    87 @PRINTLEVEL  0
     87@PRINTLEVEL  5
    8888
  • trunk/SophyaProg/PMixer/extractRS.cc

    r817 r877  
    1212#include "tvector.h"
    1313#include "vector3d.h"
    14 
     14#include "nbrandom.h"
    1515#include "timing.h"
    1616#include "sambainit.h"
     
    3434SpectralResponse * getSpectralResponse(DataCards & dc);
    3535template <class T>
    36 void addComponent(SpectralResponse&  sr, PixelMap<T>& finalMap,
    37                   PixelMap<T>& mapToAdd, RadSpectra& rs, double K=1.);
    38 template <class T>
    3936void  MeanSig(NDataBlock<T> const & dbl, double& gmoy, double& gsig);
    4037float ComputeFrequency(DataCards &,string&);
     
    4542static bool rdmap = false;    // true -> Read map first
    4643static char mapPath[256];     // Path for input maps
     44static int  hp_nside = 32;    // HealPix NSide
    4745static int  nskycomp = 0;     // Number of sky components
    4846static int  debuglev = 0;     // Debug Level
     
    5553int main(int narg, char * arg[])
    5654{
    57   if ((narg < 4) || ((narg > 1) && (strcmp(arg[1], "-h") == 0) )) {
    58     cout << "  Usage: extractRS parameterFile outputfitsnameformaps  outputfitsnameforsource [outppfname]" << endl;
     55  if ((narg < 3) || ((narg > 1) && (strcmp(arg[1], "-h") == 0) )) {
     56    cout << "  Usage: extractRS parameterFile outputfitsnameformaps  [outppfname]" << endl;
    5957    exit(0);
    6058  }
     
    9088 
    9189 
    92   cout << " extractRS/Info : NComp = " <<  nskycomp << endl;
     90  cout << " extractRS/Info : NComp = " <<  nskycomp << " SphereGorski_NSide= " << hp_nside << endl;
    9391  cout << "  ... MapPath = " << (string)mapPath << "  DebugLev= " << debuglev
    9492       << "  PrintLev= " << printlev << endl;
     
    9795  // We create an output persist file for writing debug objects
    9896  if (debuglev > 0) so = new POutPersist("extrRSdbg.ppf");
    99  
    100  
    101   TMatrix<float> outgs;
    102   bool okout = false;
     97  SphereGorski<float> SourceMap(hp_nside);
     98  SphereGorski<float> OutputMap(hp_nside);
     99  bool okout = true;
    103100 
    104101  try {
     
    120117    int nb_source;
    121118    TMatrix<float> rareSource; //par freq et par numero de source
    122        
     119   
    123120    for(sk = 0; sk<maxOfSkyComp; sk++)
    124121      {
    125        
    126122        TMatrix<float> ings;   
    127123        // Opening the file containing the map
     
    137133        if (printlev > 2)
    138134          {
    139             MeanSig(ings.DataBlock(), moy, sig );
    140             cout << " MeanSig for input map - Mean= " << moy << " Sigma= " << sig << endl;
    141           }
    142 
     135            double min = 1000000000;
     136            double max = -10000000000;
     137            for(int x=0;x<ings.NRows(); x++)
     138              {
     139                for(int y=0;y<ings.NCols(); y++)
     140                  {
     141                    if(min>ings(x,y)) min = ings(x,y);
     142                    if(max<ings(x,y)) max = ings(x,y);
     143                  }
     144              }
     145            cout << "min and max values for input map" << min << " " << max << endl;
     146          }
    143147        // Computing the frequency according to the name of the file
    144148        freq(sk) =  ComputeFrequency(dc,key);
    145149        if (printlev > 2)  cout << "filling spectrum for freq = " << freq(sk) << endl;
     150       
    146151        // Opening the file containing the point source
    147152        sprintf(buff, "%d", sk+1);
     
    169174        for(int x=0;x<ings.NRows(); x++)
    170175          {
    171             for(int y=0;x<ings.NCols(); x++)
     176            for(int y=0;y<ings.NCols(); y++)
    172177              {
    173178                spectrum(x,y) = ings(x,y)*1.e-26; //for Jansky->W
     
    185190        K = dc.DParam(key, 1, 1.);
    186191        if (debuglev > 4) {  // Writing the input map to the outppf
    187           so->PutObject(ings, key);    // $CHECK$  Reza 05/04/2000
     192          FIO_TMatrix<float> fiog;
     193          fiog.Write(*so, key);
    188194        }
    189195       
     
    205211    TVector<float> outCoeff(nbOfPix);
    206212
    207     for(int pix=1;pix<nbOfPix;pix++)
     213    for(int pix=0;pix<nbOfPix;pix++)
    208214      {
    209215        Vector smallFDeNu(maxOfSkyComp);
     
    216222        if (printlev > 10)  cout << "RadiationSpectra" << radSV << endl;
    217223
    218         TVector<float> smallFDeNuT(maxOfSkyComp);
    219         for(sk = 0; sk<maxOfSkyComp; sk++)
    220           {
    221             smallFDeNuT(sk) = smallFDeNu(sk);
    222           }
    223224        outCoeff(pix) = radSV.filteredIntegratedFlux(*sr);
    224225      }
    225 
    226     FitsIoServer fiosrs;
    227     fiosrs.save(outCoeff,arg[2]);
    228     cout << "Output Map (TMatrix<float>) written to FITS file " 
    229          << arg[2]<< endl;
    230     cout << endl;
    231 
     226   
     227    for(int i=0;i<OutputMap.NbPixels();i++)
     228      {
     229        float random = frand01();
     230        if(random == 1) random = frand01();
     231        int randomPix = random*OutputMap.NbPixels();
     232        int outpix = random*nbOfPix;
     233        OutputMap(i) = outCoeff(outpix)*1.e18;
     234      }
     235
     236   
    232237    // ---------------------------------------------------------------------
    233238    //      Integration in the detector band of the sources
     
    244249        sourceCoeff(nsource) = radSV_Source.filteredIntegratedFlux(*sr);
    245250      }
    246     FitsIoServer fiosrs_source;
    247     fiosrs_source.save(sourceCoeff,arg[3]);
    248     cout << "Output Map (TMatrix<float>) written to FITS file " 
    249          << arg[3]<< endl;
    250     cout << endl;
    251 
    252     // ---------------------------------------------------------------------
    253     //     Check of write/read on FITS file
    254     // ---------------------------------------------------------------------
    255     if (printlev > 2)
    256     {
    257       cout << " Check of write/read on FITS file for skymap!" << endl;
    258       TVector<float> outout;
    259       FitsIoServer fiotest;
    260       fiotest.load(outout, arg[2]);
    261       cout << "Coeff(2)" << outout(2) << " ? " << outCoeff(2) << endl;
    262       cout << endl;
    263     }
    264     if (printlev > 2)
    265     {
    266       cout << " Check of write/read on FITS file for sources!" << endl;
    267       FitsIoServer fiotest;
    268       TVector<float> outout2;
    269       fiotest.load(outout2, arg[3]);
    270       cout << "sourceCoeff(2)" << outout2(2) << " ? " << sourceCoeff(2) << endl;
    271     }
    272 
    273 
    274   }   // End of try block
    275  
    276  
     251
     252    for(int i=0;i<nb_source;i++)
     253      {
     254        float random = frand01();
     255        int outPix = random*OutputMap.NbPixels();
     256        SourceMap(outPix) = sourceCoeff(i);
     257        OutputMap(outPix) = OutputMap(i)+ SourceMap(outPix)*1.E18;
     258      }
     259  } 
    277260  catch (PException exc) {
    278261    msg = exc.Msg();
     
    291274 
    292275  // Saving the output map in FITS format
    293   if (okout) {
    294     FitsIoServer fios;
    295     fios.save(outgs, arg[2]);
    296     cout << "Output Map (TMatrix<float>) written to FITS file "
    297          << (string)(arg[2]) << endl;
    298     if(printlev>2) PrtTim("End of WriteFITS ");
    299     // Saving the output map in PPF format
    300     if (narg > 3) {
    301       POutPersist s(arg[3]);
    302       s.PutObject(outgs);   //  $CHECK$  Reza 05/04/2000
    303       cout << "Output Map (TMatrix<float>) written to POutPersist file " 
    304            << (string)(arg[3]) << endl;
    305       if(printlev>2) PrtTim("End of WritePPF ");
     276  if (okout)
     277    {
     278      //       {
     279      //        FitsIoServer fios;
     280      //        fios.save(SourceMap, arg[3]);
     281      //        double moy,sig;
     282      //        MeanSig(SourceMap.DataBlock(),moy,sig);
     283      //        cout << " MeanSig for Source Map - Mean= " << moy << " Sigma= " << sig << endl;
     284      //        cout << "Source Map (SphereGorski<float>) written to FITS file "
     285      //             << (string)(arg[3]) << endl;
     286      //       }
     287      {
     288        FitsIoServer fios;
     289        fios.save(OutputMap, arg[2]);
     290        double moy,sig;
     291        MeanSig(OutputMap.DataBlock(),moy,sig);
     292        cout << " MeanSig for Output Map - Mean= " << moy << " Sigma= " << sig << endl;
     293        cout << "Output Map (SphereGorski<float>) written to FITS file "
     294             << (string)(arg[2]) << endl;
     295      }
     296      if(printlev>2) PrtTim("End of WriteFITS ");
     297      // Saving the output map in PPF format
     298      if (narg > 2) {
     299        POutPersist s(arg[3]);
     300        FIO_SphereGorski<float> fiog(OutputMap);
     301        fiog.Write(s);
     302        cout << "Output Map (SphereGorski<float>) written to POutPersist file " 
     303             << (string)(arg[3]) << endl;
     304        if(printlev>2) PrtTim("End of WritePPF ");
     305      }
    306306    }
    307   }
    308307  if (so) delete so;  //  Closing the debug ppf file
    309308  return(rc);
     
    326325 
    327326  //  Checking datacards
    328   if (dc.NbParam("EXT_RS") < 1)   {
     327  if (dc.NbParam("EXT_RS") < 2)   {
    329328     rc = 71;
    330329     msg = "Invalid parameters  - Check @EXT_RS card ";
     
    337336  int ncomp = 0;
    338337  ncomp = dc.IParam("EXT_RS", 0);
     338  int nside = 32;
     339  nside = dc.IParam("EXT_RS", 1);
    339340 
    340341  for(kc=0; kc<ncomp; kc++)
     
    371372  msg = "OK";
    372373  nskycomp = ncomp;
    373  
     374  hp_nside = nside;
    374375  // Checking for PATH definition card
    375376  key = "RS_EXT_PATH";
     
    409410  if (gsig >= 0.) gsig = sqrt(gsig);
    410411}
    411 /* Nouvelle-Fonction */
    412 template <class T>
    413 void addComponent(SpectralResponse&  sr, PixelMap<T>& finalMap,
    414                   PixelMap<T>& mapToAdd, RadSpectra& rs, double K)
    415 {
    416   // finalMap = finalMap + coeff* mapToAdd
    417   // coeff    =  convolution of sr and rs
    418   // compute the coefficient corresponding to mapToAdd
    419   if (finalMap.NbPixels() != mapToAdd.NbPixels())   
    420     throw SzMismatchError("addComponent()/Error: Unequal number of Input/Output map pixels");
    421   double coeff = rs.filteredIntegratedFlux(sr) * K;
    422   if (printlev > 1)
    423     cout << " addComponent - Coeff= " << coeff << " (K= " << K << ")" << endl;
    424   for(int i=0; i<finalMap.NbPixels(); i++)
    425     {
    426       finalMap(i) += coeff * mapToAdd(i);
    427     }
    428 }
    429 
    430412
    431413/* Nouvelle-Fonction */
Note: See TracChangeset for help on using the changeset viewer.