[1626] | 1 | // Pour boucher les trous d'une sphere HEALPIX en la clusterisant
|
---|
| 2 | // dans une sphere plus petite puis en la re-extrapolant.
|
---|
| 3 | // cmv 13/6/01
|
---|
[1528] | 4 | // extrapsph -r 2 sph143k05.fits sph143k05_e.fits
|
---|
| 5 | // sphout.fits sphoutw.fits sphred.fits sphredw.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 extrapsph.cc
|
---|
| 19 | \brief \b extrapsph: Fill holes in a sphere of datas by reducing
|
---|
| 20 | it size and re-extrapolating.
|
---|
| 21 | \verbatim
|
---|
| 22 | csh> extrapsph -h
|
---|
| 23 | extrapsph [-r reduc_factor] sphin.fits sphinw.fits
|
---|
| 24 | sphout.fits [sphout_w.fits sphred.fits sphred_w.fits]
|
---|
| 25 | -r reduc : reduction factor for clustering (must be 2^n, def=2)
|
---|
| 26 | sphin.fits : input sphere
|
---|
| 27 | sphin_w.fits : input sphere filling weight
|
---|
| 28 | sphout.fits : output sphere
|
---|
| 29 | sphout_w.fits : output sphere filling weight
|
---|
| 30 | sphred.fits : output reducted sphere
|
---|
| 31 | sphred_w.fits : output reducted sphere filling weight
|
---|
| 32 | \endverbatim
|
---|
| 33 | */
|
---|
| 34 |
|
---|
[1526] | 35 | void usage();
|
---|
| 36 | void usage()
|
---|
| 37 | {
|
---|
[1626] | 38 | cout<<"extrapsph [-r reduc_factor] sphin.fits sphinw.fits"<<endl
|
---|
| 39 | <<" sphout.fits [sphout_w.fits"
|
---|
[1526] | 40 | <<" sphred.fits sphred_w.fits]"<<endl
|
---|
[1528] | 41 | <<" -r reduc : reduction factor for clustering (must be 2^n, def=2)"<<endl
|
---|
| 42 | <<" sphin.fits : input sphere"<<endl
|
---|
| 43 | <<" sphin_w.fits : input sphere filling weight"<<endl
|
---|
| 44 | <<" sphout.fits : output sphere"<<endl
|
---|
| 45 | <<" sphout_w.fits : output sphere filling weight"<<endl
|
---|
| 46 | <<" sphred.fits : output reducted sphere"<<endl
|
---|
| 47 | <<" sphred_w.fits : output reducted sphere filling weight"<<endl;
|
---|
[1526] | 48 | }
|
---|
| 49 |
|
---|
| 50 | int main(int narg, char* arg[])
|
---|
| 51 | {
|
---|
| 52 | int red=2;
|
---|
[1626] | 53 | string dum;
|
---|
[1526] | 54 | int c;
|
---|
| 55 | while((c = getopt(narg,arg,"hr:")) != -1) {
|
---|
| 56 | switch (c) {
|
---|
| 57 | case 'r' :
|
---|
| 58 | sscanf(optarg,"%d",&red);
|
---|
| 59 | break;
|
---|
| 60 | case 'h' :
|
---|
| 61 | default:
|
---|
| 62 | usage(); exit(1);
|
---|
| 63 | }
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | if(optind+2>=narg) {usage(); exit(1);}
|
---|
| 67 | char * fsphin = arg[optind];
|
---|
| 68 | char * fsphinw = arg[optind+1];
|
---|
| 69 | char * fsphout = arg[optind+2];
|
---|
| 70 | char * fsphoutw = NULL;
|
---|
| 71 | char * fsphred = NULL;
|
---|
| 72 | char * fsphredw = NULL;
|
---|
| 73 | if(optind+3<narg) fsphoutw = arg[optind+3];
|
---|
| 74 | if(optind+4<narg) fsphred = arg[optind+4];
|
---|
| 75 | if(optind+5<narg) fsphredw = arg[optind+5];
|
---|
| 76 |
|
---|
[1528] | 77 | cout<<"Input Sphere : "<<fsphin<<endl
|
---|
| 78 | <<"Input Weight Sphere : "<<fsphinw<<endl
|
---|
| 79 | <<"Output Sphere : "<<fsphout<<endl
|
---|
| 80 | <<"Output Weight Sphere : "<<fsphoutw<<endl
|
---|
| 81 | <<"Output Reducted Sphere : "<<fsphred<<endl
|
---|
| 82 | <<"Output Reducted Weight Sphere : "<<fsphredw<<endl
|
---|
[1526] | 83 | <<"Reduction : "<<red<<endl;
|
---|
| 84 |
|
---|
| 85 | // Lecture des spheres
|
---|
| 86 | SphereHEALPix<r_8> sphin;
|
---|
| 87 | {FitsInFile sfits(fsphin); sfits >> sphin;}
|
---|
| 88 | int nlat = sphin.SizeIndex();
|
---|
| 89 | int nlatr = nlat/red;
|
---|
[1528] | 90 | cout<<"Opening Input Sphere :"<<endl
|
---|
[1526] | 91 | <<" Type of map : "<<sphin.TypeOfMap()<<endl
|
---|
| 92 | <<" Number of pixels : "<<sphin.NbPixels()<<endl
|
---|
| 93 | <<" Nlat : "<<sphin.SizeIndex()<<endl;
|
---|
| 94 |
|
---|
| 95 | SphereHEALPix<r_8> sphinw;
|
---|
| 96 | {FitsInFile sfits(fsphinw); sfits >> sphinw;}
|
---|
[1528] | 97 | cout<<"Opening Input Weight Sphere :"<<endl
|
---|
[1526] | 98 | <<" Type of map : "<<sphinw.TypeOfMap()<<endl
|
---|
| 99 | <<" Number of pixels : "<<sphinw.NbPixels()<<endl
|
---|
| 100 | <<" Nlat : "<<sphinw.SizeIndex()<<endl;
|
---|
| 101 | if(sphinw.SizeIndex()!=nlat) {
|
---|
| 102 | cout<<"Incompatible sphin sphinw"<<endl;
|
---|
| 103 | exit(2);
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | // Creation des spheres reduites
|
---|
| 107 | cout<<"Creating Reducted Spheres : nlatr = "<<nlatr<<endl;
|
---|
| 108 | SphereHEALPix<r_8> sphred(nlatr);
|
---|
| 109 | sphred.SetPixels(0.);
|
---|
| 110 | SphereHEALPix<r_8> sphredw(nlatr);
|
---|
| 111 | sphredw.SetPixels(0.);
|
---|
[1528] | 112 | cout<<" Number of pixels : "<<sphred.NbPixels()<<endl
|
---|
[1526] | 113 | <<" Nlat : "<<sphred.SizeIndex()<<endl;
|
---|
| 114 |
|
---|
| 115 | // Filling reducted spheres
|
---|
| 116 | cout<<"...Filling Reducted Spheres"<<endl;
|
---|
[1528] | 117 | uint_4 n=0;
|
---|
[1545] | 118 | int_4 i, ir;
|
---|
| 119 | for(i=0;i<sphin.NbPixels();i++) {
|
---|
[1526] | 120 | if(sphinw(i)<=0.) continue;
|
---|
| 121 | double theta,phi;
|
---|
| 122 | sphin.PixThetaPhi(i,theta,phi);
|
---|
[1545] | 123 | ir = sphred.PixIndexSph(theta,phi);
|
---|
[1526] | 124 | sphred(ir) += sphin(i)*sphinw(i);
|
---|
| 125 | sphredw(ir) += sphinw(i);
|
---|
[1528] | 126 | n++;
|
---|
[1526] | 127 | }
|
---|
[1528] | 128 | cout<<" Input Sphere: Number of filled pixels "<<n<<endl;
|
---|
[1526] | 129 | cout<<"...Computing Reducted Spheres"<<endl;
|
---|
[1528] | 130 | n=0;
|
---|
[1545] | 131 | for(ir=0;ir<sphred.NbPixels();ir++)
|
---|
[1526] | 132 | if(sphredw(ir) > 0.) {sphred(ir) /= sphredw(ir); n++;}
|
---|
[1528] | 133 | cout<<" Reducted Sphere: Number of pixels filled "<<n<<endl;
|
---|
[1526] | 134 |
|
---|
| 135 | // Filling hole for Output Spheres
|
---|
| 136 | cout<<"...Filling hole for Output Spheres"<<endl;
|
---|
| 137 | n=0;
|
---|
[1545] | 138 | for(i=0;i<sphin.NbPixels();i++) {
|
---|
[1528] | 139 | if(sphinw(i)>0.) continue;
|
---|
[1526] | 140 | double theta,phi;
|
---|
[1528] | 141 | sphin.PixThetaPhi(i,theta,phi);
|
---|
[1526] | 142 | int_4 ir = sphred.PixIndexSph(theta,phi);
|
---|
| 143 | if(sphredw(ir)<=0.) continue;
|
---|
[1528] | 144 | sphin(i) = sphred(ir);
|
---|
[1626] | 145 | // On passe en negatif les pixels qui ont ete extrapoles
|
---|
[1528] | 146 | sphinw(i) = -sphredw(ir);
|
---|
[1526] | 147 | n++;
|
---|
| 148 | }
|
---|
[1528] | 149 | cout<<" Output Sphere: Number of pixels filled "<<n<<endl;
|
---|
[1526] | 150 |
|
---|
| 151 | // Ecriture des spheres
|
---|
| 152 | {
|
---|
[1626] | 153 | dum = "rm -f "; dum += fsphout; system(dum.c_str());
|
---|
[1841] | 154 | FitsOutFile sfits(fsphout, FitsFile::clear);
|
---|
[1526] | 155 | cout<<"Writing Output Sphere Fits file"<<endl;
|
---|
[1528] | 156 | sfits<<sphin;
|
---|
[1526] | 157 | }
|
---|
| 158 | if(fsphoutw) {
|
---|
[1626] | 159 | dum = "rm -f "; dum += fsphoutw; system(dum.c_str());
|
---|
[1841] | 160 | FitsOutFile sfits(fsphoutw, FitsFile::clear);
|
---|
[1526] | 161 | cout<<"Writing Output Sphere Weight Fits file"<<endl;
|
---|
[1528] | 162 | sfits<<sphinw;
|
---|
[1526] | 163 | }
|
---|
| 164 | if(fsphred) {
|
---|
[1626] | 165 | dum = "rm -f "; dum += fsphred; system(dum.c_str());
|
---|
[1841] | 166 | FitsOutFile sfits(fsphred, FitsFile::clear);
|
---|
[1526] | 167 | cout<<"Writing Reducted Sphere Fits file"<<endl;
|
---|
| 168 | sfits<<sphred;
|
---|
| 169 | }
|
---|
| 170 | if(fsphredw) {
|
---|
[1626] | 171 | dum = "rm -f "; dum += fsphredw; system(dum.c_str());
|
---|
[1841] | 172 | FitsOutFile sfits(fsphredw, FitsFile::clear);
|
---|
[1526] | 173 | cout<<"Writing Reducted Sphere Weight Fits file"<<endl;
|
---|
| 174 | sfits<<sphredw;
|
---|
| 175 | }
|
---|
| 176 |
|
---|
| 177 | exit(0);
|
---|
| 178 | }
|
---|