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 | int_4 i, ir;
|
---|
98 | for(i=0;i<sphin.NbPixels();i++) {
|
---|
99 | if(sphinw(i)<=0.) continue;
|
---|
100 | double theta,phi;
|
---|
101 | sphin.PixThetaPhi(i,theta,phi);
|
---|
102 | ir = sphred.PixIndexSph(theta,phi);
|
---|
103 | sphred(ir) += sphin(i)*sphinw(i);
|
---|
104 | sphredw(ir) += sphinw(i);
|
---|
105 | n++;
|
---|
106 | }
|
---|
107 | cout<<" Input Sphere: Number of filled pixels "<<n<<endl;
|
---|
108 | cout<<"...Computing Reducted Spheres"<<endl;
|
---|
109 | n=0;
|
---|
110 | for(ir=0;ir<sphred.NbPixels();ir++)
|
---|
111 | if(sphredw(ir) > 0.) {sphred(ir) /= sphredw(ir); n++;}
|
---|
112 | cout<<" Reducted Sphere: Number of pixels filled "<<n<<endl;
|
---|
113 |
|
---|
114 | // Filling hole for Output Spheres
|
---|
115 | cout<<"...Filling hole for Output Spheres"<<endl;
|
---|
116 | n=0;
|
---|
117 | for(i=0;i<sphin.NbPixels();i++) {
|
---|
118 | if(sphinw(i)>0.) continue;
|
---|
119 | double theta,phi;
|
---|
120 | sphin.PixThetaPhi(i,theta,phi);
|
---|
121 | int_4 ir = sphred.PixIndexSph(theta,phi);
|
---|
122 | if(sphredw(ir)<=0.) continue;
|
---|
123 | sphin(i) = sphred(ir);
|
---|
124 | sphinw(i) = -sphredw(ir);
|
---|
125 | n++;
|
---|
126 | }
|
---|
127 | cout<<" Output Sphere: Number of pixels filled "<<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<<sphin;
|
---|
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<<sphinw;
|
---|
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 | }
|
---|