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