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

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

optimisation cmv 14/6/01

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