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