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

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

Uniformisation des programmes + doc cmv 7/8/01

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