| 1 | // Pour boucher les trous d'une sphere HEALPIX utilisant une autre sphere
 | 
|---|
| 2 | //             cmv 13/6/01
 | 
|---|
| 3 | // extrap2sph -w sph143k05_e.fits sph143k05.fits sphred.fits sphout_2.fits
 | 
|---|
| 4 | // extrap2sph -m -1.e-30 -M +1.e-30 sph143k05.fits sphred.fits sphout_22.fits
 | 
|---|
| 5 | #include "machdefs.h"
 | 
|---|
| 6 | #include <unistd.h>
 | 
|---|
| 7 | #include <stdexcept>
 | 
|---|
| 8 | #include <iostream.h>
 | 
|---|
| 9 | #include <stdio.h>
 | 
|---|
| 10 | #include <stdlib.h>
 | 
|---|
| 11 | #include "skymapinit.h"
 | 
|---|
| 12 | #include "skymap.h"
 | 
|---|
| 13 | #include "fitsspherehealpix.h" 
 | 
|---|
| 14 | 
 | 
|---|
| 15 | void usage();
 | 
|---|
| 16 | void usage()
 | 
|---|
| 17 | {
 | 
|---|
| 18 | cout<<"extrap2sph [-w sphinw.fits -m valmin -M valmax]"<<endl
 | 
|---|
| 19 |     <<"           sphin.fits sphred.fits sphout.fits"<<endl
 | 
|---|
| 20 |     <<" -w sphinw.fits : input sphere  weight (def=NULL)"<<endl
 | 
|---|
| 21 |     <<" -m minval : value to identify EMPTY pixel (def=-1.e30.)"<<endl
 | 
|---|
| 22 |     <<" -M maxval : value to identify EMPTY pixel (def=+1.e30)"<<endl
 | 
|---|
| 23 |     <<"    condition for EMPTY pixel is (minval<val<maxval)"<<endl
 | 
|---|
| 24 |     <<"    (bounds are excluded, used only if sphinw.fits==NULL)"<<endl
 | 
|---|
| 25 |     <<" sphin.fits   : input sphere"<<endl
 | 
|---|
| 26 |     <<" sphred.fits  : input reducted sphere"<<endl
 | 
|---|
| 27 |     <<" sphout.fits  : output sphere"<<endl;
 | 
|---|
| 28 | }
 | 
|---|
| 29 | 
 | 
|---|
| 30 | int main(int narg, char* arg[])
 | 
|---|
| 31 | {
 | 
|---|
| 32 | bool tstmin=false, tstmax=false;
 | 
|---|
| 33 | double valmin=-1.e30, valmax=+1.e30;
 | 
|---|
| 34 | char * fsphinw = NULL;
 | 
|---|
| 35 | int c;
 | 
|---|
| 36 | while((c = getopt(narg,arg,"hm:M:w:")) != -1) {
 | 
|---|
| 37 |   switch (c) {
 | 
|---|
| 38 |   case 'm' :
 | 
|---|
| 39 |     sscanf(optarg,"%lf",&valmin);
 | 
|---|
| 40 |     tstmin=true;
 | 
|---|
| 41 |     break;
 | 
|---|
| 42 |   case 'M' :
 | 
|---|
| 43 |     sscanf(optarg,"%lf",&valmax);
 | 
|---|
| 44 |     tstmax=true;
 | 
|---|
| 45 |     break;
 | 
|---|
| 46 |   case 'w' :
 | 
|---|
| 47 |     fsphinw = optarg;
 | 
|---|
| 48 |     break;
 | 
|---|
| 49 |   case 'h' :
 | 
|---|
| 50 |   default:
 | 
|---|
| 51 |     usage(); exit(1);
 | 
|---|
| 52 |   }
 | 
|---|
| 53 | }
 | 
|---|
| 54 | 
 | 
|---|
| 55 | if(optind+2>=narg) {usage(); exit(1);}
 | 
|---|
| 56 | char * fsphin   = arg[optind];
 | 
|---|
| 57 | char * fsphred = arg[optind+1];
 | 
|---|
| 58 | char * fsphout  = arg[optind+2];
 | 
|---|
| 59 | 
 | 
|---|
| 60 | cout<<"Input Sphere          : "<<fsphin<<endl
 | 
|---|
| 61 |     <<"Input Weight Sphere   : "<<fsphinw<<endl
 | 
|---|
| 62 |     <<"Input Reducted Sphere : "<<fsphred<<endl
 | 
|---|
| 63 |     <<"Output Sphere         : "<<fsphout<<endl;
 | 
|---|
| 64 | if(!fsphinw)
 | 
|---|
| 65 |   cout<<"- test min("<<tstmin<<") : "<<valmin<<endl
 | 
|---|
| 66 |       <<"  test max("<<tstmax<<") : "<<valmax<<endl
 | 
|---|
| 67 |       <<"Condition for EMPTY pixel is :\n    ("<<valmin
 | 
|---|
| 68 |       <<" < sphere value < "<<valmax<<") bounds are excluded!"<<endl;
 | 
|---|
| 69 | 
 | 
|---|
| 70 | // Lecture des spheres
 | 
|---|
| 71 | SphereHEALPix<r_8> sphin;
 | 
|---|
| 72 | {FitsInFile sfits(fsphin); sfits >> sphin;}
 | 
|---|
| 73 | int nlat = sphin.SizeIndex();
 | 
|---|
| 74 | cout<<"Opening Input Sphere :"<<endl
 | 
|---|
| 75 |     <<"          Type of map : "<<sphin.TypeOfMap()<<endl
 | 
|---|
| 76 |     <<"     Number of pixels : "<<sphin.NbPixels()<<endl
 | 
|---|
| 77 |     <<"                 Nlat : "<<sphin.SizeIndex()<<endl;
 | 
|---|
| 78 | 
 | 
|---|
| 79 | SphereHEALPix<r_8> sphinw;
 | 
|---|
| 80 | if(fsphinw) {
 | 
|---|
| 81 |   FitsInFile sfits(fsphinw);
 | 
|---|
| 82 |   sfits >> sphinw;
 | 
|---|
| 83 |   cout<<"Opening Input Weight Sphere :"<<endl
 | 
|---|
| 84 |       <<"          Type of map : "<<sphinw.TypeOfMap()<<endl
 | 
|---|
| 85 |       <<"     Number of pixels : "<<sphinw.NbPixels()<<endl
 | 
|---|
| 86 |       <<"                 Nlat : "<<sphinw.SizeIndex()<<endl;
 | 
|---|
| 87 |   if(sphinw.SizeIndex()!=nlat) {
 | 
|---|
| 88 |     cout<<"Incompatible sphin sphinw"<<endl;
 | 
|---|
| 89 |     exit(2);
 | 
|---|
| 90 |   }
 | 
|---|
| 91 | }
 | 
|---|
| 92 | 
 | 
|---|
| 93 | SphereHEALPix<r_8> sphred;
 | 
|---|
| 94 | {FitsInFile sfits(fsphred); sfits >> sphred;}
 | 
|---|
| 95 | cout<<"Opening Input Reducted Sphere :"<<endl
 | 
|---|
| 96 |     <<"          Type of map : "<<sphred.TypeOfMap()<<endl
 | 
|---|
| 97 |     <<"     Number of pixels : "<<sphred.NbPixels()<<endl
 | 
|---|
| 98 |     <<"                 Nlat : "<<sphred.SizeIndex()<<endl;
 | 
|---|
| 99 | 
 | 
|---|
| 100 | // Filling hole for Output Sphere
 | 
|---|
| 101 | cout<<"...Filling hole for Output Sphere"<<endl;
 | 
|---|
| 102 | uint_4 n=0, n0=0;
 | 
|---|
| 103 | for(int_4 i=0;i<sphin.NbPixels();i++) {
 | 
|---|
| 104 |   if(fsphinw) {
 | 
|---|
| 105 |     if(sphinw(i)>0.) continue;
 | 
|---|
| 106 |   } else {
 | 
|---|
| 107 |     // Not Filled pixels ]valmin,valmax[
 | 
|---|
| 108 |     // Filled pixels ]-Infinity,valmin] or [valmax,+Infinity[
 | 
|---|
| 109 |     if(tstmin && sphin(i)<=valmin) continue;
 | 
|---|
| 110 |     if(tstmax && sphin(i)>=valmax) continue;
 | 
|---|
| 111 |   }
 | 
|---|
| 112 |   double theta,phi;
 | 
|---|
| 113 |   sphin.PixThetaPhi(i,theta,phi);
 | 
|---|
| 114 |   int_4 ir = sphred.PixIndexSph(theta,phi);
 | 
|---|
| 115 |   sphin(i) = sphred(ir);
 | 
|---|
| 116 |   n++; if(sphred(ir)!=0.) n0++;
 | 
|---|
| 117 | }
 | 
|---|
| 118 | cout<<"      Number of pixels filled "
 | 
|---|
| 119 |     <<n<<" (not null values "<<n0<<")"<<endl;
 | 
|---|
| 120 | 
 | 
|---|
| 121 | // Ecriture de la sphere
 | 
|---|
| 122 | {
 | 
|---|
| 123 | string dum = "rm -f "; dum += fsphout; system(dum.c_str());
 | 
|---|
| 124 | FitsOutFile sfits(fsphout);
 | 
|---|
| 125 | cout<<"Writing Output Sphere Fits file"<<endl;
 | 
|---|
| 126 | sfits<<sphin;
 | 
|---|
| 127 | }
 | 
|---|
| 128 | 
 | 
|---|
| 129 | exit(0);
 | 
|---|
| 130 | }
 | 
|---|