| [1626] | 1 | // Pour boucher les trous d'une sphere HEALPIX en utilisant | 
|---|
|  | 2 | // une autre sphere HEALPIX | 
|---|
| [1526] | 3 | //             cmv 13/6/01 | 
|---|
| [1528] | 4 | // extrap2sph -w sph143k05_e.fits sph143k05.fits sphred.fits sphout_2.fits | 
|---|
|  | 5 | // extrap2sph -m -1.e-30 -M +1.e-30 sph143k05.fits sphred.fits sphout_22.fits | 
|---|
| [1526] | 6 | #include "machdefs.h" | 
|---|
|  | 7 | #include <unistd.h> | 
|---|
|  | 8 | #include <stdexcept> | 
|---|
|  | 9 | #include <iostream.h> | 
|---|
|  | 10 | #include <stdio.h> | 
|---|
|  | 11 | #include <stdlib.h> | 
|---|
|  | 12 | #include "skymapinit.h" | 
|---|
|  | 13 | #include "skymap.h" | 
|---|
|  | 14 | #include "fitsspherehealpix.h" | 
|---|
|  | 15 |  | 
|---|
| [1626] | 16 | /*! | 
|---|
|  | 17 | \ingroup PrgMap | 
|---|
|  | 18 | \file extrap2sph.cc | 
|---|
|  | 19 | \brief \b extrap2sph: Fill holes in a sphere of datas by using | 
|---|
|  | 20 | an other sphere of datas. | 
|---|
|  | 21 | A mask to define the place to be tested in the sphere might be given. | 
|---|
|  | 22 | \verbatim | 
|---|
|  | 23 | csh> extrap2sph -h | 
|---|
|  | 24 | extrap2sph [-m valmin -M valmax -r rvalmin -R rvalmax] | 
|---|
|  | 25 | [-w sphinw.fits] sphin.fits sphred.fits sphout.fits | 
|---|
|  | 26 | -w sphinw.fits : input sphere  weight, if sphinw_value<=0. (def=NULL) | 
|---|
|  | 27 | if sphinw_value<=0. pixel has not to be filled | 
|---|
|  | 28 | -m minval : min value to identify EMPTY pixel of sphin (def=no_test) | 
|---|
|  | 29 | -M maxval : max value to identify EMPTY pixel of sphin (def=no_test) | 
|---|
|  | 30 | condition for EMPTY pixel is (minval<=val<=maxval) | 
|---|
|  | 31 | -n : negate the previous condition, condition for EMPTY pixel | 
|---|
|  | 32 | becomes: (val<minval || maxval<val) | 
|---|
|  | 33 | -r rminval : min value to identify GOOD pixel of sphred (def=no_test) | 
|---|
|  | 34 | -R rmaxval : max value to identify GOOD pixel of sphred (def=no_test) | 
|---|
|  | 35 | condition for GOOD pixel is (minval<=val<=maxval) | 
|---|
|  | 36 | -n : negate the previous condition, condition for GOOD pixel | 
|---|
|  | 37 | becomes: (val<minval || maxval<val) | 
|---|
|  | 38 | sphin.fits   : input sphere | 
|---|
|  | 39 | sphred.fits  : input reducted sphere | 
|---|
|  | 40 | sphout.fits  : output sphere | 
|---|
|  | 41 | \endverbatim | 
|---|
|  | 42 | */ | 
|---|
|  | 43 |  | 
|---|
| [1526] | 44 | void usage(); | 
|---|
|  | 45 | void usage() | 
|---|
|  | 46 | { | 
|---|
| [1626] | 47 | cout<<"extrap2sph [-m valmin -M valmax -r rvalmin -R rvalmax]"<<endl | 
|---|
|  | 48 | <<"           [-w sphinw.fits] sphin.fits sphred.fits sphout.fits"<<endl | 
|---|
|  | 49 | <<" -w sphinw.fits : input sphere  weight, if sphinw_value<=0. (def=NULL)"<<endl | 
|---|
|  | 50 | <<"                  if sphinw_value<=0. pixel has not to be filled"<<endl | 
|---|
|  | 51 | <<" -m minval : min value to identify EMPTY pixel of sphin (def=no_test)"<<endl | 
|---|
|  | 52 | <<" -M maxval : max value to identify EMPTY pixel of sphin (def=no_test)"<<endl | 
|---|
|  | 53 | <<"    condition for EMPTY pixel is (minval<=val<=maxval)"<<endl | 
|---|
|  | 54 | <<" -n : negate the previous condition, condition for EMPTY pixel"<<endl | 
|---|
|  | 55 | <<"      becomes: (val<minval || maxval<val)"<<endl | 
|---|
|  | 56 | <<" -r rminval : min value to identify GOOD pixel of sphred (def=no_test)"<<endl | 
|---|
|  | 57 | <<" -R rmaxval : max value to identify GOOD pixel of sphred (def=no_test)"<<endl | 
|---|
|  | 58 | <<"    condition for GOOD pixel is (minval<=val<=maxval)"<<endl | 
|---|
|  | 59 | <<" -n : negate the previous condition, condition for GOOD pixel"<<endl | 
|---|
|  | 60 | <<"      becomes: (val<minval || maxval<val)"<<endl | 
|---|
| [1528] | 61 | <<" sphin.fits   : input sphere"<<endl | 
|---|
| [1526] | 62 | <<" sphred.fits  : input reducted sphere"<<endl | 
|---|
|  | 63 | <<" sphout.fits  : output sphere"<<endl; | 
|---|
|  | 64 | } | 
|---|
|  | 65 |  | 
|---|
|  | 66 | int main(int narg, char* arg[]) | 
|---|
|  | 67 | { | 
|---|
| [1626] | 68 | bool tstmin=false,  tstmax=false,  neg=false; | 
|---|
|  | 69 | bool rtstmin=false, rtstmax=false, rneg=false; | 
|---|
|  | 70 | double valmin=0., valmax=0., rvalmin=0., rvalmax=0.; | 
|---|
| [1526] | 71 | char * fsphinw = NULL; | 
|---|
| [1626] | 72 | string dum; | 
|---|
| [1526] | 73 | int c; | 
|---|
| [1626] | 74 | while((c = getopt(narg,arg,"hnNm:M:r:R:w:")) != -1) { | 
|---|
| [1526] | 75 | switch (c) { | 
|---|
| [1626] | 76 | case 'n' : | 
|---|
|  | 77 | neg = true; | 
|---|
|  | 78 | break; | 
|---|
|  | 79 | case 'N' : | 
|---|
|  | 80 | rneg = true; | 
|---|
|  | 81 | break; | 
|---|
| [1528] | 82 | case 'm' : | 
|---|
|  | 83 | sscanf(optarg,"%lf",&valmin); | 
|---|
|  | 84 | tstmin=true; | 
|---|
| [1526] | 85 | break; | 
|---|
| [1528] | 86 | case 'M' : | 
|---|
|  | 87 | sscanf(optarg,"%lf",&valmax); | 
|---|
|  | 88 | tstmax=true; | 
|---|
|  | 89 | break; | 
|---|
| [1626] | 90 | case 'r' : | 
|---|
|  | 91 | sscanf(optarg,"%lf",&rvalmin); | 
|---|
|  | 92 | rtstmin=true; | 
|---|
|  | 93 | break; | 
|---|
|  | 94 | case 'R' : | 
|---|
|  | 95 | sscanf(optarg,"%lf",&rvalmax); | 
|---|
|  | 96 | rtstmax=true; | 
|---|
|  | 97 | break; | 
|---|
| [1526] | 98 | case 'w' : | 
|---|
|  | 99 | fsphinw = optarg; | 
|---|
|  | 100 | break; | 
|---|
|  | 101 | case 'h' : | 
|---|
|  | 102 | default: | 
|---|
|  | 103 | usage(); exit(1); | 
|---|
|  | 104 | } | 
|---|
|  | 105 | } | 
|---|
|  | 106 |  | 
|---|
|  | 107 | if(optind+2>=narg) {usage(); exit(1);} | 
|---|
| [1626] | 108 | char * fsphin  = arg[optind]; | 
|---|
| [1526] | 109 | char * fsphred = arg[optind+1]; | 
|---|
| [1626] | 110 | char * fsphout = arg[optind+2]; | 
|---|
| [1526] | 111 |  | 
|---|
| [1528] | 112 | cout<<"Input Sphere          : "<<fsphin<<endl | 
|---|
|  | 113 | <<"Input Weight Sphere   : "<<fsphinw<<endl | 
|---|
|  | 114 | <<"Input Reducted Sphere : "<<fsphred<<endl | 
|---|
|  | 115 | <<"Output Sphere         : "<<fsphout<<endl; | 
|---|
| [1626] | 116 | if(neg) dum = ".NOT."; else dum=""; | 
|---|
|  | 117 | cout<<"- Sphere - test min("<<tstmin<<") : "<<valmin<<endl | 
|---|
|  | 118 | <<"           test max("<<tstmax<<") : "<<valmax<<endl | 
|---|
|  | 119 | <<"           negate("<<neg<<")"<<endl | 
|---|
|  | 120 | <<"  - Condition for EMPTY pixel in Sphere is :"<<endl | 
|---|
|  | 121 | <<"    "<<dum<<"( "<<valmin<<" <= V <= "<<valmax<<" )"<<endl; | 
|---|
|  | 122 | if(rneg) dum = ".NOT."; else dum=""; | 
|---|
|  | 123 | cout<<"- Reducted Sphere - test min("<<rtstmin<<") : "<<rvalmin<<endl | 
|---|
|  | 124 | <<"                    test max("<<rtstmax<<") : "<<rvalmax<<endl | 
|---|
|  | 125 | <<"                    negate("<<rneg<<")"<<endl | 
|---|
|  | 126 | <<"  - Condition for GOOD pixel in Reducted Sphere is :"<<endl | 
|---|
|  | 127 | <<"    "<<dum<<"( "<<rvalmin<<" <= V <= "<<rvalmax<<" )"<<endl; | 
|---|
| [1526] | 128 |  | 
|---|
|  | 129 | // Lecture des spheres | 
|---|
|  | 130 | SphereHEALPix<r_8> sphin; | 
|---|
|  | 131 | {FitsInFile sfits(fsphin); sfits >> sphin;} | 
|---|
|  | 132 | int nlat = sphin.SizeIndex(); | 
|---|
| [1528] | 133 | cout<<"Opening Input Sphere :"<<endl | 
|---|
| [1526] | 134 | <<"          Type of map : "<<sphin.TypeOfMap()<<endl | 
|---|
|  | 135 | <<"     Number of pixels : "<<sphin.NbPixels()<<endl | 
|---|
|  | 136 | <<"                 Nlat : "<<sphin.SizeIndex()<<endl; | 
|---|
|  | 137 |  | 
|---|
|  | 138 | SphereHEALPix<r_8> sphinw; | 
|---|
|  | 139 | if(fsphinw) { | 
|---|
|  | 140 | FitsInFile sfits(fsphinw); | 
|---|
|  | 141 | sfits >> sphinw; | 
|---|
| [1528] | 142 | cout<<"Opening Input Weight Sphere :"<<endl | 
|---|
| [1526] | 143 | <<"          Type of map : "<<sphinw.TypeOfMap()<<endl | 
|---|
|  | 144 | <<"     Number of pixels : "<<sphinw.NbPixels()<<endl | 
|---|
|  | 145 | <<"                 Nlat : "<<sphinw.SizeIndex()<<endl; | 
|---|
|  | 146 | if(sphinw.SizeIndex()!=nlat) { | 
|---|
|  | 147 | cout<<"Incompatible sphin sphinw"<<endl; | 
|---|
|  | 148 | exit(2); | 
|---|
|  | 149 | } | 
|---|
|  | 150 | } | 
|---|
|  | 151 |  | 
|---|
|  | 152 | SphereHEALPix<r_8> sphred; | 
|---|
|  | 153 | {FitsInFile sfits(fsphred); sfits >> sphred;} | 
|---|
| [1528] | 154 | cout<<"Opening Input Reducted Sphere :"<<endl | 
|---|
| [1526] | 155 | <<"          Type of map : "<<sphred.TypeOfMap()<<endl | 
|---|
|  | 156 | <<"     Number of pixels : "<<sphred.NbPixels()<<endl | 
|---|
|  | 157 | <<"                 Nlat : "<<sphred.SizeIndex()<<endl; | 
|---|
|  | 158 |  | 
|---|
|  | 159 | // Filling hole for Output Sphere | 
|---|
|  | 160 | cout<<"...Filling hole for Output Sphere"<<endl; | 
|---|
| [1528] | 161 | uint_4 n=0, n0=0; | 
|---|
|  | 162 | for(int_4 i=0;i<sphin.NbPixels();i++) { | 
|---|
| [1626] | 163 | bool skp; | 
|---|
|  | 164 | if(fsphinw) if(sphinw(i)<=0.) continue; // Pixel out of acceptance! | 
|---|
|  | 165 |  | 
|---|
|  | 166 | // Test if pixel of Sphere has to be extrapolated | 
|---|
|  | 167 | skp = (tstmin || tstmax) ? neg : false; | 
|---|
|  | 168 | if((tstmin && sphin(i)<valmin) || (tstmax && sphin(i)>valmax)) skp = !neg; | 
|---|
|  | 169 | if(skp) continue;   // Do nothing | 
|---|
|  | 170 |  | 
|---|
| [1526] | 171 | double theta,phi; | 
|---|
| [1528] | 172 | sphin.PixThetaPhi(i,theta,phi); | 
|---|
| [1526] | 173 | int_4 ir = sphred.PixIndexSph(theta,phi); | 
|---|
| [1626] | 174 |  | 
|---|
|  | 175 | // Test if pixel of Reducted Sphere is good | 
|---|
|  | 176 | skp = (rtstmin || rtstmax) ? rneg : false; | 
|---|
|  | 177 | if((rtstmin && sphred(i)<rvalmin) || (rtstmax && sphred(i)>rvalmax)) skp = !rneg; | 
|---|
|  | 178 | if(skp) continue;   // Do nothing | 
|---|
|  | 179 |  | 
|---|
| [1528] | 180 | sphin(i) = sphred(ir); | 
|---|
|  | 181 | n++; if(sphred(ir)!=0.) n0++; | 
|---|
| [1526] | 182 | } | 
|---|
| [1528] | 183 | cout<<"      Number of pixels filled " | 
|---|
|  | 184 | <<n<<" (not null values "<<n0<<")"<<endl; | 
|---|
| [1526] | 185 |  | 
|---|
|  | 186 | // Ecriture de la sphere | 
|---|
|  | 187 | { | 
|---|
| [1626] | 188 | dum = "rm -f "; dum += fsphout; system(dum.c_str()); | 
|---|
| [1526] | 189 | FitsOutFile sfits(fsphout); | 
|---|
|  | 190 | cout<<"Writing Output Sphere Fits file"<<endl; | 
|---|
| [1528] | 191 | sfits<<sphin; | 
|---|
| [1526] | 192 | } | 
|---|
|  | 193 |  | 
|---|
|  | 194 | exit(0); | 
|---|
|  | 195 | } | 
|---|