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