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

Last change on this file since 3468 was 2615, checked in by cmv, 21 years ago

using namespace sophya enleve de machdefs.h, nouveau sopnamsp.h cmv 10/09/2004

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