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

Last change on this file since 1841 was 1841, checked in by ansari, 24 years ago

Ajout flag FitsFile::clear pour les FitsOutFile - Reza 21/12/2001

File size: 5.3 KB
RevLine 
[1626]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
[1528]4// extrapsph -r 2 sph143k05.fits sph143k05_e.fits
5// sphout.fits sphoutw.fits sphred.fits sphredw.fits
[1526]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
[1626]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
[1526]35void usage();
36void usage()
37{
[1626]38cout<<"extrapsph [-r reduc_factor] sphin.fits sphinw.fits"<<endl
39 <<" sphout.fits [sphout_w.fits"
[1526]40 <<" sphred.fits sphred_w.fits]"<<endl
[1528]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;
[1526]48}
49
50int main(int narg, char* arg[])
51{
52int red=2;
[1626]53string dum;
[1526]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
[1528]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
[1526]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;
[1528]90cout<<"Opening Input Sphere :"<<endl
[1526]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;}
[1528]97cout<<"Opening Input Weight Sphere :"<<endl
[1526]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.);
[1528]112cout<<" Number of pixels : "<<sphred.NbPixels()<<endl
[1526]113 <<" Nlat : "<<sphred.SizeIndex()<<endl;
114
115// Filling reducted spheres
116cout<<"...Filling Reducted Spheres"<<endl;
[1528]117uint_4 n=0;
[1545]118int_4 i, ir;
119for(i=0;i<sphin.NbPixels();i++) {
[1526]120 if(sphinw(i)<=0.) continue;
121 double theta,phi;
122 sphin.PixThetaPhi(i,theta,phi);
[1545]123 ir = sphred.PixIndexSph(theta,phi);
[1526]124 sphred(ir) += sphin(i)*sphinw(i);
125 sphredw(ir) += sphinw(i);
[1528]126 n++;
[1526]127}
[1528]128cout<<" Input Sphere: Number of filled pixels "<<n<<endl;
[1526]129cout<<"...Computing Reducted Spheres"<<endl;
[1528]130n=0;
[1545]131for(ir=0;ir<sphred.NbPixels();ir++)
[1526]132 if(sphredw(ir) > 0.) {sphred(ir) /= sphredw(ir); n++;}
[1528]133cout<<" Reducted Sphere: Number of pixels filled "<<n<<endl;
[1526]134
135// Filling hole for Output Spheres
136cout<<"...Filling hole for Output Spheres"<<endl;
137n=0;
[1545]138for(i=0;i<sphin.NbPixels();i++) {
[1528]139 if(sphinw(i)>0.) continue;
[1526]140 double theta,phi;
[1528]141 sphin.PixThetaPhi(i,theta,phi);
[1526]142 int_4 ir = sphred.PixIndexSph(theta,phi);
143 if(sphredw(ir)<=0.) continue;
[1528]144 sphin(i) = sphred(ir);
[1626]145 // On passe en negatif les pixels qui ont ete extrapoles
[1528]146 sphinw(i) = -sphredw(ir);
[1526]147 n++;
148}
[1528]149cout<<" Output Sphere: Number of pixels filled "<<n<<endl;
[1526]150
151// Ecriture des spheres
152{
[1626]153dum = "rm -f "; dum += fsphout; system(dum.c_str());
[1841]154FitsOutFile sfits(fsphout, FitsFile::clear);
[1526]155cout<<"Writing Output Sphere Fits file"<<endl;
[1528]156sfits<<sphin;
[1526]157}
158if(fsphoutw) {
[1626]159dum = "rm -f "; dum += fsphoutw; system(dum.c_str());
[1841]160FitsOutFile sfits(fsphoutw, FitsFile::clear);
[1526]161cout<<"Writing Output Sphere Weight Fits file"<<endl;
[1528]162sfits<<sphinw;
[1526]163}
164if(fsphred) {
[1626]165dum = "rm -f "; dum += fsphred; system(dum.c_str());
[1841]166FitsOutFile sfits(fsphred, FitsFile::clear);
[1526]167cout<<"Writing Reducted Sphere Fits file"<<endl;
168sfits<<sphred;
169}
170if(fsphredw) {
[1626]171dum = "rm -f "; dum += fsphredw; system(dum.c_str());
[1841]172FitsOutFile sfits(fsphredw, FitsFile::clear);
[1526]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.