source: Sophya/trunk/SophyaProg/PrgMap/extrapsph.cc@ 1526

Last change on this file since 1526 was 1526, checked in by cmv, 24 years ago

Pour boucher les trous dans les spheres Healpix

  • avec une sphere et sa sphere associee de poids
  • avec une sphere et une autre sphere (+ petite)

cmv 13/6/01

File size: 4.6 KB
RevLine 
[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
13void usage();
14void usage()
15{
16cout<<"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
28int main(int narg, char* arg[])
29{
30int red=2;
31int c;
32while((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
43if(optind+2>=narg) {usage(); exit(1);}
44char * fsphin = arg[optind];
45char * fsphinw = arg[optind+1];
46char * fsphout = arg[optind+2];
47char * fsphoutw = NULL;
48char * fsphred = NULL;
49char * fsphredw = NULL;
50if(optind+3<narg) fsphoutw = arg[optind+3];
51if(optind+4<narg) fsphred = arg[optind+4];
52if(optind+5<narg) fsphredw = arg[optind+5];
53
54cout<<"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
63SphereHEALPix<r_8> sphin;
64{FitsInFile sfits(fsphin); sfits >> sphin;}
65int nlat = sphin.SizeIndex();
66int nlatr = nlat/red;
67cout<<"Opening Sphere Input :"<<endl
68 <<" Type of map : "<<sphin.TypeOfMap()<<endl
69 <<" Number of pixels : "<<sphin.NbPixels()<<endl
70 <<" Nlat : "<<sphin.SizeIndex()<<endl;
71
72SphereHEALPix<r_8> sphinw;
73{FitsInFile sfits(fsphinw); sfits >> sphinw;}
74cout<<"Opening Weight Sphere Input :"<<endl
75 <<" Type of map : "<<sphinw.TypeOfMap()<<endl
76 <<" Number of pixels : "<<sphinw.NbPixels()<<endl
77 <<" Nlat : "<<sphinw.SizeIndex()<<endl;
78if(sphinw.SizeIndex()!=nlat) {
79 cout<<"Incompatible sphin sphinw"<<endl;
80 exit(2);
81}
82
83// Creation des spheres output
84cout<<"Creating Spheres for output"<<endl;
85SphereHEALPix<r_8> sphout(sphin,false);
86SphereHEALPix<r_8> sphoutw(sphinw,false);
87
88// Creation des spheres reduites
89cout<<"Creating Reducted Spheres : nlatr = "<<nlatr<<endl;
90SphereHEALPix<r_8> sphred(nlatr);
91 sphred.SetPixels(0.);
92SphereHEALPix<r_8> sphredw(nlatr);
93 sphredw.SetPixels(0.);
94cout<<"Creating Reducted Sphere :"<<endl
95 <<" Number of pixels : "<<sphred.NbPixels()<<endl
96 <<" Nlat : "<<sphred.SizeIndex()<<endl;
97
98// Filling reducted spheres
99cout<<"...Filling Reducted Spheres"<<endl;
100for(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}
108cout<<"...Computing Reducted Spheres"<<endl;
109uint_4 n=0;
110for(int_4 ir=0;ir<sphred.NbPixels();ir++)
111 if(sphredw(ir) > 0.) {sphred(ir) /= sphredw(ir); n++;}
112cout<<" Number of filled pixels "<<n<<endl;
113
114// Filling hole for Output Spheres
115cout<<"...Filling hole for Output Spheres"<<endl;
116n=0;
117for(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}
127cout<<" Number of filled pixels "<<n<<endl;
128
129// Ecriture des spheres
130{
131string dum = "rm -f "; dum += fsphout; system(dum.c_str());
132FitsOutFile sfits(fsphout);
133cout<<"Writing Output Sphere Fits file"<<endl;
134sfits<<sphout;
135}
136if(fsphoutw) {
137string dum = "rm -f "; dum += fsphoutw; system(dum.c_str());
138FitsOutFile sfits(fsphoutw);
139cout<<"Writing Output Sphere Weight Fits file"<<endl;
140sfits<<sphoutw;
141}
142if(fsphred) {
143string dum = "rm -f "; dum += fsphred; system(dum.c_str());
144FitsOutFile sfits(fsphred);
145cout<<"Writing Reducted Sphere Fits file"<<endl;
146sfits<<sphred;
147}
148if(fsphredw) {
149string dum = "rm -f "; dum += fsphredw; system(dum.c_str());
150FitsOutFile sfits(fsphredw);
151cout<<"Writing Reducted Sphere Weight Fits file"<<endl;
152sfits<<sphredw;
153}
154
155exit(0);
156}
Note: See TracBrowser for help on using the repository browser.