source: Sophya/trunk/SophyaProg/PrgMap/msksphere.cc@ 1545

Last change on this file since 1545 was 1535, checked in by cmv, 24 years ago
  • Quelques details
  • pour masquer une shpere cmv 15/6/01
File size: 3.3 KB
Line 
1// Creation d'une sphere de masquee a partir d'une sphere de masques
2// cmv 15/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<<"msksphere [-m min -M max -v valmsk]"<<endl
17 <<" sphval.fits sphmask.fits sphout.fits"<<endl
18 <<" -m min : min value"<<endl
19 <<" -M max : max value"<<endl
20 <<" condition for masking is :"<<endl
21 <<" mask_sphere_value <= min"<<endl
22 <<" OR"<<endl
23 <<" mask_sphere_value >= max"<<endl
24 <<" (bounds are included)"<<endl
25 <<" Default is mask_sphere_value <=0. (no -m and -M)"<<endl
26 <<" -v valmsk : set value for masked pixels (def=0.)"<<endl;
27}
28
29int main(int narg, char* arg[])
30{
31double vmask=0.,vmin=-1.e30,vmax=1.e30;
32bool tstmin=false,tstmax=false;
33int c;
34while((c = getopt(narg,arg,"hm:M:v:")) != -1) {
35 switch (c) {
36 case 'm' :
37 sscanf(optarg,"%lf",&vmin);
38 tstmin = true;
39 break;
40 case 'M' :
41 sscanf(optarg,"%lf",&vmax);
42 tstmax = true;
43 break;
44 case 'v' :
45 sscanf(optarg,"%lf",&vmask);
46 break;
47 case 'h' :
48 default:
49 usage(); exit(1);
50 }
51}
52
53if(optind+2>=narg) {usage(); exit(1);}
54char * sphval = arg[optind];
55char * sphmsk = arg[optind+1];
56char * sphout = arg[optind+2];
57
58cout<<"Sphere values : "<<sphval<<endl
59 <<"Sphere mask : "<<sphmsk<<endl
60 <<"Sphere out : "<<sphout<<endl
61 <<" ...min("<<tstmin<<") "<<vmin<<" max("<<tstmax<<") "<<vmax<<endl
62 <<" ...mask set value "<<vmask<<endl
63 <<"Condition for masking pixel is : "
64 <<"( Vmsk <= "<<vmin<<" OR Vmsk >= "<<vmax<<" ) bounds are included"<<endl;
65
66// Lecture de la sphere Healpix des valeurs
67SphereHEALPix<r_8> sph;
68{FitsInFile sfits(sphval); sfits >> sph;}
69cout<<"Opening Sphere HEALPix for testing values :"<<endl
70 <<" Type of map : "<<sph.TypeOfMap()<<endl
71 <<" Number of pixels : "<<sph.NbPixels()<<endl
72 <<" Nlat : "<<sph.SizeIndex()<<endl;
73
74// Lecture de la sphere Healpix des masques
75SphereHEALPix<r_8> msph;
76{FitsInFile sfits(sphmsk); sfits >> msph;}
77cout<<"Opening Sphere HEALPix for mask :"<<endl
78 <<" Type of map : "<<msph.TypeOfMap()<<endl
79 <<" Number of pixels : "<<msph.NbPixels()<<endl
80 <<" Nlat : "<<msph.SizeIndex()<<endl;
81if(msph.SizeIndex()!=sph.SizeIndex()) {
82 cout<<"Sphere of values and sphere of mask must have same NLat"<<endl;
83 exit(1);
84}
85
86// Filling Mask Sphere
87cout<<"Testing For Masked Pixels"<<endl;
88uint_4 nmask = 0;
89for(int_4 i=0;i<sph.NbPixels();i++) {
90 r_8 v = msph(i);
91 bool masked=false;
92 if(tstmin && v<=vmin) {sph(i) = vmask; masked = true;}
93 if(tstmax && v>=vmax) {sph(i) = vmask; masked = true;}
94 if(!tstmin && !tstmax && v<=0.)
95 {sph(i) = vmask; masked = true;}
96 if(masked) nmask++;
97}
98cout<<" .... Number of values masked : "<<nmask<<endl;
99cout<<" .... Fraction of values masked : "
100 <<(r_8)nmask/sph.NbPixels()*100.<<" %"<<endl;
101
102// Ecriture de la sphere Healpix sur fits
103{
104string dum = "rm -f "; dum += sphout; system(dum.c_str());
105FitsOutFile sfits(sphout);
106cout<<"Writing Output Masked Sphere Fits file"<<endl;
107sfits<<sph;
108}
109
110exit(0);
111}
Note: See TracBrowser for help on using the repository browser.