#include "machdefs.h" // Definitions specifiques SOPHYA #include #include #include "nbmath.h" #include "timing.h" #include "array.h" #include "skymap.h" #include "samba.h" #include "sambainit.h" #include "fitsspherehealpix.h" #include "fitstarray.h" /*! \ingroup PrgMap \file prjsmap.cc \brief \b prjsmap: Molleweide and sinus projection of sky maps \verbatim csh> prjsmap -h SOPHYA Version 1.1 Revision 0 (V_Fev2001) -- Mar 9 2001 15:45:31 cxx prjsmap : Molleweide and Sinus projection for sky maps Usage: prjsmap [-float/-r4] [-sinus] [-sx sizeX] [-sy sizeY] [-scale fact] [-off val][-ump val] [-invy] [-fitsin] [-fitsout] InFileName OutFileName -float (-r4): single precision sky map and projection (default = double) -sinus: Selects Sinus projection (default Molleweide projection) -sx sizeX: Projected map size in X -sy sizeY: Projected map size in Y default: sizeX = 2*sizeY ; sizeX*sizeY ~ map.NbPixels()/2 -scale fact: scale factor applied to skymap pixels (def=1.) -off val: offset value for projected map (def=0.) prj(ix, jy) = offset + scale*skymap(theta, phi) -ump val: Unmapped pixel value in projected map (def=0.) -invy: reverses the projection direction along Y (Theta) -fitsout: Select the FITS format for the output map (default PPF format) -fitsin : Select the FITS format for the input vector (default PPF format) InFileName : Input file name (HEALPix map) OutFileName : Output file name (the C_l vector) \endverbatim */ /* Nouvelle-Fonction */ void Usage(bool fgerr) { cout << endl; if (fgerr) { cout << " prjsmap : Argument Error ! prjsmap -h for usage " << endl; exit(1); } else { cout << " prjsmap : Molleweide and Sinus projection for sky maps \n" << " Usage: prjsmap [-float/-r4] [-sinus] [-sx sizeX] [-sy sizeY] [-scale fact] \n" << " [-off val][-ump val] [-invy] [-fitsin] [-fitsout] InFileName OutFileName\n" << " -float (-r4): single precision sky map and projection (default = double) \n" << " -sinus: Selects Sinus projection (default Molleweide projection) \n" << " -sx sizeX: Projected map size in X \n" << " -sy sizeY: Projected map size in Y \n" << " default: sizeX = 2*sizeY ; sizeX*sizeY ~ map.NbPixels()/2 \n" << " -scale fact: scale factor applied to skymap pixels (def=1.) \n" << " -off val: offset value for projected map (def=0.) \n" << " prj(ix, jy) = offset + scale*skymap(theta, phi) \n" << " -ump val: Unmapped pixel value in projected map (def=0.) \n" << " -invy: reverses the projection direction along Y (Theta) \n" << " -fitsout: Select the FITS format for the output map (default PPF format) \n" << " -fitsin : Select the FITS format for the input vector (default PPF format) \n" << " InFileName : Input file name (HEALPix map) \n" << " OutFileName : Output file name (the C_l vector) \n" << endl; exit(0); } } /* Nouvelle-Fonction */ template class _PrjMap { public : /* Methode */ static void PM_MeanSigma(PixelMap const & map, double& gmoy, double& gsig, T& min, T& max) { min = max = map(0); gmoy=0.; gsig = 0.; double valok; for(int k=0; kmax) max = map(k); } gmoy /= (double)map.NbPixels(); gsig = gsig/(double)map.NbPixels() - gmoy*gmoy; if (gsig >= 0.) gsig = sqrt(gsig); return; } /* Methode */ static TArray Project_Molleweide(SphericalMap const & map, int sx=0, int sy=0, T ump=0, T offset=0, T scale=1, bool invy=false) { if ( (sx <= 0) && (sy <= 0) ) { sy = sqrt((double)(map.NbPixels()/2)); sx = sy*2; } else { if (sx <= 0) sx = 2*sy; else sy = sx/2; } TArray prj(sx, sy); prj = ump; // On met tout a ump cout << " Molleweide projection (sizeX= " << sx << " sizeY= " << sy << " )" << " Scale=" << scale << " Offset=" << offset << endl; r_8 xa, yd, teta,phi, facteur; int_4 ix, jy, k; for(jy=0; jy= 0.) ) { k = map.PixIndexSph(teta, phi); prj(ix,jy,0) = offset + scale*map(k); } } } return prj; } /* Methode */ static TArray Project_Sinus(SphericalMap const & map, int sx=0, int sy=0, T ump=0, T offset=0, T scale=1, bool invy=false) { if ( (sx <= 0) && (sy <= 0) ) { sy = sqrt((double)(map.NbPixels()/2)); sx = sy*2; } else { if (sx <= 0) sx = 2*sy; else sy = sx/2; } TArray prj(sx, sy); prj = ump; // On met tout a ump cout << " Sinus projection (sizeX= " << sx << " sizeY= " << sy << " )" << " Scale=" << scale << " Offset=" << offset << endl; r_8 xa, yd, teta,phi, facteur; int_4 ix, jy, k; for(jy=0; jy= 0.) ) { k = map.PixIndexSph(teta, phi); prj(ix,jy,0) = offset + scale*map(k); } } } return prj; } /* Methode */ static void Project(string & infile, string & outfile, int sx, int sy, T ump, T offset, T scale, bool fgsin, bool invy, bool fgfitsin, bool fgfitsout) { double deg2rad = M_PI/180.; double minute2rad = M_PI/(180.*60.); SphericalMap * sphp = NULL; SphereHEALPix sphh; PPersist * pp = NULL; if (fgfitsin) { cout << "--- Reading Input FITS file " << infile << endl; FitsInFile fii(infile); fii >> sphh; sphp = &sphh; } else { cout << "--- Reading Input PPF file " << infile << endl; PInPersist ppi(infile); pp = ppi.ReadObject(); if (pp) sphp = dynamic_cast< SphericalMap * > (pp->DataObj()); else sphp = NULL; if (sphp == NULL) { cout << " Object in PPF file is not a SphericalMap or wrong data type ! " << endl; throw TypeMismatchExc("_PrjMap::Project(...) Error reading input PPF file !"); } } SphericalMap & sph = *sphp; T min, max; double mean, sigma; PM_MeanSigma(sph, mean, sigma, min, max); cout << " Input map type= " << sph.TypeOfMap() << " PixParm (=NSide for HEALPix)= " << sph.SizeIndex() << endl; cout << " Input map : NbPixels= " << sph.NbPixels() << " Resolution= " << sqrt(sph.PixSolAngle(0))/minute2rad << " Arcminutes " << endl; cout << " map.Min= " << min << " map.Max= " << max << " map.Mean= " << mean << " map.Sigma= " << sigma << endl; cout << "--- Sky map projection " << endl; TArray prj; if (fgsin) prj = Project_Sinus(sph, sx, sy, ump, offset, scale, invy); else prj = Project_Molleweide(sph, sx, sy, ump, offset, scale, invy); cout << "--- Statistics on the projected map :" ; prj.Show(); prj.MinMax(min, max); MeanSigma(prj, mean, sigma); cout << " prj.Min= " << min << " prj.Max= " << max << " prj.Mean= " << mean << " prj.Sigma= " << sigma << endl; if (fgfitsout) { cout << "--- Writing projection to Output FITS file " << outfile << endl; FitsOutFile fio(outfile); fio << prj; } else { cout << "--- Writing projection to Output PPF file " << outfile << endl; POutPersist ppo(outfile); ppo << prj; } if (pp) delete pp; } }; /* Main-Program */ int main(int narg, char *arg[]) { if ((narg > 1) && (strcmp(arg[1],"-h") == 0) ) Usage(false); double ump = 0.; double off = 0.; double scale = 1.; int sx = 0; int sy = 0; string infile; string outfile; bool fgfitsin = false; bool fgfitsout = false; bool fgr4 = false; bool fgsinus = false; bool fginvy = false; cout << " prjsmap : Decoding command line options ... " << endl; int ko=1; for (int k=1; k --> Array (float)" << endl; _PrjMap::Project(infile, outfile, sx, sy, ump, off, scale, fgsinus, fginvy, fgfitsin, fgfitsout); } else { cout << " Projecting SphericalMap --> Array (double)" << endl; _PrjMap::Project(infile, outfile, sx, sy, ump, off, scale, fgsinus, fginvy, fgfitsin, fgfitsout); } } catch (PThrowable & exc) { // Exceptions de SOPHYA cerr << " prjsmap: Catched Exception " << (string)typeid(exc).name() << " - Msg= " << exc.Msg() << endl; } catch (...) { // Autres Exceptions cerr << " prjsmap: some other exception was caught ! " << endl; } PrtTim("End of prjsmap "); return(0); }