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