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>
|
---|
7 | #include <stdio.h>
|
---|
8 | #include <stdlib.h>
|
---|
9 | #include "skymapinit.h"
|
---|
10 | #include "skymap.h"
|
---|
11 | #include "fitsspherehealpix.h"
|
---|
12 |
|
---|
13 | /*!
|
---|
14 | \ingroup PrgMap
|
---|
15 | \file msksphere.cc
|
---|
16 | \brief \b msksphere: mask a sphere of datas with a mask sphere.
|
---|
17 | \verbatim
|
---|
18 | csh> msksphere -h
|
---|
19 | msksphere [-m min -M max -v valmsk] sphval.fits sphmask.fits sphout.fits
|
---|
20 | sphval.fits : inpout sphere of datas where the pixels have to be masked
|
---|
21 | sphmask.fits : inpout masked sphere used to mask pixels
|
---|
22 | sphout.fits : output masked sphere of datas
|
---|
23 | -m min : min mask_sphere_value for MASKING the sphere pixel
|
---|
24 | -M max : max mask_sphere_value for MASKING the sphere pixel
|
---|
25 | condition for MASKING sphere pixel is (min<=mask_sphere_value<=max)
|
---|
26 | -n : negate the previous condition, condition for MASKING sphere pixel
|
---|
27 | becomes: (mask_sphere_value<minval || maxval<mask_sphere_value)
|
---|
28 | Default (no -m and -M): mask pixel if mask_sphere_value<0.
|
---|
29 | -v valmsk : set sphere value for masked pixels (def=0.)
|
---|
30 | \endverbatim
|
---|
31 | */
|
---|
32 |
|
---|
33 | void usage();
|
---|
34 | void usage()
|
---|
35 | {
|
---|
36 | cout<<"msksphere [-m min -M max -v valmsk]"
|
---|
37 | <<" sphval.fits sphmask.fits sphout.fits"<<endl
|
---|
38 | <<" sphval.fits : inpout sphere of datas where the pixels have to be masked"<<endl
|
---|
39 | <<" sphmask.fits : inpout masked sphere used to mask pixels"<<endl
|
---|
40 | <<" sphout.fits : output masked sphere of datas"<<endl
|
---|
41 | <<" -m min : min mask_sphere_value for MASKING the sphere pixel"<<endl
|
---|
42 | <<" -M max : max mask_sphere_value for MASKING the sphere pixel"<<endl
|
---|
43 | <<" condition for MASKING sphere pixel is (min<=mask_sphere_value<=max)"<<endl
|
---|
44 | <<" -n : negate the previous condition, condition for MASKING sphere pixel"<<endl
|
---|
45 | <<" becomes: (mask_sphere_value<minval || maxval<mask_sphere_value)"<<endl
|
---|
46 | <<" Default (no -m and -M): mask pixel if mask_sphere_value<0."<<endl
|
---|
47 | <<" -v valmsk : set sphere value for masked pixels (def=0.)"<<endl;
|
---|
48 | }
|
---|
49 |
|
---|
50 | int main(int narg, char* arg[])
|
---|
51 | {
|
---|
52 | double vmask=0.,vmin=-1.e30,vmax=1.e30;
|
---|
53 | bool tstmin=false,tstmax=false,negate=false;
|
---|
54 | string dum;
|
---|
55 | int c;
|
---|
56 | while((c = getopt(narg,arg,"hnm:M:v:")) != -1) {
|
---|
57 | switch (c) {
|
---|
58 | case 'n' :
|
---|
59 | negate = true;
|
---|
60 | break;
|
---|
61 | case 'm' :
|
---|
62 | sscanf(optarg,"%lf",&vmin);
|
---|
63 | tstmin = true;
|
---|
64 | break;
|
---|
65 | case 'M' :
|
---|
66 | sscanf(optarg,"%lf",&vmax);
|
---|
67 | tstmax = true;
|
---|
68 | break;
|
---|
69 | case 'v' :
|
---|
70 | sscanf(optarg,"%lf",&vmask);
|
---|
71 | break;
|
---|
72 | case 'h' :
|
---|
73 | default:
|
---|
74 | usage(); exit(1);
|
---|
75 | }
|
---|
76 | }
|
---|
77 |
|
---|
78 | if(optind+2>=narg) {usage(); exit(1);}
|
---|
79 | char * sphval = arg[optind];
|
---|
80 | char * sphmsk = arg[optind+1];
|
---|
81 | char * sphout = arg[optind+2];
|
---|
82 |
|
---|
83 | if(!tstmin && !tstmax) {tstmin=true; vmin=0.; negate=true;}
|
---|
84 |
|
---|
85 | if(negate) dum = ".NOT."; else dum="";
|
---|
86 | cout<<"Sphere values : "<<sphval<<endl
|
---|
87 | <<"Sphere mask : "<<sphmsk<<endl
|
---|
88 | <<"Sphere out : "<<sphout<<endl
|
---|
89 | <<" ...min("<<tstmin<<") "<<vmin<<endl
|
---|
90 | <<" max("<<tstmax<<") "<<vmax<<endl
|
---|
91 | <<" ...mask set value "<<vmask<<endl
|
---|
92 | <<" Condition for masking pixel is :"<<endl
|
---|
93 | <<" "<<dum<<"( "<<vmin<<" <= V <= "<<vmax<<" )"<<endl;
|
---|
94 |
|
---|
95 | // Lecture de la sphere Healpix des valeurs
|
---|
96 | SphereHEALPix<r_8> sph;
|
---|
97 | {FitsInFile sfits(sphval); sfits >> sph;}
|
---|
98 | cout<<"Opening Sphere HEALPix for testing values :"<<endl
|
---|
99 | <<" Type of map : "<<sph.TypeOfMap()<<endl
|
---|
100 | <<" Number of pixels : "<<sph.NbPixels()<<endl
|
---|
101 | <<" Nlat : "<<sph.SizeIndex()<<endl;
|
---|
102 |
|
---|
103 | // Lecture de la sphere Healpix des masques
|
---|
104 | SphereHEALPix<r_8> msph;
|
---|
105 | {FitsInFile sfits(sphmsk); sfits >> msph;}
|
---|
106 | cout<<"Opening Sphere HEALPix for mask :"<<endl
|
---|
107 | <<" Type of map : "<<msph.TypeOfMap()<<endl
|
---|
108 | <<" Number of pixels : "<<msph.NbPixels()<<endl
|
---|
109 | <<" Nlat : "<<msph.SizeIndex()<<endl;
|
---|
110 | if(msph.SizeIndex()!=sph.SizeIndex()) {
|
---|
111 | cout<<"Sphere of values and sphere of mask must have same NLat"<<endl;
|
---|
112 | exit(1);
|
---|
113 | }
|
---|
114 |
|
---|
115 | // Filling Mask Sphere
|
---|
116 | cout<<"Testing For Masked Pixels"<<endl;
|
---|
117 | uint_4 nmask = 0;
|
---|
118 | for(int_4 i=0;i<sph.NbPixels();i++) {
|
---|
119 |
|
---|
120 | bool skp = (tstmin || tstmax) ? negate : false;
|
---|
121 | if((tstmin && msph(i)<vmin) || (tstmax && msph(i)>vmax)) skp = !negate;
|
---|
122 | if(skp) continue; // Do nothing
|
---|
123 |
|
---|
124 | sph(i) = vmask;
|
---|
125 | nmask++;
|
---|
126 | }
|
---|
127 | cout<<" .... Number of values masked : "<<nmask<<endl;
|
---|
128 | cout<<" .... Fraction of values masked : "
|
---|
129 | <<(r_8)nmask/sph.NbPixels()*100.<<" %"<<endl;
|
---|
130 |
|
---|
131 | // Ecriture de la sphere Healpix sur fits
|
---|
132 | {
|
---|
133 | dum = "rm -f "; dum += sphout; system(dum.c_str());
|
---|
134 | FitsOutFile sfits(sphout, FitsFile::clear);
|
---|
135 | cout<<"Writing Output Masked Sphere Fits file"<<endl;
|
---|
136 | sfits<<sph;
|
---|
137 | }
|
---|
138 |
|
---|
139 | exit(0);
|
---|
140 | }
|
---|